summaryrefslogtreecommitdiffstats
path: root/Tests/FunctionTest
diff options
context:
space:
mode:
authorKen Martin <ken.martin@kitware.com>2007-12-03 17:44:42 (GMT)
committerKen Martin <ken.martin@kitware.com>2007-12-03 17:44:42 (GMT)
commit951444165f4c18c83efe47f8e86656df9c690983 (patch)
tree97989bfe2f1fc2e710152d64cfa3cfa55a5731d6 /Tests/FunctionTest
parent50bdabde07e4339c8ce0118a128d53eb1f9c14a0 (diff)
downloadCMake-951444165f4c18c83efe47f8e86656df9c690983.zip
CMake-951444165f4c18c83efe47f8e86656df9c690983.tar.gz
CMake-951444165f4c18c83efe47f8e86656df9c690983.tar.bz2
ENH: add functions and raise scope to cmake
Diffstat (limited to 'Tests/FunctionTest')
-rw-r--r--Tests/FunctionTest/CMakeLists.txt86
-rw-r--r--Tests/FunctionTest/functionTest.c7
2 files changed, 93 insertions, 0 deletions
diff --git a/Tests/FunctionTest/CMakeLists.txt b/Tests/FunctionTest/CMakeLists.txt
new file mode 100644
index 0000000..76c2511
--- /dev/null
+++ b/Tests/FunctionTest/CMakeLists.txt
@@ -0,0 +1,86 @@
+# a simple C only test case
+PROJECT (FunctionTest)
+
+SET(CMAKE_C_FLAGS "${CMAKE_ANSI_CFLAGS} ${CMAKE_C_FLAGS}")
+
+FUNCTION(FAILED testname)
+ MESSAGE(SEND_ERROR "${testname} failed ${ARGN}")
+ENDFUNCTION(FAILED)
+
+FUNCTION(PASS testname)
+ MESSAGE("${testname} passed ${ARGN}")
+ENDFUNCTION(PASS)
+
+
+# test scope
+SET(COUNT 3)
+FUNCTION(scope_test)
+ SET(COUNT 4)
+ENDFUNCTION(scope_test)
+scope_test()
+IF(COUNT EQUAL "3")
+ PASS("scope")
+ELSE(COUNT EQUAL "3")
+ FAILED("COUNT Got: ${COUNT}")
+ENDIF(COUNT EQUAL "3")
+
+# test ARGC
+FUNCTION(weird_name)
+ IF("${ARGC}" EQUAL "3")
+ PASS("ARGC")
+ ELSE("${ARGC}" EQUAL "3")
+ FAILED("ARGC" "Got: ${ARGC}")
+ ENDIF("${ARGC}" EQUAL "3")
+ENDFUNCTION(weird_name)
+WeIrD_nAmE(a1 a2 a3)
+
+# test ARGN
+FUNCTION(test_argn_function argument)
+ IF("${ARGN}" EQUAL "3")
+ PASS("ARGN")
+ ELSE("${ARGN}" EQUAL "3")
+ FAILED("ARGN" "Got: ${ARGN}")
+ ENDIF("${ARGN}" EQUAL "3")
+ENDFUNCTION(test_argn_function)
+Test_Argn_Function(ignored 3)
+
+# test recursion and return via raise_scope
+function (factorial argument result)
+ if (argument LESS 2)
+ set (${result} 1)
+ else (argument LESS 2)
+ math (EXPR temp "${argument} - 1")
+ factorial (${temp} tresult)
+ math (EXPR ${result} "${argument}*${tresult}")
+ endif (argument LESS 2)
+ raise_scope (${result})
+endfunction (factorial)
+
+factorial (5 fresult)
+if (fresult EQUAL 120)
+ pass("factorial")
+else (fresult EQUAL 120)
+ failed ("factorial, computed ${fresult} instead of 120")
+endif (fresult EQUAL 120)
+
+
+
+# case test
+FUNCTION(strange_function m)
+ SET(${m} strange_function)
+ RAISE_SCOPE(${m})
+ENDFUNCTION(strange_function m)
+STRANGE_FUNCTION(var)
+set(second_var "second_var")
+IF("${var}" STREQUAL "strange_function" AND "${second_var}" STREQUAL "second_var")
+ PASS("Case Test" "(${var} ${second_var})")
+ELSE("${var}" STREQUAL "strange_function" AND "${second_var}" STREQUAL "second_var")
+ FAILED("Case test" "(${var} ${second_var})")
+ENDIF("${var}" STREQUAL "strange_function" AND "${second_var}" STREQUAL "second_var")
+
+# test backing up command
+FUNCTION(ADD_EXECUTABLE exec)
+ _ADD_EXECUTABLE(mini${exec} ${ARGN})
+ENDFUNCTION(ADD_EXECUTABLE)
+
+ADD_EXECUTABLE(FunctionTest functionTest.c)
diff --git a/Tests/FunctionTest/functionTest.c b/Tests/FunctionTest/functionTest.c
new file mode 100644
index 0000000..e0ced6a
--- /dev/null
+++ b/Tests/FunctionTest/functionTest.c
@@ -0,0 +1,7 @@
+#include <stdio.h>
+
+int main(int argc, char* argv[])
+{
+ printf("Running command: %s with %d arguments\n", argv[0], argc);
+ return 0;
+}