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