xref: /trunk/main/stoc/test/testregistry.cxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_stoc.hxx"
26 
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <string.h>
30 
31 #include <sal/main.h>
32 #include <osl/module.hxx>
33 #include <osl/diagnose.h>
34 #include <osl/process.h>
35 #include <registry/registry.hxx>
36 
37 
38 #include <com/sun/star/registry/XSimpleRegistry.hpp>
39 #include <com/sun/star/lang/XServiceInfo.hpp>
40 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
41 #include <com/sun/star/beans/XPropertySet.hpp>
42 #include <cppuhelper/factory.hxx>
43 #include <cppuhelper/bootstrap.hxx>
44 #include <cppuhelper/servicefactory.hxx>
45 
46 #include <com/sun/star/lang/XComponent.hpp>
47 
48 #if defined ( UNX )
49 #include <limits.h>
50 #define _MAX_PATH PATH_MAX
51 #endif
52 
53 using namespace com::sun::star;
54 using namespace com::sun::star::uno;
55 using namespace com::sun::star::registry;
56 using namespace com::sun::star::lang;
57 using namespace com::sun::star::beans;
58 using namespace rtl;
59 using namespace osl;
60 
61 #if OSL_DEBUG_LEVEL > 0
62 #define TEST_ENSHURE(c, m)   OSL_ENSURE(c, m)
63 #else
64 #define TEST_ENSHURE(c, m)   OSL_VERIFY(c)
65 #endif
66 
67 namespace stoc_impreg
68 {
69 void SAL_CALL mergeKeys(
70     Reference< registry::XRegistryKey > const & xDest,
71     Reference< registry::XRegistryKey > const & xSource );
72 }
mergeKeys(Reference<registry::XSimpleRegistry> const & xDest,OUString const & rBaseNode,OUString const & rURL)73 static void mergeKeys(
74     Reference< registry::XSimpleRegistry > const & xDest,
75     OUString const & rBaseNode,
76     OUString const & rURL )
77 {
78     Reference< registry::XRegistryKey > xDestRoot( xDest->getRootKey() );
79     Reference< registry::XRegistryKey > xDestKey;
80     if (rBaseNode.getLength())
81     {
82         xDestKey = xDestRoot->createKey( rBaseNode );
83         xDestRoot->closeKey();
84     }
85     else
86     {
87         xDestKey = xDestRoot;
88     }
89     Reference< registry::XSimpleRegistry > xSimReg( ::cppu::createSimpleRegistry() );
90     xSimReg->open( rURL, sal_True, sal_False );
91     OSL_ASSERT( xSimReg->isValid() );
92     Reference< registry::XRegistryKey > xSourceKey( xSimReg->getRootKey() );
93     ::stoc_impreg::mergeKeys( xDestKey, xSourceKey );
94     xSourceKey->closeKey();
95     xSimReg->close();
96     xDestKey->closeKey();
97 }
98 
99 
100 OString userRegEnv("STAR_USER_REGISTRY=");
101 
getExePath()102 OUString getExePath()
103 {
104     OUString        exe;
105     OSL_VERIFY( osl_getExecutableFile( &exe.pData ) == osl_Process_E_None);
106 #if defined(WIN32) || defined(__OS2__) || defined(WNT)
107     exe = exe.copy(0, exe.getLength() - 16);
108 #else
109     exe = exe.copy(0, exe.getLength() - 12);
110 #endif
111     return exe;
112 }
113 
setStarUserRegistry()114 void setStarUserRegistry()
115 {
116     Registry *myRegistry = new Registry();
117 
118     RegistryKey rootKey, rKey, rKey2;
119 
120     OUString userReg = getExePath();
121     userReg += OUString::createFromAscii("user.rdb");
122     if(myRegistry->open(userReg, REG_READWRITE))
123     {
124         TEST_ENSHURE(!myRegistry->create(userReg), "setStarUserRegistry error 1");
125     }
126 
127     TEST_ENSHURE(!myRegistry->close(), "setStarUserRegistry error 9");
128     delete myRegistry;
129 
130     userRegEnv += OUStringToOString(userReg, RTL_TEXTENCODING_ASCII_US);
131     putenv((char *)userRegEnv.getStr());
132 }
133 
setLinkInDefaultRegistry(const OUString & linkName,const OUString & linkTarget)134 void setLinkInDefaultRegistry(const OUString& linkName, const OUString& linkTarget)
135 {
136     Registry *myRegistry = new Registry();
137 
138     RegistryKey rootKey;
139 
140     OUString appReg = getExePath();
141     appReg += OUString::createFromAscii("stoctest.rdb");
142 
143     TEST_ENSHURE(!myRegistry->open(appReg, REG_READWRITE), "setLinkInDefaultRegistry error 1");
144     TEST_ENSHURE(!myRegistry->openRootKey(rootKey), "setLinkInDefaultRegistry error 2");
145 
146     TEST_ENSHURE(!rootKey.createLink(linkName, linkTarget), "setLinkInDefaultRegistry error 3");
147 
148     TEST_ENSHURE(!rootKey.closeKey(),  "setLinkInDefaultRegistry error 4");
149     TEST_ENSHURE(!myRegistry->close(), "setLinkInDefaultRegistry error 5");
150 
151     delete myRegistry;
152 }
153 
154 
test_SimpleRegistry(OUString const & testreg,OUString const & testreg2,bool bMergeDifferently=true)155 void test_SimpleRegistry(
156     OUString const & testreg,
157     OUString const & testreg2,
158     bool bMergeDifferently = true )
159 {
160     Reference<XInterface> xIFace;
161     Module module;
162 
163     OUString dllName(
164         RTL_CONSTASCII_USTRINGPARAM("simplereg.uno" SAL_DLLEXTENSION) );
165 
166     if (module.load(dllName))
167     {
168         // try to get provider from module
169         component_getFactoryFunc pCompFactoryFunc = (component_getFactoryFunc)
170             module.getFunctionSymbol( OUString::createFromAscii(COMPONENT_GETFACTORY) );
171 
172         if (pCompFactoryFunc)
173         {
174             XSingleServiceFactory * pRet = (XSingleServiceFactory *)
175                 (*pCompFactoryFunc)(
176                     "com.sun.star.comp.stoc.SimpleRegistry", 0, 0 );
177             if (pRet)
178             {
179                 xIFace = pRet;
180                 pRet->release();
181             }
182         }
183     }
184 
185     TEST_ENSHURE( xIFace.is(), "test_SimpleRegistry error1");
186 
187     Reference<XSingleServiceFactory> xFactory( Reference<XSingleServiceFactory>::query(xIFace) );
188     xIFace.clear();
189 
190     TEST_ENSHURE( xFactory.is(), "testloader error11");
191 
192     Reference<XInterface> xIFace2 = xFactory->createInstance();
193     xFactory.clear();
194 
195     TEST_ENSHURE( xIFace2.is(), "testloader error12");
196 
197     Reference<XServiceInfo> xServInfo( Reference<XServiceInfo>::query(xIFace2) );
198 
199     TEST_ENSHURE( xServInfo.is(), "test_SimpleRegistry error2");
200 
201     TEST_ENSHURE( xServInfo->getImplementationName().equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.comp.stoc.SimpleRegistry") ), "test_SimpleRegistry error3");
202     TEST_ENSHURE( xServInfo->supportsService(OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.registry.SimpleRegistry"))), "test_SimpleRegistry error4");
203     TEST_ENSHURE( xServInfo->getSupportedServiceNames().getLength() == 1, "test_SimpleRegistry error5");
204     xServInfo.clear();
205 
206     Reference<XSimpleRegistry> xReg( Reference<XSimpleRegistry>::query(xIFace2) );
207     xIFace2.clear();
208 
209     TEST_ENSHURE( xReg.is(), "test_SimpleRegistry error6");
210 
211     try
212     {
213         xReg->open(testreg, sal_False, sal_True);
214 
215         TEST_ENSHURE( xReg->isValid() != sal_False, "test_SimpleRegistry error 7" );
216         TEST_ENSHURE( xReg->isReadOnly() == sal_False, "test_SimpleRegistry error 8" );
217 
218         Reference<XRegistryKey> xRootKey(xReg->getRootKey());
219         TEST_ENSHURE( xRootKey->isValid(), "test_SimpleRegistry error 9" );
220 
221         Reference<XRegistryKey> xKey = xRootKey->createKey(OUString( RTL_CONSTASCII_USTRINGPARAM("FirstKey") ));
222 
223         Reference<XRegistryKey> xSubKey = xKey->createKey(OUString( RTL_CONSTASCII_USTRINGPARAM("FirstSubKey") ));
224         xSubKey->setLongValue(123456789);
225 
226         xSubKey = xKey->createKey(OUString( RTL_CONSTASCII_USTRINGPARAM("SecondSubKey") ));
227         xSubKey->setAsciiValue(OUString( RTL_CONSTASCII_USTRINGPARAM("ich bin ein ascii value") ));
228 
229         xSubKey = xKey->createKey(OUString( RTL_CONSTASCII_USTRINGPARAM("ThirdSubKey") ));
230         xSubKey->setStringValue(OUString( RTL_CONSTASCII_USTRINGPARAM("ich bin ein unicode value") ));
231 
232         xSubKey = xKey->createKey(OUString( RTL_CONSTASCII_USTRINGPARAM("FourthSubKey") ));
233         Sequence<sal_Int8> aSeq((sal_Int8*)"ich bin ein binary value", 25);
234         xSubKey->setBinaryValue(aSeq);
235 
236         Sequence<OUString> seqNames = xKey->getKeyNames();
237         Sequence< Reference<XRegistryKey> > seqKeys = xKey->openKeys();
238 
239         OUString name;
240         for (sal_Int32 i=0; i < seqNames.getLength(); i++)
241         {
242             name = seqNames.getArray()[i];
243             xSubKey = seqKeys.getArray()[i];
244 
245             if (name == OUString( RTL_CONSTASCII_USTRINGPARAM("/FirstKey/FirstSubKey") ))
246             {
247                 TEST_ENSHURE( xSubKey->getLongValue() == 123456789,
248                             "test_SimpleRegistry error 10" );
249             } else
250             if (name == OUString( RTL_CONSTASCII_USTRINGPARAM("/FirstKey/SecondSubKey") ))
251             {
252                 TEST_ENSHURE( xSubKey->getAsciiValue() == OUString( RTL_CONSTASCII_USTRINGPARAM("ich bin ein ascii value") ),
253                             "test_SimpleRegistry error 11" );
254             } else
255             if (name == OUString( RTL_CONSTASCII_USTRINGPARAM("/FirstKey/ThirdSubKey") ))
256             {
257                 TEST_ENSHURE( xSubKey->getStringValue() == OUString( RTL_CONSTASCII_USTRINGPARAM("ich bin ein unicode value") ),
258                             "test_SimpleRegistry error 12" );
259             } else
260             if (name == OUString( RTL_CONSTASCII_USTRINGPARAM("/FirstKey/FourthSubKey") ))
261             {
262                 Sequence<sal_Int8> seqByte = xSubKey->getBinaryValue();
263                 TEST_ENSHURE(!strcmp(((const char*)seqByte.getArray()), "ich bin ein binary value"),
264                             "test_SimpleRegistry error 13" );
265             }
266 
267             seqKeys.getArray()[i]->closeKey();
268         }
269 
270         xKey->closeKey();
271 
272         xRootKey->deleteKey(OUString( RTL_CONSTASCII_USTRINGPARAM("FirstKey") ));
273         xRootKey->createKey(OUString( RTL_CONSTASCII_USTRINGPARAM("SecondFirstKey" )));
274 
275         xKey = xRootKey->createKey(OUString( RTL_CONSTASCII_USTRINGPARAM("SecondKey") ));
276         sal_Int32 pLongs[3] = {123, 456, 789};
277         Sequence<sal_Int32> seqLongs(pLongs, 3);
278         xKey->setLongListValue(seqLongs);
279 
280         Sequence<sal_Int32> seqLongs2;
281         seqLongs2 = xKey->getLongListValue();
282         TEST_ENSHURE( seqLongs.getLength() == 3, "test_SimpleRegistry error 14" );
283         TEST_ENSHURE( seqLongs.getArray()[0] == 123, "test_SimpleRegistry error 15" );
284         TEST_ENSHURE( seqLongs.getArray()[1] == 456, "test_SimpleRegistry error 16" );
285         TEST_ENSHURE( seqLongs.getArray()[2] == 789, "test_SimpleRegistry error 17" );
286 
287 
288         xKey = xRootKey->createKey(OUString( RTL_CONSTASCII_USTRINGPARAM("ThirdKey") ));
289         OUString pAscii[3];
290         pAscii[0] = OUString( RTL_CONSTASCII_USTRINGPARAM("Hallo") );
291         pAscii[1] = OUString( RTL_CONSTASCII_USTRINGPARAM("jetzt komm") );
292         pAscii[2] = OUString( RTL_CONSTASCII_USTRINGPARAM("ich") );
293 
294         Sequence<OUString> seqAscii(pAscii, 3);
295         xKey->setAsciiListValue(seqAscii);
296 
297         Sequence<OUString> seqAscii2;
298         seqAscii2 = xKey->getAsciiListValue();
299         TEST_ENSHURE( seqAscii2.getLength() == 3, "test_SimpleRegistry error 18" );
300         TEST_ENSHURE( seqAscii2.getArray()[0] == OUString( RTL_CONSTASCII_USTRINGPARAM("Hallo") ), "test_SimpleRegistry error 19");
301         TEST_ENSHURE( seqAscii2.getArray()[1] == OUString( RTL_CONSTASCII_USTRINGPARAM("jetzt komm") ), "test_SimpleRegistry error 20");
302         TEST_ENSHURE( seqAscii2.getArray()[2] == OUString( RTL_CONSTASCII_USTRINGPARAM("ich") ), "test_SimpleRegistry error 21");
303 
304         xKey = xRootKey->createKey(OUString( RTL_CONSTASCII_USTRINGPARAM("FourthKey") ));
305         OUString pUnicode[3];
306         pUnicode[0] = OUString( RTL_CONSTASCII_USTRINGPARAM("Hallo") );
307         pUnicode[1] = OUString( RTL_CONSTASCII_USTRINGPARAM("jetzt komm") );
308         pUnicode[2] = OUString( RTL_CONSTASCII_USTRINGPARAM("ich als unicode") );
309 
310         Sequence<OUString> seqUnicode(pUnicode, 3);
311         xKey->setStringListValue(seqUnicode);
312 
313         Sequence<OUString> seqUnicode2;
314         seqUnicode2 = xKey->getStringListValue();
315         TEST_ENSHURE( seqUnicode2.getLength() == 3, "test_SimpleRegistry error 22" );
316         TEST_ENSHURE( seqUnicode2.getArray()[0] == OUString( RTL_CONSTASCII_USTRINGPARAM("Hallo") ), "test_SimpleRegistry error 23");
317         TEST_ENSHURE( seqUnicode2.getArray()[1] == OUString( RTL_CONSTASCII_USTRINGPARAM("jetzt komm") ), "test_SimpleRegistry error 24");
318         TEST_ENSHURE( seqUnicode2.getArray()[2] == OUString( RTL_CONSTASCII_USTRINGPARAM("ich als unicode") ), "test_SimpleRegistry error 25");
319 
320 
321         xReg->open(testreg2, sal_False, sal_True);
322         TEST_ENSHURE( xReg->isValid() != sal_False, "test_SimpleRegistry error 25" );
323         xRootKey = xReg->getRootKey();
324         xKey = xRootKey->createKey(OUString( RTL_CONSTASCII_USTRINGPARAM("ThirdKey/FirstSubKey/WithSubSubKey") ));
325         xKey->closeKey();
326         TEST_ENSHURE(
327             xRootKey->createLink(
328                 OUString( RTL_CONSTASCII_USTRINGPARAM("LinkTest") ),
329                 OUString( RTL_CONSTASCII_USTRINGPARAM("/ThirdKey/FirstSubKey/WithSubSubKey") )),
330             "test_SimpleRegistry error 1212" );
331         xRootKey->closeKey();
332         xReg->close();
333 
334         xReg->open(testreg, sal_False, sal_False);
335         TEST_ENSHURE( xReg->isValid() != sal_False, "test_SimpleRegistry error 26" );
336 
337         if (bMergeDifferently)
338         {
339             mergeKeys(
340                 xReg,
341                 OUString(),
342                 testreg2 );
343         }
344         else
345         {
346             xReg->mergeKey(OUString(), testreg2);
347         }
348 
349         xRootKey = xReg->getRootKey();
350         xKey = xRootKey->openKey( OUString( RTL_CONSTASCII_USTRINGPARAM("LinkTest") ) );
351         TEST_ENSHURE(
352             xKey.is() && xKey->isValid() &&
353             xKey->getKeyName().equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("/ThirdKey/FirstSubKey/WithSubSubKey") ),
354             "test_SimpleRegistry error 1213" );
355         xKey->closeKey();
356         TEST_ENSHURE(
357             xRootKey->getKeyType( OUString( RTL_CONSTASCII_USTRINGPARAM("LinkTest") ) ) ==
358             registry::RegistryKeyType_LINK,
359             "test_SimpleRegistry error 1214" );
360 
361         xKey = xRootKey->openKey(OUString( RTL_CONSTASCII_USTRINGPARAM("FirstKey/SecondSubKey") ));
362         TEST_ENSHURE( !xKey.is(), "test_SimpleRegistry error 27" );
363 
364         // Test Links
365         xKey = xRootKey->createKey(OUString( RTL_CONSTASCII_USTRINGPARAM("FifthKey") ));
366         xKey->createLink(OUString( RTL_CONSTASCII_USTRINGPARAM("MyFirstLink") ),
367                          OUString( RTL_CONSTASCII_USTRINGPARAM("/ThirdKey/FirstSubKey") ));
368 
369         xKey = xRootKey->openKey(OUString( RTL_CONSTASCII_USTRINGPARAM("/FifthKey/MyFirstLink") ));
370         TEST_ENSHURE( xKey->isValid(), "test_SimpleRegistry error 27" );
371         TEST_ENSHURE( xKey->getKeyName() == OUString( RTL_CONSTASCII_USTRINGPARAM("/ThirdKey/FirstSubKey") ), "test_SimpleRegistry error 28" );
372 
373         xKey->createLink(OUString( RTL_CONSTASCII_USTRINGPARAM("/WithSubSubKey/MyFourthLink") ),
374                          OUString( RTL_CONSTASCII_USTRINGPARAM("/FourthKey/MySecondLink") ));
375 
376         TEST_ENSHURE( xKey->getLinkTarget(OUString( RTL_CONSTASCII_USTRINGPARAM("/WithSubSubKey/MyFourthLink") ))
377                      == OUString( RTL_CONSTASCII_USTRINGPARAM("/FourthKey/MySecondLink") ), "test_SimpleRegistry error 29" );
378 
379         try
380         {
381             TEST_ENSHURE( xKey->getResolvedName(OUString( RTL_CONSTASCII_USTRINGPARAM("/WithSubSubKey/MyFourthLink/BlaBlaBla") ))
382                          == OUString( RTL_CONSTASCII_USTRINGPARAM("/FourthKey/MySecondLink/BlaBlaBla") ), "test_SimpleRegistry error 30" );
383         }
384         catch(InvalidRegistryException&)
385         {
386         }
387 
388         xRootKey->createLink(OUString( RTL_CONSTASCII_USTRINGPARAM("/FourthKey/MySecondLink") ),
389                              OUString( RTL_CONSTASCII_USTRINGPARAM("/SixthKey/MyThirdLink") ));
390         xKey = xRootKey->createKey(OUString( RTL_CONSTASCII_USTRINGPARAM("SixthKey") ));
391         xKey->createLink(OUString( RTL_CONSTASCII_USTRINGPARAM("MyThirdLink") ),
392                          OUString( RTL_CONSTASCII_USTRINGPARAM("/FourthKey/MySecondLink") ));
393 
394         xKey = xRootKey->createKey(OUString( RTL_CONSTASCII_USTRINGPARAM("/SixthKey/SixthSubKey") ));
395 
396         try
397         {
398             xRootKey->openKey(OUString( RTL_CONSTASCII_USTRINGPARAM("/FifthKey/MyFirstLink/WithSubSubKey/MyFourthLink") ));
399         }
400         catch(InvalidRegistryException&)
401         {
402         }
403 
404         TEST_ENSHURE( xRootKey->getLinkTarget(OUString( RTL_CONSTASCII_USTRINGPARAM("/FifthKey/MyFirstLink/WithSubSubKey/MyFourthLink") ))
405                      == OUString( RTL_CONSTASCII_USTRINGPARAM("/FourthKey/MySecondLink") ), "test_SimpleRegistry error 31" );
406 
407         xRootKey->deleteLink(OUString( RTL_CONSTASCII_USTRINGPARAM("/FifthKey/MyFirstLink/WithSubSubKey/MyFourthLink") ));
408 
409         xRootKey->createLink(OUString( RTL_CONSTASCII_USTRINGPARAM("/FourthKey/MySecondLink") ),
410                              OUString( RTL_CONSTASCII_USTRINGPARAM("/ThirdKey/FirstSubKey/WithSubSubKey") ));
411 
412         xKey = xRootKey->openKey(OUString( RTL_CONSTASCII_USTRINGPARAM("SixthKey") ));
413         seqNames = xKey->getKeyNames();
414         seqKeys = xKey->openKeys();
415 
416         TEST_ENSHURE( seqNames.getArray()[0] == OUString( RTL_CONSTASCII_USTRINGPARAM("/SixthKey/SixthSubKey") ),
417                       "test_SimpleRegistry error 32" );
418         TEST_ENSHURE( seqNames.getArray()[1] == OUString( RTL_CONSTASCII_USTRINGPARAM("/SixthKey/MyThirdLink") ),
419                       "test_SimpleRegistry error 33" );
420 
421         TEST_ENSHURE( seqKeys.getArray()[0]->getKeyName() == OUString( RTL_CONSTASCII_USTRINGPARAM("/SixthKey/SixthSubKey") ),
422                       "test_SimpleRegistry error 34" );
423         TEST_ENSHURE( seqKeys.getArray()[1]->getKeyName() == OUString( RTL_CONSTASCII_USTRINGPARAM("/ThirdKey/FirstSubKey/WithSubSubKey") ),
424                       "test_SimpleRegistry error 35" );
425 
426         xRootKey->deleteLink(OUString( RTL_CONSTASCII_USTRINGPARAM("/FourthKey/MySecondLink") ));
427         xRootKey->closeKey();
428     }
429     catch(InvalidRegistryException&)
430     {
431         TEST_ENSHURE(0, "exception InvalidRegistryExcption raised while doing test_SimpleRegistry");
432     }
433     catch(InvalidValueException&)
434     {
435         TEST_ENSHURE(0, "exception InvalidValueExcption raised while doing test_SimpleRegistry()");
436     }
437 
438     xReg.clear();
439 
440     printf("Test SimpleRegistry, OK!\n");
441 }
442 
443 
test_DefaultRegistry(OUString const & testreg,OUString const & testreg2,bool bMergeDifferently=false)444 void test_DefaultRegistry(
445     OUString const & testreg,
446     OUString const & testreg2,
447     bool bMergeDifferently = false )
448 {
449     // Test NestedRegistry
450     OUString exePath( getExePath() );
451     OUString userRdb(exePath);
452     OUString applicatRdb(exePath);
453 
454     userRdb += OUString::createFromAscii("user.rdb");
455     applicatRdb += OUString::createFromAscii("stoctest.rdb");
456 
457     Reference < XMultiServiceFactory > rSMgr  = ::cppu::createRegistryServiceFactory( userRdb, applicatRdb, sal_False, OUString());
458                                                                                       //OUString::createFromAscii("//./e:/src596/stoc/wntmsci3/bin") );
459 
460     Reference< XPropertySet > xPropSet( rSMgr, UNO_QUERY);
461     TEST_ENSHURE( xPropSet.is(), "test_DefaultRegistry error0");
462 
463     Any aPropertyAny( xPropSet->getPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("Registry")) ) );
464     TEST_ENSHURE( aPropertyAny.hasValue(), "test_DefaultRegistry error1");
465 
466     Reference<XSimpleRegistry> xReg;
467     aPropertyAny >>= xReg;
468     TEST_ENSHURE( xReg.is(), "test_DefaultRegistry error1a");
469 
470     Reference<XServiceInfo> xServInfo( Reference<XServiceInfo>::query(xReg) );
471 
472     TEST_ENSHURE( xServInfo.is(), "test_DefaultRegistry error2");
473 
474     TEST_ENSHURE( xServInfo->getImplementationName() == OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.stoc.NestedRegistry") ), "test_DefualtRegistry error3");
475     TEST_ENSHURE( xServInfo->supportsService(OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.registry.NestedRegistry") )), "test_DefaultRegistry error4");
476     TEST_ENSHURE( xServInfo->getSupportedServiceNames().getLength() == 1, "test_DefaultRegistry error5");
477     xServInfo.clear();
478 
479     TEST_ENSHURE( xReg.is(), "test_DefaultRegistry error6");
480 
481     try
482     {
483         Reference<XRegistryKey> xRootKey(xReg->getRootKey());
484 
485         Reference<XRegistryKey> xKey = xRootKey->openKey(OUString( RTL_CONSTASCII_USTRINGPARAM("/UCR/com/sun/star/registry/XSimpleRegistry") ));
486 
487         TEST_ENSHURE( xKey->getKeyName() == OUString( RTL_CONSTASCII_USTRINGPARAM("/UCR/com/sun/star/registry/XSimpleRegistry") ),
488                      "test_DefaultRegistry error 7" );
489 
490         if (bMergeDifferently)
491         {
492             mergeKeys(
493                 xReg,
494                 OUString( RTL_CONSTASCII_USTRINGPARAM("Test") ),
495                 testreg );
496         }
497         else
498         {
499             xReg->mergeKey(OUString( RTL_CONSTASCII_USTRINGPARAM("Test") ), testreg );
500         }
501 
502         xKey = xRootKey->openKey(OUString( RTL_CONSTASCII_USTRINGPARAM("Test/ThirdKey/FirstSubKey/WithSubSubKey") ));
503         if (xKey.is())
504             xKey->setLongValue(123456789);
505 
506         xKey = xRootKey->openKey(OUString( RTL_CONSTASCII_USTRINGPARAM("Test/ThirdKey/FirstSubKey") ));
507         if (xKey.is())
508         {
509             xKey->createKey(OUString( RTL_CONSTASCII_USTRINGPARAM("SecondSubSubKey") ));
510 
511             Sequence<OUString> seqNames = xKey->getKeyNames();
512 
513             TEST_ENSHURE( seqNames.getLength() == 2, "test_DefaultRegistry error 8" );
514         }
515 
516         xKey = xRootKey->openKey(OUString( RTL_CONSTASCII_USTRINGPARAM("/Test/ThirdKey") ));
517         if (xKey.is())
518         {
519             RegistryValueType valueType = xKey->getValueType();
520             TEST_ENSHURE( valueType == RegistryValueType_ASCIILIST, "test_DefaultRegistry error 9" );
521 
522             Sequence<OUString> seqValue = xKey->getAsciiListValue();
523 
524             TEST_ENSHURE( seqValue.getLength() == 3, "test_DefaultRegistry error 10" );
525             TEST_ENSHURE( seqValue.getArray()[0] == OUString( RTL_CONSTASCII_USTRINGPARAM("Hallo") ),
526                           "test_DefaultRegistry error 11" );
527             TEST_ENSHURE( seqValue.getArray()[1] == OUString( RTL_CONSTASCII_USTRINGPARAM("jetzt komm") ),
528                           "test_DefaultRegistry error 12" );
529             TEST_ENSHURE( seqValue.getArray()[2] == OUString( RTL_CONSTASCII_USTRINGPARAM("ich") ),
530                           "test_DefaultRegistry error 13" );
531 
532             Sequence<sal_Int32> seqLong(3);
533             seqLong.getArray()[0] = 1234;
534             seqLong.getArray()[1] = 4567;
535             seqLong.getArray()[2] = 7890;
536 
537             xKey->setLongListValue(seqLong);
538 
539             Sequence<sal_Int32> seqLongValue = xKey->getLongListValue();
540 
541             TEST_ENSHURE( seqLongValue.getLength() == 3, "test_DefaultRegistry error 14" );
542             TEST_ENSHURE( seqLongValue.getArray()[0] == 1234, "test_DefaultRegistry error 15" );
543             TEST_ENSHURE( seqLongValue.getArray()[1] == 4567, "test_DefaultRegistry error 16" );
544             TEST_ENSHURE( seqLongValue.getArray()[2] == 7890, "test_DefaultRegistry error 17" );
545         }
546 
547         // Test Links
548         xKey = xRootKey->createKey(OUString( RTL_CONSTASCII_USTRINGPARAM("/Test/FifthKey") ));
549         xKey->createLink(OUString( RTL_CONSTASCII_USTRINGPARAM("MyFirstLink") ),
550                          OUString( RTL_CONSTASCII_USTRINGPARAM("/Test/ThirdKey/FirstSubKey") ));
551 
552         xKey = xRootKey->openKey(OUString( RTL_CONSTASCII_USTRINGPARAM("/Test/FifthKey/MyFirstLink") ));
553         TEST_ENSHURE( xKey->isValid(), "test_DefaultRegistry error 18" );
554         TEST_ENSHURE( xKey->getKeyName() == OUString( RTL_CONSTASCII_USTRINGPARAM("/Test/ThirdKey/FirstSubKey") ),
555                       "test_DefaultRegistry error 19" );
556 
557         xKey->createLink(OUString( RTL_CONSTASCII_USTRINGPARAM("/WithSubSubKey/MyFourthLink") ),
558                          OUString( RTL_CONSTASCII_USTRINGPARAM("/Test/FourthKey/MySecondLink") ));
559 
560         TEST_ENSHURE( xKey->getLinkTarget(OUString( RTL_CONSTASCII_USTRINGPARAM("/WithSubSubKey/MyFourthLink") ))
561                      == OUString( RTL_CONSTASCII_USTRINGPARAM("/Test/FourthKey/MySecondLink") ),
562                       "test_DefaultRegistry error 20" );
563 
564         try
565         {
566             TEST_ENSHURE( xKey->getResolvedName(OUString( RTL_CONSTASCII_USTRINGPARAM("/WithSubSubKey/MyFourthLink/BlaBlaBla") ))
567                           == OUString( RTL_CONSTASCII_USTRINGPARAM("/Test/FourthKey/MySecondLink/BlaBlaBla") ),
568                           "test_DefaultRegistry error 21" );
569         }
570         catch(InvalidRegistryException&)
571         {
572         }
573 
574         xRootKey->createLink(OUString( RTL_CONSTASCII_USTRINGPARAM("/Test/FourthKey/MySecondLink") ),
575                              OUString( RTL_CONSTASCII_USTRINGPARAM("/Test/SixthKey/MyThirdLink") ));
576         xKey = xRootKey->createKey(OUString( RTL_CONSTASCII_USTRINGPARAM("/Test/SixthKey") ));
577         xKey->createLink(OUString( RTL_CONSTASCII_USTRINGPARAM("MyThirdLink") ),
578                          OUString( RTL_CONSTASCII_USTRINGPARAM("/Test/FourthKey/MySecondLink") ));
579 
580         try
581         {
582             xRootKey->openKey(OUString( RTL_CONSTASCII_USTRINGPARAM("/Test/FifthKey/MyFirstLink/WithSubSubKey/MyFourthLink") ));
583         }
584         catch(InvalidRegistryException&)
585         {
586             printf("test InvalidRegistryExcption OK!\n");
587         }
588 
589         TEST_ENSHURE( xRootKey->getLinkTarget(OUString( RTL_CONSTASCII_USTRINGPARAM("/Test/FifthKey/MyFirstLink/WithSubSubKey/MyFourthLink") ))
590                      == OUString( RTL_CONSTASCII_USTRINGPARAM("/Test/FourthKey/MySecondLink") ),
591                       "test_DefaultRegistry error 22" );
592 
593         xRootKey->deleteLink(OUString( RTL_CONSTASCII_USTRINGPARAM("/Test/FifthKey/MyFirstLink/WithSubSubKey/MyFourthLink") ));
594 
595         xKey = xRootKey->openKey(OUString( RTL_CONSTASCII_USTRINGPARAM("/Test/DefaultLink/SecondSubSubKey") ));
596         if (xKey.is())
597         {
598             TEST_ENSHURE( xKey->getKeyName() == OUString( RTL_CONSTASCII_USTRINGPARAM("/Test/ThirdKey/FirstSubKey/SecondSubSubKey") ), "test_DefaultRegistry error 23" );
599         }
600         xKey = xRootKey->createKey(OUString( RTL_CONSTASCII_USTRINGPARAM("/Test/DefaultLink/ThirdSubSubKey") ));
601         if (xKey.is())
602         {
603             TEST_ENSHURE( xKey->getKeyName() == OUString( RTL_CONSTASCII_USTRINGPARAM("/Test/ThirdKey/FirstSubKey/ThirdSubSubKey") ),
604                           "test_DefaultRegistry error 24" );
605         }
606 
607         xKey = xRootKey->openKey(OUString( RTL_CONSTASCII_USTRINGPARAM("Test") ));
608         TEST_ENSHURE( xKey->isValid(), "test_DefaultRegistry error 25" );
609 
610         xRootKey->deleteKey(OUString( RTL_CONSTASCII_USTRINGPARAM("Test") ));
611 
612         if (bMergeDifferently)
613         {
614             mergeKeys(
615                 xReg,
616                 OUString( RTL_CONSTASCII_USTRINGPARAM("AllFromTestreg2") ),
617                 testreg2);
618         }
619         else
620         {
621             xReg->mergeKey(OUString( RTL_CONSTASCII_USTRINGPARAM("AllFromTestreg2") ),
622                            testreg2);
623         }
624 
625         xKey = xRootKey->openKey(OUString( RTL_CONSTASCII_USTRINGPARAM("/AllFromTestreg2/ThirdKey/FirstSubKey") ));
626         if (xKey.is())
627         {
628             xRootKey->deleteKey(OUString( RTL_CONSTASCII_USTRINGPARAM("/AllFromTestreg2") ));
629         }
630 
631     }
632     catch(InvalidRegistryException&)
633     {
634         TEST_ENSHURE(0, "exception InvalidRegistryExcption raised while doing test_DefaultRegistry");
635     }
636     catch(InvalidValueException&)
637     {
638         TEST_ENSHURE(0, "exception InvalidValueExcption raised while doing test_DefaultRegistry()");
639     }
640     try
641     {
642         xReg->close();
643     }
644     catch(InvalidRegistryException& e)
645     {
646         (void)e;
647         TEST_ENSHURE(0, OUStringToOString(e.Message,RTL_TEXTENCODING_ASCII_US).getStr());
648     }
649 
650 
651     xReg.clear();
652 
653     // shutdown
654     Reference< ::com::sun::star::lang::XComponent > xComp( rSMgr, UNO_QUERY );
655     OSL_ENSURE( xComp.is(), "### serivce manager has to implement XComponent!" );
656     xComp->dispose();
657 
658     printf("Test DefaultRegistry, OK!\n");
659 }
660 
661 
SAL_IMPLEMENT_MAIN()662 SAL_IMPLEMENT_MAIN()
663 {
664 //  setStarUserRegistry();
665     setLinkInDefaultRegistry(OUString::createFromAscii("/Test/DefaultLink"),
666                              OUString::createFromAscii("/Test/FifthKey/MyFirstLink"));
667 
668     OUString reg1( RTL_CONSTASCII_USTRINGPARAM("testreg1.rdb") );
669     OUString reg2( RTL_CONSTASCII_USTRINGPARAM("testreg2.rdb") );
670     OUString areg1( RTL_CONSTASCII_USTRINGPARAM("atestreg1.rdb") );
671     OUString areg2( RTL_CONSTASCII_USTRINGPARAM("atestreg2.rdb") );
672 
673     test_SimpleRegistry( reg1, reg2 );
674     test_DefaultRegistry( reg1, reg2 );
675     test_SimpleRegistry( areg1, areg2, true ); // use different merge
676     test_DefaultRegistry( areg1, areg2, true );
677 
678     Reference< XSimpleRegistry > xSimReg( ::cppu::createSimpleRegistry() );
679     xSimReg->open( reg1, sal_False, sal_True );
680     xSimReg->destroy();
681     xSimReg->open( reg2, sal_False, sal_True );
682     xSimReg->destroy();
683     xSimReg->open( areg1, sal_False, sal_True );
684     xSimReg->destroy();
685     xSimReg->open( areg2, sal_False, sal_True );
686     xSimReg->destroy();
687     return(0);
688 }
689