From 81ebecaea17cc18dfdda4fc3051eba08f6f076a0 Mon Sep 17 00:00:00 2001
From: Sebastien Barre <sebastien.barre@kitware.com>
Date: Mon, 1 Apr 2002 14:58:21 -0500
Subject: ENH: add test for registry-related functions (win32)

---
 Tests/Complex/CMakeLists.txt                      | 23 +++++++++++++++++++++++
 Tests/Complex/Executable/complex.cxx              | 20 +++++++++++++++++++-
 Tests/Complex/cmTestConfigure.h.in                |  6 ++++++
 Tests/ComplexOneConfig/CMakeLists.txt             | 23 +++++++++++++++++++++++
 Tests/ComplexOneConfig/Executable/complex.cxx     | 20 +++++++++++++++++++-
 Tests/ComplexOneConfig/cmTestConfigure.h.in       |  6 ++++++
 Tests/ComplexRelativePaths/CMakeLists.txt         | 23 +++++++++++++++++++++++
 Tests/ComplexRelativePaths/Executable/complex.cxx | 20 +++++++++++++++++++-
 Tests/ComplexRelativePaths/cmTestConfigure.h.in   |  6 ++++++
 9 files changed, 144 insertions(+), 3 deletions(-)

diff --git a/Tests/Complex/CMakeLists.txt b/Tests/Complex/CMakeLists.txt
index 41098aa..d5863fa 100644
--- a/Tests/Complex/CMakeLists.txt
+++ b/Tests/Complex/CMakeLists.txt
@@ -111,6 +111,29 @@ GET_SOURCE_FILE_PROPERTY(FILE_HAS_WRAP_EXCLUDE nonexisting_file2 WRAP_EXCLUDE)
 GET_SOURCE_FILE_PROPERTY(FILE_COMPILE_FLAGS nonexisting_file2 COMPILE_FLAGS)
 
 #
+# Test registry (win32)
+# Create a file, put its path in a registry key, try to find the file in that
+# path using that registry key, then remove the file and the key
+#
+IF (WIN32)
+  IF (NOT UNIX)
+    SET(dir "${Complex_BINARY_DIR}/registry_dir")
+    SET(file "registry_test_dummy")
+    SET(hkey "HKEY_CURRENT_USER\\Software\\Kitware\\CMake\\Tests\\Complex;registry_test")
+    CONFIGURE_FILE(
+      ${Complex_SOURCE_DIR}/Library/dummy
+      "${dir}/${file}"
+      COPYONLY IMMEDIATE)
+    EXEC_PROGRAM("${CCOMMAND_COMMAND} write_regv \"${hkey}\" \"${dir}\"")
+    FIND_PATH(REGISTRY_TEST_PATH
+              ${file}
+              "[${hkey}]")
+    EXEC_PROGRAM("${CCOMMAND_COMMAND} delete_regv \"${hkey}\"")
+    EXEC_PROGRAM("${CCOMMAND_COMMAND} remove \"${dir}/${file}\"")
+  ENDIF (NOT UNIX)
+ENDIF (WIN32)
+
+#
 # Configure file 
 # (plug vars to #define so that they can be tested)
 #
diff --git a/Tests/Complex/Executable/complex.cxx b/Tests/Complex/Executable/complex.cxx
index 8459571..61ffd8f 100644
--- a/Tests/Complex/Executable/complex.cxx
+++ b/Tests/Complex/Executable/complex.cxx
@@ -37,7 +37,7 @@ void ForceStringUse()
 
 void cmFailed(const char* Message, const char* m2= "")
 {
-  std::cerr << "FAILED: " << Message << m2 << "\n"; 
+  std::cout << "FAILED: " << Message << m2 << "\n"; 
   cm_failed++;
 }
 
@@ -613,6 +613,24 @@ int main()
 #endif
 
   // ----------------------------------------------------------------------
+  // Test registry (win32)
+#if defined(_WIN32) && !defined(__CYGWIN__)
+#ifndef REGISTRY_TEST_PATH
+  cmFailed("the CONFIGURE_FILE command is broken, REGISTRY_TEST_PATH is not defined.");
+#else
+  if(strcmp(REGISTRY_TEST_PATH, BINARY_DIR "/registry_dir") != 0)
+    {
+    cmFailed("the 'read registry value' function or CONFIGURE_FILE command is broken. REGISTRY_TEST_PATH == ", 
+             REGISTRY_TEST_PATH);
+    }
+  else
+    {
+    cmPassed("REGISTRY_TEST_PATH == ", REGISTRY_TEST_PATH);
+    }
+#endif
+#endif // defined(_WIN32) && !defined(__CYGWIN__)
+
+  // ----------------------------------------------------------------------
   // Summary
 
   std::cout << "Passed: " << cm_passed << "\n";
