blob: 1b369b8c326b87c39b26319f8f428dc88149c7c2 [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 Afanasyevc169a812014-05-20 20:37:29 -04003 * Copyright (c) 2013-2014 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"
24
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070025#include "boost-test.hpp"
26
Yingdi Yuf50098d2014-02-26 14:26:29 -080027namespace ndn {
28
Alexander Afanasyevd1b5c412014-03-27 15:03:51 -070029BOOST_AUTO_TEST_SUITE(UtilTestIo)
Yingdi Yuf50098d2014-02-26 14:26:29 -080030
Alexander Afanasyevd1b5c412014-03-27 15:03:51 -070031BOOST_AUTO_TEST_CASE(Basic)
Yingdi Yuf50098d2014-02-26 14:26:29 -080032{
Yingdi Yuf56c68f2014-04-24 21:50:13 -070033 BOOST_REQUIRE_NO_THROW(KeyChain("sqlite3", "file"));
34 KeyChain keyChain("sqlite3", "file");
Yingdi Yuf50098d2014-02-26 14:26:29 -080035
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070036 Name identity("/TestIO/Basic");
37 identity.appendVersion();
38
Yingdi Yuf50098d2014-02-26 14:26:29 -080039 Name certName;
Yingdi Yuf56c68f2014-04-24 21:50:13 -070040 BOOST_REQUIRE_NO_THROW(certName = keyChain.createIdentity(identity));
Yingdi Yuf50098d2014-02-26 14:26:29 -080041 shared_ptr<IdentityCertificate> idCert;
Yingdi Yuf56c68f2014-04-24 21:50:13 -070042 BOOST_REQUIRE_NO_THROW(idCert = keyChain.getCertificate(certName));
Yingdi Yuf50098d2014-02-26 14:26:29 -080043
44 std::string file("/tmp/TestIO-Basic");
45 io::save(*idCert, file);
46 shared_ptr<IdentityCertificate> readCert = io::load<IdentityCertificate>(file);
47
48 BOOST_CHECK(static_cast<bool>(readCert));
49 BOOST_CHECK(idCert->getName() == readCert->getName());
Yingdi Yuf56c68f2014-04-24 21:50:13 -070050 keyChain.deleteIdentity(identity);
Yingdi Yuf50098d2014-02-26 14:26:29 -080051}
52
53BOOST_AUTO_TEST_SUITE_END()
54
55} // namespace ndn