Utils/Logger: Target examples\nPackets: Relax annotation type restrictions
[senf.git] / Packets / VariantParser.test.cc
index 24c92ec..2ea65d4 100644 (file)
@@ -78,7 +78,10 @@ BOOST_AUTO_UNIT_TEST(VariantParser)
     };
 }
 
-namespace {
+// We can't use the unnamed namespace here since there's a bug in gcc-4.2.3 which is 
+// the default version of gcc on ubuntu hardy :-(
+// See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34213
+namespace VariantParser_test_cc_anon_namespace {
     
     struct SubParser : public senf::PacketParserBase
     { 
@@ -94,25 +97,18 @@ namespace {
     {
 #       include SENF_PARSER()
 
-        struct TestTransform {
-            typedef unsigned value_type;
-            static unsigned get(unsigned v) { return v/2; }
-            static unsigned set(unsigned v) { return 2*v; }
-        };
-        
         SENF_PARSER_SKIP_BITS( 4 );
         SENF_PARSER_BITFIELD_RO( type, 4, unsigned );
-        SENF_PARSER_PRIVATE_VARIANT( content_, transform(TestTransform, type),
-                                     (senf::VoidPacketParser)(SubParser) );
-
-        bool hasContent() const { return content_().variant() == 1; }
-        void hasContent(bool v) const { if (v) content_().init<1>(); else content_().init<0>(); }
-        SubParser content() const { return content_().get<1>(); }
+        SENF_PARSER_VARIANT( content_, type,
+                                         ( novalue( nocontent, key(10, senf::VoidPacketParser)) )
+                                         (      id( content,           SubParser              ) )
+            );
 
         SENF_PARSER_FINALIZE(TestParser);
     };
     
 }
+using namespace VariantParser_test_cc_anon_namespace;
 
 BOOST_AUTO_UNIT_TEST(VariantParserMacro)
 {
@@ -120,18 +116,21 @@ BOOST_AUTO_UNIT_TEST(VariantParserMacro)
     
     {
         TestParser v (p.data().begin(), & p.data());
-        BOOST_CHECK( ! v.hasContent() );
+        v.init();
+        BOOST_CHECK( ! v.has_content() );
         BOOST_CHECK_EQUAL( senf::bytes(v), 1u );
-        BOOST_CHECK_EQUAL( v.type(), 0u );
-        v.hasContent(true);
+        BOOST_CHECK_EQUAL( v.type(), 10u );
+        v.init_content();
         // Parser invalidated
     }
     {
         TestParser v (p.data().begin(), & p.data());
-        BOOST_CHECK( v.hasContent() );
+        BOOST_CHECK( v.has_content() );
         BOOST_CHECK_EQUAL( senf::bytes(v), 7u );
         BOOST_CHECK_EQUAL( v.content().foo(), 0u );
-        BOOST_CHECK_EQUAL( v.type(), 2u );
+        BOOST_CHECK_EQUAL( v.type(), 1u );
+        v.nocontent();
+        // Parser invalidated
     }
 }