switch to new MPL based Fraunhofer FOKUS Public License
[senf.git] / senf / Packets / 80221Bundle / MIHPacket.test.cc
index cd99702..08d3605 100644 (file)
@@ -2,23 +2,28 @@
 //
 // Copyright (C) 2009
 // Fraunhofer Institute for Open Communication Systems (FOKUS)
-// Competence Center NETwork research (NET), St. Augustin, GERMANY
-//     Thorsten Horstmann <tho@berlios.de>
 //
-// 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
-// the Free Software Foundation; either version 2 of the License, or
-// (at your option) any later version.
+// The contents of this file are subject to the Fraunhofer FOKUS Public License
+// Version 1.0 (the "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at 
+// http://senf.berlios.de/license.html
 //
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
+// The Fraunhofer FOKUS Public License Version 1.0 is based on, 
+// but modifies the Mozilla Public License Version 1.1.
+// See the full license text for the amendments.
 //
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the
-// Free Software Foundation, Inc.,
-// 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+// Software distributed under the License is distributed on an "AS IS" basis, 
+// WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 
+// for the specific language governing rights and limitations under the License.
+//
+// The Original Code is Fraunhofer FOKUS code.
+//
+// The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V. 
+// (registered association), Hansastraße 27 c, 80686 Munich, Germany.
+// All Rights Reserved.
+//
+// Contributor(s):
+//   Thorsten Horstmann <tho@berlios.de>
 
 /** \file
     \brief MIHPacket unit tests */
@@ -34,7 +39,7 @@
 #include <boost/test/test_tools.hpp>
 
 #define prefix_
-///////////////////////////////cc.p////////////////////////////////////////
+//-/////////////////////////////////////////////////////////////////////////////////////////////////
 using namespace senf;
 
 SENF_AUTO_UNIT_TEST(MIHPacket_msgId)
@@ -43,7 +48,7 @@ SENF_AUTO_UNIT_TEST(MIHPacket_msgId)
     mihPacket->sid() = 4;
     mihPacket->opcode() = 3;
     mihPacket->aid() = 42;
-    BOOST_CHECK_EQUAL( mihPacket->messageId(), 0x4c2a );        
+    BOOST_CHECK_EQUAL( mihPacket->messageId(), 0x4c2a );
 }
 
 SENF_AUTO_UNIT_TEST(MIHPacket_create_eth)
@@ -65,7 +70,7 @@ SENF_AUTO_UNIT_TEST(MIHPacket_create_string)
     mihPacket->src_mihfId().value( "senf@berlios.de");
     mihPacket->dst_mihfId().value( "test");
     mihPacket.finalizeThis();
-    
+
     unsigned char data[] = {
             // MIH header
             0x10, 0x54, 0x00, 0x00, 0x00, 0x15, 0x00, 0x19,
@@ -90,9 +95,9 @@ SENF_AUTO_UNIT_TEST(MIHPacket_create_string)
     mihPacket->dst_mihfId().maxIdLength(128);
     mihPacket->dst_mihfId().value( std::string(128, 'x'));
     mihPacket.finalizeThis();
-    // packet size is now MIH header (8 bytes) + src MIHIFId TLV (18 bytes) + 
-    // dst MIHIFId TLV (1 byte type + 2 byte TLV length + 1 byte id length + 128 id value) 
-    BOOST_CHECK_EQUAL( mihPacket.size(), unsigned(8 + 18 + 1+2+1+128));  
+    // packet size is now MIH header (8 bytes) + src MIHIFId TLV (18 bytes) +
+    // dst MIHIFId TLV (1 byte type + 2 byte TLV length + 1 byte id length + 128 id value)
+    BOOST_CHECK_EQUAL( mihPacket.size(), unsigned(8 + 18 + 1+2+1+128));
     BOOST_CHECK_EQUAL( mihPacket->payloadLength(), 18 + 1+2+1+128);
     BOOST_CHECK_EQUAL( mihPacket->dst_mihfId().length(), 1+128);
     BOOST_CHECK_EQUAL( senf::bytes(mihPacket->dst_mihfId()), 1+2+1+128);
@@ -101,9 +106,9 @@ SENF_AUTO_UNIT_TEST(MIHPacket_create_string)
     mihPacket->dst_mihfId().maxIdLength(129);
     mihPacket->dst_mihfId().value( std::string(129, 'x'));
     mihPacket.finalizeThis();
-    // packet size is now MIH header (8 bytes) + src MIHIFId TLV (18 bytes) + 
-    // dst MIHIFId TLV (1 byte type + 2 byte TLV length + 2 byte id length + 128 id value) 
-    BOOST_CHECK_EQUAL( mihPacket.size(), unsigned(8 + 18 + 1+2+2+129));  
+    // packet size is now MIH header (8 bytes) + src MIHIFId TLV (18 bytes) +
+    // dst MIHIFId TLV (1 byte type + 2 byte TLV length + 2 byte id length + 128 id value)
+    BOOST_CHECK_EQUAL( mihPacket.size(), unsigned(8 + 18 + 1+2+2+129));
     BOOST_CHECK_EQUAL( mihPacket->payloadLength(), 18 + 1+2+2+129);
     BOOST_CHECK_EQUAL( mihPacket->dst_mihfId().length(), 2+129);
     BOOST_CHECK_EQUAL( senf::bytes(mihPacket->dst_mihfId()), 1+2+2+129);
@@ -112,7 +117,7 @@ SENF_AUTO_UNIT_TEST(MIHPacket_create_string)
     mihPacket.finalizeThis();
     SENF_CHECK_EQUAL_COLLECTIONS( data, data+sizeof(data),
             mihPacket.data().begin(), mihPacket.data().end() );
-    
+
     std::ostringstream oss (std::ostringstream::out);
     SENF_CHECK_NO_THROW( mihPacket.dump( oss));
 }
