blob: 44f881cb4821062cbc25a2df56712c05468cf000 [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"
Ilya Moiseenko08723712011-09-01 17:42:12 -070022#include "ns3/ccnx-interest-header.h"
23#include "ns3/uinteger.h"
24#include "ns3/random-variable.h"
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -080025#include "ns3/packet.h"
Ilya Moiseenko08723712011-09-01 17:42:12 -070026#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:
Alexander Afanasyev864522f2012-05-31 13:33:57 -070046 ContentObjectTest ();
47 virtual ~ContentObjectTest ();
Ilya Moiseenko08723712011-09-01 17:42:12 -070048
49private:
Alexander Afanasyev864522f2012-05-31 13:33:57 -070050 virtual void DoRun (void);
Ilya Moiseenko08723712011-09-01 17:42:12 -070051};
52
53ContentObjectTest::ContentObjectTest ()
Alexander Afanasyev864522f2012-05-31 13:33:57 -070054 : TestCase ("Content Obejct Serialization Test")
Ilya Moiseenko08723712011-09-01 17:42:12 -070055{
56}
57
58ContentObjectTest::~ContentObjectTest ()
59{
60}
61
62void
63ContentObjectTest::DoRun(void)
64{
Alexander Afanasyev864522f2012-05-31 13:33:57 -070065 Packet::EnablePrinting ();
66 Packet::EnableChecking ();
67 Packet packet (10);
Ilya Moiseenko08723712011-09-01 17:42:12 -070068
Alexander Afanasyev864522f2012-05-31 13:33:57 -070069 CcnxContentObjectHeader header;
70 CcnxContentObjectTail trailer;
Ilya Moiseenko08723712011-09-01 17:42:12 -070071
Alexander Afanasyev864522f2012-05-31 13:33:57 -070072 Ptr<CcnxNameComponents> testname = Create<CcnxNameComponents> ();
73 (*testname) ("iwant")("icecream");
74 header.SetName(testname);
Ilya Moiseenko08723712011-09-01 17:42:12 -070075
Alexander Afanasyev864522f2012-05-31 13:33:57 -070076 NS_LOG_INFO ("Source: \n" << header << trailer);
Ilya Moiseenko08723712011-09-01 17:42:12 -070077
Alexander Afanasyev864522f2012-05-31 13:33:57 -070078 packet.AddHeader (header);
79 packet.AddTrailer (trailer);
Ilya Moiseenko08723712011-09-01 17:42:12 -070080
Alexander Afanasyev864522f2012-05-31 13:33:57 -070081 // NS_LOG_INFO ("Deserialized packet: \n" << packet);
Ilya Moiseenko08723712011-09-01 17:42:12 -070082
Alexander Afanasyev864522f2012-05-31 13:33:57 -070083 NS_LOG_INFO ("Removing and deserializing individual headers");
Ilya Moiseenko08723712011-09-01 17:42:12 -070084
Alexander Afanasyev864522f2012-05-31 13:33:57 -070085 CcnxContentObjectHeader targetHeader;
86 CcnxContentObjectTail targetTrailer;
Ilya Moiseenko08723712011-09-01 17:42:12 -070087
Alexander Afanasyev864522f2012-05-31 13:33:57 -070088 packet.RemoveHeader (targetHeader);
89 packet.RemoveTrailer (targetTrailer);
Ilya Moiseenko08723712011-09-01 17:42:12 -070090
91
Alexander Afanasyev864522f2012-05-31 13:33:57 -070092 NS_TEST_ASSERT_MSG_EQ (targetHeader.GetName(), *testname, "Content Object name deserialization failed");
Ilya Moiseenko08723712011-09-01 17:42:12 -070093
Alexander Afanasyev864522f2012-05-31 13:33:57 -070094 NS_TEST_ASSERT_MSG_EQ (packet.GetSize(), 10, "Content Object size inequality");
Ilya Moiseenko08723712011-09-01 17:42:12 -070095}
96
97class ContentObjectTestSuite : public TestSuite
98{
99public:
Alexander Afanasyev864522f2012-05-31 13:33:57 -0700100 ContentObjectTestSuite ();
Ilya Moiseenko08723712011-09-01 17:42:12 -0700101};
102
103ContentObjectTestSuite::ContentObjectTestSuite ()
Alexander Afanasyev864522f2012-05-31 13:33:57 -0700104 : TestSuite ("content-object-test-suite", UNIT)
Ilya Moiseenko08723712011-09-01 17:42:12 -0700105{
Alexander Afanasyev864522f2012-05-31 13:33:57 -0700106 SetDataDir (NS_TEST_SOURCEDIR);
107 AddTestCase (new ContentObjectTest);
Ilya Moiseenko08723712011-09-01 17:42:12 -0700108}
109
110static ContentObjectTestSuite suite;