PageRenderTime 44ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/registry/test/testregcpp.cxx

https://bitbucket.org/markjenkins/libreoffice_ubuntu-debian-fixes
C++ | 701 lines | 503 code | 165 blank | 33 comment | 43 complexity | c1e24db0e87ad97d6a2a818b91ffe5c4 MD5 | raw file
Possible License(s): GPL-3.0, LGPL-3.0, MPL-2.0-no-copyleft-exception, LGPL-2.1, BSD-3-Clause-No-Nuclear-License-2014
  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. #include <iostream>
  20. #include <stdio.h>
  21. #include <string.h>
  22. #include "registry/registry.hxx"
  23. #include "registry/reflread.hxx"
  24. #include "registry/reflwrit.hxx"
  25. #include "regdiagnose.h"
  26. #include <rtl/alloc.h>
  27. #include <rtl/ustring.hxx>
  28. using namespace std;
  29. using ::rtl::OUString;
  30. using ::rtl::OUStringToOString;
  31. using ::rtl::OString;
  32. void test_coreReflection()
  33. {
  34. Registry *myRegistry = new Registry();
  35. RegistryKey rootKey, key1, key2, key3, key4 ,key5, key6, key7, key8;
  36. REG_ENSURE(!myRegistry->create(OUString("ucrtest.rdb")), "testCoreReflection error 1");
  37. REG_ENSURE(!myRegistry->openRootKey(rootKey), "testCoreReflection error 2");
  38. REG_ENSURE(!rootKey.createKey(OUString("UCR"), key1), "testCoreReflection error 3");
  39. REG_ENSURE(!key1.createKey(OUString("ModuleA"), key2), "testCoreReflection error 4");
  40. REG_ENSURE(!key2.createKey(OUString("StructA"), key3), "testCoreReflection error 5");
  41. REG_ENSURE(!key2.createKey(OUString("EnumA"), key4), "testCoreReflection error 6");
  42. REG_ENSURE(!key2.createKey(OUString("XInterfaceA"), key5), "testCoreReflection error 7");
  43. REG_ENSURE(!key2.createKey(OUString("ExceptionA"), key6), "testCoreReflection error 8");
  44. REG_ENSURE(!key2.createKey(OUString("ServiceA"), key7), "testCoreReflection error 8a");
  45. REG_ENSURE(!key2.createKey(OUString("ConstantsA"), key8), "testCoreReflection error 8b");
  46. {
  47. RegistryTypeWriter writer(RT_TYPE_MODULE,
  48. OUString("ModuleA"),
  49. OUString(), 11, 0, 0);
  50. RTConstValue aConst;
  51. writer.setDoku(OUString("Hallo ich bin ein Modul"));
  52. writer.setFileName(OUString("DummyFile"));
  53. aConst.m_type = RT_TYPE_BOOL;
  54. aConst.m_value.aBool = sal_True;
  55. writer.setFieldData(0, OUString("aConstBool"),
  56. OUString("boolean"),
  57. OUString("ich bin ein boolean"),
  58. OUString("DummyFile"), RT_ACCESS_CONST, aConst);
  59. aConst.m_type = RT_TYPE_BYTE;
  60. aConst.m_value.aByte = 127;
  61. writer.setFieldData(1, OUString("aConstByte"),
  62. OUString("byte"),
  63. OUString("ich bin ein byte"),
  64. OUString("DummyFile"), RT_ACCESS_CONST, aConst);
  65. aConst.m_type = RT_TYPE_INT16;
  66. aConst.m_value.aShort = -10;
  67. writer.setFieldData(2, OUString("aConstShort"),
  68. OUString("short"),
  69. OUString("ich bin ein short"),
  70. OUString("DummyFile"), RT_ACCESS_CONST, aConst);
  71. aConst.m_type = RT_TYPE_UINT16;
  72. aConst.m_value.aUShort = 10;
  73. writer.setFieldData(3, OUString("aConstUShort"),
  74. OUString("unsigned short"),
  75. OUString("ich bin ein unsigned short"),
  76. OUString("DummyFile"), RT_ACCESS_CONST, aConst);
  77. aConst.m_type = RT_TYPE_INT32;
  78. aConst.m_value.aLong = -100000;
  79. writer.setFieldData(4, OUString("aConstLong"),
  80. OUString("long"),
  81. OUString("ich bin ein long"),
  82. OUString("DummyFile"), RT_ACCESS_CONST, aConst);
  83. aConst.m_type = RT_TYPE_UINT32;
  84. aConst.m_value.aULong = 100000;
  85. writer.setFieldData(5, OUString("aConstULong"),
  86. OUString("unsigned long"),
  87. OUString("ich bin ein unsigned long"),
  88. OUString("DummyFile"), RT_ACCESS_CONST, aConst);
  89. aConst.m_type = RT_TYPE_INT64;
  90. aConst.m_value.aHyper = -100000000;
  91. writer.setFieldData(6, OUString("aConstHyper"),
  92. OUString("hyper"),
  93. OUString("ich bin ein hyper"),
  94. OUString("DummyFile"), RT_ACCESS_CONST, aConst);
  95. aConst.m_type = RT_TYPE_UINT64;
  96. aConst.m_value.aUHyper = 100000000;
  97. writer.setFieldData(7, OUString("aConstULong"),
  98. OUString("unsigned long"),
  99. OUString("ich bin ein unsigned long"),
  100. OUString("DummyFile"), RT_ACCESS_CONST, aConst);
  101. aConst.m_type = RT_TYPE_FLOAT;
  102. aConst.m_value.aFloat = -2e-10f;
  103. writer.setFieldData(8, OUString("aConstFloat"),
  104. OUString("float"),
  105. OUString("ich bin ein float"),
  106. OUString("DummyFile"), RT_ACCESS_CONST, aConst);
  107. aConst.m_type = RT_TYPE_DOUBLE;
  108. aConst.m_value.aDouble = -2e-100; writer.setFieldData(9, OUString("aConstDouble"),
  109. OUString("double"),
  110. OUString("ich bin ein double"),
  111. OUString("DummyFile"), RT_ACCESS_CONST, aConst);
  112. aConst.m_type = RT_TYPE_STRING;
  113. OUString tmpStr("dies ist ein unicode string");
  114. aConst.m_value.aString = tmpStr.getStr();
  115. writer.setFieldData(10, OUString("aConstString"),
  116. OUString("string"),
  117. OUString("ich bin ein string"),
  118. OUString("DummyFile"), RT_ACCESS_CONST, aConst);
  119. const sal_uInt8* pBlop = writer.getBlop();
  120. sal_uInt32 aBlopSize = writer.getBlopSize();
  121. REG_ENSURE(!key2.setValue(OUString(), RG_VALUETYPE_BINARY, (void*)pBlop, aBlopSize), "testCoreReflection error 9");
  122. sal_uInt8* readBlop = (sal_uInt8*)rtl_allocateMemory(aBlopSize);
  123. REG_ENSURE(!key2.getValue(OUString(), (void*)readBlop) , "testCoreReflection error 9a");
  124. RegistryTypeReader reader(readBlop, aBlopSize, sal_True);
  125. if (reader.isValid())
  126. {
  127. REG_ENSURE(reader.getTypeName() == "ModuleA", "testCoreReflection error 9a2");
  128. RTConstValue aReadConst = reader.getFieldConstValue(4);
  129. REG_ENSURE( aReadConst.m_type == RT_TYPE_INT32, "testCoreReflection error 9a3");
  130. REG_ENSURE( aReadConst.m_value.aLong == -100000, "testCoreReflection error 9a4");
  131. aReadConst = reader.getFieldConstValue(6);
  132. REG_ENSURE( aReadConst.m_type == RT_TYPE_INT64, "testCoreReflection error 9a5");
  133. REG_ENSURE( aReadConst.m_value.aHyper == -100000000, "testCoreReflection error 9a6");
  134. aReadConst = reader.getFieldConstValue(10);
  135. OString aConstStr = OUStringToOString(aConst.m_value.aString, RTL_TEXTENCODING_ASCII_US);
  136. REG_ENSURE(aConstStr.equals("dies ist ein unicode string"), "testCoreReflection error 9b");
  137. }
  138. }
  139. {
  140. RegistryTypeWriter writer(RT_TYPE_STRUCT,
  141. OUString("ModuleA/StructA"),
  142. OUString(), 3, 0, 0);
  143. writer.setDoku(OUString("Hallo ich bin eine Struktur"));
  144. writer.setFileName(OUString("DummyFile"));
  145. writer.setFieldData(0, OUString("asal_uInt32"),
  146. OUString("unsigned long"),
  147. OUString(), OUString(), RT_ACCESS_READWRITE);
  148. writer.setFieldData(1, OUString("aXInterface"),
  149. OUString("stardiv/uno/XInterface"),
  150. OUString(), OUString(), RT_ACCESS_READWRITE);
  151. writer.setFieldData(2, OUString("aSequence"),
  152. OUString("[]ModuleA/EnumA"),
  153. OUString(), OUString(), RT_ACCESS_READWRITE);
  154. const sal_uInt8* pBlop = writer.getBlop();
  155. sal_uInt32 aBlopSize = writer.getBlopSize();
  156. REG_ENSURE(!key3.setValue(OUString(), RG_VALUETYPE_BINARY, (void*)pBlop, aBlopSize), "testCoreReflection error 9a");
  157. }
  158. {
  159. RegistryTypeWriter writer(RT_TYPE_ENUM,
  160. OUString("ModuleA/EnumA"),
  161. OUString(), 2, 0, 0);
  162. RTConstValue aConst;
  163. aConst.m_type = RT_TYPE_UINT32;
  164. aConst.m_value.aULong = 10;
  165. writer.setDoku(OUString("Hallo ich bin ein Enum"));
  166. writer.setFileName(OUString("DummyFile"));
  167. writer.setFieldData(0, OUString("ENUM_VAL_1"),
  168. OUString(), OUString("ich bin ein enum value"),
  169. OUString(), RT_ACCESS_CONST, aConst);
  170. aConst.m_value.aULong = 10;
  171. writer.setFieldData(1, OUString("ENUM_VAL_2"),
  172. OUString(), OUString(), OUString(), RT_ACCESS_CONST, aConst);
  173. const sal_uInt8* pBlop = writer.getBlop();
  174. sal_uInt32 aBlopSize = writer.getBlopSize();
  175. REG_ENSURE(!key4.setValue(OUString(), RG_VALUETYPE_BINARY, (void*)pBlop, aBlopSize), "testCoreReflection error 9b");
  176. }
  177. {
  178. RegistryTypeWriter writer(RT_TYPE_INTERFACE,
  179. OUString("ModuleA/XInterfaceA"),
  180. OUString("stardiv/uno/XInterface"),
  181. 4, 1, 0);
  182. RTConstValue aConst;
  183. RTUik aUik = {1,2,3,4,5};
  184. writer.setUik(aUik);
  185. writer.setDoku(OUString("Hallo ich bin ein Interface"));
  186. writer.setFileName(OUString("DummyFile"));
  187. writer.setFieldData(0, OUString("aString"),
  188. OUString("string"), OUString(), OUString(), RT_ACCESS_READWRITE);
  189. writer.setFieldData(1, OUString("aStruct"),
  190. OUString("ModuleA/StructA"),
  191. OUString(), OUString(), RT_ACCESS_READONLY);
  192. writer.setFieldData(2, OUString("aEnum"),
  193. OUString("ModuleA/EnumA"), OUString(), OUString(), RT_ACCESS_BOUND);
  194. aConst.m_type = RT_TYPE_UINT16;
  195. aConst.m_value.aUShort = 12;
  196. writer.setFieldData(3, OUString("aConstUShort"),
  197. OUString("unsigned short"), OUString(),
  198. OUString("DummyFile"), RT_ACCESS_CONST, aConst);
  199. writer.setMethodData(0, OUString("methodA"),
  200. OUString("double"), RT_MODE_TWOWAY, 2, 1,
  201. OUString("Hallo ich bin die methodA"));
  202. writer.setParamData(0, 0, OUString("ModuleA/StructA"),
  203. OUString("aStruct"), RT_PARAM_IN);
  204. writer.setParamData(0, 1, OUString("unsigned short"),
  205. OUString("aShort"), RT_PARAM_INOUT);
  206. writer.setExcData(0, 0, OUString("ModuleA/ExceptionA"));
  207. const sal_uInt8* pBlop = writer.getBlop();
  208. sal_uInt32 aBlopSize = writer.getBlopSize();
  209. REG_ENSURE(!key5.setValue(OUString(), RG_VALUETYPE_BINARY, (void*)pBlop, aBlopSize), "testCoreReflection error 9c");
  210. sal_uInt8* readBlop = (sal_uInt8*)rtl_allocateMemory(aBlopSize);
  211. REG_ENSURE(!key5.getValue(OUString(), (void*)readBlop) , "testCoreReflection error 9c1");
  212. RegistryTypeReader reader(readBlop, aBlopSize, sal_True);
  213. if (reader.isValid())
  214. {
  215. REG_ENSURE(reader.getTypeName() == "ModuleA/XInterfaceA", "testCoreReflection error 9c2");
  216. RTUik retUik;
  217. reader.getUik(retUik);
  218. REG_ENSURE(retUik.m_Data1 = 1, "testCoreReflection error 9c3");
  219. REG_ENSURE(retUik.m_Data2 = 2, "testCoreReflection error 9c4");
  220. REG_ENSURE(retUik.m_Data3 = 3, "testCoreReflection error 9c5");
  221. REG_ENSURE(retUik.m_Data4 = 4, "testCoreReflection error 9c6");
  222. REG_ENSURE(retUik.m_Data5 = 5, "testCoreReflection error 9c7");
  223. }
  224. }
  225. {
  226. RegistryTypeWriter writer(RT_TYPE_EXCEPTION,
  227. OUString("ModuleA/ExceptionA"),
  228. OUString(), 1, 0, 0);
  229. writer.setDoku(OUString("Hallo ich bin eine Exception"));
  230. writer.setFieldData(0, OUString("aSource"),
  231. OUString("stardiv/uno/XInterface"),
  232. OUString("ich bin ein interface member"),
  233. OUString(), RT_ACCESS_READWRITE);
  234. const sal_uInt8* pBlop = writer.getBlop();
  235. sal_uInt32 aBlopSize = writer.getBlopSize();
  236. REG_ENSURE(!key6.setValue(OUString(), RG_VALUETYPE_BINARY, (void*)pBlop, aBlopSize), "testCoreReflection error 9d");
  237. }
  238. {
  239. RegistryTypeWriter writer(RT_TYPE_SERVICE,
  240. OUString("ModuleA/ServiceA"),
  241. OUString(), 1, 0, 4);
  242. writer.setDoku(OUString("Hallo ich bin ein Service"));
  243. writer.setFileName(OUString("DummyFile"));
  244. writer.setFieldData(0, OUString("aProperty"),
  245. OUString("stardiv/uno/XInterface"),
  246. OUString("ich bin eine property"),
  247. OUString(), RT_ACCESS_READWRITE);
  248. writer.setReferenceData(0, OUString("ModuleA/XInterfaceA"), RT_REF_SUPPORTS,
  249. OUString("Hallo ich eine Reference auf ein supported interface"),
  250. RT_ACCESS_OPTIONAL);
  251. writer.setReferenceData(1, OUString("ModuleA/XInterfaceA"), RT_REF_OBSERVES,
  252. OUString("Hallo ich eine Reference auf ein observed interface"));
  253. writer.setReferenceData(2, OUString("ModuleA/ServiceB"), RT_REF_EXPORTS,
  254. OUString("Hallo ich eine Reference auf einen exported service"));
  255. writer.setReferenceData(3, OUString("ModuleA/ServiceB"), RT_REF_NEEDS,
  256. OUString("Hallo ich eine Reference auf einen needed service"));
  257. const sal_uInt8* pBlop = writer.getBlop();
  258. sal_uInt32 aBlopSize = writer.getBlopSize();
  259. REG_ENSURE(!key7.setValue(OUString(), RG_VALUETYPE_BINARY, (void*)pBlop, aBlopSize), "testCoreReflection error 9e");
  260. sal_uInt8* readBlop = (sal_uInt8*)rtl_allocateMemory(aBlopSize);
  261. REG_ENSURE(!key7.getValue(OUString(), (void*)readBlop) , "testCoreReflection error 9e2");
  262. RegistryTypeReader reader(readBlop, aBlopSize, sal_True);
  263. if (reader.isValid())
  264. {
  265. REG_ENSURE(reader.getTypeName() == "ModuleA/ServiceA", "testCoreReflection error 9e3");
  266. sal_uInt32 referenceCount = reader.getReferenceCount();
  267. REG_ENSURE( referenceCount == 4, "testCoreReflection error 9e4");
  268. OUString refName = reader.getReferenceName(0);
  269. REG_ENSURE(refName == "ModuleA/XInterfaceA", "testCoreReflection error 9e5");
  270. }
  271. }
  272. {
  273. RegistryTypeWriter writer(RT_TYPE_CONSTANTS,
  274. OUString("ModuleA/ConstansA"),
  275. OUString(), 3, 0, 0);
  276. RTConstValue aConst;
  277. writer.setDoku(OUString("Hallo ich bin eine Constants Group"));
  278. writer.setFileName(OUString("DummyFile"));
  279. aConst.m_type = RT_TYPE_BOOL;
  280. aConst.m_value.aBool = sal_True;
  281. writer.setFieldData(0, OUString("ConstantsA_aConstBool"),
  282. OUString("boolean"),
  283. OUString("ich bin ein boolean"),
  284. OUString("DummyFile"), RT_ACCESS_CONST, aConst);
  285. aConst.m_type = RT_TYPE_BYTE;
  286. aConst.m_value.aByte = 127;
  287. writer.setFieldData(1, OUString("ConstantsA_aConstByte"),
  288. OUString("byte"),
  289. OUString("ich bin ein byte"),
  290. OUString("DummyFile"), RT_ACCESS_CONST, aConst);
  291. aConst.m_type = RT_TYPE_INT16;
  292. aConst.m_value.aShort = -10;
  293. writer.setFieldData(2, OUString("ConstantsA_aConstShort"),
  294. OUString("short"),
  295. OUString("ich bin ein short"),
  296. OUString("DummyFile"), RT_ACCESS_CONST, aConst);
  297. const sal_uInt8* pBlop = writer.getBlop();
  298. sal_uInt32 aBlopSize = writer.getBlopSize();
  299. REG_ENSURE(!key8.setValue(OUString(), RG_VALUETYPE_BINARY, (void*)pBlop, aBlopSize), "testCoreReflection error 9f");
  300. }
  301. // REG_ENSURE(!myRegistry->destroy(NULL), "testCoreReflection error 10");
  302. delete myRegistry;
  303. cout << "test_coreReflection() Ok!\n";
  304. }
  305. void test_registry_CppApi()
  306. {
  307. Registry *myRegistry = new Registry();
  308. RegistryKey rootKey, key1, key2, key3, key4 ,key5, key6, key7, key8, key9;
  309. REG_ENSURE(!myRegistry->create(OUString("test.rdb")), "test_registry_CppApi error 1");
  310. REG_ENSURE(!myRegistry->openRootKey(rootKey), "test_registry_CppApi error 2");
  311. REG_ENSURE(!rootKey.createKey(OUString("myFirstKey"), key1), "test_registry_CppApi error 3");
  312. REG_ENSURE(!rootKey.createKey(OUString("mySecondKey"), key2), "test_registry_CppApi error 4");
  313. REG_ENSURE(!key1.createKey(OUString("X"), key3), "test_registry_CppApi error 5");
  314. REG_ENSURE(!key1.createKey(OUString("mySecondSubKey"), key4), "test_registry_CppApi error 6");
  315. REG_ENSURE(!rootKey.createKey(OUString("myThirdKey"), key5), "test_registry_CppApi error 6a");
  316. REG_ENSURE(!key5.createKey(OUString("1"), key4), "test_registry_CppApi error 6b");
  317. REG_ENSURE(!key4.createKey(OUString("2"), key3), "test_registry_CppApi error 6c");
  318. REG_ENSURE(!key5.openKey(OUString("1"), key4), "test_registry_CppApi error 6d");
  319. REG_ENSURE(!rootKey.openKey(OUString("/myThirdKey/1"), key4), "test_registry_CppApi error 6e");
  320. REG_ENSURE(key4.getName() == "/myThirdKey/1", "test_registry_CppApi error 6f");
  321. REG_ENSURE(!rootKey.createKey(OUString("myFourthKey"), key6), "test_registry_CppApi error 7");
  322. REG_ENSURE(!rootKey.createKey(OUString("myFifthKey"), key6), "test_registry_CppApi error 7a");
  323. REG_ENSURE(!rootKey.createKey(OUString("mySixthKey"), key6), "test_registry_CppApi error 7b");
  324. // Link Test
  325. //
  326. REG_ENSURE(!rootKey.createKey(OUString("/myFourthKey/X"), key7), "test_registry_CppApi error 7c)");;
  327. REG_ENSURE(!key6.createLink(OUString("myFirstLink"), OUString("/myFourthKey/X")), "test_registry_CppApi error 7d");
  328. REG_ENSURE(!key6.createKey(OUString("mySixthSubKey"), key7), "test_registry_CppApi error 7e");
  329. OUString linkTarget;
  330. REG_ENSURE(!key6.getLinkTarget(OUString("myFirstLink"), linkTarget), "test_registry_CppApi error 7f");
  331. REG_ENSURE(linkTarget == "/myFourthKey/X", "test_registry_CppApi error 7g");
  332. RegistryKeyNames* pSubKeyNames = new RegistryKeyNames();
  333. sal_uInt32 nSubKeys=0;
  334. REG_ENSURE(!rootKey.getKeyNames(OUString("mySixthKey"), *pSubKeyNames), "test_registry_CppApi error 7h)");
  335. REG_ENSURE(pSubKeyNames->getLength() == 2, "test_registry_CppApi error 7i)");
  336. for (sal_uInt32 i=0; i < pSubKeyNames->getLength(); i++)
  337. {
  338. if ( pSubKeyNames->getElement(i) == "/mySixthKey/myFirstLink" )
  339. {
  340. RegKeyType keyType;
  341. REG_ENSURE(!rootKey.getKeyType(pSubKeyNames->getElement(i), &keyType), "test_registry_CppApi error 7j");
  342. REG_ENSURE(keyType == RG_LINKTYPE, "test_registry_CppApi error 7k");
  343. }
  344. }
  345. REG_ENSURE(!key7.closeKey(), "test_registry_CppApi error 7k1");
  346. delete pSubKeyNames;
  347. REG_ENSURE(!rootKey.openKey(OUString("/mySixthKey/myFirstLink"), key6), "test_registry_CppApi error 7l");
  348. // REG_ENSURE(key6.getName() == "/myFourthKey/X", "test_registry_CppApi error 7m");
  349. REG_ENSURE(!rootKey.openKey(OUString("myFifthKey"), key6), "test_registry_CppApi error 7m1");
  350. REG_ENSURE(!key6.createLink(OUString("mySecondLink"),
  351. OUString("/mySixthKey/myFirstLink")), "test_registry_CppApi error 7m2");
  352. REG_ENSURE(!rootKey.openKey(OUString("/myFifthKey/mySecondLink"), key6), "test_registry_CppApi error 7m3");
  353. // REG_ENSURE(key6.getName() == "/myFourthKey/X", "test_registry_CppApi error 7m4");
  354. REG_ENSURE(!rootKey.createKey(OUString("/myFifthKey/mySecondLink/myFirstLinkSubKey"), key7), "test_registry_CppApi error 7m5");
  355. REG_ENSURE(key7.getName() == "/myFourthKey/X/myFirstLinkSubKey", "test_registry_CppApi error 7m6");
  356. REG_ENSURE(!key7.createLink(OUString("myThirdLink"), OUString("/myFifthKey/mySecondLink")), "test_registry_CppApi error 7m7");
  357. REG_ENSURE(!rootKey.openKey(OUString("/myFourthKey/X/myFirstLinkSubKey/myThirdLink"), key7), "test_registry_CppApi error 7m8");
  358. // REG_ENSURE(!key7.openKey(OUString("/myFirstLinkSubKey/myThirdLink/myFirstLinkSubKey/myThirdLink"), key6), "test_registry_CppApi error 7m9");
  359. // REG_ENSURE(key7.getName() == "/myFourthKey/X", "test_registry_CppApi error 7m10");
  360. REG_ENSURE(!key7.closeKey(), "test_registry_CppApi error 7m11");
  361. REG_ENSURE(!rootKey.deleteLink(OUString("/myFifthKey/mySecondLink")), "test_registry_CppApi error 7m12");
  362. REG_ENSURE(!rootKey.createLink(OUString("/myFifthKey/mySecondLink"),
  363. OUString("/myFourthKey/X/myFirstLinkSubKey/myThirdLink")),
  364. "test_registry_CppApi error 7m13");
  365. // REG_ENSURE(rootKey.openKey(OUString("/myFourthKey/X/myFirstLinkSubKey/myThirdLink"), key7) == REG_DETECT_RECURSION,
  366. // "test_registry_CppApi error 7m14");
  367. // REG_ENSURE(key7.closeKey() == REG_INVALID_KEY, "test_registry_CppApi error 7m11");
  368. RegistryKeyNames subKeyNames;
  369. nSubKeys=0;
  370. REG_ENSURE(!rootKey.getKeyNames(OUString("mySixthKey"), subKeyNames), "test_registry_CppApi error 7n");
  371. nSubKeys = subKeyNames.getLength();
  372. REG_ENSURE(nSubKeys == 2, "test_registry_CppApi error 7n1");
  373. REG_ENSURE(subKeyNames.getElement(0) == "/mySixthKey/myFirstLink", "test_registry_CppApi error 7p1)");
  374. REG_ENSURE(subKeyNames.getElement(1) =="/mySixthKey/mySixthSubKey", "test_registry_CppApi error 7p2");
  375. RegistryKeyArray subKeys;
  376. nSubKeys=0;
  377. REG_ENSURE(!rootKey.openSubKeys(OUString("myFirstKey"), subKeys), "test_registry_CppApi error 7o");
  378. nSubKeys = subKeys.getLength();
  379. REG_ENSURE(nSubKeys == 2, "test_registry_CppApi error 7o1");
  380. REG_ENSURE(subKeys.getElement(0).getName() == "/myFirstKey/mySecondSubKey", "test_registry_CppApi error 7p1)");
  381. REG_ENSURE(subKeys.getElement(1).getName() == "/myFirstKey/X", "test_registry_CppApi error 7p2");
  382. REG_ENSURE(!rootKey.closeSubKeys(subKeys), "test_registry_CppApi error 7q)");
  383. REG_ENSURE(!rootKey.createKey(OUString("/TEST"), key8), "test_registry_CppApi error 8");
  384. REG_ENSURE(!rootKey.createKey(OUString("/TEST/Child1"), key8), "test_registry_CppApi error 8a");
  385. REG_ENSURE(!rootKey.createKey(OUString("/TEST/Child2"), key8), "test_registry_CppApi error 8a1");
  386. REG_ENSURE(!rootKey.openKey(OUString("/TEST"), key9), "test_registry_CppApi error 8b");
  387. REG_ENSURE(!key8.closeKey() && !key9.closeKey(), "test_registry_CppApi error 8b1");
  388. REG_ENSURE(!rootKey.openKey(OUString("/TEST"), key8), "test_registry_CppApi error 8b");
  389. REG_ENSURE(!key8.closeKey(), "test_registry_CppApi error 8c");
  390. REG_ENSURE(!rootKey.openKey(OUString("TEST"), key8), "test_registry_CppApi error 8c");
  391. REG_ENSURE(!key8.closeKey(), "test_registry_CppApi error 8d");
  392. sal_Char* Value=(sal_Char*)"Mein erster Value";
  393. REG_ENSURE(!rootKey.setValue(OUString("mySecondKey"), RG_VALUETYPE_STRING, Value, 18), "test_registry_CppApi error 9");
  394. RegValueType valueType;
  395. sal_uInt32 valueSize;
  396. sal_Char* readValue;
  397. REG_ENSURE(!rootKey.getValueInfo(OUString("mySecondKey"), &valueType, &valueSize), "test_registry_CppApi error 9a");
  398. readValue = (sal_Char*)rtl_allocateMemory(valueSize);
  399. REG_ENSURE(!key2.getValue(OUString(), readValue), "test_registry_CppApi error 10");
  400. REG_ENSURE(valueType == RG_VALUETYPE_STRING, "test_registry_CppApi error 11");
  401. REG_ENSURE(valueSize == 18, "test_registry_CppApi error 12");
  402. REG_ENSURE(strcmp(readValue, Value) == 0, "test_registry_CppApi error 13");
  403. rtl_freeMemory(readValue);
  404. const sal_Char* pList[3];
  405. const sal_Char* n1= "Hallo";
  406. const sal_Char* n2= "jetzt komm";
  407. const sal_Char* n3= "ich";
  408. pList[0]=n1;
  409. pList[1]=n2;
  410. pList[2]=n3;
  411. REG_ENSURE(!rootKey.setStringListValue(OUString("myFourthKey"), (sal_Char**)pList, 3), "test_registry_CppApi error 13a");
  412. RegistryValueList<sal_Char*> valueList;
  413. REG_ENSURE(!rootKey.getStringListValue(OUString("myFourthKey"), valueList), "test_registry_CppApi error 13b");
  414. REG_ENSURE(strcmp(n1, valueList.getElement(0)) == 0, "test_registry_CppApi error 13c");
  415. REG_ENSURE(strcmp(n2, valueList.getElement(1)) == 0, "test_registry_CppApi error 13d");
  416. REG_ENSURE(strcmp(n3, valueList.getElement(2)) == 0, "test_registry_CppApi error 13e");
  417. REG_ENSURE(!rootKey.getValueInfo(OUString("myFourthKey"), &valueType, &valueSize), "test_registry_CppApi error 13e1");
  418. REG_ENSURE(valueType == RG_VALUETYPE_STRINGLIST, "test_registry_CppApi error 13e2");
  419. REG_ENSURE(valueSize == 3, "test_registry_CppApi error 13e3");
  420. sal_Int32 pLong[3];
  421. pLong[0] = 123;
  422. pLong[1] = 456;
  423. pLong[2] = 789;
  424. REG_ENSURE(!rootKey.setLongListValue(OUString("myFifthKey"), pLong, 3), "test_registry_CppApi error 13f");
  425. RegistryValueList<sal_Int32> longList;
  426. REG_ENSURE(!rootKey.getLongListValue(OUString("myFifthKey"), longList), "test_registry_CppApi error 13g");
  427. REG_ENSURE(pLong[0] == longList.getElement(0), "test_registry_CppApi error 13h");
  428. REG_ENSURE(pLong[1] == longList.getElement(1), "test_registry_CppApi error 13i");
  429. REG_ENSURE(pLong[2] == longList.getElement(2), "test_registry_CppApi error 13j");
  430. OUString sWTestValue("Mein erster Unicode Value");
  431. const sal_Unicode* wTestValue= sWTestValue.getStr();
  432. REG_ENSURE(!rootKey.setValue(OUString("mySixthKey"), RG_VALUETYPE_UNICODE, (void*)wTestValue,
  433. (rtl_ustr_getLength(wTestValue)+1)*sizeof(sal_Unicode)), "test_registry_CppApi error 13j1");
  434. REG_ENSURE(!rootKey.getValueInfo(OUString("mySixthKey"), &valueType, &valueSize), "test_registry_CppApi error 13j2");
  435. sal_Unicode* pTmpValue = (sal_Unicode*)rtl_allocateMemory(valueSize);
  436. REG_ENSURE(!rootKey.getValue(OUString("mySixthKey"), pTmpValue), "test_registry_CppApi error 13j3");
  437. REG_ENSURE(rtl_ustr_getLength(wTestValue) == rtl_ustr_getLength(pTmpValue), "test_registry_CppApi error 13j4");
  438. REG_ENSURE(rtl_ustr_compare(wTestValue, pTmpValue) == 0, "test_registry_CppApi error 13j4");
  439. const sal_Unicode* pUnicode[3];
  440. OUString w1("Hallo");
  441. OUString w2("jetzt komm");
  442. OUString w3("ich als unicode");
  443. pUnicode[0]=w1.getStr();
  444. pUnicode[1]=w2.getStr();
  445. pUnicode[2]=w3.getStr();
  446. REG_ENSURE(!rootKey.setUnicodeListValue(OUString("mySixthKey"), (sal_Unicode**)pUnicode, 3), "test_registry_CppApi error 13k");
  447. RegistryValueList<sal_Unicode*> unicodeList;
  448. REG_ENSURE(!rootKey.getUnicodeListValue(OUString("mySixthKey"), unicodeList), "test_registry_CppApi error 13l");
  449. REG_ENSURE(rtl_ustr_compare(w1, unicodeList.getElement(0)) == 0, "test_registry_CppApi error 13m");
  450. REG_ENSURE(rtl_ustr_compare(w2, unicodeList.getElement(1)) == 0, "test_registry_CppApi error 13n");
  451. REG_ENSURE(rtl_ustr_compare(w3, unicodeList.getElement(2)) == 0, "test_registry_CppApi error 13o");
  452. REG_ENSURE(!key6.closeKey(), "test_registry_CppApi error 14");
  453. REG_ENSURE(!key1.closeKey() &&
  454. !key3.closeKey() &&
  455. !key4.closeKey(), "test_registry_CppApi error 14");
  456. REG_ENSURE(!rootKey.deleteKey(OUString("myFirstKey")), "test_registry_CppApi error 15");
  457. REG_ENSURE(!key2.closeKey(), "test_registry_CppApi error 16");
  458. REG_ENSURE(!rootKey.openKey(OUString("mySecondKey"), key2), "test_registry_CppApi error 17");
  459. REG_ENSURE(!key5.closeKey(), "test_registry_CppApi error 18");
  460. REG_ENSURE(!rootKey.deleteKey(OUString("myThirdKey")), "test_registry_CppApi error 19");
  461. REG_ENSURE(rootKey.openKey(OUString("myThirdKey"), key5), "test_registry_CppApi error 20");
  462. REG_ENSURE(!key2.closeKey() &&
  463. !rootKey.closeKey(), "test_registry_CppApi error 21");
  464. REG_ENSURE(!myRegistry->close(), "test_registry_CppApi error 22");
  465. // Test loadkey
  466. RegistryKey rootKey2, key21, key22, key23, key24 , key25;
  467. REG_ENSURE(!myRegistry->create(OUString("test2.rdb")), "test_registry_CppApi error 23");
  468. REG_ENSURE(!myRegistry->openRootKey(rootKey2), "test_registry_CppApi error 24");
  469. REG_ENSURE(!rootKey2.createKey(OUString("reg2FirstKey"), key21), "test_registry_CppApi error 25");
  470. REG_ENSURE(!rootKey2.createKey(OUString("reg2SecondKey"), key22), "test_registry_CppApi error 26");
  471. REG_ENSURE(!key21.createKey(OUString("reg2FirstSubKey"), key23), "test_registry_CppApi error 27");
  472. REG_ENSURE(!key21.createKey(OUString("reg2SecondSubKey"), key24), "test_registry_CppApi error 28");
  473. REG_ENSURE(!rootKey2.createKey(OUString("reg2ThirdKey"), key25), "test_registry_CppApi error 29");
  474. sal_uInt32 nValue= 123456789;
  475. REG_ENSURE(!key23.setValue(OUString(), RG_VALUETYPE_LONG, &nValue, sizeof(sal_uInt32)), "test_registry_CppApi error 30");
  476. REG_ENSURE(!key21.closeKey() &&
  477. !key22.closeKey() &&
  478. !key23.closeKey() &&
  479. !key24.closeKey() &&
  480. !key25.closeKey() &&
  481. !rootKey2.closeKey(), "test_registry_CppApi error 31");
  482. REG_ENSURE(!myRegistry->close(), "test_registry_CppApi error 32");
  483. REG_ENSURE(!myRegistry->open(OUString("test.rdb"), REG_READWRITE), "test_registry_CppApi error 33");
  484. REG_ENSURE(!myRegistry->openRootKey(rootKey), "test_registry_CppApi error 34");
  485. REG_ENSURE(!myRegistry->loadKey(rootKey, OUString("allFromTest2"),
  486. OUString("test2.rdb")), "test_registry_CppApi error 35");
  487. REG_ENSURE(!myRegistry->saveKey(rootKey, OUString("allFromTest2"),
  488. OUString("test3.rdb")), "test_registry_CppApi error 36");
  489. REG_ENSURE(!rootKey.createKey(OUString("allFromTest3"), key1), "test_registry_CppApi error 37");
  490. REG_ENSURE(!key1.createKey(OUString("myFirstKey2"), key2), "test_registry_CppApi error 38");
  491. REG_ENSURE(!key1.createKey(OUString("mySecondKey2"), key3), "test_registry_CppApi error 39");
  492. REG_ENSURE(!myRegistry->mergeKey(rootKey, OUString("allFromTest3"),
  493. OUString("test3.rdb")), "test_registry_CppApi error 40");
  494. REG_ENSURE(!myRegistry->mergeKey(rootKey, OUString("allFromTest3"),
  495. OUString("ucrtest.rdb"), sal_True), "test_registry_CppApi error 40.a)");
  496. // REG_ENSURE(myRegistry->mergeKey(rootKey, OUString("allFromTest3"), OUString("ucrtest.rdb"), sal_True)
  497. // == REG_NO_ERROR/*REG_MERGE_CONFLICT*/, "test_registry_CppApi error 40.b)");
  498. REG_ENSURE(!key1.closeKey() &&
  499. !key2.closeKey(), "test_registry_CppApi error 41");
  500. const sal_Unicode* wValue= OUString("Mein erster Unicode Value").getStr();
  501. REG_ENSURE(!key3.setValue(OUString(), RG_VALUETYPE_UNICODE, (void*)wValue,
  502. (rtl_ustr_getLength(wValue)+1)*sizeof(sal_Unicode)), "test_registry_CppApi error 42");
  503. REG_ENSURE(!key3.closeKey(), "test_registry_CppApi error 43");
  504. REG_ENSURE(!rootKey.openKey(OUString("/allFromTest3/reg2FirstKey/reg2FirstSubKey"), key1),
  505. "test_registry_CppApi error 43.a)");
  506. REG_ENSURE(!rootKey.deleteKey(OUString("/allFromTest3/reg2FirstKey/reg2FirstSubKey")), "test_registry_CppApi error 44");
  507. REG_ENSURE(key1.getValueInfo(OUString(), &valueType, &valueSize) == REG_INVALID_KEY,
  508. "test_registry_CppApi error 44.a)");
  509. REG_ENSURE(!key1.closeKey(), "test_registry_CppApi error 44.b)");
  510. REG_ENSURE(!rootKey.closeKey(), "test_registry_CppApi error 45");
  511. REG_ENSURE(!myRegistry->close(), "test_registry_CppApi error 46");
  512. REG_ENSURE(!myRegistry->open(OUString("test.rdb"), REG_READWRITE), "test_registry_CppApi error 47");
  513. REG_ENSURE(!myRegistry->destroy(OUString("test2.rdb")), "test_registry_CppApi error 48");
  514. // REG_ENSURE(!myRegistry->destroy("test3.rdb"), "test_registry_CppApi error 49");
  515. Registry *myRegistry2 = new Registry(*myRegistry);
  516. REG_ENSURE(myRegistry->destroy(OUString()), "test_registry_CppApi error 50");
  517. delete(myRegistry2);
  518. REG_ENSURE(!myRegistry->create(OUString("destroytest.rdb")), "test_registry_CppApi error 51");
  519. REG_ENSURE(!myRegistry->close(), "test_registry_CppApi error 52");
  520. REG_ENSURE(!myRegistry->open(OUString("destroytest.rdb"), REG_READONLY), "test_registry_CppApi error 53");
  521. REG_ENSURE(!myRegistry->openRootKey(rootKey), "test_registry_CppApi error 54");
  522. REG_ENSURE(myRegistry->mergeKey(rootKey, OUString("allFromTest3"),
  523. OUString("test3.rdb")), "test_registry_CppApi error 55");
  524. REG_ENSURE(!myRegistry->destroy(OUString("test3.rdb")), "test_registry_CppApi error 56");
  525. REG_ENSURE(!rootKey.closeKey(), "test_registry_CppApi error 57");
  526. REG_ENSURE(!myRegistry->close(), "test_registry_CppApi error 58");
  527. REG_ENSURE(!myRegistry->open(OUString("destroytest.rdb"), REG_READWRITE), "test_registry_CppApi error 59");
  528. REG_ENSURE(!myRegistry->destroy(OUString()), "test_registry_CppApi error 60");
  529. REG_ENSURE(!myRegistry->open(OUString("test.rdb"), REG_READWRITE), "test_registry_CppApi error 61");
  530. REG_ENSURE(!myRegistry->destroy(OUString("ucrtest.rdb")), "test_registry_CppApi error 62");
  531. REG_ENSURE(!myRegistry->destroy(OUString()), "test_registry_CppApi error 63");
  532. delete(myRegistry);
  533. cout << "test_registry_CppApi() Ok!\n";
  534. return;
  535. }
  536. /* vim:set shiftwidth=4 softtabstop=4 expandtab: */