blob: d69123e96eba1b58aba3940a25043e2342965de7 [file] [log] [blame]
Alexander Afanasyevc169a812014-05-20 20:37:29 -04001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Yingdi Yuf50098d2014-02-26 14:26:29 -08002/**
Alexander Afanasyevaf99f462015-01-19 21:43:09 -08003 * Copyright (c) 2013-2015 Regents of the University of California.
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07004 *
5 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07006 *
Alexander Afanasyevc169a812014-05-20 20:37:29 -04007 * ndn-cxx library is free software: you can redistribute it and/or modify it under the
8 * terms of the GNU Lesser General Public License as published by the Free Software
9 * Foundation, either version 3 of the License, or (at your option) any later version.
10 *
11 * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14 *
15 * You should have received copies of the GNU General Public License and GNU Lesser
16 * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17 * <http://www.gnu.org/licenses/>.
18 *
19 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
Yingdi Yuf50098d2014-02-26 14:26:29 -080020 */
21
Yingdi Yuf50098d2014-02-26 14:26:29 -080022#include "util/io.hpp"
23#include "security/key-chain.hpp"
Yingdi Yu41546342014-11-30 23:37:53 -080024#include "identity-management-fixture.hpp"
Yingdi Yuf50098d2014-02-26 14:26:29 -080025
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070026#include "boost-test.hpp"
27
Yingdi Yuf50098d2014-02-26 14:26:29 -080028namespace ndn {
Spyridon Mastorakis429634f2015-02-19 17:35:33 -080029namespace tests {
Yingdi Yuf50098d2014-02-26 14:26:29 -080030
Spyridon Mastorakis429634f2015-02-19 17:35:33 -080031BOOST_FIXTURE_TEST_SUITE(UtilIo, security::IdentityManagementFixture)
Yingdi Yuf50098d2014-02-26 14:26:29 -080032
Alexander Afanasyevd1b5c412014-03-27 15:03:51 -070033BOOST_AUTO_TEST_CASE(Basic)
Yingdi Yuf50098d2014-02-26 14:26:29 -080034{
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070035 Name identity("/TestIO/Basic");
36 identity.appendVersion();
Yingdi Yu3ed09d02014-10-13 16:24:08 -070037 BOOST_REQUIRE(addIdentity(identity, RsaKeyParams()));
38 Name certName = m_keyChain.getDefaultCertificateNameForIdentity(identity);
Yingdi Yuf50098d2014-02-26 14:26:29 -080039 shared_ptr<IdentityCertificate> idCert;
Yingdi Yu3ed09d02014-10-13 16:24:08 -070040 BOOST_REQUIRE_NO_THROW(idCert = m_keyChain.getCertificate(certName));
Yingdi Yuf50098d2014-02-26 14:26:29 -080041
42 std::string file("/tmp/TestIO-Basic");
43 io::save(*idCert, file);
44 shared_ptr<IdentityCertificate> readCert = io::load<IdentityCertificate>(file);
45
46 BOOST_CHECK(static_cast<bool>(readCert));
47 BOOST_CHECK(idCert->getName() == readCert->getName());
Yingdi Yuf50098d2014-02-26 14:26:29 -080048}
49
50BOOST_AUTO_TEST_SUITE_END()
51
Spyridon Mastorakis429634f2015-02-19 17:35:33 -080052} // namespace tests
Yingdi Yuf50098d2014-02-26 14:26:29 -080053} // namespace ndn