From: tho Date: Mon, 24 Nov 2008 12:27:17 +0000 (+0000) Subject: Packets: fixed some tests to run under 64bit (size_type <-> range confusion) X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=1a35108f90dd4c1a1ec94cc6e765feea4b616823;p=senf.git Packets: fixed some tests to run under 64bit (size_type <-> range confusion) git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@974 270642c3-0616-0410-b53a-bc976706d245 --- diff --git a/Packets/PacketInterpreter.test.cc b/Packets/PacketInterpreter.test.cc index 49f6ebd..c790d21 100644 --- a/Packets/PacketInterpreter.test.cc +++ b/Packets/PacketInterpreter.test.cc @@ -48,11 +48,11 @@ BOOST_AUTO_UNIT_TEST(packetInterpreterBase) { senf::PacketInterpreter::ptr pi2 (senf::PacketInterpreter::create()); senf::PacketInterpreter::ptr pi1 (senf::PacketInterpreter::createBefore(pi2)); - + pi2->data().insert(pi2->data().begin(),0x02); BOOST_CHECK_EQUAL( pi1->data().size(), 1u ); BOOST_CHECK_EQUAL( pi2->data().size(), 1u ); - + senf::PacketInterpreter::ptr pi3 (pi2->parseNextAs()); BOOST_REQUIRE( pi3 ); BOOST_CHECK( pi2 == pi1->next() ); @@ -65,7 +65,7 @@ BOOST_AUTO_UNIT_TEST(packetInterpreterBase) BOOST_CHECK( pi2->as() == pi2 ); BOOST_CHECK( pi2->parseNextAs(senf::PacketInterpreter::factory()) ); BOOST_CHECK( pi2->typeId() == pi1->typeId() ); - + pi1->data().insert(pi1->data().begin(),2,0x01u); BOOST_CHECK_EQUAL( pi1->data().size(), 3u ); BOOST_CHECK_EQUAL( pi2->data().size(), 1u ); @@ -91,7 +91,7 @@ BOOST_AUTO_UNIT_TEST(packetInterpreterBase) } namespace { - struct OtherPacket + struct OtherPacket : public senf::PacketTypeBase, public senf::PacketTypeMixin { @@ -105,16 +105,17 @@ namespace { BOOST_AUTO_UNIT_TEST(packetInterpreter) { + typedef senf::PacketInterpreterBase::size_type size_type; { - BOOST_CHECK_THROW( senf::PacketInterpreter::create(4u), + BOOST_CHECK_THROW( senf::PacketInterpreter::create(size_type(4u)), senf::TruncatedPacketException ); senf::PacketInterpreter::ptr p - (senf::PacketInterpreter::create(12u)); - + (senf::PacketInterpreter::create(size_type(12u))); + BOOST_CHECK_EQUAL( p->data().size(), 12u ); BOOST_CHECK_EQUAL( std::distance(p->data().begin(),p->data().end()), 12 ); BOOST_CHECK_EQUAL( p->data()[0], 0x01u ); - + senf::PacketInterpreter::ptr p2 (p->parseNextAs()); BOOST_CHECK_EQUAL( p2->data().size(), 4u ); @@ -128,7 +129,7 @@ BOOST_AUTO_UNIT_TEST(packetInterpreter) } { - BOOST_CHECK_NO_THROW( + BOOST_CHECK_NO_THROW( senf::PacketInterpreter::create(4u,senf::noinit)); senf::PacketInterpreter::ptr p (senf::PacketInterpreter::create(senf::noinit)); @@ -147,7 +148,7 @@ BOOST_AUTO_UNIT_TEST(packetInterpreter) { senf::PacketInterpreter::ptr p - (senf::PacketInterpreter::create(12u)); + (senf::PacketInterpreter::create(size_type(12u))); senf::PacketInterpreter::ptr p2 (senf::PacketInterpreter::createAfter(p)); BOOST_CHECK_EQUAL( p2->data().size(), 0u ); @@ -159,23 +160,23 @@ BOOST_AUTO_UNIT_TEST(packetInterpreter) { senf::PacketInterpreter::ptr p - (senf::PacketInterpreter::create(12u)); + (senf::PacketInterpreter::create(size_type(12u))); senf::PacketInterpreter::ptr p2 (senf::PacketInterpreter::createAfter( p,senf::noinit)); BOOST_CHECK_EQUAL( p2->data().size(), 0u ); BOOST_CHECK_EQUAL( p->data().size(), 8u ); } - + { senf::PacketInterpreter::ptr p - (senf::PacketInterpreter::create(12u)); + (senf::PacketInterpreter::create(size_type(12u))); senf::PacketInterpreter::ptr p2 - (senf::PacketInterpreter::createAfter(p,10u)); + (senf::PacketInterpreter::createAfter(p, size_type(10u))); BOOST_CHECK_EQUAL( p2->data().size(), 10u ); BOOST_CHECK_EQUAL( p->data().size(), 18u ); BOOST_CHECK_EQUAL( p2->data()[0], 0x01u ); - BOOST_CHECK_THROW( senf::PacketInterpreter::createAfter(p,4u), + BOOST_CHECK_THROW( senf::PacketInterpreter::createAfter(p, size_type(4u)), senf::TruncatedPacketException ); BOOST_CHECK_NO_THROW( senf::PacketInterpreter::createAfter( p,4u,senf::noinit) ); @@ -183,7 +184,7 @@ BOOST_AUTO_UNIT_TEST(packetInterpreter) { senf::PacketInterpreter::ptr p - (senf::PacketInterpreter::create(10u)); + (senf::PacketInterpreter::create(size_type(10u))); senf::PacketInterpreter::byte data[] = { 0x01, 0x02, 0x03, 0x04 }; senf::PacketInterpreter::ptr p2 (senf::PacketInterpreter::createAfter(p,data)); @@ -195,7 +196,7 @@ BOOST_AUTO_UNIT_TEST(packetInterpreter) { senf::PacketInterpreter::ptr p - (senf::PacketInterpreter::create(10u)); + (senf::PacketInterpreter::create(size_type(10u))); senf::PacketInterpreter::ptr p2 (senf::PacketInterpreter::createBefore(p)); @@ -205,17 +206,19 @@ BOOST_AUTO_UNIT_TEST(packetInterpreter) senf::PacketInterpreter::ptr p3 (senf::PacketInterpreter::createBefore( p,senf::noinit)); - + BOOST_CHECK_EQUAL( p3->data().size(), 10u ); } - + } -// fields() ist tested in DefaultBundle/EthernetPacket.test.cc +// fields() is tested in DefaultBundle/EthernetPacket.test.cc // initSize() and initHeadSize() are already tested indirectly above BOOST_AUTO_UNIT_TEST(packetInterpreter_factory) { + typedef senf::PacketInterpreterBase::size_type size_type; + senf::PacketInterpreterBase::byte data[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 }; senf::PacketInterpreterBase::factory_t factory ( senf::PacketInterpreter::factory()); @@ -226,8 +229,8 @@ BOOST_AUTO_UNIT_TEST(packetInterpreter_factory) BOOST_CHECK( factory->create()->is() ); BOOST_CHECK_EQUAL( factory->create()->data().size(), 8u ); BOOST_CHECK_EQUAL( factory->create(senf::noinit)->data().size(), 0u ); - BOOST_CHECK_EQUAL( factory->create(12u)->data().size(), 12u ); - BOOST_CHECK_EQUAL( + BOOST_CHECK_EQUAL( factory->create(size_type(12u))->data().size(), 12u ); + BOOST_CHECK_EQUAL( factory->create(4u, senf::noinit)->data().size(), 4u ); BOOST_CHECK_EQUAL( factory->create(data)->data().size(), 6u ); @@ -244,16 +247,16 @@ BOOST_AUTO_UNIT_TEST(packetInterpreter_factory) BOOST_CHECK_EQUAL( p->data().size(), 8u ); BOOST_CHECK( ! p->next()->next() ); - BOOST_CHECK_EQUAL( + BOOST_CHECK_EQUAL( factory->createAfter(p, senf::noinit)->data().size(), 0u ); BOOST_CHECK_EQUAL( p->data().size(), 0u ); BOOST_CHECK( ! p->next()->next() ); - BOOST_CHECK_EQUAL( factory->createAfter(p,12u)->data().size(), 12u ); + BOOST_CHECK_EQUAL( factory->createAfter(p, size_type(12u))->data().size(), 12u ); BOOST_CHECK_EQUAL( p->data().size(), 12u ); BOOST_CHECK( ! p->next()->next() ); - BOOST_CHECK_EQUAL( + BOOST_CHECK_EQUAL( factory->createAfter(p,4u, senf::noinit)->data().size(), 4u ); BOOST_CHECK_EQUAL( p->data().size(), 4u ); BOOST_CHECK( ! p->next()->next() ); @@ -265,14 +268,14 @@ BOOST_AUTO_UNIT_TEST(packetInterpreter_factory) { senf::PacketInterpreter::ptr p - (senf::PacketInterpreter::create(4u)); - + (senf::PacketInterpreter::create(size_type(4u))); + BOOST_CHECK_EQUAL( factory->createBefore(p)->data().size(), 12u ); BOOST_REQUIRE( p->prev() ); BOOST_CHECK( ! p->prev()->prev() ); BOOST_CHECK_EQUAL( p->prev()->data().size(), 12u ); - - BOOST_CHECK_EQUAL( + + BOOST_CHECK_EQUAL( factory->createBefore(p,senf::noinit)->data().size(), 4u ); BOOST_REQUIRE( p->prev() ); BOOST_CHECK( ! p->prev()->prev() ); @@ -281,7 +284,7 @@ BOOST_AUTO_UNIT_TEST(packetInterpreter_factory) { senf::PacketInterpreter::ptr p - (senf::PacketInterpreter::create(12u)); + (senf::PacketInterpreter::create(size_type(12u))); senf::PacketInterpreterBase::ptr p2 (p->parseNextAs(factory)); BOOST_CHECK( p2->is() ); @@ -294,7 +297,7 @@ BOOST_AUTO_UNIT_TEST(packetInterpreter_factory) ///////////////////////////////cc.e//////////////////////////////////////// #undef prefix_ - + // Local Variables: // mode: c++ // fill-column: 100 diff --git a/Packets/PacketParser.test.cc b/Packets/PacketParser.test.cc index 3e53f00..66d84f3 100644 --- a/Packets/PacketParser.test.cc +++ b/Packets/PacketParser.test.cc @@ -42,7 +42,7 @@ namespace { { # include SENF_FIXED_PARSER() SENF_PARSER_FINALIZE(SimpleParser); - + using senf::PacketParserBase::check; using senf::PacketParserBase::validate; }; @@ -70,7 +70,8 @@ namespace { BOOST_AUTO_UNIT_TEST(packetParserBase) { - senf::PacketInterpreter::ptr pi (senf::PacketInterpreter::create(6u)); + senf::PacketInterpreter::ptr pi (senf::PacketInterpreter::create( + senf::PacketInterpreterBase::size_type(6u))); SimpleParser p (pi->data().begin(),&pi->data()); BOOST_CHECK( pi->data().begin() == p.i() ); @@ -94,7 +95,7 @@ BOOST_AUTO_UNIT_TEST(packetParserBase) ///////////////////////////////cc.e//////////////////////////////////////// #undef prefix_ - + // Local Variables: // mode: c++ // fill-column: 100 diff --git a/Packets/SafeIterator.test.cc b/Packets/SafeIterator.test.cc index 5a285b7..32916bb 100644 --- a/Packets/SafeIterator.test.cc +++ b/Packets/SafeIterator.test.cc @@ -1,6 +1,6 @@ // $Id$ // -// Copyright (C) 2008 +// Copyright (C) 2008 // Fraunhofer Institute for Open Communication Systems (FOKUS) // Competence Center NETwork research (NET), St. Augustin, GERMANY // Stefan Bund @@ -41,16 +41,17 @@ namespace { BOOST_AUTO_UNIT_TEST(safePacketParser) { - senf::PacketInterpreter::ptr pi (senf::PacketInterpreter::create(6u)); + senf::PacketInterpreter::ptr pi (senf::PacketInterpreter::create( + senf::PacketInterpreterBase::size_type(6u))); senf::SafePacketParserWrapper p; - + BOOST_CHECK( !p ); p = senf::UInt16Parser(pi->data().begin(),&pi->data()); BOOST_CHECK( p ); (*p) = 0x1234u; - + BOOST_CHECK_EQUAL( (*p), 0x1234u ); BOOST_CHECK_EQUAL( p->data()[0], 0x12u ); @@ -63,7 +64,7 @@ BOOST_AUTO_UNIT_TEST(safePacketParser) ///////////////////////////////cc.e//////////////////////////////////////// #undef prefix_ - + // Local Variables: // mode: c++ // fill-column: 100