1*b1cdbd2cSJim Jagielski<?xml version="1.0" encoding="UTF-8"?>
2*b1cdbd2cSJim Jagielski<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
3*b1cdbd2cSJim Jagielski<script:module xmlns:script="http://openoffice.org/2000/script" script:name="registry_XImplementationRegistration" script:language="StarBasic">
4*b1cdbd2cSJim Jagielski
5*b1cdbd2cSJim Jagielski
6*b1cdbd2cSJim Jagielski'*************************************************************************
7*b1cdbd2cSJim Jagielski'
8*b1cdbd2cSJim Jagielski'  Licensed to the Apache Software Foundation (ASF) under one
9*b1cdbd2cSJim Jagielski'  or more contributor license agreements.  See the NOTICE file
10*b1cdbd2cSJim Jagielski'  distributed with this work for additional information
11*b1cdbd2cSJim Jagielski'  regarding copyright ownership.  The ASF licenses this file
12*b1cdbd2cSJim Jagielski'  to you under the Apache License, Version 2.0 (the
13*b1cdbd2cSJim Jagielski'  "License"); you may not use this file except in compliance
14*b1cdbd2cSJim Jagielski'  with the License.  You may obtain a copy of the License at
15*b1cdbd2cSJim Jagielski'
16*b1cdbd2cSJim Jagielski'    http://www.apache.org/licenses/LICENSE-2.0
17*b1cdbd2cSJim Jagielski'
18*b1cdbd2cSJim Jagielski'  Unless required by applicable law or agreed to in writing,
19*b1cdbd2cSJim Jagielski'  software distributed under the License is distributed on an
20*b1cdbd2cSJim Jagielski'  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21*b1cdbd2cSJim Jagielski'  KIND, either express or implied.  See the License for the
22*b1cdbd2cSJim Jagielski'  specific language governing permissions and limitations
23*b1cdbd2cSJim Jagielski'  under the License.
24*b1cdbd2cSJim Jagielski'
25*b1cdbd2cSJim Jagielski'*************************************************************************
26*b1cdbd2cSJim Jagielski
27*b1cdbd2cSJim Jagielski
28*b1cdbd2cSJim Jagielski
29*b1cdbd2cSJim Jagielski
30*b1cdbd2cSJim Jagielski
31*b1cdbd2cSJim Jagielski' Be sure that all variables are dimensioned:
32*b1cdbd2cSJim Jagielskioption explicit
33*b1cdbd2cSJim Jagielski
34*b1cdbd2cSJim Jagielski
35*b1cdbd2cSJim Jagielski
36*b1cdbd2cSJim JagielskiSub RunTest()
37*b1cdbd2cSJim Jagielski
38*b1cdbd2cSJim Jagielski'*************************************************************************
39*b1cdbd2cSJim Jagielski' INTERFACE:
40*b1cdbd2cSJim Jagielski' com.sun.star.registry.XImplementationRegistration
41*b1cdbd2cSJim Jagielski'*************************************************************************
42*b1cdbd2cSJim JagielskiOn Error Goto ErrHndl
43*b1cdbd2cSJim Jagielski    Dim bOK As Boolean
44*b1cdbd2cSJim Jagielski    Dim aImplementationLoader As String
45*b1cdbd2cSJim Jagielski    Dim aImplementations As Variant
46*b1cdbd2cSJim Jagielski    Dim aMissingServices As Variant
47*b1cdbd2cSJim Jagielski    Dim aLocation As String
48*b1cdbd2cSJim Jagielski    Dim i As Integer
49*b1cdbd2cSJim Jagielski    Dim k As Integer
50*b1cdbd2cSJim Jagielski    Dim xReg As Object
51*b1cdbd2cSJim Jagielski    Dim regKey As Object
52*b1cdbd2cSJim Jagielski    Dim keyNames As Variant
53*b1cdbd2cSJim Jagielski    Dim bNeedTest As Boolean
54*b1cdbd2cSJim Jagielski
55*b1cdbd2cSJim Jagielski    xReg = createUNOService("com.sun.star.registry.SimpleRegistry")
56*b1cdbd2cSJim Jagielski    xReg.Open(utils.Path2URL(cTestDocsDir &amp; "XImpReg.reg"), false, true)
57*b1cdbd2cSJim Jagielski    aImplementationLoader = "com.sun.star.loader.Java2"
58*b1cdbd2cSJim Jagielski    aLocation = utils.Path2URL(cTestDocsDir &amp; "qadevlibs/MyPersistObjectImpl.jar")
59*b1cdbd2cSJim Jagielski
60*b1cdbd2cSJim Jagielski    Test.StartMethod("getImplementations()")
61*b1cdbd2cSJim Jagielski    bOK = true
62*b1cdbd2cSJim Jagielski    aImplementations = oObj.getImplementations(aImplementationLoader, aLocation)
63*b1cdbd2cSJim Jagielski    bOK = bOK AND i &gt;= 0
64*b1cdbd2cSJim Jagielski    for i = 0 to ubound(aImplementations)
65*b1cdbd2cSJim Jagielski        Out.Log "" &amp; i + 1 &amp; ") " &amp; aImplementations(i)
66*b1cdbd2cSJim Jagielski    next i
67*b1cdbd2cSJim Jagielski    Test.MethodTested("getImplementations()", bOK)
68*b1cdbd2cSJim Jagielski
69*b1cdbd2cSJim Jagielski    Test.StartMethod("registerImplementation()")
70*b1cdbd2cSJim Jagielski    Out.Log("Registering implementation from " &amp; aLocation)
71*b1cdbd2cSJim Jagielski    bOK = true
72*b1cdbd2cSJim Jagielski    oObj.registerImplementation(aImplementationLoader, aLocation, xReg)
73*b1cdbd2cSJim Jagielski
74*b1cdbd2cSJim Jagielski    bOK = bOK AND xReg.isValid()
75*b1cdbd2cSJim Jagielski
76*b1cdbd2cSJim Jagielski    regKey = xReg.getRootKey.openKey("IMPLEMENTATIONS")
77*b1cdbd2cSJim Jagielski    keyNames = regKey.getKeyNames()
78*b1cdbd2cSJim Jagielski    Out.Log("In registry found " &amp; ubound(keyNames) + 1 &amp; " implementations.")
79*b1cdbd2cSJim Jagielski    Dim aFlags(ubound(aImplementations())) As Boolean
80*b1cdbd2cSJim Jagielski    for i = 0 to ubound(aFlags())
81*b1cdbd2cSJim Jagielski        aFlags(i) = false
82*b1cdbd2cSJim Jagielski    next i
83*b1cdbd2cSJim Jagielski
84*b1cdbd2cSJim Jagielski    for i = 0 to ubound(keyNames())
85*b1cdbd2cSJim Jagielski        Out.Log("Found key: " &amp; keyNames(i))
86*b1cdbd2cSJim Jagielski        for k = 0 to ubound(aImplementations)
87*b1cdbd2cSJim Jagielski            if (inStr(1, keyNames(i), aImplementations(k)) &gt; 0 ) then
88*b1cdbd2cSJim Jagielski                aFlags(k) = true
89*b1cdbd2cSJim Jagielski            end if
90*b1cdbd2cSJim Jagielski        next k
91*b1cdbd2cSJim Jagielski    next i
92*b1cdbd2cSJim Jagielski
93*b1cdbd2cSJim Jagielski    for i = 0 to ubound(aFlags())
94*b1cdbd2cSJim Jagielski        if (NOT aFlags(i)) then
95*b1cdbd2cSJim Jagielski            Out.Log("Can't find information about " &amp; aImplementations(i) &amp; " in regestry")
96*b1cdbd2cSJim Jagielski            bOK = false
97*b1cdbd2cSJim Jagielski        end if
98*b1cdbd2cSJim Jagielski    next i
99*b1cdbd2cSJim Jagielski
100*b1cdbd2cSJim Jagielski    Test.MethodTested("registerImplementation()", bOK)
101*b1cdbd2cSJim Jagielski
102*b1cdbd2cSJim Jagielski    Test.StartMethod("checkInstantiation()")
103*b1cdbd2cSJim Jagielski    bOK = true
104*b1cdbd2cSJim Jagielski    Out.Log("Looking for missing services to create " &amp; aImplementations(0))
105*b1cdbd2cSJim Jagielski    aMissingServices = oObj.checkInstantiation(aImplementations(0))
106*b1cdbd2cSJim Jagielski    Out.Log("" &amp; ubound(aMissingServices) + 1 &amp; " missing services were found")
107*b1cdbd2cSJim Jagielski    for i = 0 to ubound(aMissingServices)
108*b1cdbd2cSJim Jagielski        Out.Log "" &amp; i &amp; ") " &amp; aMissingServices(i)
109*b1cdbd2cSJim Jagielski    next i
110*b1cdbd2cSJim Jagielski    Test.MethodTested("checkInstantiation()", bOK)
111*b1cdbd2cSJim Jagielski
112*b1cdbd2cSJim Jagielski    Test.StartMethod("revokeImplementation()")
113*b1cdbd2cSJim Jagielski    bOK = true
114*b1cdbd2cSJim Jagielski    bNeedTest = false
115*b1cdbd2cSJim Jagielski
116*b1cdbd2cSJim Jagielski    oObj.revokeImplementation(aLocation, xReg)
117*b1cdbd2cSJim Jagielski
118*b1cdbd2cSJim Jagielski    bOK = bOK AND xReg.isValid()
119*b1cdbd2cSJim Jagielski    regKey = xReg.getRootKey
120*b1cdbd2cSJim Jagielski    keyNames = regKey.getKeyNames()
121*b1cdbd2cSJim Jagielski    for i = 0 to ubound(keyNames())
122*b1cdbd2cSJim Jagielski        if (inStr(1, keyNames(i), "IMPLEMENTATIONS") &gt; 0) then
123*b1cdbd2cSJim Jagielski            bNeedTest = true
124*b1cdbd2cSJim Jagielski        end if
125*b1cdbd2cSJim Jagielski    next i
126*b1cdbd2cSJim Jagielski    if (NOT bNeedTest) then
127*b1cdbd2cSJim Jagielski        Out.Log("No implementation was found.")
128*b1cdbd2cSJim Jagielski    end if
129*b1cdbd2cSJim Jagielski
130*b1cdbd2cSJim Jagielski    if (bOK AND bNeedTest) then
131*b1cdbd2cSJim Jagielski        regKey = xReg.getRootKey.openKey("IMPLEMENTATIONS")
132*b1cdbd2cSJim Jagielski        Out.Log("In registry found " &amp; ubound(keyNames) + 1 &amp; " implementations.")
133*b1cdbd2cSJim Jagielski
134*b1cdbd2cSJim Jagielski        for i = 0 to ubound(aFlags())
135*b1cdbd2cSJim Jagielski            aFlags(i) = false
136*b1cdbd2cSJim Jagielski        next i
137*b1cdbd2cSJim Jagielski
138*b1cdbd2cSJim Jagielski        for i = 0 to ubound(keyNames())
139*b1cdbd2cSJim Jagielski            Out.Log("Found key: " &amp; keyNames(i))
140*b1cdbd2cSJim Jagielski            for k = 0 to ubound(aImplementations)
141*b1cdbd2cSJim Jagielski                if (inStr(1, keyNames(i), aImplementations(k)) &gt; 0 ) then
142*b1cdbd2cSJim Jagielski                    aFlags(k) = true
143*b1cdbd2cSJim Jagielski                end if
144*b1cdbd2cSJim Jagielski            next k
145*b1cdbd2cSJim Jagielski        next i
146*b1cdbd2cSJim Jagielski
147*b1cdbd2cSJim Jagielski        for i = 0 to ubound(aFlags())
148*b1cdbd2cSJim Jagielski            if (aFlags(i)) then
149*b1cdbd2cSJim Jagielski                Out.Log("Information about " &amp; aImplementations(i) &amp; " is still in regestry")
150*b1cdbd2cSJim Jagielski                bOK = false
151*b1cdbd2cSJim Jagielski            end if
152*b1cdbd2cSJim Jagielski        next i
153*b1cdbd2cSJim Jagielski    end if
154*b1cdbd2cSJim Jagielski    Test.MethodTested("revokeImplementation()", bOK)
155*b1cdbd2cSJim Jagielski
156*b1cdbd2cSJim Jagielski    xReg.Close()
157*b1cdbd2cSJim JagielskiExit Sub
158*b1cdbd2cSJim JagielskiErrHndl:
159*b1cdbd2cSJim Jagielski    Test.Exception()
160*b1cdbd2cSJim Jagielski    bOK = false
161*b1cdbd2cSJim Jagielski    resume next
162*b1cdbd2cSJim JagielskiEnd Sub
163*b1cdbd2cSJim Jagielski</script:module>
164