[Avida-cvs] [avida-svn] r658 - in development/source: testsuites tools

kaben@myxo.css.msu.edu kaben at myxo.css.msu.edu
Mon May 8 13:48:28 PDT 2006


Author: kaben
Date: 2006-05-08 16:48:28 -0400 (Mon, 08 May 2006)
New Revision: 658

Modified:
   development/source/testsuites/full-unit-tests.cc
   development/source/tools/cString.cc
   development/source/tools/cString.h
Log:

Moved cString's UnitTests function to namespace nString.



Modified: development/source/testsuites/full-unit-tests.cc
===================================================================
--- development/source/testsuites/full-unit-tests.cc	2006-05-08 20:43:21 UTC (rev 657)
+++ development/source/testsuites/full-unit-tests.cc	2006-05-08 20:48:28 UTC (rev 658)
@@ -13,7 +13,7 @@
   nFile::UnitTests(true);
   nInitFile::UnitTests(true);
   nRandom::UnitTests(true);
-  cString::UnitTests(true);
+  nString::UnitTests(true);
   cStringList::UnitTests(true);
   cTemplateTests::UnitTests(true);
 

Modified: development/source/tools/cString.cc
===================================================================
--- development/source/tools/cString.cc	2006-05-08 20:43:21 UTC (rev 657)
+++ development/source/tools/cString.cc	2006-05-08 20:48:28 UTC (rev 658)
@@ -660,14 +660,7 @@
 #include <fstream> 
 #include <string>
 