@@ -269,7 +274,7 @@ SENF_AUTO_UNIT_TEST(MIHPayload_parse)
     BOOST_CHECK_EQUAL( tlv2.type(), 0x0c);
     BOOST_CHECK_EQUAL( tlv2.length(), 0x04u);
     BOOST_CHECK_EQUAL( tlv2.value().size(), 0x04);
-    
+
     std::ostringstream oss (std::ostringstream::out);
     SENF_CHECK_NO_THROW( mihPayload.dump( oss));
 }
@@ -286,7 +291,7 @@ SENF_AUTO_UNIT_TEST(MIHPayload_create)
     MIHGenericPayloadPacket mihPayload (MIHGenericPayloadPacket::createAfter(mihPacket));
     MIHGenericPayloadPacket::Parser::tlvList_t::container tlvListContainer (
             mihPayload->tlvList() );
-    
+
     unsigned char tlv1_value[] = {
            0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09 };
     MIHGenericTLVParser tlv1 ( tlvListContainer.push_back_space());
@@ -296,7 +301,7 @@ SENF_AUTO_UNIT_TEST(MIHPayload_create)
     unsigned char tlv2_value[] = {
             0x1a, 0x2b, 0x3c, 0x4d };
     MIHGenericTLVParser tlv2 ( tlvListContainer.push_back_space());
-    tlv2.type() = 0x0c;
+    tlv2.type() = 0x43;
     tlv2.value( tlv2_value);
 
     mihPacket.finalizeAll();
@@ -319,16 +324,33 @@ SENF_AUTO_UNIT_TEST(MIHPayload_create)
             0x0a, // first bit not set, length=10
             0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, // value
             // second test tlv
-            0x0c, // type
+            0x43, // type
             0x04, // first bit not set, length=4
             0x1a, 0x2b, 0x3c, 0x4d // value
     };
     SENF_CHECK_EQUAL_COLLECTIONS( data, data+sizeof(data),
-            mihPacket.data().begin(), mihPacket.data().end() );    
+            mihPacket.data().begin(), mihPacket.data().end() );
 }
 
+SENF_AUTO_UNIT_TEST(Test_MIHFIdTLV)
+{
+    unsigned char data[] = {
+            // MIH header
+            0x10, 0x54, 0x00, 0x00, 0x00, 0x15, 0x00, 0x06,
+            // source MIHF_ID TLV:
+            0x01, 0x01, // type, length
+            0x00,       // value-length
+            // destination MIHF_ID TLV:
+            0x02, 0x01, // type, length
+            0x00        // value-length
+    };
+
+    MIHPacket mihPacket (MIHPacket::create(data));
+    BOOST_CHECK( mihPacket->src_mihfId().valueEquals( MIHFId::Multicast) );
+    BOOST_CHECK( mihPacket->dst_mihfId().valueEquals( MIHFId::Multicast) );
+}
 
-///////////////////////////////cc.e////////////////////////////////////////
+//-/////////////////////////////////////////////////////////////////////////////////////////////////
 #undef prefix_
 
 \f