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