summaryrefslogtreecommitdiff
path: root/Utilities/KWIML/test
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2011-06-27 14:08:31 -0400
committerBrad King <brad.king@kitware.com>2011-06-27 14:09:09 -0400
commitb2975adb31b891d87bb9828097a10167b811e96b (patch)
tree603e995eb053b4542225d31b3eb6513c8a64310a /Utilities/KWIML/test
parentea1a519a356cb8b6a54ca3858f20aa9560be9ccf (diff)
parent831badeca25a8eca9e92dbbb181ea69b58112b2c (diff)
downloadcmake-b2975adb31b891d87bb9828097a10167b811e96b.tar.gz
Merge branch 'upstream-kwiml' into import-KWIML
Introduce KWIML as a subtree at Utilities/KWIML.
Diffstat (limited to 'Utilities/KWIML/test')
-rw-r--r--Utilities/KWIML/test/CMakeLists.txt51
-rw-r--r--Utilities/KWIML/test/test.c35
-rw-r--r--Utilities/KWIML/test/test.cxx12
-rw-r--r--Utilities/KWIML/test/test.h35
-rw-r--r--Utilities/KWIML/test/test_ABI_C.c22
-rw-r--r--Utilities/KWIML/test/test_ABI_CXX.cxx22
-rw-r--r--Utilities/KWIML/test/test_ABI_endian.h.in47
-rw-r--r--Utilities/KWIML/test/test_INT_C.c22
-rw-r--r--Utilities/KWIML/test/test_INT_CXX.cxx22
-rw-r--r--Utilities/KWIML/test/test_INT_format.h.in188
10 files changed, 456 insertions, 0 deletions
diff --git a/Utilities/KWIML/test/CMakeLists.txt b/Utilities/KWIML/test/CMakeLists.txt
new file mode 100644
index 0000000000..aaff9e9343
--- /dev/null
+++ b/Utilities/KWIML/test/CMakeLists.txt
@@ -0,0 +1,51 @@
+#=============================================================================
+# Kitware Information Macro Library
+# Copyright 2010-2011 Kitware, Inc.
+#
+# Distributed under the OSI-approved BSD License (the "License");
+# see accompanying file Copyright.txt for details.
+#
+# This software is distributed WITHOUT ANY WARRANTY; without even the
+# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+# See the License for more information.
+#=============================================================================
+
+set(test_defs KWIML_NAMESPACE=${KWIML})
+
+# Tell CMake how to follow dependencies of sources in this directory.
+set_property(DIRECTORY
+ PROPERTY IMPLICIT_DEPENDS_INCLUDE_TRANSFORM
+ "KWIML_HEADER(%)=<${KWIML}/%>"
+ )
+
+if(KWIML_LANGUAGE_C)
+ set(test_srcs test.c)
+else()
+ set(test_srcs test.cxx)
+endif()
+if(KWIML_LANGUAGE_C)
+ list(APPEND test_defs KWIML_LANGUAGE_C)
+ list(APPEND test_srcs
+ test_ABI_C.c
+ test_INT_C.c
+ )
+endif()
+if(KWIML_LANGUAGE_CXX)
+ list(APPEND test_defs KWIML_LANGUAGE_CXX)
+ list(APPEND test_srcs
+ test_ABI_CXX.cxx
+ test_INT_CXX.cxx
+ )
+endif()
+
+foreach(th test_ABI_endian test_INT_format)
+ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/${th}.h.in
+ ${CMAKE_CURRENT_BINARY_DIR}/${th}.h @ONLY)
+endforeach()
+include_directories(BEFORE ${CMAKE_CURRENT_BINARY_DIR})
+add_executable(${KWIML}_test ${test_srcs})
+set_property(TARGET ${KWIML}_test PROPERTY COMPILE_DEFINITIONS ${test_defs})
+set_property(TARGET ${KWIML}_test PROPERTY
+ RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
+add_test(${KWIML}.test ${CMAKE_CURRENT_BINARY_DIR}/${KWIML}_test)
+set_property(TEST ${KWIML}.test PROPERTY LABELS ${KWIML_LABELS_TEST})
diff --git a/Utilities/KWIML/test/test.c b/Utilities/KWIML/test/test.c
new file mode 100644
index 0000000000..d71a28452c
--- /dev/null
+++ b/Utilities/KWIML/test/test.c
@@ -0,0 +1,35 @@
+/*============================================================================
+ Kitware Information Macro Library
+ Copyright 2010-2011 Kitware, Inc.
+
+ Distributed under the OSI-approved BSD License (the "License");
+ see accompanying file Copyright.txt for details.
+
+ This software is distributed WITHOUT ANY WARRANTY; without even the
+ implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ See the License for more information.
+============================================================================*/
+#ifdef __cplusplus
+extern "C" {
+#endif
+extern int test_ABI_C(void);
+extern int test_INT_C(void);
+extern int test_ABI_CXX(void);
+extern int test_INT_CXX(void);
+#ifdef __cplusplus
+} // extern "C"
+#endif
+
+int main(void)
+{
+ int result = 1;
+#ifdef KWIML_LANGUAGE_C
+ result = test_ABI_C() && result;
+ result = test_INT_C() && result;
+#endif
+#ifdef KWIML_LANGUAGE_CXX
+ result = test_ABI_CXX() && result;
+ result = test_INT_CXX() && result;
+#endif
+ return result? 0 : 1;
+}
diff --git a/Utilities/KWIML/test/test.cxx b/Utilities/KWIML/test/test.cxx
new file mode 100644
index 0000000000..bf614218a2
--- /dev/null
+++ b/Utilities/KWIML/test/test.cxx
@@ -0,0 +1,12 @@
+/*============================================================================
+ Kitware Information Macro Library
+ Copyright 2010-2011 Kitware, Inc.
+
+ Distributed under the OSI-approved BSD License (the "License");
+ see accompanying file Copyright.txt for details.
+
+ This software is distributed WITHOUT ANY WARRANTY; without even the
+ implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ See the License for more information.
+============================================================================*/
+#include "test.c"
diff --git a/Utilities/KWIML/test/test.h b/Utilities/KWIML/test/test.h
new file mode 100644
index 0000000000..8abb1952ac
--- /dev/null
+++ b/Utilities/KWIML/test/test.h
@@ -0,0 +1,35 @@
+/*============================================================================
+ Kitware Information Macro Library
+ Copyright 2010-2011 Kitware, Inc.
+
+ Distributed under the OSI-approved BSD License (the "License");
+ see accompanying file Copyright.txt for details.
+
+ This software is distributed WITHOUT ANY WARRANTY; without even the
+ implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ See the License for more information.
+============================================================================*/
+#ifndef KWIML_NAMESPACE
+# error "Do not include test.h outside of KWIML test files."
+#endif
+
+#ifndef KWIML_TEST_H
+#define KWIML_TEST_H
+
+/*
+ Define KWIML_HEADER macro to help the test files include kwiml
+ headers from the configured namespace directory. The macro can be
+ used like this:
+
+ #include KWIML_HEADER(ABI.h)
+*/
+#define KWIML_HEADER(x) KWIML_HEADER0(KWIML_NAMESPACE/x)
+#define KWIML_HEADER0(x) KWIML_HEADER1(x)
+#define KWIML_HEADER1(x) <x>
+
+/* Quiet MS standard library deprecation warnings. */
+#define _CRT_SECURE_NO_DEPRECATE
+
+#else
+# error "test.h included multiple times."
+#endif
diff --git a/Utilities/KWIML/test/test_ABI_C.c b/Utilities/KWIML/test/test_ABI_C.c
new file mode 100644
index 0000000000..3ca4ad3903
--- /dev/null
+++ b/Utilities/KWIML/test/test_ABI_C.c
@@ -0,0 +1,22 @@
+/*============================================================================
+ Kitware Information Macro Library
+ Copyright 2010-2011 Kitware, Inc.
+
+ Distributed under the OSI-approved BSD License (the "License");
+ see accompanying file Copyright.txt for details.
+
+ This software is distributed WITHOUT ANY WARRANTY; without even the
+ implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ See the License for more information.
+============================================================================*/
+#include "test.h"
+#include KWIML_HEADER(ABI.h)
+#include "test_ABI_endian.h"
+int test_ABI_C(void)
+{
+ if(!test_ABI_endian())
+ {
+ return 0;
+ }
+ return 1;
+}
diff --git a/Utilities/KWIML/test/test_ABI_CXX.cxx b/Utilities/KWIML/test/test_ABI_CXX.cxx
new file mode 100644
index 0000000000..7ede20e09f
--- /dev/null
+++ b/Utilities/KWIML/test/test_ABI_CXX.cxx
@@ -0,0 +1,22 @@
+/*============================================================================
+ Kitware Information Macro Library
+ Copyright 2010-2011 Kitware, Inc.
+
+ Distributed under the OSI-approved BSD License (the "License");
+ see accompanying file Copyright.txt for details.
+
+ This software is distributed WITHOUT ANY WARRANTY; without even the
+ implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ See the License for more information.
+============================================================================*/
+#include "test.h"
+#include KWIML_HEADER(ABI.h)
+#include "test_ABI_endian.h"
+extern "C" int test_ABI_CXX(void)
+{
+ if(!test_ABI_endian())
+ {
+ return 0;
+ }
+ return 1;
+}
diff --git a/Utilities/KWIML/test/test_ABI_endian.h.in b/Utilities/KWIML/test/test_ABI_endian.h.in
new file mode 100644
index 0000000000..992baeaebe
--- /dev/null
+++ b/Utilities/KWIML/test/test_ABI_endian.h.in
@@ -0,0 +1,47 @@
+/*============================================================================
+ Kitware Information Macro Library
+ Copyright 2010-2011 Kitware, Inc.
+
+ Distributed under the OSI-approved BSD License (the "License");
+ see accompanying file Copyright.txt for details.
+
+ This software is distributed WITHOUT ANY WARRANTY; without even the
+ implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ See the License for more information.
+============================================================================*/
+#include <stdio.h>
+
+#ifdef __cplusplus
+# define LANG "C++ "
+#else
+# define LANG "C "
+#endif
+
+static int test_ABI_endian(void)
+{
+ int result = 1;
+ {
+#if defined(@KWIML@_ABI_ENDIAN_ID)
+ int expect;
+ union { short s; unsigned char c[sizeof(short)]; } x;
+ x.s = 1;
+ expect = (x.c[0] == 1 ?
+ @KWIML@_ABI_ENDIAN_ID_LITTLE : @KWIML@_ABI_ENDIAN_ID_BIG);
+ printf(LANG "@KWIML@_ABI_ENDIAN_ID: expected [%d], got [%d]",
+ expect, @KWIML@_ABI_ENDIAN_ID);
+ if(@KWIML@_ABI_ENDIAN_ID == expect)
+ {
+ printf(", PASSED\n");
+ }
+ else
+ {
+ printf(", FAILED\n");
+ result = 0;
+ }
+#else
+ printf(LANG "@KWIML@_ABI_ENDIAN_ID: unknown, FAILED\n");
+ result = 0;
+#endif
+ }
+ return result;
+}
diff --git a/Utilities/KWIML/test/test_INT_C.c b/Utilities/KWIML/test/test_INT_C.c
new file mode 100644
index 0000000000..5513a0bd8f
--- /dev/null
+++ b/Utilities/KWIML/test/test_INT_C.c
@@ -0,0 +1,22 @@
+/*============================================================================
+ Kitware Information Macro Library
+ Copyright 2010-2011 Kitware, Inc.
+
+ Distributed under the OSI-approved BSD License (the "License");
+ see accompanying file Copyright.txt for details.
+
+ This software is distributed WITHOUT ANY WARRANTY; without even the
+ implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ See the License for more information.
+============================================================================*/
+#include "test.h"
+#include KWIML_HEADER(INT.h)
+#include "test_INT_format.h"
+int test_INT_C(void)
+{
+ if(!test_INT_format())
+ {
+ return 0;
+ }
+ return 1;
+}
diff --git a/Utilities/KWIML/test/test_INT_CXX.cxx b/Utilities/KWIML/test/test_INT_CXX.cxx
new file mode 100644
index 0000000000..9f74e96802
--- /dev/null
+++ b/Utilities/KWIML/test/test_INT_CXX.cxx
@@ -0,0 +1,22 @@
+/*============================================================================
+ Kitware Information Macro Library
+ Copyright 2010-2011 Kitware, Inc.
+
+ Distributed under the OSI-approved BSD License (the "License");
+ see accompanying file Copyright.txt for details.
+
+ This software is distributed WITHOUT ANY WARRANTY; without even the
+ implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ See the License for more information.
+============================================================================*/
+#include "test.h"
+#include KWIML_HEADER(INT.h)
+#include "test_INT_format.h"
+extern "C" int test_INT_CXX(void)
+{
+ if(!test_INT_format())
+ {
+ return 0;
+ }
+ return 1;
+}
diff --git a/Utilities/KWIML/test/test_INT_format.h.in b/Utilities/KWIML/test/test_INT_format.h.in
new file mode 100644
index 0000000000..72a62f259d
--- /dev/null
+++ b/Utilities/KWIML/test/test_INT_format.h.in
@@ -0,0 +1,188 @@
+/*============================================================================
+ Kitware Information Macro Library
+ Copyright 2010-2011 Kitware, Inc.
+
+ Distributed under the OSI-approved BSD License (the "License");
+ see accompanying file Copyright.txt for details.
+
+ This software is distributed WITHOUT ANY WARRANTY; without even the
+ implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ See the License for more information.
+============================================================================*/
+#include <stdio.h>
+#include <string.h>
+
+#ifdef __cplusplus
+# define LANG "C++ "
+#else
+# define LANG "C "
+#endif
+
+#define VALUE(T, U) \
+ (@KWIML@_INT_##T)((@KWIML@_INT_##U)0xab << \
+ ((sizeof(@KWIML@_INT_##T)-1)<<3)) \
+
+#define TEST_C(C, V, PRI, T, U) \
+ { \
+ @KWIML@_INT_##T const x = VALUE(T, U); \
+ @KWIML@_INT_##T y = @KWIML@_INT_##C(V); \
+ printf(LANG "@KWIML@_INT_" #C ":" \
+ " expression [%"@KWIML@_INT_PRI##PRI"]," \
+ " literal [%"@KWIML@_INT_PRI##PRI"]", x, y); \
+ if(x == y) \
+ { \
+ printf(", PASSED\n"); \
+ } \
+ else \
+ { \
+ printf(", FAILED\n"); \
+ result = 0; \
+ } \
+ }
+
+#define TEST_PRI(PRI, T, U, STR) \
+ { \
+ @KWIML@_INT_##T const x = VALUE(T, U); \
+ char const* str = STR; \
+ sprintf(buf, "%"@KWIML@_INT_PRI##PRI, x); \
+ printf(LANG "@KWIML@_INT_PRI" #PRI ":" \
+ " expected [%s], got [%s]", str, buf); \
+ if(strcmp(str, buf) == 0) \
+ { \
+ printf(", PASSED\n"); \
+ } \
+ else \
+ { \
+ printf(", FAILED\n"); \
+ result = 0; \
+ } \
+ }
+
+#define TEST_SCN(SCN, T, U, STR) TEST_SCN2(SCN, SCN, T, U, STR)
+#define TEST_SCN2(PRI, SCN, T, U, STR) \
+ { \
+ @KWIML@_INT_##T const x = VALUE(T, U); \
+ @KWIML@_INT_##T y; \
+ char const* str = STR; \
+ if(sscanf(str, "%"@KWIML@_INT_SCN##SCN, &y) != 1) \
+ { \
+ y = 0; \
+ } \
+ printf(LANG "@KWIML@_INT_SCN" #SCN ":" \
+ " expected [%"@KWIML@_INT_PRI##PRI"]," \
+ " got [%"@KWIML@_INT_PRI##PRI"]", x, y); \
+ if(x == y) \
+ { \
+ printf(", PASSED\n"); \
+ } \
+ else \
+ { \
+ printf(", FAILED\n"); \
+ result = 0; \
+ } \
+ }
+
+#define TEST(FMT, T, U, STR) TEST2(FMT, FMT, T, U, STR)
+#define TEST2(PRI, SCN, T, U, STR) \
+ TEST_PRI(PRI, T, U, STR) \
+ TEST_SCN2(PRI, SCN, T, U, STR)
+
+static int test_INT_format(void)
+{
+ int result = 1;
+ char buf[256];
+ TEST_PRI(i8, int8_t, uint8_t, "-85")
+#if defined(@KWIML@_INT_SCNi8)
+ TEST_SCN(i8, int8_t, uint8_t, "-85")
+#endif
+ TEST_PRI(d8, int8_t, uint8_t, "-85")
+#if defined(@KWIML@_INT_SCNd8)
+ TEST_SCN(d8, int8_t, uint8_t, "-85")
+#endif
+ TEST_PRI(o8, uint8_t, uint8_t, "253")
+#if defined(@KWIML@_INT_SCNo8)
+ TEST_SCN(o8, uint8_t, uint8_t, "253")
+#endif
+ TEST_PRI(u8, uint8_t, uint8_t, "171")
+#if defined(@KWIML@_INT_SCNu8)
+ TEST_SCN(u8, uint8_t, uint8_t, "171")
+#endif
+ TEST_PRI(x8, uint8_t, uint8_t, "ab")
+ TEST_PRI(X8, uint8_t, uint8_t, "AB")
+#if defined(@KWIML@_INT_SCNx8)
+ TEST_SCN(x8, uint8_t, uint8_t, "ab")
+ TEST_SCN2(X8, x8, uint8_t, uint8_t, "AB")
+#endif
+
+ TEST(i16, int16_t, uint16_t, "-21760")
+ TEST(d16, int16_t, uint16_t, "-21760")
+ TEST(o16, uint16_t, uint16_t, "125400")
+ TEST(u16, uint16_t, uint16_t, "43776")
+ TEST(x16, uint16_t, uint16_t, "ab00")
+ TEST2(X16, x16, uint16_t, uint16_t, "AB00")
+
+ TEST(i32, int32_t, uint32_t, "-1426063360")
+ TEST(d32, int32_t, uint32_t, "-1426063360")
+ TEST(o32, uint32_t, uint32_t, "25300000000")
+ TEST(u32, uint32_t, uint32_t, "2868903936")
+ TEST(x32, uint32_t, uint32_t, "ab000000")
+ TEST2(X32, x32, uint32_t, uint32_t, "AB000000")
+
+ TEST_PRI(i64, int64_t, uint64_t, "-6124895493223874560")
+#if defined(@KWIML@_INT_SCNi64)
+ TEST_SCN(i64, int64_t, uint64_t, "-6124895493223874560")
+#endif
+ TEST_PRI(d64, int64_t, uint64_t, "-6124895493223874560")
+#if defined(@KWIML@_INT_SCNd64)
+ TEST_SCN(d64, int64_t, uint64_t, "-6124895493223874560")
+#endif
+ TEST_PRI(o64, uint64_t, uint64_t, "1254000000000000000000")
+#if defined(@KWIML@_INT_SCNo64)
+ TEST_SCN(o64, uint64_t, uint64_t, "1254000000000000000000")
+#endif
+ TEST_PRI(u64, uint64_t, uint64_t, "12321848580485677056")
+#if defined(@KWIML@_INT_SCNu64)
+ TEST_SCN(u64, uint64_t, uint64_t, "12321848580485677056")
+#endif
+ TEST_PRI(x64, uint64_t, uint64_t, "ab00000000000000")
+ TEST_PRI(X64, uint64_t, uint64_t, "AB00000000000000")
+#if defined(@KWIML@_INT_SCNx64)
+ TEST_SCN(x64, uint64_t, uint64_t, "ab00000000000000")
+ TEST_SCN2(X64, x64, uint64_t, uint64_t, "AB00000000000000")
+#endif
+
+#if !defined(@KWIML@_INT_NO_INTPTR_T)
+# if @KWIML@_ABI_SIZEOF_DATA_PTR == 4
+ TEST(iPTR, intptr_t, uint32_t, "-1426063360")
+ TEST(dPTR, intptr_t, uint32_t, "-1426063360")
+# else
+ TEST(iPTR, intptr_t, uint64_t, "-6124895493223874560")
+ TEST(dPTR, intptr_t, uint64_t, "-6124895493223874560")
+# endif
+#endif
+
+#if !defined(@KWIML@_INT_NO_UINTPTR_T)
+# if @KWIML@_ABI_SIZEOF_DATA_PTR == 4
+ TEST(oPTR, uintptr_t, uintptr_t, "25300000000")
+ TEST(uPTR, uintptr_t, uintptr_t, "2868903936")
+ TEST(xPTR, uintptr_t, uintptr_t, "ab000000")
+ TEST2(XPTR, xPTR, uintptr_t, uintptr_t, "AB000000")
+# else
+ TEST(oPTR, uintptr_t, uintptr_t, "1254000000000000000000")
+ TEST(uPTR, uintptr_t, uintptr_t, "12321848580485677056")
+ TEST(xPTR, uintptr_t, uintptr_t, "ab00000000000000")
+ TEST2(XPTR, xPTR, uintptr_t, uintptr_t, "AB00000000000000")
+# endif
+#endif
+
+ TEST_C(INT8_C, -0x55, i8, int8_t, uint8_t)
+ TEST_C(UINT8_C, 0xAB, u8, uint8_t, uint8_t)
+ TEST_C(INT16_C, -0x5500, i16, int16_t, uint16_t)
+ TEST_C(UINT16_C, 0xAB00, u16, uint16_t, uint16_t)
+ TEST_C(INT32_C, -0x55000000, i32, int32_t, uint32_t)
+ TEST_C(UINT32_C, 0xAB000000, u32, uint32_t, uint32_t)
+ TEST_C(INT64_C, -0x5500000000000000, i64, int64_t, uint64_t)
+ TEST_C(UINT64_C, 0xAB00000000000000, u64, uint64_t, uint64_t)
+
+ return result;
+}