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="registry_XImplementationRegistration" 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' Be sure that all variables are dimensioned:
32option explicit
33
34
35
36Sub RunTest()
37
38'*************************************************************************
39' INTERFACE:
40' com.sun.star.registry.XImplementationRegistration
41'*************************************************************************
42On Error Goto ErrHndl
43    Dim bOK As Boolean
44    Dim aImplementationLoader As String
45    Dim aImplementations As Variant
46    Dim aMissingServices As Variant
47    Dim aLocation As String
48    Dim i As Integer
49    Dim k As Integer
50    Dim xReg As Object
51    Dim regKey As Object
52    Dim keyNames As Variant
53    Dim bNeedTest As Boolean
54
55    xReg = createUNOService("com.sun.star.registry.SimpleRegistry")
56    xReg.Open(utils.Path2URL(cTestDocsDir &amp; "XImpReg.reg"), false, true)
57    aImplementationLoader = "com.sun.star.loader.Java2"
58    aLocation = utils.Path2URL(cTestDocsDir &amp; "qadevlibs/MyPersistObjectImpl.jar")
59
60    Test.StartMethod("getImplementations()")
61    bOK = true
62    aImplementations = oObj.getImplementations(aImplementationLoader, aLocation)
63    bOK = bOK AND i &gt;= 0
64    for i = 0 to ubound(aImplementations)
65        Out.Log "" &amp; i + 1 &amp; ") " &amp; aImplementations(i)
66    next i
67    Test.MethodTested("getImplementations()", bOK)
68
69    Test.StartMethod("registerImplementation()")
70    Out.Log("Registering implementation from " &amp; aLocation)
71    bOK = true
72    oObj.registerImplementation(aImplementationLoader, aLocation, xReg)
73
74    bOK = bOK AND xReg.isValid()
75
76    regKey = xReg.getRootKey.openKey("IMPLEMENTATIONS")
77    keyNames = regKey.getKeyNames()
78    Out.Log("In registry found " &amp; ubound(keyNames) + 1 &amp; " implementations.")
79    Dim aFlags(ubound(aImplementations())) As Boolean
80    for i = 0 to ubound(aFlags())
81        aFlags(i) = false
82    next i
83
84    for i = 0 to ubound(keyNames())
85        Out.Log("Found key: " &amp; keyNames(i))
86        for k = 0 to ubound(aImplementations)
87            if (inStr(1, keyNames(i), aImplementations(k)) &gt; 0 ) then
88                aFlags(k) = true
89            end if
90        next k
91    next i
92
93    for i = 0 to ubound(aFlags())
94        if (NOT aFlags(i)) then
95            Out.Log("Can't find information about " &amp; aImplementations(i) &amp; " in regestry")
96            bOK = false
97        end if
98    next i
99
100    Test.MethodTested("registerImplementation()", bOK)
101
102    Test.StartMethod("checkInstantiation()")
103    bOK = true
104    Out.Log("Looking for missing services to create " &amp; aImplementations(0))
105    aMissingServices = oObj.checkInstantiation(aImplementations(0))
106    Out.Log("" &amp; ubound(aMissingServices) + 1 &amp; " missing services were found")
107    for i = 0 to ubound(aMissingServices)
108        Out.Log "" &amp; i &amp; ") " &amp; aMissingServices(i)
109    next i
110    Test.MethodTested("checkInstantiation()", bOK)
111
112    Test.StartMethod("revokeImplementation()")
113    bOK = true
114    bNeedTest = false
115
116    oObj.revokeImplementation(aLocation, xReg)
117
118    bOK = bOK AND xReg.isValid()
119    regKey = xReg.getRootKey
120    keyNames = regKey.getKeyNames()
121    for i = 0 to ubound(keyNames())
122        if (inStr(1, keyNames(i), "IMPLEMENTATIONS") &gt; 0) then
123            bNeedTest = true
124        end if
125    next i
126    if (NOT bNeedTest) then
127        Out.Log("No implementation was found.")
128    end if
129
130    if (bOK AND bNeedTest) then
131        regKey = xReg.getRootKey.openKey("IMPLEMENTATIONS")
132        Out.Log("In registry found " &amp; ubound(keyNames) + 1 &amp; " implementations.")
133
134        for i = 0 to ubound(aFlags())
135            aFlags(i) = false
136        next i
137
138        for i = 0 to ubound(keyNames())
139            Out.Log("Found key: " &amp; keyNames(i))
140            for k = 0 to ubound(aImplementations)
141                if (inStr(1, keyNames(i), aImplementations(k)) &gt; 0 ) then
142                    aFlags(k) = true
143                end if
144            next k
145        next i
146
147        for i = 0 to ubound(aFlags())
148            if (aFlags(i)) then
149                Out.Log("Information about " &amp; aImplementations(i) &amp; " is still in regestry")
150                bOK = false
151            end if
152        next i
153    end if
154    Test.MethodTested("revokeImplementation()", bOK)
155
156    xReg.Close()
157Exit Sub
158ErrHndl:
159    Test.Exception()
160    bOK = false
161    resume next
162End Sub
163</script:module>
164