blob: 0a3e422dcdcc40a19609dc2f6e9ea43823c15195 [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 {
29
Yingdi Yu3ed09d02014-10-13 16:24:08 -070030BOOST_FIXTURE_TEST_SUITE(UtilTestIo, security::IdentityManagementFixture)
Yingdi Yuf50098d2014-02-26 14:26:29 -080031
Alexander Afanasyevd1b5c412014-03-27 15:03:51 -070032BOOST_AUTO_TEST_CASE(Basic)
Yingdi Yuf50098d2014-02-26 14:26:29 -080033{
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070034 Name identity("/TestIO/Basic");
35 identity.appendVersion();
Yingdi Yu3ed09d02014-10-13 16:24:08 -070036 BOOST_REQUIRE(addIdentity(identity, RsaKeyParams()));
37 Name certName = m_keyChain.getDefaultCertificateNameForIdentity(identity);
Yingdi Yuf50098d2014-02-26 14:26:29 -080038 shared_ptr<IdentityCertificate> idCert;
Yingdi Yu3ed09d02014-10-13 16:24:08 -070039 BOOST_REQUIRE_NO_THROW(idCert = m_keyChain.getCertificate(certName));
Yingdi Yuf50098d2014-02-26 14:26:29 -080040
41 std::string file("/tmp/TestIO-Basic");
42 io::save(*idCert, file);
43 shared_ptr<IdentityCertificate> readCert = io::load<IdentityCertificate>(file);
44
45 BOOST_CHECK(static_cast<bool>(readCert));
46 BOOST_CHECK(idCert->getName() == readCert->getName());
Yingdi Yuf50098d2014-02-26 14:26:29 -080047}
48
49BOOST_AUTO_TEST_SUITE_END()
50
51} // namespace ndn