blob: 38f3ca14943f62c1fc984fbb153d122da190f85a [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{
Yingdi Yuf56c68f2014-04-24 21:50:13 -070024 BOOST_REQUIRE_NO_THROW(KeyChain("sqlite3", "file"));
25 KeyChain keyChain("sqlite3", "file");
Yingdi Yuf50098d2014-02-26 14:26:29 -080026
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070027 Name identity("/TestIO/Basic");
28 identity.appendVersion();
29
Yingdi Yuf50098d2014-02-26 14:26:29 -080030 Name certName;
Yingdi Yuf56c68f2014-04-24 21:50:13 -070031 BOOST_REQUIRE_NO_THROW(certName = keyChain.createIdentity(identity));
Yingdi Yuf50098d2014-02-26 14:26:29 -080032 shared_ptr<IdentityCertificate> idCert;
Yingdi Yuf56c68f2014-04-24 21:50:13 -070033 BOOST_REQUIRE_NO_THROW(idCert = keyChain.getCertificate(certName));
Yingdi Yuf50098d2014-02-26 14:26:29 -080034
35 std::string file("/tmp/TestIO-Basic");
36 io::save(*idCert, file);
37 shared_ptr<IdentityCertificate> readCert = io::load<IdentityCertificate>(file);
38
39 BOOST_CHECK(static_cast<bool>(readCert));
40 BOOST_CHECK(idCert->getName() == readCert->getName());
Yingdi Yuf56c68f2014-04-24 21:50:13 -070041 keyChain.deleteIdentity(identity);
Yingdi Yuf50098d2014-02-26 14:26:29 -080042}
43
44BOOST_AUTO_TEST_SUITE_END()
45
46} // namespace ndn