X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Packets%2FDefaultBundle%2FUDPPacket.test.cc;h=6df940989adb88782cb9be2d88ff768cc5e4537d;hb=a58be9dbd48369f2c0469b5c214406d26f1feefa;hp=a53543e8c638ffdf7920e49cd13ada6f49e2edf0;hpb=9357448dc66bc9acfd3bd8db423deb75bcd6a2c4;p=senf.git diff --git a/Packets/DefaultBundle/UDPPacket.test.cc b/Packets/DefaultBundle/UDPPacket.test.cc index a53543e..6df9409 100644 --- a/Packets/DefaultBundle/UDPPacket.test.cc +++ b/Packets/DefaultBundle/UDPPacket.test.cc @@ -1,9 +1,9 @@ // $Id$ // // Copyright (C) 2006 -// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) -// Kompetenzzentrum fuer Satelitenkommunikation (SatCom) -// Stefan Bund +// Fraunhofer Institute for Open Communication Systems (FOKUS) +// Competence Center NETwork research (NET), St. Augustin, GERMANY +// Stefan Bund // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -27,32 +27,14 @@ // Custom includes #include "UDPPacket.hh" +#include "IPv4Packet.hh" -#include +#include "../../Utils/auto_unit_test.hh" #include #define prefix_ ///////////////////////////////cc.p//////////////////////////////////////// -using namespace senf; - -BOOST_AUTO_UNIT_TEST(udpPacket_parser) -{ - unsigned char data[] = { 0x01, 0x02, 0x03, 0x04, - 0x05, 0x06, 0x07, 0x08 - }; - - typedef unsigned char * iterator; - Parse_UDP p(data); - - BOOST_CHECK_EQUAL( p.source(), 0x0102 ); - BOOST_CHECK_EQUAL( p.destination(), 0x0304 ); - BOOST_CHECK_EQUAL( p.length(), 0x0506 ); - BOOST_CHECK_EQUAL( p.crc(), 0x0708 ); - -} - - BOOST_AUTO_UNIT_TEST(udpPacket_packet) { @@ -60,15 +42,42 @@ BOOST_AUTO_UNIT_TEST(udpPacket_packet) 0x05, 0x06, 0x07, 0x08 }; - UDPPacket::ptr p (Packet::create(data, data+sizeof(data))); + senf::UDPPacket p (senf::UDPPacket::create(data)); BOOST_CHECK_EQUAL( p->source(), 0x0102 ); BOOST_CHECK_EQUAL( p->destination(), 0x0304 ); BOOST_CHECK_EQUAL( p->length(), 0x0506 ); - BOOST_CHECK_EQUAL( p->crc(), 0x0708 ); - + BOOST_CHECK_EQUAL( p->checksum(), 0x0708 ); } +BOOST_AUTO_UNIT_TEST(udpPacket_create) +{ + unsigned char data[] = { 0x45, 0x00, 0x00, 0x26, 0x00, 0x00, 0x40, 0x00, + 0x40, 0x11, 0x3c, 0xc5, 0x7f, 0x00, 0x00, 0x01, + 0x7f, 0x00, 0x00, 0x01, 0x5b, 0xa0, 0x30, 0x39, + 0x00, 0x12, 0xfa, 0x6e, 0x54, 0x45, 0x53, 0x54, + 0x2d, 0x57, 0x52, 0x49, 0x54, 0x45 }; + + senf::IPv4Packet ip (senf::IPv4Packet::create()); + ip->source() = senf::INet4Address::Loopback; + ip->destination() = senf::INet4Address::Loopback; + ip->df() = true; + ip->ttl() = 64; + + senf::UDPPacket udp (senf::UDPPacket::createAfter(ip)); + udp->source() = 23456; + udp->destination() = 12345; + + senf::DataPacket::createAfter(udp,std::string("TEST-WRITE")); + + // validates, since the checksum is 0 and thus ignored ! + BOOST_CHECK( udp->validateChecksum() ); + + ip.finalizeAll(); + BOOST_CHECK_EQUAL_COLLECTIONS( data, data+sizeof(data), + ip.data().begin(), ip.data().end() ); + BOOST_CHECK( udp->validateChecksum() ); +} ///////////////////////////////cc.e//////////////////////////////////////// @@ -81,4 +90,6 @@ BOOST_AUTO_UNIT_TEST(udpPacket_packet) // c-file-style: "senf" // indent-tabs-mode: nil // ispell-local-dictionary: "american" +// compile-command: "scons -u test" +// comment-column: 40 // End: