blob: 4413724c0ed6cb0c72b4924fc186c7adf22878f7 [file] [log] [blame]
Ilya Moiseenko3e15eff2011-08-30 13:33:09 -07001#include "ns3/test.h"
2#include "ns3/annotated-topology-reader.h"
3#include "ns3/ccnx-interest-header.h"
4#include "ns3/uinteger.h"
5#include "ns3/random-variable.h"
6#include <limits>
7#include "ns3/ccnx-header-helper.h"
8#include "ns3/header.h"
9#include "ns3/ccnx-name-components.h"
10#include "ns3/nstime.h"
11#include "ns3/buffer.h"
12#include "ns3/log.h"
13
14using namespace ns3;
15
16NS_LOG_COMPONENT_DEFINE ("InterestHeaderSerializationTest");
17
18class InterestHeaderSerializationTest : public TestCase
19{
20public:
21 //static const uint32_t N_RUNS = 5;
22 //static const uint32_t N_BINS = 50;
23 //static const uint32_t N_MEASUREMENTS = 1000000;
24
25 InterestHeaderSerializationTest ();
26 virtual ~InterestHeaderSerializationTest ();
27
28 //double ChiSquaredTest (UniformVariable &u);
29
30private:
31 virtual void DoRun (void);
32};
33
34InterestHeaderSerializationTest::InterestHeaderSerializationTest ()
35: TestCase ("Interest Header Serialization Test")
36{
37}
38
39InterestHeaderSerializationTest::~InterestHeaderSerializationTest ()
40{
41}
42
43void
44InterestHeaderSerializationTest::DoRun(void)
45{
46 //ReportStart();
47 //SetVerbose(true);
48 NS_LOG_INFO ("Test started");
49 uint32_t randomNonce = UniformVariable().GetInteger(1, std::numeric_limits<uint32_t>::max ());
50 Ptr<CcnxNameComponents> testname = Create<CcnxNameComponents> ();
51 (*testname) ("test") ("test2");
52
53 Ptr<CcnxNameComponents> exclude = Create<CcnxNameComponents> ();
54 (*testname) ("exclude") ("exclude2");
55
56 Time lifetime = Seconds(4.0);
57 bool child = true;
58
59 uint32_t maxSuffixComponents = 40;
60 uint32_t minSuffixComponents = 20;
61
62 CcnxInterestHeader interestHeader;
63 interestHeader.SetNonce(randomNonce);
64 interestHeader.SetName(testname);
65 interestHeader.SetInterestLifetime(lifetime);
66 interestHeader.SetChildSelector(child);
67 interestHeader.SetExclude(exclude);
68 interestHeader.SetMaxSuffixComponents(maxSuffixComponents);
69 interestHeader.SetMinSuffixComponents(minSuffixComponents);
70
71 uint32_t size = interestHeader.GetSerializedSize();
72 //uint32_t size = 5;
73 NS_TEST_ASSERT_MSG_EQ (false, true, "GetSize = " << size);
74 Buffer buf(size);
75 Buffer::Iterator iter = buf.Begin ();
76 //interestHeader.
77 //interestHeader.Serialize(iter);
78
79 iter = buf.Begin ();
80 CcnxInterestHeader target;
81 //target.Deserialize(iter);
82
83 /*if(target.GetNonce() == randomNonce)
84 {
85
86 ReportCaseFailure();
87 }*/
88 NS_TEST_ASSERT_MSG_EQ (target.GetNonce(), randomNonce, "Interest Header nonce deserialization failed");
89
90 //NS_TEST_ASSERT_MSG_EQ (target.GetName(), testname, "Interest Header name deserialization failed");
91
92 NS_TEST_ASSERT_MSG_EQ (target.GetInterestLifetime(), lifetime, "Interest Header lifetime deserialization failed");
93
94 //NS_TEST_ASSERT_MSG_EQ (target.GetChildSelector(), child, "Interest Header childselector deserialization failed");
95
96 //NS_TEST_ASSERT_MSG_EQ (target.GetExclude(), exclude, "Interest Header exclude deserialization failed");
97
98 NS_TEST_ASSERT_MSG_EQ (target.GetMaxSuffixComponents(), (int)maxSuffixComponents, "Interest Header maxSuffixComponents deserialization failed");
99
100 NS_TEST_ASSERT_MSG_EQ (target.GetMinSuffixComponents(), (int)minSuffixComponents, "Interest Header minSuffixComponents deserialization failed");
101}
102
103class InterestHeaderSerializationTestSuite : public TestSuite
104{
105public:
106 InterestHeaderSerializationTestSuite ();
107};
108
109InterestHeaderSerializationTestSuite::InterestHeaderSerializationTestSuite ()
110: TestSuite ("interest-header-serialization-test-suite", UNIT)
111{
112 AddTestCase (new InterestHeaderSerializationTest);
113}
114
115static InterestHeaderSerializationTestSuite suite;