blob: eff1304035ba130ec0ddc73872ed09ee2d7a9686 [file] [log] [blame]
Ilya Moiseenko08723712011-09-01 17:42:12 -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/test.h"
22#include "ns3/annotated-topology-reader.h"
23#include "ns3/ccnx-interest-header.h"
24#include "ns3/uinteger.h"
25#include "ns3/random-variable.h"
26#include <limits>
27#include "ns3/ccnx-header-helper.h"
28#include "ns3/header.h"
29#include "ns3/ccnx-name-components.h"
30#include "ns3/nstime.h"
31#include "ns3/buffer.h"
32#include "ns3/log.h"
33#include "ns3/ccnx-content-object-header.h"
34#include <iostream>
35#include <fstream>
36#include <sstream>
37
38using namespace ns3;
39using namespace std;
40
41NS_LOG_COMPONENT_DEFINE ("ContentObjectTest");
42
43class ContentObjectTest : public TestCase
44{
45public:
46 ContentObjectTest ();
47 virtual ~ContentObjectTest ();
48
49private:
50 virtual void DoRun (void);
51};
52
53ContentObjectTest::ContentObjectTest ()
54: TestCase ("Content Obejct Serialization Test")
55{
56}
57
58ContentObjectTest::~ContentObjectTest ()
59{
60}
61
62void
63ContentObjectTest::DoRun(void)
64{
65 Packet::EnablePrinting ();
66 Packet::EnableChecking ();
67 Packet packet (10);
68
69 CcnxContentObjectHeader header;
70 CcnxContentObjectTail trailer;
71
72 Ptr<CcnxNameComponents> testname = Create<CcnxNameComponents> ();
73 (*testname) ("iwant")("icecream");
74 header.SetName(testname);
75
76 NS_LOG_INFO ("Source: \n" << header << trailer);
77
78 packet.AddHeader (header);
79 packet.AddTrailer (trailer);
80
81 // NS_LOG_INFO ("Deserialized packet: \n" << packet);
82
83 NS_LOG_INFO ("Removing and deserializing individual headers");
84
85 CcnxContentObjectHeader targetHeader;
86 CcnxContentObjectTail targetTrailer;
87
88 packet.RemoveHeader (targetHeader);
89 packet.RemoveTrailer (targetTrailer);
90
91
92 NS_TEST_ASSERT_MSG_EQ (targetHeader.GetName(), *testname, "Content Object name deserialization failed");
93
94 NS_TEST_ASSERT_MSG_EQ (packet.GetSize(), 10, "Content Object size inequality");
95}
96
97class ContentObjectTestSuite : public TestSuite
98{
99public:
100 ContentObjectTestSuite ();
101};
102
103ContentObjectTestSuite::ContentObjectTestSuite ()
104: TestSuite ("content-object-test-suite", UNIT)
105{
106 SetDataDir (NS_TEST_SOURCEDIR);
107 AddTestCase (new ContentObjectTest);
108}
109
110static ContentObjectTestSuite suite;