Yingdi Yu | a1a688f | 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 | |
| 10 | #include "profile-data.h" |
| 11 | #include <ndn-cpp-dev/security/key-chain.hpp> |
| 12 | #include <ndn-cpp-dev/util/time.hpp> |
| 13 | |
| 14 | using namespace ndn; |
| 15 | using namespace std; |
| 16 | using namespace chronos; |
| 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 | |
| 27 | OBufferStream os; |
| 28 | profile.encode(os); |
| 29 | |
| 30 | shared_ptr<Buffer> encoded = os.buf(); |
| 31 | |
| 32 | boost::iostreams::stream |
| 33 | <boost::iostreams::array_source> is (reinterpret_cast<const char*>(encoded->buf ()), encoded->size ()); |
| 34 | |
| 35 | Profile decodedProfile; |
| 36 | decodedProfile.decode(is); |
| 37 | |
| 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 | |
| 43 | BOOST_AUTO_TEST_CASE(EncodeDecodeProfileData) |
| 44 | { |
| 45 | Name identity("/ndn/ucla/yingdi"); |
| 46 | Profile profile(identity); |
| 47 | profile["name"] = "Yingdi Yu"; |
| 48 | profile["school"] = "UCLA"; |
| 49 | |
| 50 | ProfileData profileData(profile); |
| 51 | |
| 52 | KeyChainImpl<SecPublicInfoSqlite3, SecTpmFile> keyChain; |
| 53 | Name signingIdentity("/EncodeDecodeProfile/EncodeDecodeProfileData"); |
| 54 | keyChain.createIdentity(signingIdentity); |
| 55 | keyChain.signByIdentity(profileData, signingIdentity); |
| 56 | |
| 57 | Block encodedBlock = profileData.wireEncode(); |
| 58 | |
| 59 | Data decodedData; |
| 60 | decodedData.wireDecode(encodedBlock); |
| 61 | |
| 62 | ProfileData decodedProfileData(decodedData); |
| 63 | Profile decodedProfile = decodedProfileData.getProfile(); |
| 64 | |
| 65 | BOOST_CHECK_EQUAL(profileData.getIdentityName(), string("/ndn/ucla/yingdi")); |
| 66 | BOOST_CHECK_EQUAL(decodedProfile["name"], string("Yingdi Yu")); |
| 67 | BOOST_CHECK_EQUAL(decodedProfile["school"], string("UCLA")); |
| 68 | |
| 69 | keyChain.deleteIdentity(signingIdentity); |
| 70 | } |
| 71 | |
| 72 | |
| 73 | BOOST_AUTO_TEST_SUITE_END() |