]> ruin.nu Git - germs.git/commitdiff
some initial tests
authorMichael Andreen <harv@ruin.nu>
Thu, 14 Jun 2007 13:39:17 +0000 (13:39 +0000)
committerMichael Andreen <harv@ruin.nu>
Thu, 14 Jun 2007 13:39:17 +0000 (13:39 +0000)
test/CMakeLists.txt [new file with mode: 0644]
test/exampletest.cpp [new file with mode: 0644]
test/geneordertest.cpp [new file with mode: 0644]
test/main.cpp [new file with mode: 0644]
test/qtmain.cpp [new file with mode: 0644]

diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
new file mode 100644 (file)
index 0000000..0810962
--- /dev/null
@@ -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 (file)
index 0000000..32ad2a3
--- /dev/null
@@ -0,0 +1,75 @@
+#ifndef __GENEORDERTEST_H__
+#define __GENEORDERTEST_H__
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+/* 
+ * 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<long>     l1 (new long (12));
+               std::auto_ptr<long>     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 (file)
index 0000000..cc29694
--- /dev/null
@@ -0,0 +1,39 @@
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+#include <geneorder.h>
+
+/* 
+ * 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 (file)
index 0000000..4eca9d0
--- /dev/null
@@ -0,0 +1,34 @@
+#include <cppunit/BriefTestProgressListener.h>
+#include <cppunit/CompilerOutputter.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+#include <cppunit/TestResult.h>
+#include <cppunit/TestResultCollector.h>
+#include <cppunit/TestRunner.h>
+
+
+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 (file)
index 0000000..e650040
--- /dev/null
@@ -0,0 +1,19 @@
+#include <qapplication.h>
+#include <cppunit/ui/qt/TestRunner.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+
+
+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;
+}
+