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