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="frame_XDispatchRecorder" 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' Be sure that all variables are dimensioned:
38option explicit
39
40'*************************************************************************
41' This Interface/Service test depends on the following GLOBAL variables,
42' which must be specified in the object creation:
43
44' - Global dispRecFrame As Object
45
46'*************************************************************************
47
48
49
50
51
52Sub RunTest()
53
54'*************************************************************************
55' INTERFACE:
56' com.sun.star.frame.XDispatchRecorder
57'*************************************************************************
58On Error Goto ErrHndl
59    Dim bOK As Boolean
60
61    Test.StartMethod("startRecording()")
62    bOK = true
63    oObj.startRecording(dispRecFrame)
64    Test.MethodTested("startRecording()", bOK)
65
66    Test.StartMethod("endRecording()")
67    bOK = true
68    Dim dispURL As com.sun.star.util.URL
69    dispURL = parseURL(".uno:InsertText")
70    Dim dispArgs(0) As new com.sun.star.beans.PropertyValue
71    dispArgs(0).Name = "Text"
72    dispArgs(0).Value = "XDispatchRecorder.endRecording()"
73    Out.log("Dispatching event for frame ...")
74    Dim disp As Object
75    disp = dispRecFrame.queryDispatch(dispURL, "", 0)
76    disp.dispatch(dispURL, dispArgs())
77    wait(2000)
78    Out.log("Ending record ...")
79    oObj.endRecording()
80    Out.log("Getting macro ... :")
81    Dim macro As String
82    macro = oObj.getRecordedMacro()
83    Out.log("'" + macro + "'")
84    if (len(macro) &lt;&gt; 0) then
85        bOK = instr(macro, dispURL.Complete) &gt; -1 and _
86              instr(macro, dispArgs(0).Value) &gt; -1
87        if (Not bOK) then
88            Out.log("Dispatch URL '" + dispURL.Complete _
89            + "' or its argument '" + dispArgs(0).Value _
90            + "' was not found in macro returned - FAILED")
91        end if
92    else
93        bOK = false
94    end if
95    Test.MethodTested("endRecording()", bOK)
96
97    Test.StartMethod("recordDispatch()")
98    bOK = true
99    Out.log("Recording dispatch ...")
100    oObj.recordDispatch(dispURL, dispArgs())
101    Out.log("Getting macro ... :")
102    macro = oObj.getRecordedMacro()
103    Out.log("'" + macro + "'")
104    if (len(macro) &lt;&gt; 0) then
105        bOK = instr(macro, dispURL.Complete) &gt; -1 and _
106              instr(macro, dispArgs(0).Value) &gt; -1
107        if (Not bOK) then
108            Out.log("Dispatch URL '" + dispURL.Complete _
109            + "' or its argument '" + dispArgs(0).Value _
110            + "' was not found in macro returned - FAILED")
111        end if
112    else
113        bOK = false
114    end if
115    Test.MethodTested("recordDispatch()", bOK)
116
117    Test.StartMethod("recordDispatchAsComment()")
118    bOK = true
119    Out.log("Recording dispatch ...")
120    oObj.recordDispatchAsComment(dispURL, dispArgs())
121    Out.log("Getting macro ... :")
122    macro = oObj.getRecordedMacro()
123    Out.log("'" + macro + "'")
124    if (len(macro) &lt;&gt; 0) then
125        bOK = instr(macro, dispURL.Complete) &gt; -1 and _
126              instr(macro, dispArgs(0).Value) &gt; -1
127        if (Not bOK) then
128            Out.log("Dispatch URL '" + dispURL.Complete _
129            + "' or its argument '" + dispArgs(0).Value _
130            + "' was not found in macro returned - FAILED")
131        end if
132    else
133        bOK = false
134    end if
135    Test.MethodTested("recordDispatchAsComment()", bOK)
136
137    Test.StartMethod("getRecordedMacro()")
138    bOK = true
139    Test.MethodTested("getRecordedMacro()", bOK)
140Exit Sub
141ErrHndl:
142    Test.Exception()
143    bOK = false
144    resume next
145End Sub
146
147Function parseURL(complURL As String) As com.sun.star.util.URL
148    Dim url As new com.sun.star.util.URL
149    url.Complete = complURL
150    Dim urlTrans As Object
151    urlTrans = createUnoService("com.sun.star.util.URLTransformer")
152    urlTrans.parseStrict(url)
153    parseURL = url
154End Function
155</script:module>
156