Resync
[CMakeLuaTailorHgBridge.git] / CMakeLua / Source / kwsys / testRegistry.cxx
blobf2435585a1915d7bfcfd0a629fe8f4e4647d72be
1 /*=========================================================================
3 Program: ParaView
4 Module: $RCSfile: testRegistry.cxx,v $
6 Copyright (c) Kitware, Inc.
7 All rights reserved.
8 See Copyright.txt or http://www.paraview.org/HTML/Copyright.html for details.
10 This software is distributed WITHOUT ANY WARRANTY; without even
11 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12 PURPOSE. See the above copyright notices for more information.
14 =========================================================================*/
15 #include "kwsysPrivate.h"
17 #include KWSYS_HEADER(Registry.hxx)
18 #include KWSYS_HEADER(ios/iostream)
19 #include <string.h>
21 // Work-around CMake dependency scanning limitation. This must
22 // duplicate the above list of headers.
23 #if 0
24 # include "Registry.hxx.in"
25 # include "kwsys_ios_iostream.h.in"
26 #endif
28 #define IFT(x,res) if ( !x ) \
29 { \
30 res = 1; \
31 kwsys_ios::cout << "Error in: " << #x << kwsys_ios::endl; \
33 #define IFNT(x,res) if ( x ) \
34 { \
35 res = 1; \
36 kwsys_ios::cout << "Error in: " << #x << kwsys_ios::endl; \
39 #define CHE(x,y,res) if ( x && strcmp(x,y) ) \
40 { \
41 res = 1; \
42 kwsys_ios::cout << "Error, " << x << " != " << y << kwsys_ios::endl; \
45 int testRegistry(int, char*[])
47 int res = 0;
49 kwsys::Registry reg;
50 reg.SetTopLevel("TestRegistry");
52 IFT(reg.SetValue("TestSubkey", "TestKey1", "Test Value 1"), res);
53 IFT(reg.SetValue("TestSubkey1", "TestKey2", "Test Value 2"), res);
54 IFT(reg.SetValue("TestSubkey", "TestKey3", "Test Value 3"), res);
55 IFT(reg.SetValue("TestSubkey2", "TestKey4", "Test Value 4"), res);
57 const char *buffer;
58 IFT(reg.ReadValue("TestSubkey", "TestKey1", &buffer), res);
59 CHE(buffer, "Test Value 1", res);
60 IFT(reg.ReadValue("TestSubkey1", "TestKey2", &buffer), res);
61 CHE(buffer, "Test Value 2", res);
62 IFT(reg.ReadValue("TestSubkey", "TestKey3", &buffer), res);
63 CHE(buffer, "Test Value 3", res);
64 IFT(reg.ReadValue("TestSubkey2", "TestKey4", &buffer), res);
65 CHE(buffer, "Test Value 4", res);
67 IFT(reg.SetValue("TestSubkey", "TestKey1", "New Test Value 1"), res);
68 IFT(reg.SetValue("TestSubkey1", "TestKey2", "New Test Value 2"), res);
69 IFT(reg.SetValue("TestSubkey", "TestKey3", "New Test Value 3"), res);
70 IFT(reg.SetValue("TestSubkey2", "TestKey4", "New Test Value 4"), res);
72 IFT(reg.ReadValue("TestSubkey", "TestKey1", &buffer), res);
73 CHE(buffer, "New Test Value 1", res);
74 IFT(reg.ReadValue("TestSubkey1", "TestKey2", &buffer), res);
75 CHE(buffer, "New Test Value 2", res);
76 IFT(reg.ReadValue("TestSubkey", "TestKey3", &buffer), res);
77 CHE(buffer, "New Test Value 3", res);
78 IFT(reg.ReadValue("TestSubkey2", "TestKey4", &buffer), res);
79 CHE(buffer, "New Test Value 4", res);
81 IFT( reg.DeleteValue("TestSubkey", "TestKey1"), res);
82 IFNT(reg.ReadValue( "TestSubkey", "TestKey1", &buffer), res);
83 IFT( reg.DeleteValue("TestSubkey1", "TestKey2"), res);
84 IFNT(reg.ReadValue( "TestSubkey1", "TestKey2", &buffer), res);
85 IFT( reg.DeleteValue("TestSubkey", "TestKey3"), res);
86 IFNT(reg.ReadValue( "TestSubkey", "TestKey3", &buffer), res);
87 IFT( reg.DeleteValue("TestSubkey2", "TestKey4"), res);
88 IFNT(reg.ReadValue( "TestSubkey2", "TestKey5", &buffer), res);
90 const char* longStringWithNewLines = "Value with embedded CR and LF characters CR='\015' LF='\012' CRLF='\015\012'";
91 IFT(reg.SetValue("TestSubkeyWithVeryLongInFactSoLongItsHardToImagineAnybodyWouldReallyDoItLongName", "TestKey1", longStringWithNewLines), res);
92 IFT(reg.ReadValue("TestSubkeyWithVeryLongInFactSoLongItsHardToImagineAnybodyWouldReallyDoItLongName", "TestKey1", &buffer), res);
93 CHE(buffer, longStringWithNewLines, res);
94 IFT(reg.DeleteValue("TestSubkeyWithVeryLongInFactSoLongItsHardToImagineAnybodyWouldReallyDoItLongName", "TestKey1"), res);
95 IFNT(reg.ReadValue("TestSubkeyWithVeryLongInFactSoLongItsHardToImagineAnybodyWouldReallyDoItLongName", "TestKey1", &buffer), res);
97 IFT(reg.SetValue("TestSubkeyWith = EqualSignChar", "TestKey = 1", "Some value"), res);
98 IFT(reg.ReadValue("TestSubkeyWith = EqualSignChar", "TestKey = 1", &buffer), res);
99 CHE(buffer, "Some value", res);
100 IFT(reg.DeleteValue("TestSubkeyWith = EqualSignChar", "TestKey = 1"), res);
101 IFNT(reg.ReadValue("TestSubkeyWith = EqualSignChar", "TestKey = 1", &buffer), res);
103 if ( res )
105 kwsys_ios::cout << "Test failed" << kwsys_ios::endl;
107 else
109 kwsys_ios::cout << "Test passed" << kwsys_ios::endl;
111 return res;