[Avida-SVN] r1129 - in extras: . source/targets/TestAvida source/testsuites source/tools

avidaedward at myxo.css.msu.edu avidaedward at myxo.css.msu.edu
Mon Dec 11 19:35:56 PST 2006


Author: avidaedward
Date: 2006-12-11 22:35:56 -0500 (Mon, 11 Dec 2006)
New Revision: 1129

Modified:
   extras/
   extras/source/targets/TestAvida/TestAvida.cpp
   extras/source/testsuites/nAnalyze.cpp
   extras/source/testsuites/nTestLib.cpp
   extras/source/tools/cTestLib.cpp
   extras/source/tools/cTestLib.h
Log:
 r1102 at Kaben-Nanlohys-MacBook-Pro-15:  kaben | 2006-11-22 15:42:30 -0500
 * Crossported bugfixes to Avida testing system from Blacksilver.
 - Added associated test of testing system.
 
 * Added testsuite for cAnalyze.
 



Property changes on: extras
___________________________________________________________________
Name: svk:merge
   - 079b078a-dbed-46b9-b3da-37668d4295ca:/avida/local/extras:1101
   + 079b078a-dbed-46b9-b3da-37668d4295ca:/avida/local/extras:1102

Modified: extras/source/targets/TestAvida/TestAvida.cpp
===================================================================
--- extras/source/targets/TestAvida/TestAvida.cpp	2006-12-12 03:35:55 UTC (rev 1128)
+++ extras/source/targets/TestAvida/TestAvida.cpp	2006-12-12 03:35:56 UTC (rev 1129)
@@ -12,6 +12,7 @@
 
 /* Declare the testsuites collections. */
 /* This is only necessary for loading tests in otherwise dead code. */
+namespace nAnalyze { void PhysicalLink(); }
 namespace nChangeList { void PhysicalLink(); }
 namespace nDataEntry { void PhysicalLink(); }
 namespace nDataFile { void PhysicalLink(); }
