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