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