Add (optional) unit test infrastructure
authorThomas Jarosch <thomas.jarosch@intra2net.com>
Fri, 2 Sep 2011 09:40:41 +0000 (11:40 +0200)
committerThomas Jarosch <thomas.jarosch@intra2net.com>
Fri, 2 Sep 2011 09:40:41 +0000 (11:40 +0200)
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.

CMakeLists.txt
test/CMakeLists.txt [new file with mode: 0644]
test/basic.cpp [new file with mode: 0644]
test/baudrate.cpp [new file with mode: 0644]

index 73517cf..30f8a9f 100644 (file)
@@ -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 (file)
index 0000000..424cbca
--- /dev/null
@@ -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 (file)
index 0000000..3710916
--- /dev/null
@@ -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 <boost/test/unit_test.hpp>
+
+#include <ftdi.h>
+
+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 (file)
index 0000000..163950b
--- /dev/null
@@ -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/test/unit_test.hpp>
+
+BOOST_AUTO_TEST_SUITE(Baudrate)
+
+BOOST_AUTO_TEST_CASE(Simple)
+{
+}
+
+BOOST_AUTO_TEST_SUITE_END()