avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cutt...@apache.org
Subject svn commit: r817753 - in /hadoop/avro/trunk: CHANGES.txt src/c++/ src/c++/test/testgen.cc src/c++/test/unittest.cc
Date Tue, 22 Sep 2009 18:34:49 GMT
Author: cutting
Date: Tue Sep 22 18:34:42 2009
New Revision: 817753

URL: http://svn.apache.org/viewvc?rev=817753&view=rev
Log:
AVRO-99.  Use Boost framework for C++ unit tests.  Contributed by Scott Banachowski.

Modified:
    hadoop/avro/trunk/CHANGES.txt
    hadoop/avro/trunk/src/c++/   (props changed)
    hadoop/avro/trunk/src/c++/test/testgen.cc
    hadoop/avro/trunk/src/c++/test/unittest.cc

Modified: hadoop/avro/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/CHANGES.txt?rev=817753&r1=817752&r2=817753&view=diff
==============================================================================
--- hadoop/avro/trunk/CHANGES.txt (original)
+++ hadoop/avro/trunk/CHANGES.txt Tue Sep 22 18:34:42 2009
@@ -1,5 +1,20 @@
 Avro Change Log
 
+Trunk (unreleased changes)
+
+  INCOMPATIBLE CHANGES
+
+  NEW FEATURES
+
+  IMPROVEMENTS
+
+    AVRO-99.  Use Boost framework for C++ unit tests.
+    (Scott Banachowski via cutting)
+
+  OPTIMIZATIONS
+
+  BUG FIXES
+
 Avro 1.1.0 (8 September 2009)
 
   INCOMPATIBLE CHANGES

Propchange: hadoop/avro/trunk/src/c++/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Tue Sep 22 18:34:42 2009
@@ -1,2 +1,6 @@
 obj
 test.avro
+unittest
+testparser
+precompile
+testgen

Modified: hadoop/avro/trunk/src/c++/test/testgen.cc
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c%2B%2B/test/testgen.cc?rev=817753&r1=817752&r2=817753&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c++/test/testgen.cc (original)
+++ hadoop/avro/trunk/src/c++/test/testgen.cc Tue Sep 22 18:34:42 2009
@@ -19,6 +19,7 @@
 #include <string.h>
 #include <fstream>
 #include <sstream>
+#include <boost/test/included/unit_test_framework.hpp>
 
 #include "code.hh"
 #include "OutputStreamer.hh"
