blob: 7e56fd17dae0d51140a439c4623c1b9f94ae5dd3 [file] [log] [blame]
Jeff Thompsonfa306642013-06-17 15:06:57 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/*
3 * Copyright (c) 2013, Regents of the University of California
4 * Alexander Afanasyev
5 *
6 * BSD license, See the LICENSE file for more information
7 *
8 * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
9 */
10
11#include "ndn-cpp/wire/ccnb.h"
12#include "ndn-cpp/interest.h"
13
14#include <unistd.h>
15#include <fstream>
16
17#include <boost/date_time/posix_time/posix_time.hpp>
18#include <boost/test/unit_test.hpp>
19#include <boost/make_shared.hpp>
20
21#include "logging.h"
22
23using namespace ndn;
24using namespace std;
25using namespace boost;
26
27BOOST_AUTO_TEST_SUITE(InterestTests)
28
29static const string Interest1 ("\x01\xD2\xF2\x00\x05\x9A\x8E\x32\x00\x05\xA2\x8E\x32\x00\x05\xAA\x8E\x31\x00\x02"
30 "\xFA\x8E\x34\x00\x02\xD2\x8E\x30\x00\x03\x82\x95\xA0\x00\x00\x00",
31 36);
32
33static const string Interest2 ("\x01\xD2\xF2\x00\x05\x9A\x8E\x32\x00\x05\xA2\x8E\x32\x00\x03\x82\x95\xA0\x00\x00"
34 "\x00",
35 21);
36
37static const string Interest3 ("\x01\xD2\xF2\x00\x05\x9A\x8E\x32\x00\x05\xA2\x8E\x32\x00\x02\xDA\xFA\xA5\x61\x6C" \
38 "\x65\x78\x00\xFA\xC5\x7A\x68\x65\x6E\x6B\x61\x69\x30\x00\xEA\x00\xFA\xC5\x7A\x68" \
39 "\x65\x6E\x6B\x61\x69\x31\x00\xFA\x01\x8D\x6C\x6F\x6F\x6F\x6F\x6F\x6F\x6F\x6F\x6F" \
40 "\x6F\x6F\x6F\x6F\x6F\x6E\x67\x00\xEA\x00\x00\x05\xAA\x8E\x31\x00\x02\xFA\x8E\x34" \
41 "\x00\x02\xD2\x8E\x30\x00\x03\x82\x95\xA0\x00\x00\x00", 93);
42
43BOOST_AUTO_TEST_CASE (Basic)
44{
45 INIT_LOGGERS ();
46
47 Interest i;
48 i.setName (Name ("/test"));
49 i.setMinSuffixComponents (2);
50 i.setMaxSuffixComponents (2);
51 i.setInterestLifetime (posix_time::seconds (10));
52 i.setScope (Interest::SCOPE_LOCAL_CCND);
53 i.setAnswerOriginKind (Interest::AOK_STALE);
54 i.setChildSelector (Interest::CHILD_RIGHT);
55 // i.setPublisherPublicKeyDigest (?);
56
57 ostringstream os;
58 wire::Ccnb::appendInterest (os, i);
59 string Interest0 = os.str ();
60 BOOST_CHECK_EQUAL_COLLECTIONS (Interest0.begin (), Interest0.end (),
61 Interest1.begin (), Interest1.end ());
62
63 i.getExclude ().excludeOne (name::Component ("alex"));
64 i.getExclude ().excludeRange (name::Component ("zhenkai0"), name::Component("zhenkai1"));
65 i.getExclude ().excludeAfter (name::Component ("loooooooooooooong"));
66
67 BOOST_CHECK_EQUAL (boost::lexical_cast<string> (i.getExclude ()), "alex zhenkai0 ----> zhenkai1 loooooooooooooong ----> ");
68
69 os.str (""); os.clear ();
70 wire::Ccnb::appendInterest (os, i);
71 Interest0 = os.str ();
72 BOOST_CHECK_EQUAL_COLLECTIONS (Interest0.begin (), Interest0.end (),
73 Interest3.begin (), Interest3.end ());
74}
75
76// BOOST_AUTO_TEST_CASE (Charbuf)
77// {
78// INIT_LOGGERS ();
79
80// Interest i;
81// i.setName (Name ("/test"));
82// i.setMinSuffixComponents (2);
83// i.setMaxSuffixComponents (2);
84// i.setInterestLifetime (posix_time::seconds (10));
85
86// charbuf_stream stream;
87// wire::Ccnb::appendInterest (stream, i);
88
89// BOOST_CHECK_EQUAL_COLLECTIONS (reinterpret_cast<char*> (stream.buf ().getBuf ()->buf),
90// reinterpret_cast<char*> (stream.buf ().getBuf ()->buf+stream.buf ().getBuf ()->length),
91// Interest2.begin (), Interest2.end ());
92
93// }
94
95BOOST_AUTO_TEST_SUITE_END()