blob: c003c7055d82550a7bc3e9b5ccfeeae20aa3e24b [file] [log] [blame]
Yingdi Yufa4ce792014-02-06 18:09:22 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/**
3 * Copyright (C) 2013 Regents of the University of California.
4 * @author: Yingdi Yu <yingdi@cs.ucla.edu>
5 * See COPYING for copyright and distribution information.
6 */
7
8#include <boost/test/unit_test.hpp>
9
Yingdi Yu0b0a7362014-08-05 16:31:30 -070010#include "profile.hpp"
11#include <ndn-cxx/encoding/buffer-stream.hpp>
Yingdi Yufa4ce792014-02-06 18:09:22 -080012
Qiuhan Ding52f13832015-03-06 14:05:59 -080013namespace chronochat {
14namespace tests {
Yingdi Yu0b0a7362014-08-05 16:31:30 -070015
16using std::string;
Yingdi Yufa4ce792014-02-06 18:09:22 -080017
18BOOST_AUTO_TEST_SUITE(TestProfile)
19
20BOOST_AUTO_TEST_CASE(EncodeDecodeProfile)
21{
22 Name identity("/ndn/ucla/yingdi");
23 Profile profile(identity);
24 profile["name"] = "Yingdi Yu";
25 profile["school"] = "UCLA";
26
Yingdi Yu0b0a7362014-08-05 16:31:30 -070027 ndn::OBufferStream os;
Yingdi Yufa4ce792014-02-06 18:09:22 -080028 profile.encode(os);
29
Yingdi Yu0b0a7362014-08-05 16:31:30 -070030 ndn::ConstBufferPtr encoded = os.buf();
Yingdi Yufa4ce792014-02-06 18:09:22 -080031
Yingdi Yu0b0a7362014-08-05 16:31:30 -070032 boost::iostreams::stream
33 <boost::iostreams::array_source> is(reinterpret_cast<const char*>(encoded->buf()),
34 encoded->size ());
35
36 Profile decodedProfile;
Yingdi Yufa4ce792014-02-06 18:09:22 -080037 decodedProfile.decode(is);
Yingdi Yu0b0a7362014-08-05 16:31:30 -070038
Yingdi Yufa4ce792014-02-06 18:09:22 -080039 BOOST_CHECK_EQUAL(decodedProfile.getIdentityName().toUri(), string("/ndn/ucla/yingdi"));
40 BOOST_CHECK_EQUAL(decodedProfile["name"], string("Yingdi Yu"));
41 BOOST_CHECK_EQUAL(decodedProfile["school"], string("UCLA"));
42}
43
Yingdi Yufa4ce792014-02-06 18:09:22 -080044BOOST_AUTO_TEST_SUITE_END()
Yingdi Yu0b0a7362014-08-05 16:31:30 -070045
Qiuhan Ding52f13832015-03-06 14:05:59 -080046} // namespace tests
47} // namespace chronochat