From bef4a9fc121deae7ba81687eee1c73fe61e5ca33 Mon Sep 17 00:00:00 2001 From: Michael Andreen Date: Thu, 14 Jun 2007 13:39:17 +0000 Subject: [PATCH] some initial tests --- test/CMakeLists.txt | 20 +++++++++++ test/exampletest.cpp | 75 ++++++++++++++++++++++++++++++++++++++++++ test/geneordertest.cpp | 39 ++++++++++++++++++++++ test/main.cpp | 34 +++++++++++++++++++ test/qtmain.cpp | 19 +++++++++++ 5 files changed, 187 insertions(+) create mode 100644 test/CMakeLists.txt create mode 100644 test/exampletest.cpp create mode 100644 test/geneordertest.cpp create mode 100644 test/main.cpp create mode 100644 test/qtmain.cpp diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 0000000..0810962 --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,20 @@ +PROJECT(GeneSort) + +SET(CMAKE_VERBOSE_MAKEFILE OFF) + +ADD_DEFINITIONS(-Wall -O2) + +find_package(Qt3 REQUIRED) + +INCLUDE_DIRECTORIES(. ../src ${QT_INCLUDE_DIR}) +link_directories(${QT_LIB_DIR}) +add_definitions(${QT_DEFINITIONS}) + +SET(TESTSRC geneordertest) + +ADD_EXECUTABLE(tester main ${TESTSRC}) + +ADD_EXECUTABLE(qttester qtmain ${TESTSRC}) + +TARGET_LINK_LIBRARIES(tester cppunit) +TARGET_LINK_LIBRARIES(qttester cppunit qttestrunnerd ${QT_LIBRARIES}) diff --git a/test/exampletest.cpp b/test/exampletest.cpp new file mode 100644 index 0000000..32ad2a3 --- /dev/null +++ b/test/exampletest.cpp @@ -0,0 +1,75 @@ +#ifndef __GENEORDERTEST_H__ +#define __GENEORDERTEST_H__ + +#include +#include + +/* + * A test case that is designed to produce + * example errors and failures. + * + */ + +#define TESTNAME ExampleTest + + +class TESTNAME : public CPPUNIT_NS::TestFixture +{ + CPPUNIT_TEST_SUITE( TESTNAME ); + CPPUNIT_TEST( example ); + CPPUNIT_TEST( anotherExample ); + CPPUNIT_TEST( testAdd ); + CPPUNIT_TEST( testEquals ); + CPPUNIT_TEST_SUITE_END(); + +protected: + + double m_value1; + double m_value2; +public: + + void setUp (){ + m_value1 = 2.0; + m_value2 = 3.0; + } + +protected: + + void example () + { + CPPUNIT_ASSERT_DOUBLES_EQUAL (1.0, 1.1, 0.05); + CPPUNIT_ASSERT (1 == 0); + CPPUNIT_ASSERT (1 == 1); + } + + void anotherExample () + { + CPPUNIT_ASSERT (1 == 2); + } + + void testAdd () + { + double result = m_value1 + m_value2; + CPPUNIT_ASSERT (result == 6.0); + } + + void testEquals () + { + std::auto_ptr l1 (new long (12)); + std::auto_ptr l2 (new long (12)); + + CPPUNIT_ASSERT_EQUAL (12, 12); + CPPUNIT_ASSERT_EQUAL (12L, 12L); + CPPUNIT_ASSERT_EQUAL (*l1, *l2); + + CPPUNIT_ASSERT (12L == 12L); + CPPUNIT_ASSERT_EQUAL (12, 13); + CPPUNIT_ASSERT_DOUBLES_EQUAL (12.0, 11.99, 0.5); + } +}; + +CPPUNIT_TEST_SUITE_REGISTRATION( TESTNAME ); + +#undef TESTNAME + +#endif diff --git a/test/geneordertest.cpp b/test/geneordertest.cpp new file mode 100644 index 0000000..cc29694 --- /dev/null +++ b/test/geneordertest.cpp @@ -0,0 +1,39 @@ +#include +#include + +#include + +/* + * A test case that is designed to produce + * example errors and failures. + * + */ + +#define TESTNAME GeneOrderTest + + +class TESTNAME : public CPPUNIT_NS::TestFixture +{ + CPPUNIT_TEST_SUITE( TESTNAME ); + CPPUNIT_TEST( testCreate ); + CPPUNIT_TEST_SUITE_END(); + +protected: + + double m_value1; + double m_value2; +public: + + void setUp (){ + } + +protected: + + void testCreate (){ + CPPUNIT_ASSERT (1 == 0); + } +}; + +CPPUNIT_TEST_SUITE_REGISTRATION( TESTNAME ); + +#undef TESTNAME diff --git a/test/main.cpp b/test/main.cpp new file mode 100644 index 0000000..4eca9d0 --- /dev/null +++ b/test/main.cpp @@ -0,0 +1,34 @@ +#include +#include +#include +#include +#include +#include + + +int +main( int argc, char* argv[] ) +{ + // Create the event manager and test controller + CPPUNIT_NS::TestResult controller; + + // Add a listener that colllects test result + CPPUNIT_NS::TestResultCollector result; + controller.addListener( &result ); + + // Add a listener that print dots as test run. + CPPUNIT_NS::BriefTestProgressListener progress; + controller.addListener( &progress ); + + // Add the top suite to the test runner + CPPUNIT_NS::TestRunner runner; + runner.addTest( CPPUNIT_NS::TestFactoryRegistry::getRegistry().makeTest() ); + runner.run( controller ); + + // Print test in a compiler compatible format. + CPPUNIT_NS::CompilerOutputter outputter( &result, CPPUNIT_NS::stdCOut() ); + outputter.write(); + + return result.wasSuccessful() ? 0 : 1; +} + diff --git a/test/qtmain.cpp b/test/qtmain.cpp new file mode 100644 index 0000000..e650040 --- /dev/null +++ b/test/qtmain.cpp @@ -0,0 +1,19 @@ +#include +#include +#include + + +int main( int argc, char** argv ) +{ + QApplication app( argc, argv ); + + //CPPUNIT_NS::QtUi::TestRunner runner; + + CPPUNIT_NS::QtTestRunner runner; + + runner.addTest( CPPUNIT_NS::TestFactoryRegistry::getRegistry().makeTest() ); + runner.run( true ); + + return 0; +} + -- 2.39.2