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 | |
| 6 | #include <boost/test/unit_test.hpp> |
| 7 | |
| 8 | #include "util/io.hpp" |
| 9 | #include "security/key-chain.hpp" |
| 10 | |
| 11 | namespace ndn { |
| 12 | |
| 13 | BOOST_AUTO_TEST_SUITE(TestIO) |
| 14 | |
| 15 | BOOST_AUTO_TEST_CASE (Basic) |
| 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 |