@@ -49,22 +50,23 @@
 
 void checkArray(const avrouser::Array_of_double &a1, const avrouser::Array_of_double
&a2) 
 {
-    assert((a1.value.size() == a2.value.size()) && (a1.value.size() == 3));
+    BOOST_CHECK_EQUAL(a1.value.size(), 3U);
+    BOOST_CHECK_EQUAL(a1.value.size(), a2.value.size());
     for(size_t i = 0; i < a1.value.size(); ++i) {
-        assert(a1.value[i] == a2.value[i]);
+        BOOST_CHECK_EQUAL(a1.value[i], a2.value[i]);
     }
 }
 
 void checkMap(const avrouser::Map_of_int &map1, const avrouser::Map_of_int &map2)

 {
-    assert(map1.value.size() == map2.value.size());
+    BOOST_CHECK_EQUAL(map1.value.size(), map2.value.size());
     avrouser::Map_of_int::MapType::const_iterator iter1 = map1.value.begin();
     avrouser::Map_of_int::MapType::const_iterator end   = map1.value.end();
     avrouser::Map_of_int::MapType::const_iterator iter2 = map2.value.begin();
 
     while(iter1 != end) {
-        assert(iter1->first == iter2->first);
-        assert(iter1->second == iter2->second);
+        BOOST_CHECK_EQUAL(iter1->first, iter2->first);
+        BOOST_CHECK_EQUAL(iter1->second, iter2->second);
         ++iter1;
         ++iter2;
     }
@@ -72,40 +74,41 @@
 
 void checkBytes(const std::vector<uint8_t> &v1, const std::vector<uint8_t>
&v2)
 {
-    assert((v1.size() == v2.size()) && (v1.size() == 2));
+    BOOST_CHECK_EQUAL(v1.size(), 2U);
+    BOOST_CHECK_EQUAL(v1.size(), v2.size());
     for(size_t i = 0; i < v1.size(); ++i) {
-        assert(v1[i] == v2[i]);
+        BOOST_CHECK_EQUAL(v1[i], v2[i]);
     }
 }
 
 void checkOk(const avrouser::RootRecord &rec1, const avrouser::RootRecord &rec2)
 {
-    assert(rec1.mylong == rec1.mylong);
+    BOOST_CHECK_EQUAL(rec1.mylong, rec1.mylong);
     checkMap(rec1.mymap, rec2.mymap);
     checkArray(rec1.myarray, rec2.myarray);
 
-    assert(rec1.myenum.value == rec2.myenum.value);
+    BOOST_CHECK_EQUAL(rec1.myenum.value, rec2.myenum.value);
 
-    assert(rec1.myunion.choice == rec2.myunion.choice);
+    BOOST_CHECK_EQUAL(rec1.myunion.choice, rec2.myunion.choice);
     // in this test I know choice was 1
     {
-        assert(rec1.myunion.choice == 1);
+        BOOST_CHECK_EQUAL(rec1.myunion.choice, 1);
         checkMap(rec1.myunion.getValue<avrouser::Map_of_int>(), rec2.myunion.getValue<avrouser::Map_of_int>());
     }
 
-    assert(rec1.anotherunion.choice == rec2.anotherunion.choice);
+    BOOST_CHECK_EQUAL(rec1.anotherunion.choice, rec2.anotherunion.choice);
     // in this test I know choice was 0
     {
-        assert(rec1.anotherunion.choice == 0);
+        BOOST_CHECK_EQUAL(rec1.anotherunion.choice, 0);
         typedef std::vector<uint8_t> mytype;
         checkBytes(rec1.anotherunion.getValue<mytype>(), rec2.anotherunion.getValue<avrouser::Union_of_bytes_null::T0>());
     }
 
-    assert(rec1.mybool == rec2.mybool);
+    BOOST_CHECK_EQUAL(rec1.mybool, rec2.mybool);
     for(int i = 0; i < static_cast<int>(avrouser::md5::fixedSize); ++i) {
-        assert(rec1.myfixed.value[i] == rec2.myfixed.value[i]);
+        BOOST_CHECK_EQUAL(rec1.myfixed.value[i], rec2.myfixed.value[i]);
     }
-    assert(rec1.anotherint == rec1.anotherint);
+    BOOST_CHECK_EQUAL(rec1.anotherint, rec1.anotherint);
 
 }
 
@@ -161,7 +164,7 @@
     testParserValid(schema, myRecord);
 }
 
-int main() 
+void testGen() 
 {
     uint8_t fixed[] =  {0, 1, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
 
@@ -187,6 +190,15 @@
     myRecord.bytes.push_back(20);
 
     runTests(myRecord);
+}
+
+boost::unit_test::test_suite*
+init_unit_test_suite( int argc, char* argv[] ) 
+{
+    using namespace boost::unit_test;
 
+    test_suite* test= BOOST_TEST_SUITE( "Avro C++ generated code test suite" );
+    test->add( BOOST_TEST_CASE( &testGen ) );
 
+    return test;
 }

Modified: hadoop/avro/trunk/src/c++/test/unittest.cc
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c%2B%2B/test/unittest.cc?rev=817753&r1=817752&r2=817753&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c++/test/unittest.cc (original)
+++ hadoop/avro/trunk/src/c++/test/unittest.cc Tue Sep 22 18:34:42 2009
@@ -18,8 +18,8 @@
 
 #include <iostream>
 #include <fstream>
-#include <cassert>
 #include <sstream>
+#include <boost/test/included/unit_test_framework.hpp>
 
 #include "Zigzag.hh"
 #include "Node.hh"
@@ -219,7 +219,7 @@
                 std::cout << i << ":" << d << '\n';
             }
         } while(size != 0);
-        assert(d = 1000.0);
+        BOOST_CHECK_EQUAL(d, 1000.0);
     }
 
     template <typename Parser>
