blob: 98486853fa424ebb68e834ca2c12d331203028bd [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
Yingdi Yu0b0a7362014-08-05 16:31:30 -070013namespace chronos {
14
15using std::string;
Yingdi Yufa4ce792014-02-06 18:09:22 -080016
17BOOST_AUTO_TEST_SUITE(TestProfile)
18
19BOOST_AUTO_TEST_CASE(EncodeDecodeProfile)
20{
21 Name identity("/ndn/ucla/yingdi");
22 Profile profile(identity);
23 profile["name"] = "Yingdi Yu";
24 profile["school"] = "UCLA";
25
Yingdi Yu0b0a7362014-08-05 16:31:30 -070026 ndn::OBufferStream os;
Yingdi Yufa4ce792014-02-06 18:09:22 -080027 profile.encode(os);
28
Yingdi Yu0b0a7362014-08-05 16:31:30 -070029 ndn::ConstBufferPtr encoded = os.buf();
Yingdi Yufa4ce792014-02-06 18:09:22 -080030
Yingdi Yu0b0a7362014-08-05 16:31:30 -070031 boost::iostreams::stream
32 <boost::iostreams::array_source> is(reinterpret_cast<const char*>(encoded->buf()),
33 encoded->size ());
34
35 Profile decodedProfile;
Yingdi Yufa4ce792014-02-06 18:09:22 -080036 decodedProfile.decode(is);
Yingdi Yu0b0a7362014-08-05 16:31:30 -070037
Yingdi Yufa4ce792014-02-06 18:09:22 -080038 BOOST_CHECK_EQUAL(decodedProfile.getIdentityName().toUri(), string("/ndn/ucla/yingdi"));
39 BOOST_CHECK_EQUAL(decodedProfile["name"], string("Yingdi Yu"));
40 BOOST_CHECK_EQUAL(decodedProfile["school"], string("UCLA"));
41}
42
Yingdi Yufa4ce792014-02-06 18:09:22 -080043BOOST_AUTO_TEST_SUITE_END()
Yingdi Yu0b0a7362014-08-05 16:31:30 -070044
45} // namespace chronos