Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 1 | /* -*- 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 Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 10 | #include "profile.h" |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 11 | |
| 12 | using namespace ndn; |
| 13 | using namespace std; |
| 14 | using namespace chronos; |
| 15 | |
| 16 | BOOST_AUTO_TEST_SUITE(TestProfile) |
| 17 | |
| 18 | BOOST_AUTO_TEST_CASE(EncodeDecodeProfile) |
| 19 | { |
| 20 | Name identity("/ndn/ucla/yingdi"); |
| 21 | Profile profile(identity); |
| 22 | profile["name"] = "Yingdi Yu"; |
| 23 | profile["school"] = "UCLA"; |
| 24 | |
| 25 | OBufferStream os; |
| 26 | profile.encode(os); |
| 27 | |
| 28 | shared_ptr<Buffer> encoded = os.buf(); |
| 29 | |
| 30 | boost::iostreams::stream |
| 31 | <boost::iostreams::array_source> is (reinterpret_cast<const char*>(encoded->buf ()), encoded->size ()); |
| 32 | |
| 33 | Profile decodedProfile; |
| 34 | decodedProfile.decode(is); |
| 35 | |
| 36 | BOOST_CHECK_EQUAL(decodedProfile.getIdentityName().toUri(), string("/ndn/ucla/yingdi")); |
| 37 | BOOST_CHECK_EQUAL(decodedProfile["name"], string("Yingdi Yu")); |
| 38 | BOOST_CHECK_EQUAL(decodedProfile["school"], string("UCLA")); |
| 39 | } |
| 40 | |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 41 | BOOST_AUTO_TEST_SUITE_END() |