tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / wizards / source / sfunittests / SF_Register.xba
blob360abba50381e56fa263e5e64942e15af4878929
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="SF_Register" script:language="StarBasic" script:moduleType="normal">REM =======================================================================================================================
4 REM === The ScriptForge library and its associated libraries are part of the LibreOffice project. ===
5 REM === The SFUnitTests library is one of the associated libraries. ===
6 REM === Full documentation is available on https://help.libreoffice.org/ ===
7 REM =======================================================================================================================
9 Option Compatible
10 Option Explicit
12 &apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;
13 &apos;&apos;&apos; SF_Register
14 &apos;&apos;&apos; ===========
15 &apos;&apos;&apos; The ScriptForge framework includes
16 &apos;&apos;&apos; the master ScriptForge library
17 &apos;&apos;&apos; a number of &quot;associated&quot; libraries SF*
18 &apos;&apos;&apos; any user/contributor extension wanting to fit into the framework
19 &apos;&apos;&apos;
20 &apos;&apos;&apos; The main methods in this module allow the current library to cling to ScriptForge
21 &apos;&apos;&apos; - RegisterScriptServices
22 &apos;&apos;&apos; Register the list of services implemented by the current library
23 &apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;
25 REM ================================================================== EXCEPTIONS
27 Private Const UNITTESTLIBRARYERROR = &quot;UNITTESTLIBRARYERROR&quot;
29 REM ============================================================== PUBLIC METHODS
31 REM -----------------------------------------------------------------------------
32 Public Sub RegisterScriptServices() As Variant
33 &apos;&apos;&apos; Register into ScriptForge the list of the services implemented by the current library
34 &apos;&apos;&apos; Each library pertaining to the framework must implement its own version of this method
35 &apos;&apos;&apos;
36 &apos;&apos;&apos; It consists in successive calls to the RegisterService() and RegisterEventManager() methods
37 &apos;&apos;&apos; with 2 arguments:
38 &apos;&apos;&apos; ServiceName: the name of the service as a case-insensitive string
39 &apos;&apos;&apos; ServiceReference: the reference as an object
40 &apos;&apos;&apos; If the reference refers to a module, then return the module as an object:
41 &apos;&apos;&apos; GlobalScope.Library.Module
42 &apos;&apos;&apos; If the reference is a class instance, then return a string referring to the method
43 &apos;&apos;&apos; containing the New statement creating the instance
44 &apos;&apos;&apos; &quot;libraryname.modulename.function&quot;
46 With GlobalScope.ScriptForge.SF_Services
47 .RegisterService(&quot;UnitTest&quot;, &quot;SFUnitTests.SF_Register._NewUnitTest&quot;) &apos; Reference to the function initializing the service
48 End With
50 End Sub &apos; SFUnitTests.SF_Register.RegisterScriptServices
52 REM =========================================================== PRIVATE FUNCTIONS
54 REM -----------------------------------------------------------------------------
55 Public Function _NewUnitTest(Optional ByVal pvArgs As Variant) As Object
56 &apos;&apos;&apos; Create a new instance of the SF_UnitTest class
57 &apos; Args:
58 &apos;&apos;&apos; Location: if empty, the location of the library is presumed to be in GlobalScope.BasicLibraries
59 &apos;&apos;&apos; Alternatives are:
60 &apos;&apos;&apos; - the name of a document: see SF_UI.WindowName
61 &apos;&apos;&apos; - an explicit SFDocuments.Document instance
62 &apos;&apos;&apos; - the component containing the library, typically ThisComponent
63 &apos;&apos;&apos; LibraryName: the name of the library containing the test code
64 &apos;&apos;&apos; Returns:
65 &apos;&apos;&apos; The instance or Nothing
66 &apos;&apos;&apos; Exceptions:
67 &apos;&apos;&apos; UNITTESTLIBRARYNOTFOUND The library could not be found
69 Dim oUnitTest As Object &apos; Return value
70 Dim vLocation As Variant &apos; Alias of pvArgs(0)
71 Dim vLibraryName As Variant &apos; alias of pvArgs(1)
72 Dim vLocations As Variant &apos; &quot;user&quot;, &quot;share&quot; or document
73 Dim sLocation As String &apos; A single location
74 Dim sTargetLocation As String &apos; &quot;user&quot; or the document name
75 Dim vLanguages As Variant &apos; &quot;Basic&quot;, &quot;Python&quot;, ... programming languages
76 Dim sLanguage As String &apos; A single programming language
77 Dim vLibraries As Variant &apos; Library names
78 Dim sLibrary As String &apos; A single library
79 Dim vModules As Variant &apos; Module names
80 Dim sModule As String &apos; A single module
81 Dim vModuleNames As Variant &apos; Module names
82 Dim oRoot As Object &apos; com.sun.star.script.browse.BrowseNodeFactory
83 Dim iLibrary As Integer &apos; The index of the target location in vLibraries
85 Dim FSO As Object &apos; SF_FileSystem
86 Dim i As Integer, j As Integer, k As Integer, l As Integer
88 Const cstService = &quot;SFUnitTests.UnitTest&quot;
90 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
92 Check:
93 If IsMissing(pvArgs) Or IsEmpty(pvArgs) Then pvArgs = Array()
94 If UBound(pvArgs) &gt;= 0 Then vLocation = pvArgs(0) Else vLocation = &quot;&quot;
95 If IsEmpty(vLocation) Then vLocation = &quot;&quot;
96 If UBound(pvArgs) &gt;= 1 Then vLibraryName = pvArgs(1) Else vLibraryName = &quot;&quot;
97 If IsEmpty(vLibraryName) Then vLibraryName = &quot;&quot;
98 If Not ScriptForge.SF_Utils._Validate(vLocation, &quot;Location&quot;, Array(V_STRING, ScriptForge.V_OBJECT)) Then GoTo Finally
99 If Not ScriptForge.SF_Utils._Validate(vLibraryName, &quot;LibraryName&quot;, V_STRING) Then GoTo Finally
101 Set oUnitTest = Nothing
102 Set FSO = CreateScriptService(&quot;ScriptForge.FileSystem&quot;)
104 &apos; Determine the library container hosting the test code
106 &apos; Browsing starts from root element
107 Set oRoot = SF_Utils._GetUNOService(&quot;BrowseNodeFactory&quot;).createView(com.sun.star.script.browse.BrowseNodeFactoryViewTypes.MACROORGANIZER)
109 If Len(vLibraryName) &gt; 0 Then
111 &apos; Determine the target location, as a string. The location is either:
112 &apos; - the last component of a document&apos;s file name
113 &apos; - &quot;user&quot; = My Macros &amp; Dialogs
114 If VarType(vLocation) = ScriptForge.V_OBJECT Then
115 sTargetLocation = FSO.GetName(vLocation.URL)
116 ElseIf Len(vLocation) = 0 Then
117 sTargetLocation = &quot;user&quot; &apos; Testing code is presumed NOT in &quot;share&quot;
118 Else
119 sTargetLocation = FSO.GetName(vLocation)
120 End If
122 &apos; Exploration is done via tree nodes
123 iLibrary = -1
124 If Not IsNull(oRoot) Then
125 If oRoot.hasChildNodes() Then
126 vLocations = oRoot.getChildNodes()
127 For i = 0 To UBound(vLocations)
128 sLocation = vLocations(i).getName()
129 If sLocation = sTargetLocation Then
130 If vLocations(i).hasChildNodes() Then
131 vLanguages = vLocations(i).getChildNodes()
132 For j = 0 To UBound(vLanguages)
133 sLanguage = vLanguages(j).getName()
134 &apos; Consider Basic libraries only
135 If sLanguage = &quot;Basic&quot; Then
136 If vLanguages(j).hasChildNodes() Then
137 vLibraries = vLanguages(j).getChildNodes()
138 For k = 0 To UBound(vLibraries)
139 sLibrary = vLibraries(k).getName()
140 &apos; Consider the targeted library only
141 If sLibrary = vLibraryName Then
142 iLibrary = k
143 If vLibraries(k).hasChildNodes() Then
144 vModules = vLibraries(k).getChildNodes()
145 vModuleNames = Array()
146 For l = 0 To UBound(vModules)
147 sModule = vModules(l).getName()
148 vModuleNames = ScriptForge.SF_Array.Append(vModuleNames, sModule)
149 Next l
150 End If
151 Exit For
152 End If
153 Next k
154 End If
155 End If
156 If iLibrary &gt;= 0 Then Exit For
157 Next j
158 End If
159 End If
160 If iLibrary &gt;= 0 Then Exit For
161 Next i
162 End If
163 End If
164 If iLibrary &lt; 0 Then GoTo CatchLibrary
166 End If
168 Try:
169 &apos; Create the unittest Basic object and initialize its attributes
170 Set oUnitTest = New SF_UnitTest
171 With oUnitTest
172 Set .[Me] = oUnitTest
173 If Len(vLibraryName) &gt; 0 Then
174 .LibrariesContainer = sTargetLocation
175 .Scope = Iif(sTargetLocation = &quot;user&quot;, &quot;application&quot;, &quot;document&quot;)
176 .Libraries = vLibraries
177 .LibraryName = sLibrary
178 .LibraryIndex = iLibrary
179 .Modules = vModules
180 .ModuleNames = vModuleNames
181 ._ExecutionMode = .FULLMODE
182 ._WhenAssertionFails = .FAILSTOPSUITE
183 &apos; Launch the test timer
184 .TestTimer = CreateScriptService(&quot;ScriptForge.Timer&quot;, True)
185 Else
186 ._ExecutionMode = .SIMPLEMODE
187 ._WhenAssertionFails = .FAILIMMEDIATESTOP
188 End If
189 End With
191 Finally:
192 Set _NewUnitTest = oUnitTest
193 Exit Function
194 Catch:
195 GoTo Finally
196 CatchLibrary:
197 ScriptForge.SF_Exception.RaiseFatal(UNITTESTLIBRARYERROR, vLibraryName)
198 GoTo Finally
199 End Function &apos; SFUnitTests.SF_Register._NewUnitTest
201 REM ============================================== END OF SFUNITTESTS.SF_REGISTER
202 </script:module>