@@ -243,7 +243,7 @@
         printNext(p);
         int64_t longval = p.getLong();
         std::cout << longval << '\n';
-        assert(longval == 1000);
+        BOOST_CHECK_EQUAL(longval, 1000);
 
         readMap(p);
         readArray(p);
@@ -260,7 +260,7 @@
         printNext(p);
         bool boolval = p.getBool();
         std::cout << boolval << '\n';
-        assert(boolval == true);
+        BOOST_CHECK_EQUAL(boolval, true);
 
         printNext(p);
         readFixed(p);
@@ -268,7 +268,7 @@
         printNext(p);
         int32_t intval = p.getInt();
         std::cout << intval << '\n';
-        assert(intval == -3456);
+        BOOST_CHECK_EQUAL(intval, -3456);
     }
 
     void readRawData() {
@@ -314,22 +314,12 @@
 
     void compare(int32_t val) {
         uint32_t encoded = encodeZigzag32(val);
-        if (decodeZigzag32(encoded) != val) {
-            std::cout << val << '\n';
-            std::cout << encoded << '\n';
-            std::cout << decodeZigzag32(encoded) << '\n';
-            assert(0);
-        }
+        BOOST_CHECK_EQUAL(decodeZigzag32(encoded), val);
     }
 
     void compare(int64_t val) {
         uint64_t encoded = encodeZigzag64(val);
-        if (decodeZigzag64(encoded) != val) {
-            std::cout << val << '\n';
-            std::cout << encoded << '\n';
-            std::cout << decodeZigzag64(encoded) << '\n';
-            assert(0);
-        }
+        BOOST_CHECK_EQUAL(decodeZigzag64(encoded), val);
     }
 
     template<typename IntType>
@@ -372,13 +362,13 @@
         RecordSchema rec(name);
 
         NodePtr node = map_.locateSymbol(name);
-        assert(node == 0);
+        BOOST_CHECK(node == 0);
 
         map_.registerSymbol(rec.root());
 
         node = map_.locateSymbol(name);
-        assert(node);
-        assert(node->name() == name);
+        BOOST_CHECK(node);
+        BOOST_CHECK_EQUAL(node->name(), name);
         std::cout << "Found " << name << " registered\n";
     }
 
@@ -520,29 +510,28 @@
 };
 
 
-int main()
+boost::unit_test::test_suite*
+init_unit_test_suite( int argc, char* argv[] ) 
 {
-    bool pass = true;
-    try {
-        TestEncoding test1;
-        test1.test();
+    using namespace boost::unit_test;
 
-        TestSchema test2;
-        test2.test();
+    test_suite* test= BOOST_TEST_SUITE( "Avro C++ unit test suite" );
 
-        TestSymbolMap test3;
-        test3.test();
+    boost::shared_ptr<TestEncoding> encodingTester( new TestEncoding );
+    test->add( BOOST_CLASS_TEST_CASE( &TestEncoding::test, encodingTester ));
 
-        TestNested test4;
-        test4.test();
+    boost::shared_ptr<TestSchema> schemaTester( new TestSchema );
+    test->add( BOOST_CLASS_TEST_CASE( &TestSchema::test, schemaTester ));
 
-        TestGenerated test5;
-        test5.test();
-    }
-    catch (std::exception &e) {
-        std::cout << "Failed unit test due to exception: " << e.what() <<
std::endl;
-        pass = false;
-    }
+    boost::shared_ptr<TestSymbolMap> symbolMapTester( new TestSymbolMap );
+    test->add( BOOST_CLASS_TEST_CASE( &TestSymbolMap::test, symbolMapTester ));
 
-    return pass ? 0 : 1;
+    boost::shared_ptr<TestNested> nestedTester( new TestNested );
+    test->add( BOOST_CLASS_TEST_CASE( &TestNested::test, nestedTester ));
+
+    boost::shared_ptr<TestGenerated> generatedTester( new TestGenerated );
+    test->add( BOOST_CLASS_TEST_CASE( &TestGenerated::test, generatedTester ));
+
+    return test;
 }
+



Mime
View raw message