testRegistry.cxx 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. // Work-around CMake dependency scanning limitation. This must
  15. // duplicate the above list of headers.
  16. #if 0
  17. # include "Registry.hxx.in"
  18. # include "kwsys_ios_iostream.h.in"
  19. #endif
  20. #define IFT(x,res) if ( !x ) \
  21. { \
  22. res = 1; \
  23. kwsys_ios::cout << "Error in: " << #x << kwsys_ios::endl; \
  24. }
  25. #define IFNT(x,res) if ( x ) \
  26. { \
  27. res = 1; \
  28. kwsys_ios::cout << "Error in: " << #x << kwsys_ios::endl; \
  29. }
  30. #define CHE(x,y,res) if ( x && y && strcmp(x,y) ) \
  31. { \
  32. res = 1; \
  33. kwsys_ios::cout << "Error, " << x << " != " << y << kwsys_ios::endl; \
  34. }
  35. int main(int, char**)
  36. {
  37. int res = 0;
  38. kwsys::Registry reg;
  39. reg.SetTopLevel("TestRegistry");
  40. IFT(reg.SetValue("TestSubkey", "TestKey1", "Test Value 1"), res);
  41. IFT(reg.SetValue("TestSubkey1", "TestKey2", "Test Value 2"), res);
  42. IFT(reg.SetValue("TestSubkey", "TestKey3", "Test Value 3"), res);
  43. IFT(reg.SetValue("TestSubkey2", "TestKey4", "Test Value 4"), res);
  44. const char *buffer;
  45. IFT(reg.ReadValue("TestSubkey", "TestKey1", &buffer), res);
  46. CHE(buffer, "Test Value 1", res);
  47. IFT(reg.ReadValue("TestSubkey1", "TestKey2", &buffer), res);
  48. CHE(buffer, "Test Value 2", res);
  49. IFT(reg.ReadValue("TestSubkey", "TestKey3", &buffer), res);
  50. CHE(buffer, "Test Value 3", res);
  51. IFT(reg.ReadValue("TestSubkey2", "TestKey4", &buffer), res);
  52. CHE(buffer, "Test Value 4", res);
  53. IFT(reg.SetValue("TestSubkey", "TestKey1", "New Test Value 1"), res);
  54. IFT(reg.SetValue("TestSubkey1", "TestKey2", "New Test Value 2"), res);
  55. IFT(reg.SetValue("TestSubkey", "TestKey3", "New Test Value 3"), res);
  56. IFT(reg.SetValue("TestSubkey2", "TestKey4", "New Test Value 4"), res);
  57. IFT(reg.ReadValue("TestSubkey", "TestKey1", &buffer), res);
  58. CHE(buffer, "New Test Value 1", res);
  59. IFT(reg.ReadValue("TestSubkey1", "TestKey2", &buffer), res);
  60. CHE(buffer, "New Test Value 2", res);
  61. IFT(reg.ReadValue("TestSubkey", "TestKey3", &buffer), res);
  62. CHE(buffer, "New Test Value 3", res);
  63. IFT(reg.ReadValue("TestSubkey2", "TestKey4", &buffer), res);
  64. CHE(buffer, "New Test Value 4", res);
  65. IFT( reg.DeleteValue("TestSubkey", "TestKey1"), res);
  66. IFNT(reg.ReadValue( "TestSubkey", "TestKey1", &buffer), res);
  67. IFT( reg.DeleteValue("TestSubkey1", "TestKey2"), res);
  68. IFNT(reg.ReadValue( "TestSubkey1", "TestKey2", &buffer), res);
  69. IFT( reg.DeleteValue("TestSubkey", "TestKey3"), res);
  70. IFNT(reg.ReadValue( "TestSubkey", "TestKey3", &buffer), res);
  71. IFT( reg.DeleteValue("TestSubkey2", "TestKey4"), res);
  72. IFNT(reg.ReadValue( "TestSubkey2", "TestKey5", &buffer), res);
  73. const char* longStringWithNewLines = "Value with embedded CR and LF characters CR='\015' LF='\012' CRLF='\015\012'";
  74. IFT(reg.SetValue("TestSubkeyWithVeryLongInFactSoLongItsHardToImagineAnybodyWouldReallyDoItLongName", "TestKey1", longStringWithNewLines), res);
  75. IFT(reg.ReadValue("TestSubkeyWithVeryLongInFactSoLongItsHardToImagineAnybodyWouldReallyDoItLongName", "TestKey1", &buffer), res);
  76. CHE(buffer, longStringWithNewLines, res);
  77. IFT(reg.DeleteValue("TestSubkeyWithVeryLongInFactSoLongItsHardToImagineAnybodyWouldReallyDoItLongName", "TestKey1"), res);
  78. IFNT(reg.ReadValue("TestSubkeyWithVeryLongInFactSoLongItsHardToImagineAnybodyWouldReallyDoItLongName", "TestKey1", &buffer), res);
  79. IFT(reg.SetValue("TestSubkeyWith = EqualSignChar", "TestKey = 1", "Some value"), res);
  80. IFT(reg.ReadValue("TestSubkeyWith = EqualSignChar", "TestKey = 1", &buffer), res);
  81. CHE(buffer, "Some value", res);
  82. IFT(reg.DeleteValue("TestSubkeyWith = EqualSignChar", "TestKey = 1"), res);
  83. IFNT(reg.ReadValue("TestSubkeyWith = EqualSignChar", "TestKey = 1", &buffer), res);
  84. if ( res )
  85. {
  86. kwsys_ios::cout << "Test failed" << kwsys_ios::endl;
  87. }
  88. else
  89. {
  90. kwsys_ios::cout << "Test passed" << kwsys_ios::endl;
  91. }
  92. return res;
  93. }