[svn] commit: r103 - in /branches/jinmei-cppunittests/src/lib/dns: name_cxxtest.h name_unittest.cc

BIND 10 source code commits bind10-changes at lists.isc.org
Tue Oct 20 06:56:13 UTC 2009


Author: jinmei
Date: Tue Oct 20 06:56:12 2009
New Revision: 103

Log:
use setup/teardown in cxxtest

Modified:
    branches/jinmei-cppunittests/src/lib/dns/name_cxxtest.h
    branches/jinmei-cppunittests/src/lib/dns/name_unittest.cc

Modified: branches/jinmei-cppunittests/src/lib/dns/name_cxxtest.h
==============================================================================
--- branches/jinmei-cppunittests/src/lib/dns/name_cxxtest.h (original)
+++ branches/jinmei-cppunittests/src/lib/dns/name_cxxtest.h Tue Oct 20 06:56:12 2009
@@ -18,26 +18,32 @@
 #define __NAME_CXXTEST_H 1
 
 #include <dns/name.h>
+
 #include <cxxtest/TestSuite.h>
 
 using ISC::DNS::Name;
 
 class NameTest : public CxxTest::TestSuite {
 public:
+    void setUp() { example_name = new Name("www.example.com"); }
+    void tearDown() { delete example_name; }
+
     // test functions must begin with test or Test
     void test_get_length()
     {
-        Name name("www.example.com");
-        TS_ASSERT_EQUALS(17, static_cast<int>(name.get_length()));
+        TS_ASSERT_EQUALS(17, static_cast<int>(example_name->get_length()));
     }
 
     void test_to_text()
     {
-        Name name("www.isc.org");
+        TS_ASSERT_EQUALS(std::string("www.example.com"),
+                         example_name->to_text(true));
+        TS_ASSERT_EQUALS(std::string("www.example.com."),
+                         example_name->to_text(false));
+    }
 
-        TS_ASSERT_EQUALS(std::string("www.isc.org"), name.to_text(true));
-        TS_ASSERT_EQUALS(std::string("www.isc.org."), name.to_text(false));
-    }
+    int canary;
+    Name* example_name;
 };
 
 #endif // __NAME_CXXTEST_H

Modified: branches/jinmei-cppunittests/src/lib/dns/name_unittest.cc
==============================================================================
--- branches/jinmei-cppunittests/src/lib/dns/name_unittest.cc (original)
+++ branches/jinmei-cppunittests/src/lib/dns/name_unittest.cc Tue Oct 20 06:56:12 2009
@@ -23,7 +23,6 @@
 using ISC::DNS::Name;
 
 class NameTest : public CppUnit::TestFixture {
-public:
     void get_length();
     void to_text();
 
@@ -31,24 +30,40 @@
     CPPUNIT_TEST(get_length);
     CPPUNIT_TEST(to_text);
     CPPUNIT_TEST_SUITE_END();
+public:
+    NameTest() { example_name = NULL; }
+    void setUp();
+    void tearDown();
+protected:
+    Name* example_name;
 };
 
 CPPUNIT_TEST_SUITE_REGISTRATION(NameTest);
 
 void
+NameTest::setUp()
+{
+    example_name = new Name("www.example.com");
+                          //01234567890123456 => length should be 17.
+}
+
+void
+NameTest::tearDown()
+{
+    delete example_name;
+}
+
+void
 NameTest::get_length()
 {
-    Name name("www.example.com");
-            //01234567890123456 => length should be 17.
-
-    CPPUNIT_ASSERT_EQUAL(17, static_cast<int>(name.get_length()));
+    CPPUNIT_ASSERT_EQUAL(17, static_cast<int>(example_name->get_length()));
 }
 
 void
 NameTest::to_text()
 {
-    Name name("www.isc.org");
-
-    CPPUNIT_ASSERT_EQUAL(std::string("www.isc.org"), name.to_text(true));
-    CPPUNIT_ASSERT_EQUAL(std::string("www.isc.org."), name.to_text(false));
+    CPPUNIT_ASSERT_EQUAL(std::string("www.example.com"),
+                         example_name->to_text(true));
+    CPPUNIT_ASSERT_EQUAL(std::string("www.example.com."),
+                         example_name->to_text(false));
 }




More information about the bind10-changes mailing list