Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
Yingdi Yu | f50098d | 2014-02-26 14:26:29 -0800 | [diff] [blame] | 2 | /** |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 3 | * Copyright (c) 2013-2014, Regents of the University of California. |
| 4 | * All rights reserved. |
| 5 | * |
| 6 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
| 7 | * See AUTHORS.md for complete list of ndn-cxx authors and contributors. |
| 8 | * |
| 9 | * This file licensed under New BSD License. See COPYING for detailed information about |
| 10 | * ndn-cxx library copyright, permissions, and redistribution restrictions. |
Yingdi Yu | f50098d | 2014-02-26 14:26:29 -0800 | [diff] [blame] | 11 | */ |
| 12 | |
Yingdi Yu | f50098d | 2014-02-26 14:26:29 -0800 | [diff] [blame] | 13 | #include "util/io.hpp" |
| 14 | #include "security/key-chain.hpp" |
| 15 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 16 | #include "boost-test.hpp" |
| 17 | |
Yingdi Yu | f50098d | 2014-02-26 14:26:29 -0800 | [diff] [blame] | 18 | namespace ndn { |
| 19 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 20 | BOOST_AUTO_TEST_SUITE(UtilTestIo) |
Yingdi Yu | f50098d | 2014-02-26 14:26:29 -0800 | [diff] [blame] | 21 | |
Alexander Afanasyev | d1b5c41 | 2014-03-27 15:03:51 -0700 | [diff] [blame] | 22 | BOOST_AUTO_TEST_CASE(Basic) |
Yingdi Yu | f50098d | 2014-02-26 14:26:29 -0800 | [diff] [blame] | 23 | { |
| 24 | KeyChainImpl<SecPublicInfoSqlite3, SecTpmFile> keychain; |
| 25 | |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 26 | Name identity("/TestIO/Basic"); |
| 27 | identity.appendVersion(); |
| 28 | |
Yingdi Yu | f50098d | 2014-02-26 14:26:29 -0800 | [diff] [blame] | 29 | Name certName; |
| 30 | BOOST_REQUIRE_NO_THROW(certName = keychain.createIdentity(identity)); |
| 31 | shared_ptr<IdentityCertificate> idCert; |
| 32 | BOOST_REQUIRE_NO_THROW(idCert = keychain.getCertificate(certName)); |
| 33 | |
| 34 | std::string file("/tmp/TestIO-Basic"); |
| 35 | io::save(*idCert, file); |
| 36 | shared_ptr<IdentityCertificate> readCert = io::load<IdentityCertificate>(file); |
| 37 | |
| 38 | BOOST_CHECK(static_cast<bool>(readCert)); |
| 39 | BOOST_CHECK(idCert->getName() == readCert->getName()); |
| 40 | keychain.deleteIdentity(identity); |
| 41 | } |
| 42 | |
| 43 | BOOST_AUTO_TEST_SUITE_END() |
| 44 | |
| 45 | } // namespace ndn |