@@ -28,6 +29,7 @@
 cStaticInitialization s_null_initializer(void){
   /* Load the testsuites collections. */
   /* This is only necessary for loading tests in otherwise dead code. */
+  nAnalyze::PhysicalLink();
   nChangeList::PhysicalLink();
   nDataEntry::PhysicalLink();
   nDataFile::PhysicalLink();

Modified: extras/source/testsuites/nAnalyze.cpp
===================================================================
--- extras/source/testsuites/nAnalyze.cpp	2006-12-12 03:35:55 UTC (rev 1128)
+++ extras/source/testsuites/nAnalyze.cpp	2006-12-12 03:35:56 UTC (rev 1129)
@@ -11,7 +11,8 @@
 
 /* Tests. */
 namespace nAnalyze {
-  /* Test-helpers.  */
+/* Test-helpers. {{{1 */
+  /* save_stuff {{{2 */
   template <class T>
   void save_stuff(const T &s, const char * filename){
     std::ofstream ofs(filename);
@@ -19,6 +20,7 @@
     oa.ArkvObj("cAnalyze_Archive", s);
   }
 
+  /* restore_stuff {{{2 */
   template <class T>
   void restore_stuff(T &s, const char * filename) {
     std::ifstream ifs(filename);
@@ -26,7 +28,35 @@
     ia.ArkvObj("cAnalyze_Archive", s);
   }
 
-  /* Unit tests. */
+/* Brainstorms. {{{1 */
+  /* cAnalyze_Brainstorm_HelloWorld {{{2 */
+  namespace Brainstorm_HelloWorld {
+    void test(const cStringList &attrs){
+      if(!attrs.HasString("HelloWorld")){
+        cout << "XXX Skipping HelloWorld test." << endl;
+        return;
+      }
+      cout << "XXX This is a test stub. It needs filling-in. @kgn" << endl;
+      /* Make sure testing is working with successes and failures. @kgn */
+      TEST(true);
+      TEST(false);
+    }
+    cAddTestSuite t("cAnalyze_Brainstorm_HelloWorld", test);
+  }
+
+  /* cAnalyze_Brainstorm_CumulativeStemminess {{{2 */
+  namespace Brainstorm_CumulativeStemminess {
+    void test(){
+      cout << "XXX This is a test stub. It needs filling-in. @kgn" << endl;
+      /* Make sure testing is working with successes and failures. @kgn */
+      TEST(true);
+      TEST(false);
+    }
+    cAddTestSuite t("cAnalyze_Brainstorm_CumulativeStemminess", test);
+  }
+
+/* Unit tests. {{{1 */
+  /* cAnalyze_UnitTest_HelloWorld {{{2 */
   namespace UnitTest_HelloWorld {
     void test(const cStringList &attrs){
       if(!attrs.HasString("HelloWorld")){
@@ -41,6 +71,7 @@
     cAddTestSuite t("cAnalyze_UnitTest_HelloWorld", test);
   }
 
+  /* cAnalyze_UnitTest_Archiving {{{2 */
   namespace UnitTest_Archiving {
     void test(const cStringList &attrs){
       if(!attrs.HasString("Template")){
@@ -71,6 +102,7 @@
     cAddTestSuite t("cAnalyze_UnitTest_Archiving", test);
   }
 
+  // }}}1
   /*
   This function does nothing;
   but if the compiler sees that this function is called, then the

Modified: extras/source/testsuites/nTestLib.cpp
===================================================================
--- extras/source/testsuites/nTestLib.cpp	2006-12-12 03:35:55 UTC (rev 1128)
+++ extras/source/testsuites/nTestLib.cpp	2006-12-12 03:35:56 UTC (rev 1129)
@@ -4,7 +4,7 @@
 using namespace std;
 
 namespace nTestLib {
-  /* Brainstorms. */
+  /* Brainstorm. */
   namespace Brainstorm_HelloWorld {
     void test(const cStringList &attrs){
       if(!attrs.HasString("HelloWorld")){
@@ -13,6 +13,8 @@
       }
       cout << "XXX This is a test stub. It needs filling-in. @kgn" << endl;
       /* Make sure testing is working with successes and failures. @kgn */
+      bool test_bool = false;
+      TEST(test_bool);
       TEST(true);
       TEST(false);
     }
@@ -34,6 +36,129 @@
     cAddTestSuite t("cTestLib_UnitTest_HelloWorld", test);
   }
 
+  namespace UnitTest_SupportsAndRegAndUnreg {
+    void testVoid(){}
+    void testAttr(const cStringList &attrs){}
+    void test(){
+
+      /* Test a testrunner taking no args. */
+      TEST(!cTestLib::getLib().supports("cTestLib_SupportsAndRegAndUnreg_testVoid"));
+      cTestLib::getLib().reg("cTestLib_SupportsAndRegAndUnreg_testVoid", testVoid);
+      TEST(cTestLib::getLib().supports("cTestLib_SupportsAndRegAndUnreg_testVoid"));
+      cTestLib::getLib().unreg("cTestLib_SupportsAndRegAndUnreg_testVoid");
+      TEST(!cTestLib::getLib().supports("cTestLib_SupportsAndRegAndUnreg_testVoid"));
+
+      /* Test a testrunner taking attributes as arg. */
+      TEST(!cTestLib::getLib().supports("cTestLib_SupportsAndRegAndUnreg_testAttr"));
+      cTestLib::getLib().reg("cTestLib_SupportsAndRegAndUnreg_testAttr", testAttr);
+      TEST(cTestLib::getLib().supports("cTestLib_SupportsAndRegAndUnreg_testAttr"));
+      cTestLib::getLib().unreg("cTestLib_SupportsAndRegAndUnreg_testAttr");
+      TEST(!cTestLib::getLib().supports("cTestLib_SupportsAndRegAndUnreg_testAttr"));
+    }
+    cAddTestSuite t("cTestLib_UnitTest_SupportsAndRegAndUnreg", test);
+  }
+
+  /* Regression. */
+  namespace Regression_ErrorLoadingTestrunnerByKey {
+    void testVoid(){}
+    void test1(){
+      {
+        /* Sanity check. */
+        TEST(!cTestLib::getLib().supports(
+          "cTestLib_Regression_ErrorLoadingTestrunnerByKey_testVoid"
+        ));
+        /* Register testVoid function. */
+        cTestLib::getLib().reg(
+          "cTestLib_Regression_ErrorLoadingTestrunnerByKey_testVoid",
+          testVoid
+        );
+        TEST(cTestLib::getLib().supports(
+          "cTestLib_Regression_ErrorLoadingTestrunnerByKey_testVoid"
+        ));
+
+        /* Test 'tryRun'. */
+        cTestLib::getLib().tryRun(
+          "cTestLib_Regression_ErrorLoadingTestrunnerByKey_testVoid",
+          cStringList()
+        );
+
+        /* Unregister testVoid function. */
+        cTestLib::getLib().unreg(
+          "cTestLib_Regression_ErrorLoadingTestrunnerByKey_testVoid"
+        );
+        TEST(!cTestLib::getLib().supports(
+          "cTestLib_Regression_ErrorLoadingTestrunnerByKey_testVoid"
+        ));
+      }
+    }
+    cAddTestSuite t1("cTestLib_Regression_ErrorLoadingTestrunnerByKey1", test1);
+
+    void testAttr(const cStringList &attributes){}
+    void test2(){
+      {
+        /* Sanity check. */
+        TEST(!cTestLib::getLib().supports(
+          "cTestLib_Regression_ErrorLoadingTestrunnerByKey_testAttr"
+        ));
+        /* Register testAttr function. */
+        cTestLib::getLib().reg(
+          "cTestLib_Regression_ErrorLoadingTestrunnerByKey_testAttr",
+          testAttr
+        );
+        TEST(cTestLib::getLib().supports(
+          "cTestLib_Regression_ErrorLoadingTestrunnerByKey_testAttr"
+        ));
+
+        /* Test 'tryRun'. */
+        cTestLib::getLib().tryRun(
+          "cTestLib_Regression_ErrorLoadingTestrunnerByKey_testAttr",
+          cStringList()
+        );
+
+        /* Unregister testAttr function. */
+        cTestLib::getLib().unreg(
+          "cTestLib_Regression_ErrorLoadingTestrunnerByKey_testAttr"
+        );
+        TEST(!cTestLib::getLib().supports(
+          "cTestLib_Regression_ErrorLoadingTestrunnerByKey_testAttr"
+        ));
+      }
+    }
+    cAddTestSuite t2("cTestLib_Regression_ErrorLoadingTestrunnerByKey2", test2);
+
+    bool try_run_was_called;
+    class myTestLib : public cTestLib {
+    public:
+      virtual void tryRun(cString key, const cStringList &attributes){
+        try_run_was_called = true;
+      }
+    };
+    void test3(){
+      {
+        myTestLib tl;
+
+        /* Sanity check. */
+        TEST(!tl.supports("cTestLib_Regression_ErrorLoadingTestrunnerByKey_testVoid"));
+        /* Register testVoid function. */
+        tl.reg("cTestLib_Regression_ErrorLoadingTestrunnerByKey_testVoid", testVoid);
+        TEST(tl.supports("cTestLib_Regression_ErrorLoadingTestrunnerByKey_testVoid"));
+
+        try_run_was_called = false;
+        tl.tryRun("cTestLib_Regression_ErrorLoadingTestrunnerByKey_testVoid", cStringList());
+        TEST(true == try_run_was_called);
+
+        try_run_was_called = false;
+        tl.tryRun("cTestLib_Regression_ErrorLoadingTestrunnerByKey_testVoid", cStringList());
+        TEST(true == try_run_was_called);
+
+        /* Unregister testVoid function. */
+        tl.unreg("cTestLib_Regression_ErrorLoadingTestrunnerByKey_testVoid");
+        TEST(!tl.supports("cTestLib_Regression_ErrorLoadingTestrunnerByKey_testVoid"));
+      }
+    }
+    cAddTestSuite t3("cTestLib_Regression_ErrorLoadingTestrunnerByKey3", test3);
+  }
+
   /*
   This function does nothing;
   but if the compiler sees that this function is called, then the

Modified: extras/source/tools/cTestLib.cpp
===================================================================
--- extras/source/tools/cTestLib.cpp	2006-12-12 03:35:55 UTC (rev 1128)
+++ extras/source/tools/cTestLib.cpp	2006-12-12 03:35:56 UTC (rev 1129)
@@ -20,6 +20,7 @@
   m_test_runners_with_attributes.Add(key, test_runner);
   return true;
 }
+
 bool cTestLib::unreg(const cString &key){
   Testrunner tr;
   TestrunnerWithAttrs tra;
@@ -30,6 +31,7 @@
 bool cTestLib::supports(const cString &key){
   return (m_test_runners.HasEntry(key) || m_test_runners_with_attributes.HasEntry(key));
 }
+
 void cTestLib::run(cString key){
   Testrunner test_runner;
 
@@ -46,7 +48,11 @@
 /* XXX Needs tests relating to Attributes -- @kgn */
 void cTestLib::tryRun(cString key, const cStringList &attributes){
   if(supports(key)){
-    run(key, attributes);
+    if(m_test_runners.HasEntry(key)){
+      run(key);
+    } else if(m_test_runners_with_attributes.HasEntry(key)){
+      run(key, attributes);
+    }
   } else {
     bool found_match = false;
     {

Modified: extras/source/tools/cTestLib.h
===================================================================
--- extras/source/tools/cTestLib.h	2006-12-12 03:35:55 UTC (rev 1128)
+++ extras/source/tools/cTestLib.h	2006-12-12 03:35:56 UTC (rev 1129)
@@ -12,13 +12,11 @@
 #endif
 
 typedef void(*Testrunner)(void);
-/* XXX Attributes */
 typedef void(*TestrunnerWithAttrs)(const cStringList &);
 
 class cTestLib {
 protected:
   tDictionary<Testrunner> m_test_runners;
-  /* XXX Attributes */
   tDictionary<TestrunnerWithAttrs> m_test_runners_with_attributes;
 public:
   bool reg(const cString &key, Testrunner test_runner);
@@ -26,7 +24,6 @@
   bool unreg(const cString &key);
   bool supports(const cString &key);
   void asLists(tList<cString> & name_list, tList<Testrunner> & value_list);
-  /* XXX Attributes */
   void asLists(tList<cString> & name_list, tList<TestrunnerWithAttrs> & value_list);
   void tryRun(cString key, const cStringList &attributes);
   void run(cString key);
@@ -42,9 +39,9 @@
   cAddTestSuite& operator=(const cAddTestSuite&); // @not_implemented
 public:
   cAddTestSuite(const cString &key, Testrunner test_runner);
-  /* XXX Attributes */
   cAddTestSuite(const cString &key, TestrunnerWithAttrs test_runner);
 };
 void addTestSuite(const cString &key, Testrunner test_runner);
+void addTestSuite(const cString &key, TestrunnerWithAttrs test_runner);
 
 #endif




More information about the Avida-cvs mailing list