1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: testregistry.cxx,v $
10 * $Revision: 1.21.16.2 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_stoc.hxx"
39 #include <osl/module.hxx>
40 #include <osl/diagnose.h>
41 #include <osl/process.h>
42 #include <registry/registry.hxx>
45 #include <com/sun/star/registry/XSimpleRegistry.hpp>
46 #include <com/sun/star/lang/XServiceInfo.hpp>
47 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
48 #include <com/sun/star/beans/XPropertySet.hpp>
49 #include <cppuhelper/factory.hxx>
50 #include <cppuhelper/bootstrap.hxx>
51 #include <cppuhelper/servicefactory.hxx>
53 #include <com/sun/star/lang/XComponent.hpp>
57 #define _MAX_PATH PATH_MAX
60 using namespace com::sun::star
;
61 using namespace com::sun::star::uno
;
62 using namespace com::sun::star::registry
;
63 using namespace com::sun::star::lang
;
64 using namespace com::sun::star::beans
;
68 #if OSL_DEBUG_LEVEL > 0
69 #define TEST_ENSHURE(c, m) OSL_ENSURE(c, m)
71 #define TEST_ENSHURE(c, m) OSL_VERIFY(c)
76 void SAL_CALL
mergeKeys(
77 Reference
< registry::XRegistryKey
> const & xDest
,
78 Reference
< registry::XRegistryKey
> const & xSource
)
79 SAL_THROW( (registry::InvalidRegistryException
, registry::MergeConflictException
) );
81 static void mergeKeys(
82 Reference
< registry::XSimpleRegistry
> const & xDest
,
83 OUString
const & rBaseNode
,
84 OUString
const & rURL
)
85 SAL_THROW( (registry::InvalidRegistryException
, registry::MergeConflictException
) )
87 Reference
< registry::XRegistryKey
> xDestRoot( xDest
->getRootKey() );
88 Reference
< registry::XRegistryKey
> xDestKey
;
89 if (rBaseNode
.getLength())
91 xDestKey
= xDestRoot
->createKey( rBaseNode
);
92 xDestRoot
->closeKey();
98 Reference
< registry::XSimpleRegistry
> xSimReg( ::cppu::createSimpleRegistry() );
99 xSimReg
->open( rURL
, sal_True
, sal_False
);
100 OSL_ASSERT( xSimReg
->isValid() );
101 Reference
< registry::XRegistryKey
> xSourceKey( xSimReg
->getRootKey() );
102 ::stoc_impreg::mergeKeys( xDestKey
, xSourceKey
);
103 xSourceKey
->closeKey();
105 xDestKey
->closeKey();
109 OString
userRegEnv("STAR_USER_REGISTRY=");
111 OUString
getExePath()
114 OSL_VERIFY( osl_getExecutableFile( &exe
.pData
) == osl_Process_E_None
);
115 #if defined(WIN32) || defined(__OS2__) || defined(WNT)
116 exe
= exe
.copy(0, exe
.getLength() - 16);
118 exe
= exe
.copy(0, exe
.getLength() - 12);
123 void setStarUserRegistry()
125 Registry
*myRegistry
= new Registry();
127 RegistryKey rootKey
, rKey
, rKey2
;
129 OUString userReg
= getExePath();
130 userReg
+= OUString::createFromAscii("user.rdb");
131 if(myRegistry
->open(userReg
, REG_READWRITE
))
133 TEST_ENSHURE(!myRegistry
->create(userReg
), "setStarUserRegistry error 1");
136 TEST_ENSHURE(!myRegistry
->close(), "setStarUserRegistry error 9");
139 userRegEnv
+= OUStringToOString(userReg
, RTL_TEXTENCODING_ASCII_US
);
140 putenv((char *)userRegEnv
.getStr());
143 void setLinkInDefaultRegistry(const OUString
& linkName
, const OUString
& linkTarget
)
145 Registry
*myRegistry
= new Registry();
149 OUString appReg
= getExePath();
150 appReg
+= OUString::createFromAscii("stoctest.rdb");
152 TEST_ENSHURE(!myRegistry
->open(appReg
, REG_READWRITE
), "setLinkInDefaultRegistry error 1");
153 TEST_ENSHURE(!myRegistry
->openRootKey(rootKey
), "setLinkInDefaultRegistry error 2");
155 TEST_ENSHURE(!rootKey
.createLink(linkName
, linkTarget
), "setLinkInDefaultRegistry error 3");
157 TEST_ENSHURE(!rootKey
.closeKey(), "setLinkInDefaultRegistry error 4");
158 TEST_ENSHURE(!myRegistry
->close(), "setLinkInDefaultRegistry error 5");
164 void test_SimpleRegistry(
165 OUString
const & testreg
,
166 OUString
const & testreg2
,
167 bool bMergeDifferently
= true )
169 Reference
<XInterface
> xIFace
;
173 RTL_CONSTASCII_USTRINGPARAM("simplereg.uno" SAL_DLLEXTENSION
) );
175 if (module
.load(dllName
))
177 // try to get provider from module
178 component_getFactoryFunc pCompFactoryFunc
= (component_getFactoryFunc
)
179 module
.getFunctionSymbol( OUString::createFromAscii(COMPONENT_GETFACTORY
) );
181 if (pCompFactoryFunc
)
183 XSingleServiceFactory
* pRet
= (XSingleServiceFactory
*)
185 "com.sun.star.comp.stoc.SimpleRegistry", 0, 0 );
194 TEST_ENSHURE( xIFace
.is(), "test_SimpleRegistry error1");
196 Reference
<XSingleServiceFactory
> xFactory( Reference
<XSingleServiceFactory
>::query(xIFace
) );
199 TEST_ENSHURE( xFactory
.is(), "testloader error11");
201 Reference
<XInterface
> xIFace2
= xFactory
->createInstance();
204 TEST_ENSHURE( xIFace2
.is(), "testloader error12");
206 Reference
<XServiceInfo
> xServInfo( Reference
<XServiceInfo
>::query(xIFace2
) );
208 TEST_ENSHURE( xServInfo
.is(), "test_SimpleRegistry error2");
210 TEST_ENSHURE( xServInfo
->getImplementationName().equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.comp.stoc.SimpleRegistry") ), "test_SimpleRegistry error3");
211 TEST_ENSHURE( xServInfo
->supportsService(OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.registry.SimpleRegistry"))), "test_SimpleRegistry error4");
212 TEST_ENSHURE( xServInfo
->getSupportedServiceNames().getLength() == 1, "test_SimpleRegistry error5");
215 Reference
<XSimpleRegistry
> xReg( Reference
<XSimpleRegistry
>::query(xIFace2
) );
218 TEST_ENSHURE( xReg
.is(), "test_SimpleRegistry error6");
222 xReg
->open(testreg
, sal_False
, sal_True
);
224 TEST_ENSHURE( xReg
->isValid() != sal_False
, "test_SimpleRegistry error 7" );
225 TEST_ENSHURE( xReg
->isReadOnly() == sal_False
, "test_SimpleRegistry error 8" );
227 Reference
<XRegistryKey
> xRootKey(xReg
->getRootKey());
228 TEST_ENSHURE( xRootKey
->isValid(), "test_SimpleRegistry error 9" );
230 Reference
<XRegistryKey
> xKey
= xRootKey
->createKey(OUString( RTL_CONSTASCII_USTRINGPARAM("FirstKey") ));
232 Reference
<XRegistryKey
> xSubKey
= xKey
->createKey(OUString( RTL_CONSTASCII_USTRINGPARAM("FirstSubKey") ));
233 xSubKey
->setLongValue(123456789);
235 xSubKey
= xKey
->createKey(OUString( RTL_CONSTASCII_USTRINGPARAM("SecondSubKey") ));
236 xSubKey
->setAsciiValue(OUString( RTL_CONSTASCII_USTRINGPARAM("ich bin ein acsii value") ));
238 xSubKey
= xKey
->createKey(OUString( RTL_CONSTASCII_USTRINGPARAM("ThirdSubKey") ));
239 xSubKey
->setStringValue(OUString( RTL_CONSTASCII_USTRINGPARAM("ich bin ein unicode value") ));
241 xSubKey
= xKey
->createKey(OUString( RTL_CONSTASCII_USTRINGPARAM("FourthSubKey") ));
242 Sequence
<sal_Int8
> aSeq((sal_Int8
*)"ich bin ein binary value", 25);
243 xSubKey
->setBinaryValue(aSeq
);
245 Sequence
<OUString
> seqNames
= xKey
->getKeyNames();
246 Sequence
< Reference
<XRegistryKey
> > seqKeys
= xKey
->openKeys();
249 for (sal_Int32 i
=0; i
< seqNames
.getLength(); i
++)
251 name
= seqNames
.getArray()[i
];
252 xSubKey
= seqKeys
.getArray()[i
];
254 if (name
== OUString( RTL_CONSTASCII_USTRINGPARAM("/FirstKey/FirstSubKey") ))
256 TEST_ENSHURE( xSubKey
->getLongValue() == 123456789,
257 "test_SimpleRegistry error 10" );
259 if (name
== OUString( RTL_CONSTASCII_USTRINGPARAM("/FirstKey/SecondSubKey") ))
261 TEST_ENSHURE( xSubKey
->getAsciiValue() == OUString( RTL_CONSTASCII_USTRINGPARAM("ich bin ein acsii value") ),
262 "test_SimpleRegistry error 11" );
264 if (name
== OUString( RTL_CONSTASCII_USTRINGPARAM("/FirstKey/ThirdSubKey") ))
266 TEST_ENSHURE( xSubKey
->getStringValue() == OUString( RTL_CONSTASCII_USTRINGPARAM("ich bin ein unicode value") ),
267 "test_SimpleRegistry error 12" );
269 if (name
== OUString( RTL_CONSTASCII_USTRINGPARAM("/FirstKey/FourthSubKey") ))
271 Sequence
<sal_Int8
> seqByte
= xSubKey
->getBinaryValue();
272 TEST_ENSHURE(!strcmp(((const char*)seqByte
.getArray()), "ich bin ein binary value"),
273 "test_SimpleRegistry error 13" );
276 seqKeys
.getArray()[i
]->closeKey();
281 xRootKey
->deleteKey(OUString( RTL_CONSTASCII_USTRINGPARAM("FirstKey") ));
282 xRootKey
->createKey(OUString( RTL_CONSTASCII_USTRINGPARAM("SecondFirstKey" )));
284 xKey
= xRootKey
->createKey(OUString( RTL_CONSTASCII_USTRINGPARAM("SecondKey") ));
285 sal_Int32 pLongs
[3] = {123, 456, 789};
286 Sequence
<sal_Int32
> seqLongs(pLongs
, 3);
287 xKey
->setLongListValue(seqLongs
);
289 Sequence
<sal_Int32
> seqLongs2
;
290 seqLongs2
= xKey
->getLongListValue();
291 TEST_ENSHURE( seqLongs
.getLength() == 3, "test_SimpleRegistry error 14" );
292 TEST_ENSHURE( seqLongs
.getArray()[0] == 123, "test_SimpleRegistry error 15" );
293 TEST_ENSHURE( seqLongs
.getArray()[1] == 456, "test_SimpleRegistry error 16" );
294 TEST_ENSHURE( seqLongs
.getArray()[2] == 789, "test_SimpleRegistry error 17" );
297 xKey
= xRootKey
->createKey(OUString( RTL_CONSTASCII_USTRINGPARAM("ThirdKey") ));
299 pAscii
[0] = OUString( RTL_CONSTASCII_USTRINGPARAM("Hallo") );
300 pAscii
[1] = OUString( RTL_CONSTASCII_USTRINGPARAM("jetzt komm") );
301 pAscii
[2] = OUString( RTL_CONSTASCII_USTRINGPARAM("ich") );
303 Sequence
<OUString
> seqAscii(pAscii
, 3);
304 xKey
->setAsciiListValue(seqAscii
);
306 Sequence
<OUString
> seqAscii2
;
307 seqAscii2
= xKey
->getAsciiListValue();
308 TEST_ENSHURE( seqAscii2
.getLength() == 3, "test_SimpleRegistry error 18" );
309 TEST_ENSHURE( seqAscii2
.getArray()[0] == OUString( RTL_CONSTASCII_USTRINGPARAM("Hallo") ), "test_SimpleRegistry error 19");
310 TEST_ENSHURE( seqAscii2
.getArray()[1] == OUString( RTL_CONSTASCII_USTRINGPARAM("jetzt komm") ), "test_SimpleRegistry error 20");
311 TEST_ENSHURE( seqAscii2
.getArray()[2] == OUString( RTL_CONSTASCII_USTRINGPARAM("ich") ), "test_SimpleRegistry error 21");
313 xKey
= xRootKey
->createKey(OUString( RTL_CONSTASCII_USTRINGPARAM("FourthKey") ));
314 OUString pUnicode
[3];
315 pUnicode
[0] = OUString( RTL_CONSTASCII_USTRINGPARAM("Hallo") );
316 pUnicode
[1] = OUString( RTL_CONSTASCII_USTRINGPARAM("jetzt komm") );
317 pUnicode
[2] = OUString( RTL_CONSTASCII_USTRINGPARAM("ich als unicode") );
319 Sequence
<OUString
> seqUnicode(pUnicode
, 3);
320 xKey
->setStringListValue(seqUnicode
);
322 Sequence
<OUString
> seqUnicode2
;
323 seqUnicode2
= xKey
->getStringListValue();
324 TEST_ENSHURE( seqUnicode2
.getLength() == 3, "test_SimpleRegistry error 22" );
325 TEST_ENSHURE( seqUnicode2
.getArray()[0] == OUString( RTL_CONSTASCII_USTRINGPARAM("Hallo") ), "test_SimpleRegistry error 23");
326 TEST_ENSHURE( seqUnicode2
.getArray()[1] == OUString( RTL_CONSTASCII_USTRINGPARAM("jetzt komm") ), "test_SimpleRegistry error 24");
327 TEST_ENSHURE( seqUnicode2
.getArray()[2] == OUString( RTL_CONSTASCII_USTRINGPARAM("ich als unicode") ), "test_SimpleRegistry error 25");
330 xReg
->open(testreg2
, sal_False
, sal_True
);
331 TEST_ENSHURE( xReg
->isValid() != sal_False
, "test_SimpleRegistry error 25" );
332 xRootKey
= xReg
->getRootKey();
333 xKey
= xRootKey
->createKey(OUString( RTL_CONSTASCII_USTRINGPARAM("ThirdKey/FirstSubKey/WithSubSubKey") ));
336 xRootKey
->createLink(
337 OUString( RTL_CONSTASCII_USTRINGPARAM("LinkTest") ),
338 OUString( RTL_CONSTASCII_USTRINGPARAM("/ThirdKey/FirstSubKey/WithSubSubKey") )),
339 "test_SimpleRegistry error 1212" );
340 xRootKey
->closeKey();
343 xReg
->open(testreg
, sal_False
, sal_False
);
344 TEST_ENSHURE( xReg
->isValid() != sal_False
, "test_SimpleRegistry error 26" );
346 if (bMergeDifferently
)
355 xReg
->mergeKey(OUString(), testreg2
);
358 xRootKey
= xReg
->getRootKey();
359 xKey
= xRootKey
->openKey( OUString( RTL_CONSTASCII_USTRINGPARAM("LinkTest") ) );
361 xKey
.is() && xKey
->isValid() &&
362 xKey
->getKeyName().equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("/ThirdKey/FirstSubKey/WithSubSubKey") ),
363 "test_SimpleRegistry error 1213" );
366 xRootKey
->getKeyType( OUString( RTL_CONSTASCII_USTRINGPARAM("LinkTest") ) ) ==
367 registry::RegistryKeyType_LINK
,
368 "test_SimpleRegistry error 1214" );
370 xKey
= xRootKey
->openKey(OUString( RTL_CONSTASCII_USTRINGPARAM("FirstKey/SecondSubKey") ));
371 TEST_ENSHURE( !xKey
.is(), "test_SimpleRegistry error 27" );
374 xKey
= xRootKey
->createKey(OUString( RTL_CONSTASCII_USTRINGPARAM("FifthKey") ));
375 xKey
->createLink(OUString( RTL_CONSTASCII_USTRINGPARAM("MyFirstLink") ),
376 OUString( RTL_CONSTASCII_USTRINGPARAM("/ThirdKey/FirstSubKey") ));
378 xKey
= xRootKey
->openKey(OUString( RTL_CONSTASCII_USTRINGPARAM("/FifthKey/MyFirstLink") ));
379 TEST_ENSHURE( xKey
->isValid(), "test_SimpleRegistry error 27" );
380 TEST_ENSHURE( xKey
->getKeyName() == OUString( RTL_CONSTASCII_USTRINGPARAM("/ThirdKey/FirstSubKey") ), "test_SimpleRegistry error 28" );
382 xKey
->createLink(OUString( RTL_CONSTASCII_USTRINGPARAM("/WithSubSubKey/MyFourthLink") ),
383 OUString( RTL_CONSTASCII_USTRINGPARAM("/FourthKey/MySecondLink") ));
385 TEST_ENSHURE( xKey
->getLinkTarget(OUString( RTL_CONSTASCII_USTRINGPARAM("/WithSubSubKey/MyFourthLink") ))
386 == OUString( RTL_CONSTASCII_USTRINGPARAM("/FourthKey/MySecondLink") ), "test_SimpleRegistry error 29" );
390 TEST_ENSHURE( xKey
->getResolvedName(OUString( RTL_CONSTASCII_USTRINGPARAM("/WithSubSubKey/MyFourthLink/BlaBlaBla") ))
391 == OUString( RTL_CONSTASCII_USTRINGPARAM("/FourthKey/MySecondLink/BlaBlaBla") ), "test_SimpleRegistry error 30" );
393 catch(InvalidRegistryException
&)
397 xRootKey
->createLink(OUString( RTL_CONSTASCII_USTRINGPARAM("/FourthKey/MySecondLink") ),
398 OUString( RTL_CONSTASCII_USTRINGPARAM("/SixthKey/MyThirdLink") ));
399 xKey
= xRootKey
->createKey(OUString( RTL_CONSTASCII_USTRINGPARAM("SixthKey") ));
400 xKey
->createLink(OUString( RTL_CONSTASCII_USTRINGPARAM("MyThirdLink") ),
401 OUString( RTL_CONSTASCII_USTRINGPARAM("/FourthKey/MySecondLink") ));
403 xKey
= xRootKey
->createKey(OUString( RTL_CONSTASCII_USTRINGPARAM("/SixthKey/SixthSubKey") ));
407 xRootKey
->openKey(OUString( RTL_CONSTASCII_USTRINGPARAM("/FifthKey/MyFirstLink/WithSubSubKey/MyFourthLink") ));
409 catch(InvalidRegistryException
&)
413 TEST_ENSHURE( xRootKey
->getLinkTarget(OUString( RTL_CONSTASCII_USTRINGPARAM("/FifthKey/MyFirstLink/WithSubSubKey/MyFourthLink") ))
414 == OUString( RTL_CONSTASCII_USTRINGPARAM("/FourthKey/MySecondLink") ), "test_SimpleRegistry error 31" );
416 xRootKey
->deleteLink(OUString( RTL_CONSTASCII_USTRINGPARAM("/FifthKey/MyFirstLink/WithSubSubKey/MyFourthLink") ));
418 xRootKey
->createLink(OUString( RTL_CONSTASCII_USTRINGPARAM("/FourthKey/MySecondLink") ),
419 OUString( RTL_CONSTASCII_USTRINGPARAM("/ThirdKey/FirstSubKey/WithSubSubKey") ));
421 xKey
= xRootKey
->openKey(OUString( RTL_CONSTASCII_USTRINGPARAM("SixthKey") ));
422 seqNames
= xKey
->getKeyNames();
423 seqKeys
= xKey
->openKeys();
425 TEST_ENSHURE( seqNames
.getArray()[0] == OUString( RTL_CONSTASCII_USTRINGPARAM("/SixthKey/SixthSubKey") ),
426 "test_SimpleRegistry error 32" );
427 TEST_ENSHURE( seqNames
.getArray()[1] == OUString( RTL_CONSTASCII_USTRINGPARAM("/SixthKey/MyThirdLink") ),
428 "test_SimpleRegistry error 33" );
430 TEST_ENSHURE( seqKeys
.getArray()[0]->getKeyName() == OUString( RTL_CONSTASCII_USTRINGPARAM("/SixthKey/SixthSubKey") ),
431 "test_SimpleRegistry error 34" );
432 TEST_ENSHURE( seqKeys
.getArray()[1]->getKeyName() == OUString( RTL_CONSTASCII_USTRINGPARAM("/ThirdKey/FirstSubKey/WithSubSubKey") ),
433 "test_SimpleRegistry error 35" );
435 xRootKey
->deleteLink(OUString( RTL_CONSTASCII_USTRINGPARAM("/FourthKey/MySecondLink") ));
436 xRootKey
->closeKey();
438 catch(InvalidRegistryException
&)
440 TEST_ENSHURE(0, "exception InvalidRegistryExcption raised while doing test_SimpleRegistry");
442 catch(InvalidValueException
&)
444 TEST_ENSHURE(0, "exception InvalidValueExcption raised while doing test_SimpleRegistry()");
449 printf("Test SimpleRegistry, OK!\n");
453 void test_DefaultRegistry(
454 OUString
const & testreg
,
455 OUString
const & testreg2
,
456 bool bMergeDifferently
= false )
458 // Test NestedRegistry
459 OUString
exePath( getExePath() );
460 OUString
userRdb(exePath
);
461 OUString
applicatRdb(exePath
);
463 userRdb
+= OUString::createFromAscii("user.rdb");
464 applicatRdb
+= OUString::createFromAscii("stoctest.rdb");
466 Reference
< XMultiServiceFactory
> rSMgr
= ::cppu::createRegistryServiceFactory( userRdb
, applicatRdb
, sal_False
, OUString());
467 //OUString::createFromAscii("//./e:/src596/stoc/wntmsci3/bin") );
469 Reference
< XPropertySet
> xPropSet( rSMgr
, UNO_QUERY
);
470 TEST_ENSHURE( xPropSet
.is(), "test_DefaultRegistry error0");
472 Any
aPropertyAny( xPropSet
->getPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("Registry")) ) );
473 TEST_ENSHURE( aPropertyAny
.hasValue(), "test_DefaultRegistry error1");
475 Reference
<XSimpleRegistry
> xReg
;
476 aPropertyAny
>>= xReg
;
477 TEST_ENSHURE( xReg
.is(), "test_DefaultRegistry error1a");
479 Reference
<XServiceInfo
> xServInfo( Reference
<XServiceInfo
>::query(xReg
) );
481 TEST_ENSHURE( xServInfo
.is(), "test_DefaultRegistry error2");
483 TEST_ENSHURE( xServInfo
->getImplementationName() == OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.stoc.NestedRegistry") ), "test_DefualtRegistry error3");
484 TEST_ENSHURE( xServInfo
->supportsService(OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.registry.NestedRegistry") )), "test_DefaultRegistry error4");
485 TEST_ENSHURE( xServInfo
->getSupportedServiceNames().getLength() == 1, "test_DefaultRegistry error5");
488 TEST_ENSHURE( xReg
.is(), "test_DefaultRegistry error6");
492 Reference
<XRegistryKey
> xRootKey(xReg
->getRootKey());
494 Reference
<XRegistryKey
> xKey
= xRootKey
->openKey(OUString( RTL_CONSTASCII_USTRINGPARAM("/UCR/com/sun/star/registry/XSimpleRegistry") ));
496 TEST_ENSHURE( xKey
->getKeyName() == OUString( RTL_CONSTASCII_USTRINGPARAM("/UCR/com/sun/star/registry/XSimpleRegistry") ),
497 "test_DefaultRegistry error 7" );
499 if (bMergeDifferently
)
503 OUString( RTL_CONSTASCII_USTRINGPARAM("Test") ),
508 xReg
->mergeKey(OUString( RTL_CONSTASCII_USTRINGPARAM("Test") ), testreg
);
511 xKey
= xRootKey
->openKey(OUString( RTL_CONSTASCII_USTRINGPARAM("Test/ThirdKey/FirstSubKey/WithSubSubKey") ));
513 xKey
->setLongValue(123456789);
515 xKey
= xRootKey
->openKey(OUString( RTL_CONSTASCII_USTRINGPARAM("Test/ThirdKey/FirstSubKey") ));
518 xKey
->createKey(OUString( RTL_CONSTASCII_USTRINGPARAM("SecondSubSubKey") ));
520 Sequence
<OUString
> seqNames
= xKey
->getKeyNames();
522 TEST_ENSHURE( seqNames
.getLength() == 2, "test_DefaultRegistry error 8" );
525 xKey
= xRootKey
->openKey(OUString( RTL_CONSTASCII_USTRINGPARAM("/Test/ThirdKey") ));
528 RegistryValueType valueType
= xKey
->getValueType();
529 TEST_ENSHURE( valueType
== RegistryValueType_ASCIILIST
, "test_DefaultRegistry error 9" );
531 Sequence
<OUString
> seqValue
= xKey
->getAsciiListValue();
533 TEST_ENSHURE( seqValue
.getLength() == 3, "test_DefaultRegistry error 10" );
534 TEST_ENSHURE( seqValue
.getArray()[0] == OUString( RTL_CONSTASCII_USTRINGPARAM("Hallo") ),
535 "test_DefaultRegistry error 11" );
536 TEST_ENSHURE( seqValue
.getArray()[1] == OUString( RTL_CONSTASCII_USTRINGPARAM("jetzt komm") ),
537 "test_DefaultRegistry error 12" );
538 TEST_ENSHURE( seqValue
.getArray()[2] == OUString( RTL_CONSTASCII_USTRINGPARAM("ich") ),
539 "test_DefaultRegistry error 13" );
541 Sequence
<sal_Int32
> seqLong(3);
542 seqLong
.getArray()[0] = 1234;
543 seqLong
.getArray()[1] = 4567;
544 seqLong
.getArray()[2] = 7890;
546 xKey
->setLongListValue(seqLong
);
548 Sequence
<sal_Int32
> seqLongValue
= xKey
->getLongListValue();
550 TEST_ENSHURE( seqLongValue
.getLength() == 3, "test_DefaultRegistry error 14" );
551 TEST_ENSHURE( seqLongValue
.getArray()[0] == 1234, "test_DefaultRegistry error 15" );
552 TEST_ENSHURE( seqLongValue
.getArray()[1] == 4567, "test_DefaultRegistry error 16" );
553 TEST_ENSHURE( seqLongValue
.getArray()[2] == 7890, "test_DefaultRegistry error 17" );
557 xKey
= xRootKey
->createKey(OUString( RTL_CONSTASCII_USTRINGPARAM("/Test/FifthKey") ));
558 xKey
->createLink(OUString( RTL_CONSTASCII_USTRINGPARAM("MyFirstLink") ),
559 OUString( RTL_CONSTASCII_USTRINGPARAM("/Test/ThirdKey/FirstSubKey") ));
561 xKey
= xRootKey
->openKey(OUString( RTL_CONSTASCII_USTRINGPARAM("/Test/FifthKey/MyFirstLink") ));
562 TEST_ENSHURE( xKey
->isValid(), "test_DefaultRegistry error 18" );
563 TEST_ENSHURE( xKey
->getKeyName() == OUString( RTL_CONSTASCII_USTRINGPARAM("/Test/ThirdKey/FirstSubKey") ),
564 "test_DefaultRegistry error 19" );
566 xKey
->createLink(OUString( RTL_CONSTASCII_USTRINGPARAM("/WithSubSubKey/MyFourthLink") ),
567 OUString( RTL_CONSTASCII_USTRINGPARAM("/Test/FourthKey/MySecondLink") ));
569 TEST_ENSHURE( xKey
->getLinkTarget(OUString( RTL_CONSTASCII_USTRINGPARAM("/WithSubSubKey/MyFourthLink") ))
570 == OUString( RTL_CONSTASCII_USTRINGPARAM("/Test/FourthKey/MySecondLink") ),
571 "test_DefaultRegistry error 20" );
575 TEST_ENSHURE( xKey
->getResolvedName(OUString( RTL_CONSTASCII_USTRINGPARAM("/WithSubSubKey/MyFourthLink/BlaBlaBla") ))
576 == OUString( RTL_CONSTASCII_USTRINGPARAM("/Test/FourthKey/MySecondLink/BlaBlaBla") ),
577 "test_DefaultRegistry error 21" );
579 catch(InvalidRegistryException
&)
583 xRootKey
->createLink(OUString( RTL_CONSTASCII_USTRINGPARAM("/Test/FourthKey/MySecondLink") ),
584 OUString( RTL_CONSTASCII_USTRINGPARAM("/Test/SixthKey/MyThirdLink") ));
585 xKey
= xRootKey
->createKey(OUString( RTL_CONSTASCII_USTRINGPARAM("/Test/SixthKey") ));
586 xKey
->createLink(OUString( RTL_CONSTASCII_USTRINGPARAM("MyThirdLink") ),
587 OUString( RTL_CONSTASCII_USTRINGPARAM("/Test/FourthKey/MySecondLink") ));
591 xRootKey
->openKey(OUString( RTL_CONSTASCII_USTRINGPARAM("/Test/FifthKey/MyFirstLink/WithSubSubKey/MyFourthLink") ));
593 catch(InvalidRegistryException
&)
595 printf("test InvalidRegistryExcption OK!\n");
598 TEST_ENSHURE( xRootKey
->getLinkTarget(OUString( RTL_CONSTASCII_USTRINGPARAM("/Test/FifthKey/MyFirstLink/WithSubSubKey/MyFourthLink") ))
599 == OUString( RTL_CONSTASCII_USTRINGPARAM("/Test/FourthKey/MySecondLink") ),
600 "test_DefaultRegistry error 22" );
602 xRootKey
->deleteLink(OUString( RTL_CONSTASCII_USTRINGPARAM("/Test/FifthKey/MyFirstLink/WithSubSubKey/MyFourthLink") ));
604 xKey
= xRootKey
->openKey(OUString( RTL_CONSTASCII_USTRINGPARAM("/Test/DefaultLink/SecondSubSubKey") ));
607 TEST_ENSHURE( xKey
->getKeyName() == OUString( RTL_CONSTASCII_USTRINGPARAM("/Test/ThirdKey/FirstSubKey/SecondSubSubKey") ), "test_DefaultRegistry error 23" );
609 xKey
= xRootKey
->createKey(OUString( RTL_CONSTASCII_USTRINGPARAM("/Test/DefaultLink/ThirdSubSubKey") ));
612 TEST_ENSHURE( xKey
->getKeyName() == OUString( RTL_CONSTASCII_USTRINGPARAM("/Test/ThirdKey/FirstSubKey/ThirdSubSubKey") ),
613 "test_DefaultRegistry error 24" );
616 xKey
= xRootKey
->openKey(OUString( RTL_CONSTASCII_USTRINGPARAM("Test") ));
617 TEST_ENSHURE( xKey
->isValid(), "test_DefaultRegistry error 25" );
619 xRootKey
->deleteKey(OUString( RTL_CONSTASCII_USTRINGPARAM("Test") ));
621 if (bMergeDifferently
)
625 OUString( RTL_CONSTASCII_USTRINGPARAM("AllFromTestreg2") ),
630 xReg
->mergeKey(OUString( RTL_CONSTASCII_USTRINGPARAM("AllFromTestreg2") ),
634 xKey
= xRootKey
->openKey(OUString( RTL_CONSTASCII_USTRINGPARAM("/AllFromTestreg2/ThirdKey/FirstSubKey") ));
637 xRootKey
->deleteKey(OUString( RTL_CONSTASCII_USTRINGPARAM("/AllFromTestreg2") ));
641 catch(InvalidRegistryException
&)
643 TEST_ENSHURE(0, "exception InvalidRegistryExcption raised while doing test_DefaultRegistry");
645 catch(InvalidValueException
&)
647 TEST_ENSHURE(0, "exception InvalidValueExcption raised while doing test_DefaultRegistry()");
653 catch(InvalidRegistryException
& e
)
656 TEST_ENSHURE(0, OUStringToOString(e
.Message
,RTL_TEXTENCODING_ASCII_US
).getStr());
663 Reference
< ::com::sun::star::lang::XComponent
> xComp( rSMgr
, UNO_QUERY
);
664 OSL_ENSURE( xComp
.is(), "### serivce manager has to implement XComponent!" );
667 printf("Test DefaultRegistry, OK!\n");
673 // setStarUserRegistry();
674 setLinkInDefaultRegistry(OUString::createFromAscii("/Test/DefaultLink"),
675 OUString::createFromAscii("/Test/FifthKey/MyFirstLink"));
677 OUString
reg1( RTL_CONSTASCII_USTRINGPARAM("testreg1.rdb") );
678 OUString
reg2( RTL_CONSTASCII_USTRINGPARAM("testreg2.rdb") );
679 OUString
areg1( RTL_CONSTASCII_USTRINGPARAM("atestreg1.rdb") );
680 OUString
areg2( RTL_CONSTASCII_USTRINGPARAM("atestreg2.rdb") );
682 test_SimpleRegistry( reg1
, reg2
);
683 test_DefaultRegistry( reg1
, reg2
);
684 test_SimpleRegistry( areg1
, areg2
, true ); // use different merge
685 test_DefaultRegistry( areg1
, areg2
, true );
687 Reference
< XSimpleRegistry
> xSimReg( ::cppu::createSimpleRegistry() );
688 xSimReg
->open( reg1
, sal_False
, sal_True
);
690 xSimReg
->open( reg2
, sal_False
, sal_True
);
692 xSimReg
->open( areg1
, sal_False
, sal_True
);
694 xSimReg
->open( areg2
, sal_False
, sal_True
);