-namespace utString_hello_world {
-  void test(){
-    BOOST_TEST(true);
-    BOOST_TEST(false);
-  }
-}
-
-namespace utString_archiving {
+namespace nString {
   /*
   Test-helpers.
   */
@@ -704,146 +697,160 @@
     ia.ArkvObj("s", s);
   }
 
-  void test(){
-    { 
-      BOOST_TEST(true);
-      std::string filename("./cString_basic_serialization.xml");
 
-      BOOST_TEST(0 == A::s_instance_ct);
-      A *a(new A);
-      BOOST_TEST(1 == A::s_instance_ct);
 
-      /*
-      Both instances of cString should share a single cStringData instance.
-      */
-      BOOST_TEST(cString("blah.") == a->m_s1);
-      BOOST_TEST(cString("blah.") == a->m_s2);
-      const char *s1(a->m_s1);
-      const char *s2(a->m_s2);
-      BOOST_TEST(s1 == s2);
 
-      /*
-      Both pointers should point to one cString instance.
-      */
-      BOOST_TEST(cString("ick.") == *a->m_ps1);
-      BOOST_TEST(cString("ick.") == *a->m_ps2);
-      const char *s3(*a->m_ps1);
-      const char *s4(*a->m_ps2);
-      BOOST_TEST(s3 == s4);
-
-      save_stuff<>(a, filename.c_str());
-      delete a;
-      BOOST_TEST(0 == A::s_instance_ct);
-
-      restore_stuff<>(a, filename.c_str());
-      BOOST_TEST(1 == A::s_instance_ct);
-
-      /*
-      Both instances of cString should share a single cStringData instance.
-      */
-      BOOST_TEST(cString("blah.") == a->m_s1);
-      BOOST_TEST(cString("blah.") == a->m_s2);
-      /*
-      We have decided to not track cStringData instance sharing;
-      consequently we now expect that if two strings sharing data are
-      both saved and then reloaded, the reloaded versions no longer
-      share data.
-      This prevents a certain kind of memory leak.
-      @kgn
-      */
-      const char *s5(a->m_s1);
-      const char *s6(a->m_s2);
-      BOOST_TEST(s5 != s6);
-
-      /*
-      Both pointers should point to one cString instance.
-      */
-      BOOST_TEST(cString("ick.") == *a->m_ps1);
-      BOOST_TEST(cString("ick.") == *a->m_ps2);
-      const char *s7(*a->m_ps1);
-      const char *s8(*a->m_ps2);
-      BOOST_TEST(s7 == s8);
-
-      delete a;
-      BOOST_TEST(0 == A::s_instance_ct);
-
-      std::remove(filename.c_str());
+  namespace utString_hello_world {
+    void test(){
+      BOOST_TEST(true);
+      BOOST_TEST(false);
     }
-    {
-      BOOST_TEST(true);
-      std::string filename("./cString_basic_serialization_2.xml");
+  }
+  
+  namespace utString_archiving {
+    void test(){
+      { 
+        BOOST_TEST(true);
+        std::string filename("./cString_basic_serialization.xml");
+  
+        BOOST_TEST(0 == A::s_instance_ct);
+        A *a(new A);
+        BOOST_TEST(1 == A::s_instance_ct);
+  
+        /*
+        Both instances of cString should share a single cStringData instance.
+        */
+        BOOST_TEST(cString("blah.") == a->m_s1);
+        BOOST_TEST(cString("blah.") == a->m_s2);
+        const char *s1(a->m_s1);
+        const char *s2(a->m_s2);
+        BOOST_TEST(s1 == s2);
+  
+        /*
+        Both pointers should point to one cString instance.
+        */
+        BOOST_TEST(cString("ick.") == *a->m_ps1);
+        BOOST_TEST(cString("ick.") == *a->m_ps2);
+        const char *s3(*a->m_ps1);
+        const char *s4(*a->m_ps2);
+        BOOST_TEST(s3 == s4);
+  
+        save_stuff<>(a, filename.c_str());
+        delete a;
+        BOOST_TEST(0 == A::s_instance_ct);
+  
+        restore_stuff<>(a, filename.c_str());
+        BOOST_TEST(1 == A::s_instance_ct);
+  
+        /*
+        Both instances of cString should share a single cStringData instance.
+        */
+        BOOST_TEST(cString("blah.") == a->m_s1);
+        BOOST_TEST(cString("blah.") == a->m_s2);
+        /*
+        We have decided to not track cStringData instance sharing;
+        consequently we now expect that if two strings sharing data are
+        both saved and then reloaded, the reloaded versions no longer
+        share data.
+        This prevents a certain kind of memory leak.
+        @kgn
+        */
+        const char *s5(a->m_s1);
+        const char *s6(a->m_s2);
+        BOOST_TEST(s5 != s6);
+  
+        /*
+        Both pointers should point to one cString instance.
+        */
+        BOOST_TEST(cString("ick.") == *a->m_ps1);
+        BOOST_TEST(cString("ick.") == *a->m_ps2);
+        const char *s7(*a->m_ps1);
+        const char *s8(*a->m_ps2);
+        BOOST_TEST(s7 == s8);
+  
+        delete a;
+        BOOST_TEST(0 == A::s_instance_ct);
+  
+        std::remove(filename.c_str());
+      }
+      {
+        BOOST_TEST(true);
+        std::string filename("./cString_basic_serialization_2.xml");
+  
+        BOOST_TEST(0 == A::s_instance_ct);
+        A *a(new A);
+        BOOST_TEST(1 == A::s_instance_ct);
+  
+        /*
+        Both instances of cString were sharing a single cStringData
+        instance, but assigning a new string to the first should create a
+        new, unshared cStringData instance; so now each cString should
+        have its own cStringData.
+        */
+        a->m_s1 = "bleah.";
+        BOOST_TEST(cString("bleah.") == a->m_s1);
+        BOOST_TEST(cString("blah.") == a->m_s2);
+        const char *s1(a->m_s1);
+        const char *s2(a->m_s2);
+        BOOST_TEST(s1 != s2);
+  
+        /*
+        Both pointers should point to one cString instance.
+        */
+        *a->m_ps1 = "ack.";
+        BOOST_TEST(cString("ack.") == *a->m_ps1);
+        BOOST_TEST(cString("ack.") == *a->m_ps2);
+        const char *s3(*a->m_ps1);
+        const char *s4(*a->m_ps2);
+        BOOST_TEST(s3 == s4);
+  
+        save_stuff<>(a, filename.c_str());
+        delete a;
+        BOOST_TEST(0 == A::s_instance_ct);
+  
+        restore_stuff<>(a, filename.c_str());
+        BOOST_TEST(1 == A::s_instance_ct);
+  
+        /*
+        Each cString should have its own cStringData.
+        */
+        BOOST_TEST(cString("bleah.") == a->m_s1);
+        BOOST_TEST(cString("blah.") == a->m_s2);
+        const char *s5(a->m_s1);
+        const char *s6(a->m_s2);
+        BOOST_TEST(s5 != s6);
+  
+        /*
+        Both pointers should point to one cString instance.
+        */
+        BOOST_TEST(cString("ack.") == *a->m_ps1);
+        BOOST_TEST(cString("ack.") == *a->m_ps2);
+        const char *s7(*a->m_ps1);
+        const char *s8(*a->m_ps2);
+        BOOST_TEST(s7 == s8);
+  
+  
+        delete a;
+        BOOST_TEST(0 == A::s_instance_ct);
+  
+        std::remove(filename.c_str());
+      }
+    }
+  } // utString_archiving
 
-      BOOST_TEST(0 == A::s_instance_ct);
-      A *a(new A);
-      BOOST_TEST(1 == A::s_instance_ct);
 
-      /*
-      Both instances of cString were sharing a single cStringData
-      instance, but assigning a new string to the first should create a
-      new, unshared cStringData instance; so now each cString should
-      have its own cStringData.
-      */
-      a->m_s1 = "bleah.";
-      BOOST_TEST(cString("bleah.") == a->m_s1);
-      BOOST_TEST(cString("blah.") == a->m_s2);
-      const char *s1(a->m_s1);
-      const char *s2(a->m_s2);
-      BOOST_TEST(s1 != s2);
-
-      /*
-      Both pointers should point to one cString instance.
-      */
-      *a->m_ps1 = "ack.";
-      BOOST_TEST(cString("ack.") == *a->m_ps1);
-      BOOST_TEST(cString("ack.") == *a->m_ps2);
-      const char *s3(*a->m_ps1);
-      const char *s4(*a->m_ps2);
-      BOOST_TEST(s3 == s4);
-
-      save_stuff<>(a, filename.c_str());
-      delete a;
-      BOOST_TEST(0 == A::s_instance_ct);
-
-      restore_stuff<>(a, filename.c_str());
-      BOOST_TEST(1 == A::s_instance_ct);
-
-      /*
-      Each cString should have its own cStringData.
-      */
-      BOOST_TEST(cString("bleah.") == a->m_s1);
-      BOOST_TEST(cString("blah.") == a->m_s2);
-      const char *s5(a->m_s1);
-      const char *s6(a->m_s2);
-      BOOST_TEST(s5 != s6);
-
-      /*
-      Both pointers should point to one cString instance.
-      */
-      BOOST_TEST(cString("ack.") == *a->m_ps1);
-      BOOST_TEST(cString("ack.") == *a->m_ps2);
-      const char *s7(*a->m_ps1);
-      const char *s8(*a->m_ps2);
-      BOOST_TEST(s7 == s8);
-
-
-      delete a;
-      BOOST_TEST(0 == A::s_instance_ct);
-
-      std::remove(filename.c_str());
+  
+  void UnitTests(bool full)
+  {
+    //if(full) {
+    //  std::cout << "utString_hello_world" << std::endl;
+    //  utString_hello_world::test();
+    //}
+    if(full) {
+      std::cout << "utString_archiving" << std::endl;
+      utString_archiving::test();
     }
   }
-}
+} // nString
 
-void cString::UnitTests(bool full)
-{
-  //if(full) {
-  //  std::cout << "utString_hello_world" << std::endl;
-  //  utString_hello_world::test();
-  //}
-  if(full) {
-    std::cout << "utString_archiving" << std::endl;
-    utString_archiving::test();
-  }
-}
-
 #endif // ENABLE_UNIT_TESTS

Modified: development/source/tools/cString.h
===================================================================
--- development/source/tools/cString.h	2006-05-08 20:43:21 UTC (rev 657)
+++ development/source/tools/cString.h	2006-05-08 20:48:28 UTC (rev 658)
@@ -572,18 +572,19 @@
   cStringData * value;
 
 // }}} End Internals
+};
 
 
 #ifdef ENABLE_UNIT_TESTS
-public:
+namespace nString {
   /**
    * Run unit tests
    *
    * @param full Run full test suite; if false, just the fast tests.
    **/
-  static void UnitTests(bool full = false);
+  void UnitTests(bool full = false);
+}
 #endif  
-};
 
 
 // {{{ ** External cString Functions **




More information about the Avida-cvs mailing list