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