Alexander Afanasyev | f1e013f | 2012-07-11 17:59:40 -0700 | [diff] [blame] | 1 | /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /* |
| 3 | * Copyright (c) 2011 University of California, Los Angeles |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License version 2 as |
| 7 | * published by the Free Software Foundation; |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 17 | * |
| 18 | * Author: Ilya Moiseenko <iliamo@cs.ucla.edu> |
| 19 | */ |
| 20 | |
| 21 | #include "ns3/core-module.h" |
| 22 | #include "ns3/ndnSIM-module.h" |
| 23 | #include "ndnSIM-serialization.h" |
| 24 | |
| 25 | #include <boost/lexical_cast.hpp> |
| 26 | |
| 27 | using namespace std; |
| 28 | |
| 29 | namespace ns3 |
| 30 | { |
| 31 | |
| 32 | NS_LOG_COMPONENT_DEFINE ("NdnSimSerialization"); |
| 33 | |
| 34 | void |
| 35 | InterestSerializationTest::DoRun () |
| 36 | { |
| 37 | CcnxInterestHeader source; |
| 38 | source.SetName (Create<CcnxNameComponents> (boost::lexical_cast<CcnxNameComponents> ("/test/test2"))); |
| 39 | NS_TEST_ASSERT_MSG_EQ (source.GetName (), boost::lexical_cast<CcnxNameComponents> ("/test/test2"), "set/get name failed"); |
| 40 | |
| 41 | source.SetMinSuffixComponents (20); |
| 42 | NS_TEST_ASSERT_MSG_EQ (source.GetMinSuffixComponents (), 20, "set/get minSuffixComponents failed"); |
| 43 | |
| 44 | source.SetMaxSuffixComponents (40); |
| 45 | NS_TEST_ASSERT_MSG_EQ (source.GetMaxSuffixComponents (), 40, "set/get maxSuffixComponents failed"); |
| 46 | |
| 47 | source.SetExclude (Create<CcnxNameComponents> (boost::lexical_cast<CcnxNameComponents> ("/exclude/exclude2"))); |
| 48 | NS_TEST_ASSERT_MSG_EQ (source.GetExclude (), boost::lexical_cast<CcnxNameComponents> ("/exclude/exclude2"), "set/get exclude failed"); |
| 49 | |
| 50 | source.SetChildSelector (false); |
| 51 | NS_TEST_ASSERT_MSG_EQ (source.IsEnabledChildSelector (), false, "set/get child selector failed"); |
| 52 | source.SetChildSelector (true); |
| 53 | NS_TEST_ASSERT_MSG_EQ (source.IsEnabledChildSelector (), true, "set/get child selector failed"); |
| 54 | |
| 55 | source.SetAnswerOriginKind (false); |
| 56 | NS_TEST_ASSERT_MSG_EQ (source.IsEnabledAnswerOriginKind (), false, "set/get answer origin kind failed"); |
| 57 | source.SetAnswerOriginKind (true); |
| 58 | NS_TEST_ASSERT_MSG_EQ (source.IsEnabledAnswerOriginKind (), true, "set/get answer origin kind failed"); |
| 59 | |
| 60 | source.SetScope (2); |
| 61 | NS_TEST_ASSERT_MSG_EQ (source.GetScope (), 2, "set/get scope failed"); |
| 62 | |
| 63 | source.SetInterestLifetime (Seconds (100)); |
| 64 | NS_TEST_ASSERT_MSG_EQ (source.GetInterestLifetime (), Seconds (100), "set/get interest lifetime failed"); |
| 65 | |
| 66 | source.SetNonce (200); |
| 67 | NS_TEST_ASSERT_MSG_EQ (source.GetNonce (), 200, "set/get nonce failed"); |
| 68 | |
| 69 | source.SetNack (10); |
| 70 | NS_TEST_ASSERT_MSG_EQ (source.GetNack (), 10, "set/get NACK failed"); |
| 71 | |
| 72 | Packet packet (0); |
| 73 | //serialization |
| 74 | packet.AddHeader (source); |
| 75 | |
| 76 | //deserialization |
| 77 | CcnxInterestHeader target; |
| 78 | packet.RemoveHeader (target); |
| 79 | |
| 80 | NS_TEST_ASSERT_MSG_EQ (source.GetName () , target.GetName () , "source/target name failed"); |
| 81 | NS_TEST_ASSERT_MSG_EQ (source.GetMinSuffixComponents () , target.GetMinSuffixComponents () , "source/target minSuffixComponents failed"); |
| 82 | NS_TEST_ASSERT_MSG_EQ (source.GetMaxSuffixComponents () , target.GetMaxSuffixComponents () , "source/target maxSuffixComponents failed"); |
| 83 | NS_TEST_ASSERT_MSG_EQ (source.GetExclude () , target.GetExclude () , "source/target exclude failed"); |
| 84 | NS_TEST_ASSERT_MSG_EQ (source.IsEnabledChildSelector () , target.IsEnabledChildSelector () , "source/target child selector failed"); |
| 85 | NS_TEST_ASSERT_MSG_EQ (source.IsEnabledAnswerOriginKind (), target.IsEnabledAnswerOriginKind (), "source/target answer origin kind failed"); |
| 86 | NS_TEST_ASSERT_MSG_EQ (source.GetScope () , target.GetScope () , "source/target scope failed"); |
| 87 | NS_TEST_ASSERT_MSG_EQ (source.GetInterestLifetime () , target.GetInterestLifetime () , "source/target interest lifetime failed"); |
| 88 | NS_TEST_ASSERT_MSG_EQ (source.GetNonce () , target.GetNonce () , "source/target nonce failed"); |
| 89 | NS_TEST_ASSERT_MSG_EQ (source.GetNack () , target.GetNack () , "source/target NACK failed"); |
| 90 | } |
| 91 | |
| 92 | void |
| 93 | ContentObjectSerializationTest::DoRun () |
| 94 | { |
| 95 | // NS_TEST_ASSERT_MSG_EQ (true, false, "test not implemented yet"); |
| 96 | } |
| 97 | |
| 98 | } |
| 99 | |