From b75c229444d8072fd63df2d723fb9cbec81f53f4 Mon Sep 17 00:00:00 2001 From: Andy Cedilnik Date: Thu, 10 Jul 2003 14:29:30 -0400 Subject: ENH: Add test for string and file commands --- Source/CMakeLists.txt | 5 ++++ Tests/StringFileTest/CMakeLists.txt | 46 +++++++++++++++++++++++++++++++++++++ Tests/StringFileTest/InputFile.h.in | 21 +++++++++++++++++ Tests/StringFileTest/StringFile.cxx | 24 +++++++++++++++++++ 4 files changed, 96 insertions(+) create mode 100644 Tests/StringFileTest/CMakeLists.txt create mode 100644 Tests/StringFileTest/InputFile.h.in create mode 100644 Tests/StringFileTest/StringFile.cxx diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt index c1ef09c..cadff58 100644 --- a/Source/CMakeLists.txt +++ b/Source/CMakeLists.txt @@ -168,6 +168,11 @@ IF(BUILD_TESTING) ${CMake_BINARY_DIR}/Tests/SystemInformation DumpInformation) + ADD_TEST(StringFileTest ${EXECUTABLE_OUTPUT_PATH}/cmaketest + ${CMake_SOURCE_DIR}/Tests/StringFileTest + ${CMake_BINARY_DIR}/Tests/StringFileTest + StringFileTest) + ADD_TEST(TryCompile ${EXECUTABLE_OUTPUT_PATH}/cmaketest ${CMake_SOURCE_DIR}/Tests/TryCompile ${CMake_BINARY_DIR}/Tests/TryCompile diff --git a/Tests/StringFileTest/CMakeLists.txt b/Tests/StringFileTest/CMakeLists.txt new file mode 100644 index 0000000..bd404a4 --- /dev/null +++ b/Tests/StringFileTest/CMakeLists.txt @@ -0,0 +1,46 @@ +PROJECT(StringFileTest) +INCLUDE_DIRECTORIES(${StringFileTest_BINARY_DIR}) + +FILE(READ "${CMAKE_CURRENT_SOURCE_DIR}/InputFile.h.in" infile) +STRING(REGEX MATCH "[cC][mM][aA][kK][eE]" rmvar "CMake is great") +STRING(REGEX MATCHALL "[cC][mM][aA][kK][eE]" rmallvar "CMake is better than cmake or CMake") +STRING(REGEX REPLACE "[Aa][uU][tT][oO]([cC][oO][nN][fF]|[mM][aA][kK][eE])" + "CMake" rrepvar "People should use Autoconf and Automake") +STRING(COMPARE EQUAL "CMake" "Autoconf" nceqvar) +STRING(COMPARE EQUAL "CMake" "CMake" ceqvar) +STRING(COMPARE NOTEQUAL "CMake" "Autoconf" cneqvar) +STRING(COMPARE NOTEQUAL "CMake" "CMake" ncneqvar) +STRING(COMPARE LESS "before" "after" nclvar) +STRING(COMPARE LESS "max" "min" clvar) +STRING(COMPARE GREATER "before" "after" cgvar) +STRING(COMPARE GREATER "max" "min" ncgvar) +STRING(ASCII 67 109 97 107 101 savar) +STRING(TOUPPER "CMake" tuvar) +STRING(TOLOWER "CMake" tlvar) + +FILE(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/Includes") + +SET(file "${CMAKE_CURRENT_BINARY_DIR}/Includes/Values.h") +FILE(WRITE "${file}" "/* this file is generated */\n") +FOREACH(var + rmvar + rmallvar + rrepvar + nceqvar + ceqvar + cneqvar + ncneqvar + nclvar + clvar + cgvar + ncgvar + savar + tuvar + tlvar) + FILE(APPEND "${file}" "#define ${var} \"${${var}}\"") +ENDFOREACH(var) + +STRING(REGEX REPLACE "includefile" "${file}" outfile "${infile}") +FILE(WRITE "${CMAKE_CURRENT_BINARY_DIR}/OutputFile.h" "${outfile}") + +ADD_EXECUTABLE(StringFileTest StringFile.cxx) diff --git a/Tests/StringFileTest/InputFile.h.in b/Tests/StringFileTest/InputFile.h.in new file mode 100644 index 0000000..1bda5af --- /dev/null +++ b/Tests/StringFileTest/InputFile.h.in @@ -0,0 +1,21 @@ +#include "includefile" + +int CheckMethod(const char* var, const char* val ) +{ + if ( !var ) + { + printf("Var not specified\n"); + return 1; + } + if ( !val ) + { + printf("Val not specified\n"); + return 1; + } + if ( strcmp(var, val) != 0) + { + printf("Var (%s) and Val (%s) are not the same...\n", var, val); + return 1; + } + return 0; +} diff --git a/Tests/StringFileTest/StringFile.cxx b/Tests/StringFileTest/StringFile.cxx new file mode 100644 index 0000000..6c3a7e3 --- /dev/null +++ b/Tests/StringFileTest/StringFile.cxx @@ -0,0 +1,24 @@ +#include +#include "OutputFile.h" + +int main(int, char*[]) +{ + int res = 0; + + res += CheckMethod(rmvar, "CMake"); + res += CheckMethod(rmallvar, "CMake;cmake;CMake"); + res += CheckMethod(rrepvar, "People should use CMake and CMake"); + res += CheckMethod(nceqvar, "0"); + res += CheckMethod(ceqvar, "1"); + res += CheckMethod(cneqvar, "1"); + res += CheckMethod(ncneqvar, "0"); + res += CheckMethod(nclvar, "0"); + res += CheckMethod(clvar, "1"); + res += CheckMethod(cgvar, "1"); + res += CheckMethod(ncgvar, "0"); + res += CheckMethod(savar, "Cmake"); + res += CheckMethod(tuvar, "CMAKE"); + res += CheckMethod(tlvar, "cmake"); + + return res; +} -- cgit v0.12