testRegistry.cxx 4.7 KB

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