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' Licensed to the Apache Software Foundation (ASF) under one 9' or more contributor license agreements. See the NOTICE file 10' distributed with this work for additional information 11' regarding copyright ownership. The ASF licenses this file 12' to you under the Apache License, Version 2.0 (the 13' "License"); you may not use this file except in compliance 14' with the License. You may obtain a copy of the License at 15' 16' http://www.apache.org/licenses/LICENSE-2.0 17' 18' Unless required by applicable law or agreed to in writing, 19' software distributed under the License is distributed on an 20' "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 21' KIND, either express or implied. See the License for the 22' specific language governing permissions and limitations 23' under the License. 24' 25'************************************************************************* 26 27 28 29 30 31 32Dim iCB1_changedContents As Integer 33Dim iCB2_changedContents As Integer 34Dim bListenerWasCalled As Boolean 35 36 37Sub RunTest() 38 39'************************************************************************* 40' INTERFACE: 41' com.sun.star.datatransfer.clipboard.XClipboardNotifier 42'************************************************************************* 43On Error Goto ErrHndl 44 Dim bOK As Boolean 45 Dim oListener1 As Object 46 Dim oListener2 As Object 47 Dim iTime As Integer 48 49 iCB1_changedContents = 0 : iCB2_changedContents = 0 50 51 oListener1 = createUNOListener("CB1_", "com.sun.star.datatransfer.clipboard.XClipboardListener") 52 oListener2 = createUNOListener("CB2_", "com.sun.star.datatransfer.clipboard.XClipboardListener") 53 54 Test.StartMethod("addClipboardListener()") 55 bOK = true 56 Out.Log("Adding two listeners...") 57 oObj.addClipboardListener(oListener1) 58 oObj.addClipboardListener(oListener2) 59 if (bPerformInteractiveTests) then 60 bListenerWasCalled = false 61 MsgBox("After closing this window try to copy something into clipboard... You have aprox. 10 sec. for this...") 62 iTime = 0 63 while ((NOT bListenerWasCalled) AND (iTime < 10)) 64 wait 1000 65 iTime = iTime + 1 66 wend 67 if (NOT bListenerWasCalled) then 68 Out.Log("No listener was called in 10 sec!") 69 MsgBox("No listener was called in 10 sec!") 70 bOK = false 71 else 72 MsgBox("Listener was called!") 73 bOK = bOK AND (iCB1_changedContents = 1) AND (iCB2_changedContents = 1) 74 end if 75 else 76 Out.Log("This is an interactive test. To test this use parameter PERFORMINTERACTIVETESTS in ini file.") 77 end if 78 Test.MethodTested("addClipboardListener()", bOK) 79 80 Test.StartMethod("removeClipboardListener()") 81 bOK = true 82 iCB1_changedContents = 0 : iCB2_changedContents = 0 83 84 Out.Log("Removing second listener...") 85 oObj.removeClipboardListener(oListener2) 86 if (bPerformInteractiveTests) then 87 bListenerWasCalled = false 88 MsgBox("Repeat again: After closing this window try to copy something into clipboard... You have aprox. 10 sec. for this...") 89 iTime = 0 90 while ((NOT bListenerWasCalled) AND (iTime < 10)) 91 wait 1000 92 iTime = iTime + 1 93 wend 94 if (NOT bListenerWasCalled) then 95 Out.Log("No listener was called in 10 sec!") 96 MsgBox("No listener was called in 10 sec!") 97 bOK = false 98 else 99 MsgBox("Listener was called!") 100 bOK = bOK AND (iCB1_changedContents = 1) AND (iCB2_changedContents = 0) 101 end if 102 else 103 Out.Log("This is an interactive test. To test this use parameter PERFORMINTERACTIVETESTS in ini file.") 104 end if 105 Test.MethodTested("removeClipboardListener()", bOK) 106 107 Out.Log("Removing first listener...") 108 oObj.removeClipboardListener(oListener1) 109 110Exit Sub 111ErrHndl: 112 Test.Exception() 113 bOK = false 114 resume next 115End Sub 116 117Sub CB1_changedContents(event As Object) 118 iCB1_changedContents = iCB1_changedContents + 1 119 Out.Log("CB1_changedContents() was called!") 120 bListenerWasCalled = true 121End Sub 122 123Sub CB2_changedContents(event As Object) 124 iCB2_changedContents = iCB2_changedContents + 1 125 Out.Log("CB2_changedContents() was called!") 126 bListenerWasCalled = true 127End Sub 128</script:module> 129