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 | |
Qiuhan Ding | 52f1383 | 2015-03-06 14:05:59 -0800 | [diff] [blame^] | 13 | namespace chronochat { |
| 14 | namespace tests { |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 15 | |
| 16 | using std::string; |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 17 | |
| 18 | BOOST_AUTO_TEST_SUITE(TestProfile) |
| 19 | |
| 20 | BOOST_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 Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 27 | ndn::OBufferStream os; |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 28 | profile.encode(os); |
| 29 | |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 30 | ndn::ConstBufferPtr encoded = os.buf(); |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 31 | |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 32 | boost::iostreams::stream |
| 33 | <boost::iostreams::array_source> is(reinterpret_cast<const char*>(encoded->buf()), |
| 34 | encoded->size ()); |
| 35 | |
| 36 | Profile decodedProfile; |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 37 | decodedProfile.decode(is); |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 38 | |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 39 | 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 Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 44 | BOOST_AUTO_TEST_SUITE_END() |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 45 | |
Qiuhan Ding | 52f1383 | 2015-03-06 14:05:59 -0800 | [diff] [blame^] | 46 | } // namespace tests |
| 47 | } // namespace chronochat |