blob: bb976a066a1a01e0dcef600015aa88f811d7635a [file] [log] [blame]
shockjianga5ae48c2014-07-27 23:21:41 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014, Regents of the University of California.
4 *
5 * This file is part of NDNS (Named Data Networking Domain Name Service).
6 * See AUTHORS.md for complete list of NDNS authors and contributors.
7 *
8 * NDNS is free software: you can redistribute it and/or modify it under the terms
9 * of the GNU General Public License as published by the Free Software Foundation,
10 * either version 3 of the License, or (at your option) any later version.
11 *
12 * NDNS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * NDNS, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include "response.hpp"
21#include "rr.hpp"
22#include "query.hpp"
23#include "rr.hpp"
24
25#include "boost-test.hpp"
26#include <string>
27
28
29namespace ndn {
30namespace ndns {
31namespace tests {
32
33
34using namespace std;
35
36BOOST_AUTO_TEST_SUITE(response)
37
38BOOST_AUTO_TEST_CASE(Encode)
39{
40
41 printbegin("response:Encode");
42
43 Response re, re2;
44 cout<<"construct a Response Instance"<<endl;
45 vector<RR> vec;
46
47 RR rr;
48 std::string ex3 = "www3.ex.com";
49 uint32_t id = 203;
50 rr.setRrdata(ex3);
51 rr.setId(id);
52 vec.push_back(rr);
53
54
55 RR rr2;
56 std::string ex4 = "www4.ex.com";
57 id = 204;
58 rr2.setRrdata(ex4);
59 rr2.setId(id);
60 vec.push_back(rr2);
61
62 ndns::Query q;
63 Name n1("/dns.google.com");
64 Name n2("/www.baidu.com");
65 q.setAuthorityZone(n1);
66 q.setRrLabel(n2);
67 q.setQueryType(ndns::Query::QUERY_DNS_R);
68 Interest interest = q.toInterest();
69 Name n3(q.toInterest().getName());
70 n3.appendNumber((uint64_t)1313344);
71
72 re.setQueryName(n3);
73 re.setFreshness(time::milliseconds(4444));
74 re.setRrs(vec);
75
76
77
78 cout<<"before encode"<<endl;
79 //ndn::Block block = re.wireEncode();
80 //re.wireEncode();
81 Data data = re.toData();
82 cout<<re.toData()<<endl;
83
84 cout<<"Encode finishes"<<endl;
85
86
87 re2.fromData(n2, data);
88 BOOST_CHECK_EQUAL(re.getQueryName(), re2.getQueryName());
89 BOOST_CHECK_EQUAL(re.getContentType(), re2.getContentType());
90 BOOST_CHECK_EQUAL(re.getResponseType(), re2.getResponseType());
91 BOOST_CHECK_EQUAL(re.getRrs().size(), re2.getRrs().size());
92 BOOST_CHECK_EQUAL(re.getRrs()[0], re2.getRrs()[0]);
93 BOOST_CHECK_EQUAL(re.getRrs()[1], re2.getRrs()[1]);
94
95
96 printend("response:Encode");
97}
98
99BOOST_AUTO_TEST_SUITE_END()
100
101
102} // namespace tests
103} // namespace ndns
104} // namespace ndn