diff --git a/Tests/Complex/cmTestConfigure.h.in b/Tests/Complex/cmTestConfigure.h.in
index e27607a..5edff15 100644
--- a/Tests/Complex/cmTestConfigure.h.in
+++ b/Tests/Complex/cmTestConfigure.h.in
@@ -48,3 +48,9 @@
 #cmakedefine FILE_HAS_ABSTRACT
 #cmakedefine FILE_HAS_WRAP_EXCLUDE
 #define FILE_COMPILE_FLAGS "${FILE_COMPILE_FLAGS}"
+
+// Test registry read
+
+#if defined(_WIN32) && !defined(__CYGWIN__)
+#define REGISTRY_TEST_PATH "${REGISTRY_TEST_PATH}"
+#endif
diff --git a/Tests/ComplexOneConfig/CMakeLists.txt b/Tests/ComplexOneConfig/CMakeLists.txt
index 41098aa..d5863fa 100644
--- a/Tests/ComplexOneConfig/CMakeLists.txt
+++ b/Tests/ComplexOneConfig/CMakeLists.txt
@@ -111,6 +111,29 @@ GET_SOURCE_FILE_PROPERTY(FILE_HAS_WRAP_EXCLUDE nonexisting_file2 WRAP_EXCLUDE)
 GET_SOURCE_FILE_PROPERTY(FILE_COMPILE_FLAGS nonexisting_file2 COMPILE_FLAGS)
 
 #
+# Test registry (win32)
+# Create a file, put its path in a registry key, try to find the file in that
+# path using that registry key, then remove the file and the key
+#
+IF (WIN32)
+  IF (NOT UNIX)
+    SET(dir "${Complex_BINARY_DIR}/registry_dir")
+    SET(file "registry_test_dummy")
+    SET(hkey "HKEY_CURRENT_USER\\Software\\Kitware\\CMake\\Tests\\Complex;registry_test")
+    CONFIGURE_FILE(
+      ${Complex_SOURCE_DIR}/Library/dummy
+      "${dir}/${file}"
+      COPYONLY IMMEDIATE)
+    EXEC_PROGRAM("${CCOMMAND_COMMAND} write_regv \"${hkey}\" \"${dir}\"")
+    FIND_PATH(REGISTRY_TEST_PATH
+              ${file}
+              "[${hkey}]")
+    EXEC_PROGRAM("${CCOMMAND_COMMAND} delete_regv \"${hkey}\"")
+    EXEC_PROGRAM("${CCOMMAND_COMMAND} remove \"${dir}/${file}\"")
+  ENDIF (NOT UNIX)
+ENDIF (WIN32)
+
+#
 # Configure file 
 # (plug vars to #define so that they can be tested)
 #
diff --git a/Tests/ComplexOneConfig/Executable/complex.cxx b/Tests/ComplexOneConfig/Executable/complex.cxx
index 8459571..61ffd8f 100644
--- a/Tests/ComplexOneConfig/Executable/complex.cxx
+++ b/Tests/ComplexOneConfig/Executable/complex.cxx
@@ -37,7 +37,7 @@ void ForceStringUse()
 
 void cmFailed(const char* Message, const char* m2= "")
 {
-  std::cerr << "FAILED: " << Message << m2 << "\n"; 
+  std::cout << "FAILED: " << Message << m2 << "\n"; 
   cm_failed++;
 }
 
@@ -613,6 +613,24 @@ int main()
 #endif
 
   // ----------------------------------------------------------------------
+  // Test registry (win32)
+#if defined(_WIN32) && !defined(__CYGWIN__)
+#ifndef REGISTRY_TEST_PATH
+  cmFailed("the CONFIGURE_FILE command is broken, REGISTRY_TEST_PATH is not defined.");
+#else
+  if(strcmp(REGISTRY_TEST_PATH, BINARY_DIR "/registry_dir") != 0)
+    {
+    cmFailed("the 'read registry value' function or CONFIGURE_FILE command is broken. REGISTRY_TEST_PATH == ", 
+             REGISTRY_TEST_PATH);
+    }
+  else
+    {
+    cmPassed("REGISTRY_TEST_PATH == ", REGISTRY_TEST_PATH);
+    }
+#endif
+#endif // defined(_WIN32) && !defined(__CYGWIN__)
+
+  // ----------------------------------------------------------------------
   // Summary
 
   std::cout << "Passed: " << cm_passed << "\n";
diff --git a/Tests/ComplexOneConfig/cmTestConfigure.h.in b/Tests/ComplexOneConfig/cmTestConfigure.h.in
index e27607a..5edff15 100644
--- a/Tests/ComplexOneConfig/cmTestConfigure.h.in
+++ b/Tests/ComplexOneConfig/cmTestConfigure.h.in
@@ -48,3 +48,9 @@
 #cmakedefine FILE_HAS_ABSTRACT
 #cmakedefine FILE_HAS_WRAP_EXCLUDE
 #define FILE_COMPILE_FLAGS "${FILE_COMPILE_FLAGS}"
