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