Yingdi Yu | f50098d | 2014-02-26 14:26:29 -0800 | [diff] [blame] | 1 | /** |
| 2 | * Copyright (C) 2013 Regents of the University of California. |
| 3 | * See COPYING for copyright and distribution information. |
| 4 | */ |
| 5 | |
Yingdi Yu | f50098d | 2014-02-26 14:26:29 -0800 | [diff] [blame] | 6 | #include "util/io.hpp" |
| 7 | #include "security/key-chain.hpp" |
| 8 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 9 | #include "boost-test.hpp" |
| 10 | |
Yingdi Yu | f50098d | 2014-02-26 14:26:29 -0800 | [diff] [blame] | 11 | namespace ndn { |
| 12 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 13 | BOOST_AUTO_TEST_SUITE(UtilTestIo) |
Yingdi Yu | f50098d | 2014-02-26 14:26:29 -0800 | [diff] [blame] | 14 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 15 | BOOST_AUTO_TEST_CASE(Basic) |
Yingdi Yu | f50098d | 2014-02-26 14:26:29 -0800 | [diff] [blame] | 16 | { |
| 17 | KeyChainImpl<SecPublicInfoSqlite3, SecTpmFile> keychain; |
| 18 | |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 19 | Name identity("/TestIO/Basic"); |
| 20 | identity.appendVersion(); |
| 21 | |
Yingdi Yu | f50098d | 2014-02-26 14:26:29 -0800 | [diff] [blame] | 22 | Name certName; |
| 23 | BOOST_REQUIRE_NO_THROW(certName = keychain.createIdentity(identity)); |
| 24 | shared_ptr<IdentityCertificate> idCert; |
| 25 | BOOST_REQUIRE_NO_THROW(idCert = keychain.getCertificate(certName)); |
| 26 | |
| 27 | std::string file("/tmp/TestIO-Basic"); |
| 28 | io::save(*idCert, file); |
| 29 | shared_ptr<IdentityCertificate> readCert = io::load<IdentityCertificate>(file); |
| 30 | |
| 31 | BOOST_CHECK(static_cast<bool>(readCert)); |
| 32 | BOOST_CHECK(idCert->getName() == readCert->getName()); |
| 33 | keychain.deleteIdentity(identity); |
| 34 | } |
| 35 | |
| 36 | BOOST_AUTO_TEST_SUITE_END() |
| 37 | |
| 38 | } // namespace ndn |