+
+// Test registry read
+
+#if defined(_WIN32) && !defined(__CYGWIN__)
+#define REGISTRY_TEST_PATH "${REGISTRY_TEST_PATH}"
+#endif
diff --git a/Tests/ComplexRelativePaths/CMakeLists.txt b/Tests/ComplexRelativePaths/CMakeLists.txt
index 41098aa..d5863fa 100644
--- a/Tests/ComplexRelativePaths/CMakeLists.txt
+++ b/Tests/ComplexRelativePaths/CMakeLists.txt
@@ -111,6 +111,29 @@ GET_SOURCE_FILE_PROPERTY(FILE_HAS_WRAP_EXCLUDE nonexisting_file2 WRAP_EXCLUDE)
 GET_SOURCE_FILE_PROPERTY(FILE_COMPILE_FLAGS nonexisting_file2 COMPILE_FLAGS)
 
 #
+# Test registry (win32)
+# Create a file, put its path in a registry key, try to find the file in that
+# path using that registry key, then remove the file and the key
+#
+IF (WIN32)
+  IF (NOT UNIX)
+    SET(dir "${Complex_BINARY_DIR}/registry_dir")
+    SET(file "registry_test_dummy")
+    SET(hkey "HKEY_CURRENT_USER\\Software\\Kitware\\CMake\\Tests\\Complex;registry_test")
+    CONFIGURE_FILE(
+      ${Complex_SOURCE_DIR}/Library/dummy
+      "${dir}/${file}"
+      COPYONLY IMMEDIATE)
+    EXEC_PROGRAM("${CCOMMAND_COMMAND} write_regv \"${hkey}\" \"${dir}\"")
+    FIND_PATH(REGISTRY_TEST_PATH
+              ${file}
+              "[${hkey}]")
+    EXEC_PROGRAM("${CCOMMAND_COMMAND} delete_regv \"${hkey}\"")
+    EXEC_PROGRAM("${CCOMMAND_COMMAND} remove \"${dir}/${file}\"")
+  ENDIF (NOT UNIX)
+ENDIF (WIN32)
+
+#
 # Configure file 
 # (plug vars to #define so that they can be tested)
 #
diff --git a/Tests/ComplexRelativePaths/Executable/complex.cxx b/Tests/ComplexRelativePaths/Executable/complex.cxx
index 8459571..61ffd8f 100644
--- a/Tests/ComplexRelativePaths/Executable/complex.cxx
+++ b/Tests/ComplexRelativePaths/Executable/complex.cxx
@@ -37,7 +37,7 @@ void ForceStringUse()
 
 void cmFailed(const char* Message, const char* m2= "")
 {
-  std::cerr << "FAILED: " << Message << m2 << "\n"; 
+  std::cout << "FAILED: " << Message << m2 << "\n"; 
   cm_failed++;
 }
 
@@ -613,6 +613,24 @@ int main()
 #endif
 
   // ----------------------------------------------------------------------
+  // Test registry (win32)
+#if defined(_WIN32) && !defined(__CYGWIN__)
+#ifndef REGISTRY_TEST_PATH
+  cmFailed("the CONFIGURE_FILE command is broken, REGISTRY_TEST_PATH is not defined.");
+#else
+  if(strcmp(REGISTRY_TEST_PATH, BINARY_DIR "/registry_dir") != 0)
+    {
+    cmFailed("the 'read registry value' function or CONFIGURE_FILE command is broken. REGISTRY_TEST_PATH == ", 
+             REGISTRY_TEST_PATH);
+    }
+  else
+    {
+    cmPassed("REGISTRY_TEST_PATH == ", REGISTRY_TEST_PATH);
+    }
+#endif
+#endif // defined(_WIN32) && !defined(__CYGWIN__)
+
+  // ----------------------------------------------------------------------
   // Summary
 
   std::cout << "Passed: " << cm_passed << "\n";
diff --git a/Tests/ComplexRelativePaths/cmTestConfigure.h.in b/Tests/ComplexRelativePaths/cmTestConfigure.h.in
index e27607a..5edff15 100644
--- a/Tests/ComplexRelativePaths/cmTestConfigure.h.in
+++ b/Tests/ComplexRelativePaths/cmTestConfigure.h.in
@@ -48,3 +48,9 @@
 #cmakedefine FILE_HAS_ABSTRACT
 #cmakedefine FILE_HAS_WRAP_EXCLUDE
 #define FILE_COMPILE_FLAGS "${FILE_COMPILE_FLAGS}"
+
+// Test registry read
+
+#if defined(_WIN32) && !defined(__CYGWIN__)
+#define REGISTRY_TEST_PATH "${REGISTRY_TEST_PATH}"
+#endif
-- 
cgit v0.12