blob: dff675e6e8cda694edae40b107c9e6c446f25358 [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 *
Alexander Afanasyevcf6dc922012-08-10 16:55:27 -070018 * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
19 * Ilya Moiseenko <iliamo@cs.ucla.edu>
Alexander Afanasyevf1e013f2012-07-11 17:59:40 -070020 */
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
28using namespace std;
29
Alexander Afanasyevcf6dc922012-08-10 16:55:27 -070030namespace ns3 {
31
32using namespace ndn;
Alexander Afanasyevf1e013f2012-07-11 17:59:40 -070033
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070034NS_LOG_COMPONENT_DEFINE ("ndn.Serialization");
Alexander Afanasyevf1e013f2012-07-11 17:59:40 -070035
36void
37InterestSerializationTest::DoRun ()
38{
Alexander Afanasyevcf6dc922012-08-10 16:55:27 -070039 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 Afanasyevf1e013f2012-07-11 17:59:40 -070042
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 Afanasyevcf6dc922012-08-10 16:55:27 -070049 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 Afanasyevf1e013f2012-07-11 17:59:40 -070051
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 Afanasyevcf6dc922012-08-10 16:55:27 -070079 InterestHeader target;
Alexander Afanasyevf1e013f2012-07-11 17:59:40 -070080 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
94void
95ContentObjectSerializationTest::DoRun ()
96{
97 // NS_TEST_ASSERT_MSG_EQ (true, false, "test not implemented yet");
98}
99
100}
101