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 | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 10 | #include "profile.hpp" |
| 11 | #include <ndn-cxx/encoding/buffer-stream.hpp> |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 12 | |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 13 | namespace chronos { |
| 14 | |
| 15 | using std::string; |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 16 | |
| 17 | BOOST_AUTO_TEST_SUITE(TestProfile) |
| 18 | |
| 19 | BOOST_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 Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 26 | ndn::OBufferStream os; |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 27 | profile.encode(os); |
| 28 | |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 29 | ndn::ConstBufferPtr encoded = os.buf(); |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 30 | |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 31 | boost::iostreams::stream |
| 32 | <boost::iostreams::array_source> is(reinterpret_cast<const char*>(encoded->buf()), |
| 33 | encoded->size ()); |
| 34 | |
| 35 | Profile decodedProfile; |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 36 | decodedProfile.decode(is); |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 37 | |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 38 | 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 Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 43 | BOOST_AUTO_TEST_SUITE_END() |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 44 | |
| 45 | } // namespace chronos |