summaryrefslogtreecommitdiffstats
path: root/Tests
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2009-12-17 20:15:34 (GMT)
committerBrad King <brad.king@kitware.com>2009-12-17 20:15:34 (GMT)
commit11e6b513c2d642628e047369773188b0d485c581 (patch)
tree458ab7ebe45db0fc8dc3bb25e5657ae02f640b68 /Tests
parentc9b726c314c9c399975fbea3c673852310ee45e6 (diff)
downloadCMake-11e6b513c2d642628e047369773188b0d485c581.zip
CMake-11e6b513c2d642628e047369773188b0d485c581.tar.gz
CMake-11e6b513c2d642628e047369773188b0d485c581.tar.bz2
Test the CheckTypeSize module
We create test "Module.CheckTypeSize" to verify that type sizes get detected correctly.
Diffstat (limited to 'Tests')
-rw-r--r--Tests/CMakeLists.txt2
-rw-r--r--Tests/Module/CheckTypeSize/CMakeLists.txt18
-rw-r--r--Tests/Module/CheckTypeSize/CheckTypeSize.c122
-rw-r--r--Tests/Module/CheckTypeSize/config.h.in39
4 files changed, 181 insertions, 0 deletions
diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt
index 0081a6e..4c6b333 100644
--- a/Tests/CMakeLists.txt
+++ b/Tests/CMakeLists.txt
@@ -172,6 +172,8 @@ IF(BUILD_TESTING)
"${CMake_BINARY_DIR}/Tests/CMakeBuildTest.cmake")
LIST(APPEND TEST_BUILD_DIRS ${CMAKE_BUILD_TEST_BINARY_DIR})
+ ADD_TEST_MACRO(Module.CheckTypeSize CheckTypeSize)
+
# If we are running right now with a UnixMakefiles based generator,
# build the "Simple" test with the ExtraGenerators, if available
# This doesn't test whether the generated project files work (unfortunately),
diff --git a/Tests/Module/CheckTypeSize/CMakeLists.txt b/Tests/Module/CheckTypeSize/CMakeLists.txt
new file mode 100644
index 0000000..45e9f67
--- /dev/null
+++ b/Tests/Module/CheckTypeSize/CMakeLists.txt
@@ -0,0 +1,18 @@
+cmake_minimum_required(VERSION 2.8.1 FATAL_ERROR)
+project(CheckTypeSize C)
+
+include(CheckTypeSize)
+check_type_size("void*" SIZEOF_DATA_PTR)
+check_type_size(char SIZEOF_CHAR)
+check_type_size(short SIZEOF_SHORT)
+check_type_size(int SIZEOF_INT)
+check_type_size(long SIZEOF_LONG)
+check_type_size("long long" SIZEOF_LONG_LONG)
+check_type_size(__int64 SIZEOF___INT64)
+check_type_size(size_t SIZEOF_SIZE_T)
+check_type_size(ssize_t SIZEOF_SSIZE_T)
+
+configure_file(config.h.in config.h)
+include_directories(${CheckTypeSize_BINARY_DIR})
+
+add_executable(CheckTypeSize CheckTypeSize.c)
diff --git a/Tests/Module/CheckTypeSize/CheckTypeSize.c b/Tests/Module/CheckTypeSize/CheckTypeSize.c
new file mode 100644
index 0000000..602c834
--- /dev/null
+++ b/Tests/Module/CheckTypeSize/CheckTypeSize.c
@@ -0,0 +1,122 @@
+#include "config.h"
+
+#ifdef HAVE_SYS_TYPES_H
+# include <sys/types.h>
+#endif
+#ifdef HAVE_STDINT_H
+# include <stdint.h>
+#endif
+#ifdef HAVE_STDDEF_H
+# include <stddef.h>
+#endif
+
+#include <stdio.h>
+
+#define CHECK(t,m) do { \
+ if(sizeof(t) != m) \
+ { \
+ printf(#m ": expected %d, got %d (line %d)\n", \
+ (int)sizeof(t), (int)m, __LINE__); \
+ result = 1; \
+ } \
+ } while(0)
+
+#define NODEF(m) do { \
+ printf(#m": not defined (line %d)\n", __LINE__); \
+ result = 1; \
+ } while(0)
+
+int main()
+{
+ int result = 0;
+
+ /* void* */
+#if !defined(HAVE_SIZEOF_DATA_PTR)
+ NODEF(HAVE_SIZEOF_DATA_PTR);
+#endif
+#if defined(SIZEOF_DATA_PTR)
+ CHECK(void*, SIZEOF_DATA_PTR);
+#else
+ NODEF(SIZEOF_DATA_PTR);
+#endif
+
+ /* char */
+#if !defined(HAVE_SIZEOF_CHAR)
+ NODEF(HAVE_SIZEOF_CHAR);
+#endif
+#if defined(SIZEOF_CHAR)
+ CHECK(char, SIZEOF_CHAR);
+#else
+ NODEF(SIZEOF_CHAR);
+#endif
+
+ /* short */
+#if !defined(HAVE_SIZEOF_SHORT)
+ NODEF(HAVE_SIZEOF_SHORT);
+#endif
+#if defined(SIZEOF_SHORT)
+ CHECK(short, SIZEOF_SHORT);
+#else
+ NODEF(SIZEOF_SHORT);
+#endif
+
+ /* int */
+#if !defined(HAVE_SIZEOF_INT)
+ NODEF(HAVE_SIZEOF_INT);
+#endif
+#if defined(SIZEOF_INT)
+ CHECK(int, SIZEOF_INT);
+#else
+ NODEF(SIZEOF_INT);
+#endif
+
+ /* long */
+#if !defined(HAVE_SIZEOF_LONG)
+ NODEF(HAVE_SIZEOF_LONG);
+#endif
+#if defined(SIZEOF_LONG)
+ CHECK(long, SIZEOF_LONG);
+#else
+ NODEF(SIZEOF_LONG);
+#endif
+
+ /* long long */
+#if defined(SIZEOF_LONG_LONG)
+ CHECK(long long, SIZEOF_LONG_LONG);
+# if !defined(HAVE_SIZEOF_LONG_LONG)
+ NODEF(HAVE_SIZEOF_LONG_LONG);
+# endif
+#endif
+
+ /* __int64 */
+#if defined(SIZEOF___INT64)
+ CHECK(__int64, SIZEOF___INT64);
+# if !defined(HAVE_SIZEOF___INT64)
+ NODEF(HAVE_SIZEOF___INT64);
+# endif
+#elif defined(HAVE_SIZEOF___INT64)
+ NODEF(SIZEOF___INT64);
+#endif
+
+ /* size_t */
+#if !defined(HAVE_SIZEOF_SIZE_T)
+ NODEF(HAVE_SIZEOF_SIZE_T);
+#endif
+#if defined(SIZEOF_SIZE_T)
+ CHECK(size_t, SIZEOF_SIZE_T);
+#else
+ NODEF(SIZEOF_SIZE_T);
+#endif
+
+ /* ssize_t */
+#if defined(SIZEOF_SSIZE_T)
+ CHECK(ssize_t, SIZEOF_SSIZE_T);
+# if !defined(HAVE_SIZEOF_SSIZE_T)
+ NODEF(HAVE_SIZEOF_SSIZE_T);
+# endif
+#elif defined(HAVE_SIZEOF_SSIZE_T)
+ NODEF(SIZEOF_SSIZE_T);
+#endif
+
+ return result;
+}
diff --git a/Tests/Module/CheckTypeSize/config.h.in b/Tests/Module/CheckTypeSize/config.h.in
new file mode 100644
index 0000000..b5bfbf6
--- /dev/null
+++ b/Tests/Module/CheckTypeSize/config.h.in
@@ -0,0 +1,39 @@
+#cmakedefine HAVE_SYS_TYPES_H
+#cmakedefine HAVE_STDINT_H
+#cmakedefine HAVE_STDDEF_H
+
+/* void* */
+#cmakedefine HAVE_SIZEOF_DATA_PTR
+@SIZEOF_DATA_PTR_CODE@
+
+/* char */
+#cmakedefine HAVE_SIZEOF_CHAR
+@SIZEOF_CHAR_CODE@
+
+/* short */
+#cmakedefine HAVE_SIZEOF_SHORT
+@SIZEOF_SHORT_CODE@
+
+/* int */
+#cmakedefine HAVE_SIZEOF_INT
+@SIZEOF_INT_CODE@
+
+/* long */
+#cmakedefine HAVE_SIZEOF_LONG
+@SIZEOF_LONG_CODE@
+
+/* long long */
+#cmakedefine HAVE_SIZEOF_LONG_LONG
+@SIZEOF_LONG_LONG_CODE@
+
+/* __int64 */
+#cmakedefine HAVE_SIZEOF___INT64
+@SIZEOF___INT64_CODE@
+
+/* size_t */
+#cmakedefine HAVE_SIZEOF_SIZE_T
+@SIZEOF_SIZE_T_CODE@
+
+/* ssize_t */
+#cmakedefine HAVE_SIZEOF_SSIZE_T
+@SIZEOF_SSIZE_T_CODE@