From: Thomas Jarosch Date: Fri, 2 Sep 2011 09:40:41 +0000 (+0200) Subject: Add (optional) unit test infrastructure X-Git-Tag: v1.0rc1~87 X-Git-Url: http://developer.intra2net.com/git/?p=libftdi;a=commitdiff_plain;h=a87a0712f7166d3418a7b522b44ffbce97a93d50 Add (optional) unit test infrastructure Requires unit test framework from boost so we can test the C and C++ code. Also has automatic test registration and the ability to run tests individually. --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 73517cf..30f8a9f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -99,6 +99,7 @@ add_subdirectory(bindings) add_subdirectory(ftdi_eeprom) add_subdirectory(examples) add_subdirectory(packages) +add_subdirectory(test) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 0000000..424cbca --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,30 @@ +# Optional unit test + +find_package(Boost COMPONENTS unit_test_framework) + +if(Boost_UNIT_TEST_FRAMEWORK_FOUND) + + message(STATUS "Building unit test") + + enable_testing() + + INCLUDE_DIRECTORIES(BEFORE ${CMAKE_SOURCE_DIR}/src) + + set(cpp_tests + basic.cpp + baudrate.cpp + ) + + add_executable(test_libftdi ${cpp_tests}) + target_link_libraries(test_libftdi ftdi ${Boost_UNIT_TEST_FRAMEWORK_LIBRARIES}) + + add_test(test_libftdi test_libftdi) + + # Add custom target so we run easily run "make check" + add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} DEPENDS test_libftdi) + +else(Boost_UNIT_TEST_FRAMEWORK_FOUND) + + message(STATUS "NOT building unit test (requires boost unit test framework)") + +endif(Boost_UNIT_TEST_FRAMEWORK_FOUND) diff --git a/test/basic.cpp b/test/basic.cpp new file mode 100644 index 0000000..3710916 --- /dev/null +++ b/test/basic.cpp @@ -0,0 +1,33 @@ +/**@file +@brief Test basic FTDI functionality + +@author Thomas Jarosch +*/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU Lesser General Public License * + * version 2.1 as published by the Free Software Foundation; * + * * + ***************************************************************************/ + +#define BOOST_TEST_DYN_LINK +#define BOOST_TEST_MAIN +#include + +#include + +BOOST_AUTO_TEST_SUITE(Basic) + +BOOST_AUTO_TEST_CASE(SimpleInit) +{ + ftdi_context ftdi; + + int rtn_init = ftdi_init(&ftdi); + BOOST_REQUIRE_EQUAL(0, rtn_init); + + ftdi_deinit(&ftdi); +} + +BOOST_AUTO_TEST_SUITE_END() diff --git a/test/baudrate.cpp b/test/baudrate.cpp new file mode 100644 index 0000000..163950b --- /dev/null +++ b/test/baudrate.cpp @@ -0,0 +1,24 @@ +/**@file +@brief Test baudrate calculator code + +@author Thomas Jarosch +*/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU Lesser General Public License * + * version 2.1 as published by the Free Software Foundation; * + * * + ***************************************************************************/ + +#define BOOST_TEST_DYN_LINK +#include + +BOOST_AUTO_TEST_SUITE(Baudrate) + +BOOST_AUTO_TEST_CASE(Simple) +{ +} + +BOOST_AUTO_TEST_SUITE_END()