From 8d77a473045e35ca5484b7457e170236866d84c6 Mon Sep 17 00:00:00 2001 From: Jared Duke Date: Fri, 5 Sep 2014 17:42:59 -0700 Subject: [PATCH] Support unit tests for non-MSVC builds The currently included version of cppunit supports compilation only with MSVC compilers, as it lacks the necessary config-auto.h header typically generated via configure. Address this by using CMake to auto-generate the configuration header for all other compilers, restoring balance to the universe. --- code/AssbinExporter.cpp | 2 + test/CMakeLists.txt | 105 ++++++++++++++++++++++++ test/unit/cppunit-config/config.h.cmake | 103 +++++++++++++++++++++++ test/unit/utRemoveComments.cpp | 2 +- 4 files changed, 211 insertions(+), 1 deletion(-) create mode 100644 test/unit/cppunit-config/config.h.cmake diff --git a/code/AssbinExporter.cpp b/code/AssbinExporter.cpp index a330dfd45..82a0046d4 100644 --- a/code/AssbinExporter.cpp +++ b/code/AssbinExporter.cpp @@ -51,6 +51,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # include "../contrib/zlib/zlib.h" #endif +#include + #ifndef ASSIMP_BUILD_NO_EXPORT #ifndef ASSIMP_BUILD_NO_ASSBIN_EXPORTER diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 92b618558..1889b3798 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -16,6 +16,111 @@ SOURCE_GROUP( unit FILES ) if(WIN32) +# cpppunit provides configuration headers for MSVC. Other plaforms require +# explicit creation at configure time. +if(NOT MSVC) + # Generates include/cppunit/config-auto.h + # This is originally done by autoconf + + include(CheckIncludeFile) + include(CheckIncludeFileCXX) + include(CheckCXXSourceCompiles) + include(CheckCSourceCompiles) + include(CheckLibraryExists) + include(CheckFunctionExists) + + check_include_file_cxx(sstream CPPUNIT_HAVE_SSTREAM) + check_include_file_cxx(strstream CPPUNIT_HAVE_STRSTREAM) + set (CMAKE_REQUIRED_DEFINITIONS -DHAVE_STRSTREAM=CPPUNIT_HAVE_STRSTREAM) + check_cxx_source_compiles( + "#ifdef HAVE_STRSTREAM + # include + #else + # include + #endif + int main() { + std::ostrstream message; + message << \"Hello\"; + return 0; + }" CPPUNIT_HAVE_CLASS_STRSTREAM) + + check_include_file_cxx(cmath CPPUNIT_HAVE_CMATH) + #Not used, dld library is obsolete anyway HAVE_DLD + #Not used HAVE_DLERROR + check_include_file(dlfcn.h CPPUNIT_HAVE_DLFCN_H) + + check_c_source_compiles( + "#include + int main() { + return finite(3); + }" CPPUNIT_HAVE_FINITE) + + check_c_source_compiles( + "#include + int main() { + return _finite(3); + }" CPPUNIT_HAVE__FINITE) + + #Not used CPPUNIT_HAVE_GCC_ABI_DEMANGLE + #Not used HAVE_INTTYPES_H + + check_c_source_compiles( + "#include + int main() { + return isfinite(3); + }" CPPUNIT_HAVE_ISFINITE) + + check_library_exists(dl dlopen "" CPPUNIT_HAVE_LIBDL) + #Not used HAVE_MEMORY_H + + check_cxx_source_compiles( + "namespace Outer { + namespace Inner { + int i = 0; + } + } + using namespace Outer::Inner; + int main() { + return i; + }" CPPUNIT_HAVE_NAMESPACES) + + check_cxx_source_compiles( + "#include + class Base { + public: + Base() {} + virtual int f() { return 0; } + }; + class Derived : public Base { + public: + Derived() {} + virtual int f() { return 1; } + }; + int main() { + Derived d; + Base * ptr = &d; + return typeid(*ptr) == typeid(Derived); + }" CPPUNIT_HAVE_RTTI) + + check_library_exists(dl shl_load "" CPPUNIT_HAVE_SHL_LOAD) + #Not used HAVE_STDINT_H + #Not used HAVE_STDLIB_H + #Not used HAVE_STRINGS_H + #Not used HAVE_STRING_H + #Not used HAVE_SYS_STAT_H + #Not used HAVE_SYS_TYPES_H + #Not used HAVE_UNISTD_H + #Not used PACKAGE + #Not used PACKAGE_BUGREPORT + #Not used PACKAGE_NAME + #Not used PACKAGE_STRING + #Not used PACKAGE_TARNAME + #Not used PACKAGE_VERSION + #Not used STDC_HEADERS + check_include_file_cxx(typeinfo CPPUNIT_USE_TYPEINFO_NAME) + configure_file(unit/cppunit-config/config.h.cmake ${CMAKE_CURRENT_SOURCE_DIR}/../contrib/cppunit-1.12.1/include/cppunit/config-auto.h) +endif() + SET( CPPUNIT_SRCS ../contrib/cppunit-1.12.1/src/cppunit/AdditionalMessage.cpp ../contrib/cppunit-1.12.1/src/cppunit/Asserter.cpp diff --git a/test/unit/cppunit-config/config.h.cmake b/test/unit/cppunit-config/config.h.cmake new file mode 100644 index 000000000..7185b7400 --- /dev/null +++ b/test/unit/cppunit-config/config.h.cmake @@ -0,0 +1,103 @@ +/* Inspired by config/config.h.in, config.h.cmake is used by CMake. */ + +/* define if library uses std::string::compare(string,pos,n) */ +//Not used #undef FUNC_STRING_COMPARE_STRING_FIRST + +/* define to 1 if the library defines strstream */ +#cmakedefine01 CPPUNIT_HAVE_CLASS_STRSTREAM + +/* Define to 1 if you have the header file. */ +#cmakedefine01 CPPUNIT_HAVE_CMATH + +/* Define if you have the GNU dld library. */ +//Not used, dld library is obsolete anyway #undef HAVE_DLD + +/* Define to 1 if you have the `dlerror' function. */ +//Not used #undef HAVE_DLERROR + +/* Define to 1 if you have the header file. */ +#cmakedefine01 CPPUNIT_HAVE_DLFCN_H + +/* Define to 1 if you have the `finite' function. */ +#cmakedefine01 CPPUNIT_HAVE_FINITE + +/* Define to 1 if you have the `_finite' function. */ +#cmakedefine01 CPPUNIT_HAVE__FINITE + +/* define to 1 if the compiler supports GCC C ABI name demangling */ +//Not used #undef CPPUNIT_HAVE_GCC_ABI_DEMANGLE + +/* Define to 1 if you have the header file. */ +//Not used #undef HAVE_INTTYPES_H + +/* define if compiler has isfinite */ +#cmakedefine CPPUNIT_HAVE_ISFINITE + +/* Define if you have the libdl library or equivalent. */ +#cmakedefine CPPUNIT_HAVE_LIBDL + +/* Define to 1 if you have the header file. */ +//Not used #undef HAVE_MEMORY_H + +/* define to 1 if the compiler implements namespaces */ +#cmakedefine01 CPPUNIT_HAVE_NAMESPACES + +/* define to 1 if the compiler supports Run-Time Type Identification */ +#cmakedefine01 CPPUNIT_HAVE_RTTI + +/* Define if you have the shl_load function. */ +#cmakedefine CPPUNIT_HAVE_SHL_LOAD + +/* define to 1 if the compiler has stringstream */ +#cmakedefine01 CPPUNIT_HAVE_SSTREAM + +/* Define to 1 if you have the header file. */ +//Not used #undef HAVE_STDINT_H + +/* Define to 1 if you have the header file. */ +//Not used #undef HAVE_STDLIB_H + +/* Define to 1 if you have the header file. */ +//Not used #undef HAVE_STRINGS_H + +/* Define to 1 if you have the header file. */ +//Not used #undef HAVE_STRING_H + +/* Define to 1 if you have the header file. */ +#cmakedefine01 CPPUNIT_HAVE_STRSTREAM + +/* Define to 1 if you have the header file. */ +//Not used #undef HAVE_SYS_STAT_H + +/* Define to 1 if you have the header file. */ +//Not used #undef HAVE_SYS_TYPES_H + +/* Define to 1 if you have the header file. */ +//Not used #undef HAVE_UNISTD_H + +/* Name of package */ +//Not used #undef PACKAGE + +/* Define to the address where bug reports for this package should be sent. */ +//Not used #undef PACKAGE_BUGREPORT + +/* Define to the full name of this package. */ +//Not used #undef PACKAGE_NAME + +/* Define to the full name and version of this package. */ +//Not used #undef PACKAGE_STRING + +/* Define to the one symbol short name of this package. */ +//Not used #undef PACKAGE_TARNAME + +/* Define to the version of this package. */ +//Not used #undef PACKAGE_VERSION + +/* Define to 1 if you have the ANSI C header files. */ +//Not used #undef STDC_HEADERS + +/* Define to 1 to use type_info::name() for class names */ +#cmakedefine01 CPPUNIT_USE_TYPEINFO_NAME + +/* Version number of package */ +#define CPPUNIT_VERSION @CppUnit_VERSION@ diff --git a/test/unit/utRemoveComments.cpp b/test/unit/utRemoveComments.cpp index 5779946eb..7f2ce9c82 100644 --- a/test/unit/utRemoveComments.cpp +++ b/test/unit/utRemoveComments.cpp @@ -49,7 +49,7 @@ void RemoveCommentsTest :: testMultiLineComments (void) " comment across multiple lines */" " / * Incomplete comment */ /* /* multiple comments */ */"; - const char* szTestResult = + const char* szTestResult = " \n" "valid text " " "