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 | * |
Alexander Afanasyev | cf6dc92 | 2012-08-10 16:55:27 -0700 | [diff] [blame^] | 18 | * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
| 19 | * Ilya Moiseenko <iliamo@cs.ucla.edu> |
Alexander Afanasyev | f1e013f | 2012-07-11 17:59:40 -0700 | [diff] [blame] | 20 | */ |
| 21 | |
| 22 | #include "ns3/core-module.h" |
| 23 | #include "ns3/ndnSIM-module.h" |
| 24 | #include "ndnSIM-serialization.h" |
| 25 | |
| 26 | #include <boost/lexical_cast.hpp> |
| 27 | |
| 28 | using namespace std; |
| 29 | |
Alexander Afanasyev | cf6dc92 | 2012-08-10 16:55:27 -0700 | [diff] [blame^] | 30 | namespace ns3 { |
| 31 | |
| 32 | using namespace ndn; |
Alexander Afanasyev | f1e013f | 2012-07-11 17:59:40 -0700 | [diff] [blame] | 33 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 34 | NS_LOG_COMPONENT_DEFINE ("ndn.Serialization"); |
Alexander Afanasyev | f1e013f | 2012-07-11 17:59:40 -0700 | [diff] [blame] | 35 | |
| 36 | void |
| 37 | InterestSerializationTest::DoRun () |
| 38 | { |
Alexander Afanasyev | cf6dc92 | 2012-08-10 16:55:27 -0700 | [diff] [blame^] | 39 | InterestHeader source; |
| 40 | source.SetName (Create<NameComponents> (boost::lexical_cast<NameComponents> ("/test/test2"))); |
| 41 | NS_TEST_ASSERT_MSG_EQ (source.GetName (), boost::lexical_cast<NameComponents> ("/test/test2"), "set/get name failed"); |
Alexander Afanasyev | f1e013f | 2012-07-11 17:59:40 -0700 | [diff] [blame] | 42 | |
| 43 | source.SetMinSuffixComponents (20); |
| 44 | NS_TEST_ASSERT_MSG_EQ (source.GetMinSuffixComponents (), 20, "set/get minSuffixComponents failed"); |
| 45 | |
| 46 | source.SetMaxSuffixComponents (40); |
| 47 | NS_TEST_ASSERT_MSG_EQ (source.GetMaxSuffixComponents (), 40, "set/get maxSuffixComponents failed"); |
| 48 | |
Alexander Afanasyev | cf6dc92 | 2012-08-10 16:55:27 -0700 | [diff] [blame^] | 49 | source.SetExclude (Create<NameComponents> (boost::lexical_cast<NameComponents> ("/exclude/exclude2"))); |
| 50 | NS_TEST_ASSERT_MSG_EQ (source.GetExclude (), boost::lexical_cast<NameComponents> ("/exclude/exclude2"), "set/get exclude failed"); |
Alexander Afanasyev | f1e013f | 2012-07-11 17:59:40 -0700 | [diff] [blame] | 51 | |
| 52 | source.SetChildSelector (false); |
| 53 | NS_TEST_ASSERT_MSG_EQ (source.IsEnabledChildSelector (), false, "set/get child selector failed"); |
| 54 | source.SetChildSelector (true); |
| 55 | NS_TEST_ASSERT_MSG_EQ (source.IsEnabledChildSelector (), true, "set/get child selector failed"); |
| 56 | |
| 57 | source.SetAnswerOriginKind (false); |
| 58 | NS_TEST_ASSERT_MSG_EQ (source.IsEnabledAnswerOriginKind (), false, "set/get answer origin kind failed"); |
| 59 | source.SetAnswerOriginKind (true); |
| 60 | NS_TEST_ASSERT_MSG_EQ (source.IsEnabledAnswerOriginKind (), true, "set/get answer origin kind failed"); |
| 61 | |
| 62 | source.SetScope (2); |
| 63 | NS_TEST_ASSERT_MSG_EQ (source.GetScope (), 2, "set/get scope failed"); |
| 64 | |
| 65 | source.SetInterestLifetime (Seconds (100)); |
| 66 | NS_TEST_ASSERT_MSG_EQ (source.GetInterestLifetime (), Seconds (100), "set/get interest lifetime failed"); |
| 67 | |
| 68 | source.SetNonce (200); |
| 69 | NS_TEST_ASSERT_MSG_EQ (source.GetNonce (), 200, "set/get nonce failed"); |
| 70 | |
| 71 | source.SetNack (10); |
| 72 | NS_TEST_ASSERT_MSG_EQ (source.GetNack (), 10, "set/get NACK failed"); |
| 73 | |
| 74 | Packet packet (0); |
| 75 | //serialization |
| 76 | packet.AddHeader (source); |
| 77 | |
| 78 | //deserialization |
Alexander Afanasyev | cf6dc92 | 2012-08-10 16:55:27 -0700 | [diff] [blame^] | 79 | InterestHeader target; |
Alexander Afanasyev | f1e013f | 2012-07-11 17:59:40 -0700 | [diff] [blame] | 80 | packet.RemoveHeader (target); |
| 81 | |
| 82 | NS_TEST_ASSERT_MSG_EQ (source.GetName () , target.GetName () , "source/target name failed"); |
| 83 | NS_TEST_ASSERT_MSG_EQ (source.GetMinSuffixComponents () , target.GetMinSuffixComponents () , "source/target minSuffixComponents failed"); |
| 84 | NS_TEST_ASSERT_MSG_EQ (source.GetMaxSuffixComponents () , target.GetMaxSuffixComponents () , "source/target maxSuffixComponents failed"); |
| 85 | NS_TEST_ASSERT_MSG_EQ (source.GetExclude () , target.GetExclude () , "source/target exclude failed"); |
| 86 | NS_TEST_ASSERT_MSG_EQ (source.IsEnabledChildSelector () , target.IsEnabledChildSelector () , "source/target child selector failed"); |
| 87 | NS_TEST_ASSERT_MSG_EQ (source.IsEnabledAnswerOriginKind (), target.IsEnabledAnswerOriginKind (), "source/target answer origin kind failed"); |
| 88 | NS_TEST_ASSERT_MSG_EQ (source.GetScope () , target.GetScope () , "source/target scope failed"); |
| 89 | NS_TEST_ASSERT_MSG_EQ (source.GetInterestLifetime () , target.GetInterestLifetime () , "source/target interest lifetime failed"); |
| 90 | NS_TEST_ASSERT_MSG_EQ (source.GetNonce () , target.GetNonce () , "source/target nonce failed"); |
| 91 | NS_TEST_ASSERT_MSG_EQ (source.GetNack () , target.GetNack () , "source/target NACK failed"); |
| 92 | } |
| 93 | |
| 94 | void |
| 95 | ContentObjectSerializationTest::DoRun () |
| 96 | { |
| 97 | // NS_TEST_ASSERT_MSG_EQ (true, false, "test not implemented yet"); |
| 98 | } |
| 99 | |
| 100 | } |
| 101 | |