blob: ffb9c61edf5635a83aa1873cd08d2107afb2281b [file] [log] [blame]
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
Yingdi Yuf50098d2014-02-26 14:26:29 -08002/**
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07003 * 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 Yuf50098d2014-02-26 14:26:29 -080011 */
12
Yingdi Yuf50098d2014-02-26 14:26:29 -080013#include "util/io.hpp"
14#include "security/key-chain.hpp"
15
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070016#include "boost-test.hpp"
17
Yingdi Yuf50098d2014-02-26 14:26:29 -080018namespace ndn {
19
Alexander Afanasyevd1b5c412014-03-27 15:03:51 -070020BOOST_AUTO_TEST_SUITE(UtilTestIo)
Yingdi Yuf50098d2014-02-26 14:26:29 -080021
Alexander Afanasyevd1b5c412014-03-27 15:03:51 -070022BOOST_AUTO_TEST_CASE(Basic)
Yingdi Yuf50098d2014-02-26 14:26:29 -080023{
24 KeyChainImpl<SecPublicInfoSqlite3, SecTpmFile> keychain;
25
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070026 Name identity("/TestIO/Basic");
27 identity.appendVersion();
28
Yingdi Yuf50098d2014-02-26 14:26:29 -080029 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
43BOOST_AUTO_TEST_SUITE_END()
44
45} // namespace ndn