blob: 9342317456a36d91f41bd026b6e2b2ba7b1a1016 [file] [log] [blame]
Alexander Afanasyevf1e013f2012-07-11 17:59:40 -07001/* -*- 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
27using namespace std;
28
29namespace ns3
30{
31
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070032NS_LOG_COMPONENT_DEFINE ("ndn.Serialization");
Alexander Afanasyevf1e013f2012-07-11 17:59:40 -070033
34void
35InterestSerializationTest::DoRun ()
36{
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070037 NdnInterestHeader source;
38 source.SetName (Create<NdnNameComponents> (boost::lexical_cast<NdnNameComponents> ("/test/test2")));
39 NS_TEST_ASSERT_MSG_EQ (source.GetName (), boost::lexical_cast<NdnNameComponents> ("/test/test2"), "set/get name failed");
Alexander Afanasyevf1e013f2012-07-11 17:59:40 -070040
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
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070047 source.SetExclude (Create<NdnNameComponents> (boost::lexical_cast<NdnNameComponents> ("/exclude/exclude2")));
48 NS_TEST_ASSERT_MSG_EQ (source.GetExclude (), boost::lexical_cast<NdnNameComponents> ("/exclude/exclude2"), "set/get exclude failed");
Alexander Afanasyevf1e013f2012-07-11 17:59:40 -070049
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
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070077 NdnInterestHeader target;
Alexander Afanasyevf1e013f2012-07-11 17:59:40 -070078 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
92void
93ContentObjectSerializationTest::DoRun ()
94{
95 // NS_TEST_ASSERT_MSG_EQ (true, false, "test not implemented yet");
96}
97
98}
99