1<?xml version="1.0" encoding="UTF-8"?> 2<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd"> 3<script:module xmlns:script="http://openoffice.org/2000/script" script:name="datatransfer_clipboard_XClipboardNotifier" script:language="StarBasic"> 4 5 6'************************************************************************* 7' 8' DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 9' 10' Copyright 2000, 2010 Oracle and/or its affiliates. 11' 12' OpenOffice.org - a multi-platform office productivity suite 13' 14' This file is part of OpenOffice.org. 15' 16' OpenOffice.org is free software: you can redistribute it and/or modify 17' it under the terms of the GNU Lesser General Public License version 3 18' only, as published by the Free Software Foundation. 19' 20' OpenOffice.org is distributed in the hope that it will be useful, 21' but WITHOUT ANY WARRANTY; without even the implied warranty of 22' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 23' GNU Lesser General Public License version 3 for more details 24' (a copy is included in the LICENSE file that accompanied this code). 25' 26' You should have received a copy of the GNU Lesser General Public License 27' version 3 along with OpenOffice.org. If not, see 28' <http://www.openoffice.org/license.html> 29' for a copy of the LGPLv3 License. 30' 31'************************************************************************* 32***** 33'************************************************************************* 34 35 36 37 38Dim iCB1_changedContents As Integer 39Dim iCB2_changedContents As Integer 40Dim bListenerWasCalled As Boolean 41 42 43Sub RunTest() 44 45'************************************************************************* 46' INTERFACE: 47' com.sun.star.datatransfer.clipboard.XClipboardNotifier 48'************************************************************************* 49On Error Goto ErrHndl 50 Dim bOK As Boolean 51 Dim oListener1 As Object 52 Dim oListener2 As Object 53 Dim iTime As Integer 54 55 iCB1_changedContents = 0 : iCB2_changedContents = 0 56 57 oListener1 = createUNOListener("CB1_", "com.sun.star.datatransfer.clipboard.XClipboardListener") 58 oListener2 = createUNOListener("CB2_", "com.sun.star.datatransfer.clipboard.XClipboardListener") 59 60 Test.StartMethod("addClipboardListener()") 61 bOK = true 62 Out.Log("Adding two listeners...") 63 oObj.addClipboardListener(oListener1) 64 oObj.addClipboardListener(oListener2) 65 if (bPerformInteractiveTests) then 66 bListenerWasCalled = false 67 MsgBox("After closing this window try to copy something into clipboard... You have aprox. 10 sec. for this...") 68 iTime = 0 69 while ((NOT bListenerWasCalled) AND (iTime < 10)) 70 wait 1000 71 iTime = iTime + 1 72 wend 73 if (NOT bListenerWasCalled) then 74 Out.Log("No listener was called in 10 sec!") 75 MsgBox("No listener was called in 10 sec!") 76 bOK = false 77 else 78 MsgBox("Listener was called!") 79 bOK = bOK AND (iCB1_changedContents = 1) AND (iCB2_changedContents = 1) 80 end if 81 else 82 Out.Log("This is an interactive test. To test this use parameter PERFORMINTERACTIVETESTS in ini file.") 83 end if 84 Test.MethodTested("addClipboardListener()", bOK) 85 86 Test.StartMethod("removeClipboardListener()") 87 bOK = true 88 iCB1_changedContents = 0 : iCB2_changedContents = 0 89 90 Out.Log("Removing second listener...") 91 oObj.removeClipboardListener(oListener2) 92 if (bPerformInteractiveTests) then 93 bListenerWasCalled = false 94 MsgBox("Repeat again: After closing this window try to copy something into clipboard... You have aprox. 10 sec. for this...") 95 iTime = 0 96 while ((NOT bListenerWasCalled) AND (iTime < 10)) 97 wait 1000 98 iTime = iTime + 1 99 wend 100 if (NOT bListenerWasCalled) then 101 Out.Log("No listener was called in 10 sec!") 102 MsgBox("No listener was called in 10 sec!") 103 bOK = false 104 else 105 MsgBox("Listener was called!") 106 bOK = bOK AND (iCB1_changedContents = 1) AND (iCB2_changedContents = 0) 107 end if 108 else 109 Out.Log("This is an interactive test. To test this use parameter PERFORMINTERACTIVETESTS in ini file.") 110 end if 111 Test.MethodTested("removeClipboardListener()", bOK) 112 113 Out.Log("Removing first listener...") 114 oObj.removeClipboardListener(oListener1) 115 116Exit Sub 117ErrHndl: 118 Test.Exception() 119 bOK = false 120 resume next 121End Sub 122 123Sub CB1_changedContents(event As Object) 124 iCB1_changedContents = iCB1_changedContents + 1 125 Out.Log("CB1_changedContents() was called!") 126 bListenerWasCalled = true 127End Sub 128 129Sub CB2_changedContents(event As Object) 130 iCB2_changedContents = iCB2_changedContents + 1 131 Out.Log("CB2_changedContents() was called!") 132 bListenerWasCalled = true 133End Sub 134</script:module> 135