/registry/test/testregcpp.cxx
C++ | 701 lines | 503 code | 165 blank | 33 comment | 43 complexity | c1e24db0e87ad97d6a2a818b91ffe5c4 MD5 | raw file
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2/* 3 * This file is part of the LibreOffice project. 4 * 5 * This Source Code Form is subject to the terms of the Mozilla Public 6 * License, v. 2.0. If a copy of the MPL was not distributed with this 7 * file, You can obtain one at http://mozilla.org/MPL/2.0/. 8 * 9 * This file incorporates work covered by the following license notice: 10 * 11 * Licensed to the Apache Software Foundation (ASF) under one or more 12 * contributor license agreements. See the NOTICE file distributed 13 * with this work for additional information regarding copyright 14 * ownership. The ASF licenses this file to you under the Apache 15 * License, Version 2.0 (the "License"); you may not use this file 16 * except in compliance with the License. You may obtain a copy of 17 * the License at http://www.apache.org/licenses/LICENSE-2.0 . 18 */ 19 20 21#include <iostream> 22#include <stdio.h> 23#include <string.h> 24 25#include "registry/registry.hxx" 26#include "registry/reflread.hxx" 27#include "registry/reflwrit.hxx" 28#include "regdiagnose.h" 29#include <rtl/alloc.h> 30#include <rtl/ustring.hxx> 31 32using namespace std; 33 34using ::rtl::OUString; 35using ::rtl::OUStringToOString; 36using ::rtl::OString; 37 38void test_coreReflection() 39{ 40 Registry *myRegistry = new Registry(); 41 42 RegistryKey rootKey, key1, key2, key3, key4 ,key5, key6, key7, key8; 43 44 REG_ENSURE(!myRegistry->create(OUString("ucrtest.rdb")), "testCoreReflection error 1"); 45 REG_ENSURE(!myRegistry->openRootKey(rootKey), "testCoreReflection error 2"); 46 47 REG_ENSURE(!rootKey.createKey(OUString("UCR"), key1), "testCoreReflection error 3"); 48 REG_ENSURE(!key1.createKey(OUString("ModuleA"), key2), "testCoreReflection error 4"); 49 REG_ENSURE(!key2.createKey(OUString("StructA"), key3), "testCoreReflection error 5"); 50 REG_ENSURE(!key2.createKey(OUString("EnumA"), key4), "testCoreReflection error 6"); 51 REG_ENSURE(!key2.createKey(OUString("XInterfaceA"), key5), "testCoreReflection error 7"); 52 REG_ENSURE(!key2.createKey(OUString("ExceptionA"), key6), "testCoreReflection error 8"); 53 REG_ENSURE(!key2.createKey(OUString("ServiceA"), key7), "testCoreReflection error 8a"); 54 REG_ENSURE(!key2.createKey(OUString("ConstantsA"), key8), "testCoreReflection error 8b"); 55 56 { 57 RegistryTypeWriter writer(RT_TYPE_MODULE, 58 OUString("ModuleA"), 59 OUString(), 11, 0, 0); 60 61 RTConstValue aConst; 62 63 writer.setDoku(OUString("Hallo ich bin ein Modul")); 64 writer.setFileName(OUString("DummyFile")); 65 66 aConst.m_type = RT_TYPE_BOOL; 67 aConst.m_value.aBool = sal_True; 68 writer.setFieldData(0, OUString("aConstBool"), 69 OUString("boolean"), 70 OUString("ich bin ein boolean"), 71 OUString("DummyFile"), RT_ACCESS_CONST, aConst); 72 aConst.m_type = RT_TYPE_BYTE; 73 aConst.m_value.aByte = 127; 74 writer.setFieldData(1, OUString("aConstByte"), 75 OUString("byte"), 76 OUString("ich bin ein byte"), 77 OUString("DummyFile"), RT_ACCESS_CONST, aConst); 78 aConst.m_type = RT_TYPE_INT16; 79 aConst.m_value.aShort = -10; 80 writer.setFieldData(2, OUString("aConstShort"), 81 OUString("short"), 82 OUString("ich bin ein short"), 83 OUString("DummyFile"), RT_ACCESS_CONST, aConst); 84 aConst.m_type = RT_TYPE_UINT16; 85 aConst.m_value.aUShort = 10; 86 writer.setFieldData(3, OUString("aConstUShort"), 87 OUString("unsigned short"), 88 OUString("ich bin ein unsigned short"), 89 OUString("DummyFile"), RT_ACCESS_CONST, aConst); 90 aConst.m_type = RT_TYPE_INT32; 91 aConst.m_value.aLong = -100000; 92 writer.setFieldData(4, OUString("aConstLong"), 93 OUString("long"), 94 OUString("ich bin ein long"), 95 OUString("DummyFile"), RT_ACCESS_CONST, aConst); 96 aConst.m_type = RT_TYPE_UINT32; 97 aConst.m_value.aULong = 100000; 98 writer.setFieldData(5, OUString("aConstULong"), 99 OUString("unsigned long"), 100 OUString("ich bin ein unsigned long"), 101 OUString("DummyFile"), RT_ACCESS_CONST, aConst); 102 aConst.m_type = RT_TYPE_INT64; 103 aConst.m_value.aHyper = -100000000; 104 writer.setFieldData(6, OUString("aConstHyper"), 105 OUString("hyper"), 106 OUString("ich bin ein hyper"), 107 OUString("DummyFile"), RT_ACCESS_CONST, aConst); 108 aConst.m_type = RT_TYPE_UINT64; 109 aConst.m_value.aUHyper = 100000000; 110 writer.setFieldData(7, OUString("aConstULong"), 111 OUString("unsigned long"), 112 OUString("ich bin ein unsigned long"), 113 OUString("DummyFile"), RT_ACCESS_CONST, aConst); 114 aConst.m_type = RT_TYPE_FLOAT; 115 aConst.m_value.aFloat = -2e-10f; 116 writer.setFieldData(8, OUString("aConstFloat"), 117 OUString("float"), 118 OUString("ich bin ein float"), 119 OUString("DummyFile"), RT_ACCESS_CONST, aConst); 120 aConst.m_type = RT_TYPE_DOUBLE; 121 aConst.m_value.aDouble = -2e-100; writer.setFieldData(9, OUString("aConstDouble"), 122 OUString("double"), 123 OUString("ich bin ein double"), 124 OUString("DummyFile"), RT_ACCESS_CONST, aConst); 125 aConst.m_type = RT_TYPE_STRING; 126 OUString tmpStr("dies ist ein unicode string"); 127 aConst.m_value.aString = tmpStr.getStr(); 128 129 writer.setFieldData(10, OUString("aConstString"), 130 OUString("string"), 131 OUString("ich bin ein string"), 132 OUString("DummyFile"), RT_ACCESS_CONST, aConst); 133 134 const sal_uInt8* pBlop = writer.getBlop(); 135 sal_uInt32 aBlopSize = writer.getBlopSize(); 136 137 REG_ENSURE(!key2.setValue(OUString(), RG_VALUETYPE_BINARY, (void*)pBlop, aBlopSize), "testCoreReflection error 9"); 138 139 sal_uInt8* readBlop = (sal_uInt8*)rtl_allocateMemory(aBlopSize); 140 REG_ENSURE(!key2.getValue(OUString(), (void*)readBlop) , "testCoreReflection error 9a"); 141 142 RegistryTypeReader reader(readBlop, aBlopSize, sal_True); 143 144 if (reader.isValid()) 145 { 146 REG_ENSURE(reader.getTypeName() == "ModuleA", "testCoreReflection error 9a2"); 147 148 RTConstValue aReadConst = reader.getFieldConstValue(4); 149 REG_ENSURE( aReadConst.m_type == RT_TYPE_INT32, "testCoreReflection error 9a3"); 150 REG_ENSURE( aReadConst.m_value.aLong == -100000, "testCoreReflection error 9a4"); 151 152 aReadConst = reader.getFieldConstValue(6); 153 REG_ENSURE( aReadConst.m_type == RT_TYPE_INT64, "testCoreReflection error 9a5"); 154 REG_ENSURE( aReadConst.m_value.aHyper == -100000000, "testCoreReflection error 9a6"); 155 156 aReadConst = reader.getFieldConstValue(10); 157 OString aConstStr = OUStringToOString(aConst.m_value.aString, RTL_TEXTENCODING_ASCII_US); 158 REG_ENSURE(aConstStr.equals("dies ist ein unicode string"), "testCoreReflection error 9b"); 159 } 160 161 } 162 163 { 164 RegistryTypeWriter writer(RT_TYPE_STRUCT, 165 OUString("ModuleA/StructA"), 166 OUString(), 3, 0, 0); 167 168 writer.setDoku(OUString("Hallo ich bin eine Struktur")); 169 writer.setFileName(OUString("DummyFile")); 170 171 writer.setFieldData(0, OUString("asal_uInt32"), 172 OUString("unsigned long"), 173 OUString(), OUString(), RT_ACCESS_READWRITE); 174 writer.setFieldData(1, OUString("aXInterface"), 175 OUString("stardiv/uno/XInterface"), 176 OUString(), OUString(), RT_ACCESS_READWRITE); 177 writer.setFieldData(2, OUString("aSequence"), 178 OUString("[]ModuleA/EnumA"), 179 OUString(), OUString(), RT_ACCESS_READWRITE); 180 181 const sal_uInt8* pBlop = writer.getBlop(); 182 sal_uInt32 aBlopSize = writer.getBlopSize(); 183 184 REG_ENSURE(!key3.setValue(OUString(), RG_VALUETYPE_BINARY, (void*)pBlop, aBlopSize), "testCoreReflection error 9a"); 185 } 186 187 { 188 RegistryTypeWriter writer(RT_TYPE_ENUM, 189 OUString("ModuleA/EnumA"), 190 OUString(), 2, 0, 0); 191 192 RTConstValue aConst; 193 194 aConst.m_type = RT_TYPE_UINT32; 195 aConst.m_value.aULong = 10; 196 197 writer.setDoku(OUString("Hallo ich bin ein Enum")); 198 writer.setFileName(OUString("DummyFile")); 199 200 writer.setFieldData(0, OUString("ENUM_VAL_1"), 201 OUString(), OUString("ich bin ein enum value"), 202 OUString(), RT_ACCESS_CONST, aConst); 203 204 aConst.m_value.aULong = 10; 205 writer.setFieldData(1, OUString("ENUM_VAL_2"), 206 OUString(), OUString(), OUString(), RT_ACCESS_CONST, aConst); 207 208 const sal_uInt8* pBlop = writer.getBlop(); 209 sal_uInt32 aBlopSize = writer.getBlopSize(); 210 211 REG_ENSURE(!key4.setValue(OUString(), RG_VALUETYPE_BINARY, (void*)pBlop, aBlopSize), "testCoreReflection error 9b"); 212 } 213 214 { 215 RegistryTypeWriter writer(RT_TYPE_INTERFACE, 216 OUString("ModuleA/XInterfaceA"), 217 OUString("stardiv/uno/XInterface"), 218 4, 1, 0); 219 RTConstValue aConst; 220 221 RTUik aUik = {1,2,3,4,5}; 222 223 writer.setUik(aUik); 224 writer.setDoku(OUString("Hallo ich bin ein Interface")); 225 writer.setFileName(OUString("DummyFile")); 226 227 writer.setFieldData(0, OUString("aString"), 228 OUString("string"), OUString(), OUString(), RT_ACCESS_READWRITE); 229 writer.setFieldData(1, OUString("aStruct"), 230 OUString("ModuleA/StructA"), 231 OUString(), OUString(), RT_ACCESS_READONLY); 232 writer.setFieldData(2, OUString("aEnum"), 233 OUString("ModuleA/EnumA"), OUString(), OUString(), RT_ACCESS_BOUND); 234 aConst.m_type = RT_TYPE_UINT16; 235 aConst.m_value.aUShort = 12; 236 writer.setFieldData(3, OUString("aConstUShort"), 237 OUString("unsigned short"), OUString(), 238 OUString("DummyFile"), RT_ACCESS_CONST, aConst); 239 240 writer.setMethodData(0, OUString("methodA"), 241 OUString("double"), RT_MODE_TWOWAY, 2, 1, 242 OUString("Hallo ich bin die methodA")); 243 writer.setParamData(0, 0, OUString("ModuleA/StructA"), 244 OUString("aStruct"), RT_PARAM_IN); 245 writer.setParamData(0, 1, OUString("unsigned short"), 246 OUString("aShort"), RT_PARAM_INOUT); 247 writer.setExcData(0, 0, OUString("ModuleA/ExceptionA")); 248 249 const sal_uInt8* pBlop = writer.getBlop(); 250 sal_uInt32 aBlopSize = writer.getBlopSize(); 251 252 REG_ENSURE(!key5.setValue(OUString(), RG_VALUETYPE_BINARY, (void*)pBlop, aBlopSize), "testCoreReflection error 9c"); 253 254 sal_uInt8* readBlop = (sal_uInt8*)rtl_allocateMemory(aBlopSize); 255 REG_ENSURE(!key5.getValue(OUString(), (void*)readBlop) , "testCoreReflection error 9c1"); 256 257 RegistryTypeReader reader(readBlop, aBlopSize, sal_True); 258 259 if (reader.isValid()) 260 { 261 REG_ENSURE(reader.getTypeName() == "ModuleA/XInterfaceA", "testCoreReflection error 9c2"); 262 263 RTUik retUik; 264 reader.getUik(retUik); 265 REG_ENSURE(retUik.m_Data1 = 1, "testCoreReflection error 9c3"); 266 REG_ENSURE(retUik.m_Data2 = 2, "testCoreReflection error 9c4"); 267 REG_ENSURE(retUik.m_Data3 = 3, "testCoreReflection error 9c5"); 268 REG_ENSURE(retUik.m_Data4 = 4, "testCoreReflection error 9c6"); 269 REG_ENSURE(retUik.m_Data5 = 5, "testCoreReflection error 9c7"); 270 } 271 272 } 273 274 { 275 RegistryTypeWriter writer(RT_TYPE_EXCEPTION, 276 OUString("ModuleA/ExceptionA"), 277 OUString(), 1, 0, 0); 278 279 writer.setDoku(OUString("Hallo ich bin eine Exception")); 280 281 writer.setFieldData(0, OUString("aSource"), 282 OUString("stardiv/uno/XInterface"), 283 OUString("ich bin ein interface member"), 284 OUString(), RT_ACCESS_READWRITE); 285 286 const sal_uInt8* pBlop = writer.getBlop(); 287 sal_uInt32 aBlopSize = writer.getBlopSize(); 288 289 REG_ENSURE(!key6.setValue(OUString(), RG_VALUETYPE_BINARY, (void*)pBlop, aBlopSize), "testCoreReflection error 9d"); 290 } 291 292 { 293 RegistryTypeWriter writer(RT_TYPE_SERVICE, 294 OUString("ModuleA/ServiceA"), 295 OUString(), 1, 0, 4); 296 297 writer.setDoku(OUString("Hallo ich bin ein Service")); 298 writer.setFileName(OUString("DummyFile")); 299 300 writer.setFieldData(0, OUString("aProperty"), 301 OUString("stardiv/uno/XInterface"), 302 OUString("ich bin eine property"), 303 OUString(), RT_ACCESS_READWRITE); 304 305 writer.setReferenceData(0, OUString("ModuleA/XInterfaceA"), RT_REF_SUPPORTS, 306 OUString("Hallo ich eine Reference auf ein supported interface"), 307 RT_ACCESS_OPTIONAL); 308 writer.setReferenceData(1, OUString("ModuleA/XInterfaceA"), RT_REF_OBSERVES, 309 OUString("Hallo ich eine Reference auf ein observed interface")); 310 writer.setReferenceData(2, OUString("ModuleA/ServiceB"), RT_REF_EXPORTS, 311 OUString("Hallo ich eine Reference auf einen exported service")); 312 writer.setReferenceData(3, OUString("ModuleA/ServiceB"), RT_REF_NEEDS, 313 OUString("Hallo ich eine Reference auf einen needed service")); 314 315 const sal_uInt8* pBlop = writer.getBlop(); 316 sal_uInt32 aBlopSize = writer.getBlopSize(); 317 318 REG_ENSURE(!key7.setValue(OUString(), RG_VALUETYPE_BINARY, (void*)pBlop, aBlopSize), "testCoreReflection error 9e"); 319 sal_uInt8* readBlop = (sal_uInt8*)rtl_allocateMemory(aBlopSize); 320 REG_ENSURE(!key7.getValue(OUString(), (void*)readBlop) , "testCoreReflection error 9e2"); 321 322 RegistryTypeReader reader(readBlop, aBlopSize, sal_True); 323 324 if (reader.isValid()) 325 { 326 REG_ENSURE(reader.getTypeName() == "ModuleA/ServiceA", "testCoreReflection error 9e3"); 327 328 sal_uInt32 referenceCount = reader.getReferenceCount(); 329 REG_ENSURE( referenceCount == 4, "testCoreReflection error 9e4"); 330 331 OUString refName = reader.getReferenceName(0); 332 REG_ENSURE(refName == "ModuleA/XInterfaceA", "testCoreReflection error 9e5"); 333 } 334 } 335 336 { 337 RegistryTypeWriter writer(RT_TYPE_CONSTANTS, 338 OUString("ModuleA/ConstansA"), 339 OUString(), 3, 0, 0); 340 341 RTConstValue aConst; 342 343 writer.setDoku(OUString("Hallo ich bin eine Constants Group")); 344 writer.setFileName(OUString("DummyFile")); 345 346 aConst.m_type = RT_TYPE_BOOL; 347 aConst.m_value.aBool = sal_True; 348 writer.setFieldData(0, OUString("ConstantsA_aConstBool"), 349 OUString("boolean"), 350 OUString("ich bin ein boolean"), 351 OUString("DummyFile"), RT_ACCESS_CONST, aConst); 352 aConst.m_type = RT_TYPE_BYTE; 353 aConst.m_value.aByte = 127; 354 writer.setFieldData(1, OUString("ConstantsA_aConstByte"), 355 OUString("byte"), 356 OUString("ich bin ein byte"), 357 OUString("DummyFile"), RT_ACCESS_CONST, aConst); 358 aConst.m_type = RT_TYPE_INT16; 359 aConst.m_value.aShort = -10; 360 writer.setFieldData(2, OUString("ConstantsA_aConstShort"), 361 OUString("short"), 362 OUString("ich bin ein short"), 363 OUString("DummyFile"), RT_ACCESS_CONST, aConst); 364 365 const sal_uInt8* pBlop = writer.getBlop(); 366 sal_uInt32 aBlopSize = writer.getBlopSize(); 367 368 REG_ENSURE(!key8.setValue(OUString(), RG_VALUETYPE_BINARY, (void*)pBlop, aBlopSize), "testCoreReflection error 9f"); 369 } 370 371// REG_ENSURE(!myRegistry->destroy(NULL), "testCoreReflection error 10"); 372 delete myRegistry; 373 374 cout << "test_coreReflection() Ok!\n"; 375} 376 377void test_registry_CppApi() 378{ 379 Registry *myRegistry = new Registry(); 380 381 RegistryKey rootKey, key1, key2, key3, key4 ,key5, key6, key7, key8, key9; 382 383 REG_ENSURE(!myRegistry->create(OUString("test.rdb")), "test_registry_CppApi error 1"); 384 REG_ENSURE(!myRegistry->openRootKey(rootKey), "test_registry_CppApi error 2"); 385 386 REG_ENSURE(!rootKey.createKey(OUString("myFirstKey"), key1), "test_registry_CppApi error 3"); 387 REG_ENSURE(!rootKey.createKey(OUString("mySecondKey"), key2), "test_registry_CppApi error 4"); 388 REG_ENSURE(!key1.createKey(OUString("X"), key3), "test_registry_CppApi error 5"); 389 REG_ENSURE(!key1.createKey(OUString("mySecondSubKey"), key4), "test_registry_CppApi error 6"); 390 REG_ENSURE(!rootKey.createKey(OUString("myThirdKey"), key5), "test_registry_CppApi error 6a"); 391 392 REG_ENSURE(!key5.createKey(OUString("1"), key4), "test_registry_CppApi error 6b"); 393 REG_ENSURE(!key4.createKey(OUString("2"), key3), "test_registry_CppApi error 6c"); 394 REG_ENSURE(!key5.openKey(OUString("1"), key4), "test_registry_CppApi error 6d"); 395 REG_ENSURE(!rootKey.openKey(OUString("/myThirdKey/1"), key4), "test_registry_CppApi error 6e"); 396 REG_ENSURE(key4.getName() == "/myThirdKey/1", "test_registry_CppApi error 6f"); 397 398 REG_ENSURE(!rootKey.createKey(OUString("myFourthKey"), key6), "test_registry_CppApi error 7"); 399 REG_ENSURE(!rootKey.createKey(OUString("myFifthKey"), key6), "test_registry_CppApi error 7a"); 400 REG_ENSURE(!rootKey.createKey(OUString("mySixthKey"), key6), "test_registry_CppApi error 7b"); 401 402 // Link Test 403 // 404 405 REG_ENSURE(!rootKey.createKey(OUString("/myFourthKey/X"), key7), "test_registry_CppApi error 7c)");; 406 REG_ENSURE(!key6.createLink(OUString("myFirstLink"), OUString("/myFourthKey/X")), "test_registry_CppApi error 7d"); 407 REG_ENSURE(!key6.createKey(OUString("mySixthSubKey"), key7), "test_registry_CppApi error 7e"); 408 409 OUString linkTarget; 410 REG_ENSURE(!key6.getLinkTarget(OUString("myFirstLink"), linkTarget), "test_registry_CppApi error 7f"); 411 REG_ENSURE(linkTarget == "/myFourthKey/X", "test_registry_CppApi error 7g"); 412 413 RegistryKeyNames* pSubKeyNames = new RegistryKeyNames(); 414 sal_uInt32 nSubKeys=0; 415 416 REG_ENSURE(!rootKey.getKeyNames(OUString("mySixthKey"), *pSubKeyNames), "test_registry_CppApi error 7h)"); 417 REG_ENSURE(pSubKeyNames->getLength() == 2, "test_registry_CppApi error 7i)"); 418 419 for (sal_uInt32 i=0; i < pSubKeyNames->getLength(); i++) 420 { 421 if ( pSubKeyNames->getElement(i) == "/mySixthKey/myFirstLink" ) 422 { 423 RegKeyType keyType; 424 REG_ENSURE(!rootKey.getKeyType(pSubKeyNames->getElement(i), &keyType), "test_registry_CppApi error 7j"); 425 REG_ENSURE(keyType == RG_LINKTYPE, "test_registry_CppApi error 7k"); 426 } 427 } 428 429 REG_ENSURE(!key7.closeKey(), "test_registry_CppApi error 7k1"); 430 delete pSubKeyNames; 431 432 REG_ENSURE(!rootKey.openKey(OUString("/mySixthKey/myFirstLink"), key6), "test_registry_CppApi error 7l"); 433// REG_ENSURE(key6.getName() == "/myFourthKey/X", "test_registry_CppApi error 7m"); 434 435 REG_ENSURE(!rootKey.openKey(OUString("myFifthKey"), key6), "test_registry_CppApi error 7m1"); 436 REG_ENSURE(!key6.createLink(OUString("mySecondLink"), 437 OUString("/mySixthKey/myFirstLink")), "test_registry_CppApi error 7m2"); 438 439 REG_ENSURE(!rootKey.openKey(OUString("/myFifthKey/mySecondLink"), key6), "test_registry_CppApi error 7m3"); 440// REG_ENSURE(key6.getName() == "/myFourthKey/X", "test_registry_CppApi error 7m4"); 441 442 REG_ENSURE(!rootKey.createKey(OUString("/myFifthKey/mySecondLink/myFirstLinkSubKey"), key7), "test_registry_CppApi error 7m5"); 443 REG_ENSURE(key7.getName() == "/myFourthKey/X/myFirstLinkSubKey", "test_registry_CppApi error 7m6"); 444 445 REG_ENSURE(!key7.createLink(OUString("myThirdLink"), OUString("/myFifthKey/mySecondLink")), "test_registry_CppApi error 7m7"); 446 REG_ENSURE(!rootKey.openKey(OUString("/myFourthKey/X/myFirstLinkSubKey/myThirdLink"), key7), "test_registry_CppApi error 7m8"); 447// REG_ENSURE(!key7.openKey(OUString("/myFirstLinkSubKey/myThirdLink/myFirstLinkSubKey/myThirdLink"), key6), "test_registry_CppApi error 7m9"); 448// REG_ENSURE(key7.getName() == "/myFourthKey/X", "test_registry_CppApi error 7m10"); 449 REG_ENSURE(!key7.closeKey(), "test_registry_CppApi error 7m11"); 450 451 REG_ENSURE(!rootKey.deleteLink(OUString("/myFifthKey/mySecondLink")), "test_registry_CppApi error 7m12"); 452 453 REG_ENSURE(!rootKey.createLink(OUString("/myFifthKey/mySecondLink"), 454 OUString("/myFourthKey/X/myFirstLinkSubKey/myThirdLink")), 455 "test_registry_CppApi error 7m13"); 456 457// REG_ENSURE(rootKey.openKey(OUString("/myFourthKey/X/myFirstLinkSubKey/myThirdLink"), key7) == REG_DETECT_RECURSION, 458// "test_registry_CppApi error 7m14"); 459 460// REG_ENSURE(key7.closeKey() == REG_INVALID_KEY, "test_registry_CppApi error 7m11"); 461 462 RegistryKeyNames subKeyNames; 463 nSubKeys=0; 464 465 REG_ENSURE(!rootKey.getKeyNames(OUString("mySixthKey"), subKeyNames), "test_registry_CppApi error 7n"); 466 467 nSubKeys = subKeyNames.getLength(); 468 REG_ENSURE(nSubKeys == 2, "test_registry_CppApi error 7n1"); 469 REG_ENSURE(subKeyNames.getElement(0) == "/mySixthKey/myFirstLink", "test_registry_CppApi error 7p1)"); 470 REG_ENSURE(subKeyNames.getElement(1) =="/mySixthKey/mySixthSubKey", "test_registry_CppApi error 7p2"); 471 472 473 RegistryKeyArray subKeys; 474 nSubKeys=0; 475 476 REG_ENSURE(!rootKey.openSubKeys(OUString("myFirstKey"), subKeys), "test_registry_CppApi error 7o"); 477 478 nSubKeys = subKeys.getLength(); 479 REG_ENSURE(nSubKeys == 2, "test_registry_CppApi error 7o1"); 480 REG_ENSURE(subKeys.getElement(0).getName() == "/myFirstKey/mySecondSubKey", "test_registry_CppApi error 7p1)"); 481 REG_ENSURE(subKeys.getElement(1).getName() == "/myFirstKey/X", "test_registry_CppApi error 7p2"); 482 483 REG_ENSURE(!rootKey.closeSubKeys(subKeys), "test_registry_CppApi error 7q)"); 484 485 486 REG_ENSURE(!rootKey.createKey(OUString("/TEST"), key8), "test_registry_CppApi error 8"); 487 REG_ENSURE(!rootKey.createKey(OUString("/TEST/Child1"), key8), "test_registry_CppApi error 8a"); 488 REG_ENSURE(!rootKey.createKey(OUString("/TEST/Child2"), key8), "test_registry_CppApi error 8a1"); 489 REG_ENSURE(!rootKey.openKey(OUString("/TEST"), key9), "test_registry_CppApi error 8b"); 490 REG_ENSURE(!key8.closeKey() && !key9.closeKey(), "test_registry_CppApi error 8b1"); 491 REG_ENSURE(!rootKey.openKey(OUString("/TEST"), key8), "test_registry_CppApi error 8b"); 492 REG_ENSURE(!key8.closeKey(), "test_registry_CppApi error 8c"); 493 REG_ENSURE(!rootKey.openKey(OUString("TEST"), key8), "test_registry_CppApi error 8c"); 494 REG_ENSURE(!key8.closeKey(), "test_registry_CppApi error 8d"); 495 496 497 sal_Char* Value=(sal_Char*)"Mein erster Value"; 498 REG_ENSURE(!rootKey.setValue(OUString("mySecondKey"), RG_VALUETYPE_STRING, Value, 18), "test_registry_CppApi error 9"); 499 500 RegValueType valueType; 501 sal_uInt32 valueSize; 502 sal_Char* readValue; 503 REG_ENSURE(!rootKey.getValueInfo(OUString("mySecondKey"), &valueType, &valueSize), "test_registry_CppApi error 9a"); 504 505 readValue = (sal_Char*)rtl_allocateMemory(valueSize); 506 REG_ENSURE(!key2.getValue(OUString(), readValue), "test_registry_CppApi error 10"); 507 508 REG_ENSURE(valueType == RG_VALUETYPE_STRING, "test_registry_CppApi error 11"); 509 REG_ENSURE(valueSize == 18, "test_registry_CppApi error 12"); 510 REG_ENSURE(strcmp(readValue, Value) == 0, "test_registry_CppApi error 13"); 511 rtl_freeMemory(readValue); 512 513 const sal_Char* pList[3]; 514 const sal_Char* n1= "Hallo"; 515 const sal_Char* n2= "jetzt komm"; 516 const sal_Char* n3= "ich"; 517 518 pList[0]=n1; 519 pList[1]=n2; 520 pList[2]=n3; 521 522 REG_ENSURE(!rootKey.setStringListValue(OUString("myFourthKey"), (sal_Char**)pList, 3), "test_registry_CppApi error 13a"); 523 524 RegistryValueList<sal_Char*> valueList; 525 REG_ENSURE(!rootKey.getStringListValue(OUString("myFourthKey"), valueList), "test_registry_CppApi error 13b"); 526 527 REG_ENSURE(strcmp(n1, valueList.getElement(0)) == 0, "test_registry_CppApi error 13c"); 528 REG_ENSURE(strcmp(n2, valueList.getElement(1)) == 0, "test_registry_CppApi error 13d"); 529 REG_ENSURE(strcmp(n3, valueList.getElement(2)) == 0, "test_registry_CppApi error 13e"); 530 531 REG_ENSURE(!rootKey.getValueInfo(OUString("myFourthKey"), &valueType, &valueSize), "test_registry_CppApi error 13e1"); 532 REG_ENSURE(valueType == RG_VALUETYPE_STRINGLIST, "test_registry_CppApi error 13e2"); 533 REG_ENSURE(valueSize == 3, "test_registry_CppApi error 13e3"); 534 535 sal_Int32 pLong[3]; 536 pLong[0] = 123; 537 pLong[1] = 456; 538 pLong[2] = 789; 539 540 REG_ENSURE(!rootKey.setLongListValue(OUString("myFifthKey"), pLong, 3), "test_registry_CppApi error 13f"); 541 542 RegistryValueList<sal_Int32> longList; 543 REG_ENSURE(!rootKey.getLongListValue(OUString("myFifthKey"), longList), "test_registry_CppApi error 13g"); 544 545 REG_ENSURE(pLong[0] == longList.getElement(0), "test_registry_CppApi error 13h"); 546 REG_ENSURE(pLong[1] == longList.getElement(1), "test_registry_CppApi error 13i"); 547 REG_ENSURE(pLong[2] == longList.getElement(2), "test_registry_CppApi error 13j"); 548 549 550 OUString sWTestValue("Mein erster Unicode Value"); 551 const sal_Unicode* wTestValue= sWTestValue.getStr(); 552 REG_ENSURE(!rootKey.setValue(OUString("mySixthKey"), RG_VALUETYPE_UNICODE, (void*)wTestValue, 553 (rtl_ustr_getLength(wTestValue)+1)*sizeof(sal_Unicode)), "test_registry_CppApi error 13j1"); 554 555 REG_ENSURE(!rootKey.getValueInfo(OUString("mySixthKey"), &valueType, &valueSize), "test_registry_CppApi error 13j2"); 556 sal_Unicode* pTmpValue = (sal_Unicode*)rtl_allocateMemory(valueSize); 557 REG_ENSURE(!rootKey.getValue(OUString("mySixthKey"), pTmpValue), "test_registry_CppApi error 13j3"); 558 REG_ENSURE(rtl_ustr_getLength(wTestValue) == rtl_ustr_getLength(pTmpValue), "test_registry_CppApi error 13j4"); 559 REG_ENSURE(rtl_ustr_compare(wTestValue, pTmpValue) == 0, "test_registry_CppApi error 13j4"); 560 561 const sal_Unicode* pUnicode[3]; 562 OUString w1("Hallo"); 563 OUString w2("jetzt komm"); 564 OUString w3("ich als unicode"); 565 566 pUnicode[0]=w1.getStr(); 567 pUnicode[1]=w2.getStr(); 568 pUnicode[2]=w3.getStr(); 569 570 REG_ENSURE(!rootKey.setUnicodeListValue(OUString("mySixthKey"), (sal_Unicode**)pUnicode, 3), "test_registry_CppApi error 13k"); 571 572 RegistryValueList<sal_Unicode*> unicodeList; 573 REG_ENSURE(!rootKey.getUnicodeListValue(OUString("mySixthKey"), unicodeList), "test_registry_CppApi error 13l"); 574 575 REG_ENSURE(rtl_ustr_compare(w1, unicodeList.getElement(0)) == 0, "test_registry_CppApi error 13m"); 576 REG_ENSURE(rtl_ustr_compare(w2, unicodeList.getElement(1)) == 0, "test_registry_CppApi error 13n"); 577 REG_ENSURE(rtl_ustr_compare(w3, unicodeList.getElement(2)) == 0, "test_registry_CppApi error 13o"); 578 579 REG_ENSURE(!key6.closeKey(), "test_registry_CppApi error 14"); 580 581 REG_ENSURE(!key1.closeKey() && 582 !key3.closeKey() && 583 !key4.closeKey(), "test_registry_CppApi error 14"); 584 585 REG_ENSURE(!rootKey.deleteKey(OUString("myFirstKey")), "test_registry_CppApi error 15"); 586 587 REG_ENSURE(!key2.closeKey(), "test_registry_CppApi error 16"); 588 REG_ENSURE(!rootKey.openKey(OUString("mySecondKey"), key2), "test_registry_CppApi error 17"); 589 590 REG_ENSURE(!key5.closeKey(), "test_registry_CppApi error 18"); 591 592 REG_ENSURE(!rootKey.deleteKey(OUString("myThirdKey")), "test_registry_CppApi error 19"); 593 594 REG_ENSURE(rootKey.openKey(OUString("myThirdKey"), key5), "test_registry_CppApi error 20"); 595 596 REG_ENSURE(!key2.closeKey() && 597 !rootKey.closeKey(), "test_registry_CppApi error 21"); 598 599 REG_ENSURE(!myRegistry->close(), "test_registry_CppApi error 22"); 600 601 // Test loadkey 602 RegistryKey rootKey2, key21, key22, key23, key24 , key25; 603 604 REG_ENSURE(!myRegistry->create(OUString("test2.rdb")), "test_registry_CppApi error 23"); 605 REG_ENSURE(!myRegistry->openRootKey(rootKey2), "test_registry_CppApi error 24"); 606 607 REG_ENSURE(!rootKey2.createKey(OUString("reg2FirstKey"), key21), "test_registry_CppApi error 25"); 608 REG_ENSURE(!rootKey2.createKey(OUString("reg2SecondKey"), key22), "test_registry_CppApi error 26"); 609 REG_ENSURE(!key21.createKey(OUString("reg2FirstSubKey"), key23), "test_registry_CppApi error 27"); 610 REG_ENSURE(!key21.createKey(OUString("reg2SecondSubKey"), key24), "test_registry_CppApi error 28"); 611 REG_ENSURE(!rootKey2.createKey(OUString("reg2ThirdKey"), key25), "test_registry_CppApi error 29"); 612 613 sal_uInt32 nValue= 123456789; 614 REG_ENSURE(!key23.setValue(OUString(), RG_VALUETYPE_LONG, &nValue, sizeof(sal_uInt32)), "test_registry_CppApi error 30"); 615 616 REG_ENSURE(!key21.closeKey() && 617 !key22.closeKey() && 618 !key23.closeKey() && 619 !key24.closeKey() && 620 !key25.closeKey() && 621 !rootKey2.closeKey(), "test_registry_CppApi error 31"); 622 623 REG_ENSURE(!myRegistry->close(), "test_registry_CppApi error 32"); 624 625 REG_ENSURE(!myRegistry->open(OUString("test.rdb"), REG_READWRITE), "test_registry_CppApi error 33"); 626 REG_ENSURE(!myRegistry->openRootKey(rootKey), "test_registry_CppApi error 34"); 627 628 REG_ENSURE(!myRegistry->loadKey(rootKey, OUString("allFromTest2"), 629 OUString("test2.rdb")), "test_registry_CppApi error 35"); 630 REG_ENSURE(!myRegistry->saveKey(rootKey, OUString("allFromTest2"), 631 OUString("test3.rdb")), "test_registry_CppApi error 36"); 632 633 REG_ENSURE(!rootKey.createKey(OUString("allFromTest3"), key1), "test_registry_CppApi error 37"); 634 REG_ENSURE(!key1.createKey(OUString("myFirstKey2"), key2), "test_registry_CppApi error 38"); 635 REG_ENSURE(!key1.createKey(OUString("mySecondKey2"), key3), "test_registry_CppApi error 39"); 636 637 REG_ENSURE(!myRegistry->mergeKey(rootKey, OUString("allFromTest3"), 638 OUString("test3.rdb")), "test_registry_CppApi error 40"); 639 REG_ENSURE(!myRegistry->mergeKey(rootKey, OUString("allFromTest3"), 640 OUString("ucrtest.rdb"), sal_True), "test_registry_CppApi error 40.a)"); 641 642// REG_ENSURE(myRegistry->mergeKey(rootKey, OUString("allFromTest3"), OUString("ucrtest.rdb"), sal_True) 643// == REG_NO_ERROR/*REG_MERGE_CONFLICT*/, "test_registry_CppApi error 40.b)"); 644 645 REG_ENSURE(!key1.closeKey() && 646 !key2.closeKey(), "test_registry_CppApi error 41"); 647 648 const sal_Unicode* wValue= OUString("Mein erster Unicode Value").getStr(); 649 REG_ENSURE(!key3.setValue(OUString(), RG_VALUETYPE_UNICODE, (void*)wValue, 650 (rtl_ustr_getLength(wValue)+1)*sizeof(sal_Unicode)), "test_registry_CppApi error 42"); 651 652 REG_ENSURE(!key3.closeKey(), "test_registry_CppApi error 43"); 653 654 REG_ENSURE(!rootKey.openKey(OUString("/allFromTest3/reg2FirstKey/reg2FirstSubKey"), key1), 655 "test_registry_CppApi error 43.a)"); 656 REG_ENSURE(!rootKey.deleteKey(OUString("/allFromTest3/reg2FirstKey/reg2FirstSubKey")), "test_registry_CppApi error 44"); 657 REG_ENSURE(key1.getValueInfo(OUString(), &valueType, &valueSize) == REG_INVALID_KEY, 658 "test_registry_CppApi error 44.a)"); 659 REG_ENSURE(!key1.closeKey(), "test_registry_CppApi error 44.b)"); 660 661 REG_ENSURE(!rootKey.closeKey(), "test_registry_CppApi error 45"); 662 663 REG_ENSURE(!myRegistry->close(), "test_registry_CppApi error 46"); 664 665 REG_ENSURE(!myRegistry->open(OUString("test.rdb"), REG_READWRITE), "test_registry_CppApi error 47"); 666 667 REG_ENSURE(!myRegistry->destroy(OUString("test2.rdb")), "test_registry_CppApi error 48"); 668// REG_ENSURE(!myRegistry->destroy("test3.rdb"), "test_registry_CppApi error 49"); 669 670 Registry *myRegistry2 = new Registry(*myRegistry); 671 672 REG_ENSURE(myRegistry->destroy(OUString()), "test_registry_CppApi error 50"); 673 674 delete(myRegistry2); 675 676 REG_ENSURE(!myRegistry->create(OUString("destroytest.rdb")), "test_registry_CppApi error 51"); 677 REG_ENSURE(!myRegistry->close(), "test_registry_CppApi error 52"); 678 REG_ENSURE(!myRegistry->open(OUString("destroytest.rdb"), REG_READONLY), "test_registry_CppApi error 53"); 679 REG_ENSURE(!myRegistry->openRootKey(rootKey), "test_registry_CppApi error 54"); 680 681 REG_ENSURE(myRegistry->mergeKey(rootKey, OUString("allFromTest3"), 682 OUString("test3.rdb")), "test_registry_CppApi error 55"); 683 REG_ENSURE(!myRegistry->destroy(OUString("test3.rdb")), "test_registry_CppApi error 56"); 684 685 REG_ENSURE(!rootKey.closeKey(), "test_registry_CppApi error 57"); 686 REG_ENSURE(!myRegistry->close(), "test_registry_CppApi error 58"); 687 REG_ENSURE(!myRegistry->open(OUString("destroytest.rdb"), REG_READWRITE), "test_registry_CppApi error 59"); 688 REG_ENSURE(!myRegistry->destroy(OUString()), "test_registry_CppApi error 60"); 689 690 REG_ENSURE(!myRegistry->open(OUString("test.rdb"), REG_READWRITE), "test_registry_CppApi error 61"); 691 REG_ENSURE(!myRegistry->destroy(OUString("ucrtest.rdb")), "test_registry_CppApi error 62"); 692 REG_ENSURE(!myRegistry->destroy(OUString()), "test_registry_CppApi error 63"); 693 delete(myRegistry); 694 695 cout << "test_registry_CppApi() Ok!\n"; 696 697 return; 698} 699 700 701/* vim:set shiftwidth=4 softtabstop=4 expandtab: */