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