blob: 0ba1342600dbf74bdb977403c8e8ffb72517fb85 [file] [log] [blame]
Yingdi Yuf50098d2014-02-26 14:26:29 -08001/**
2 * Copyright (C) 2013 Regents of the University of California.
3 * See COPYING for copyright and distribution information.
4 */
5
Yingdi Yuf50098d2014-02-26 14:26:29 -08006#include "util/io.hpp"
7#include "security/key-chain.hpp"
8
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -07009#include "boost-test.hpp"
10
Yingdi Yuf50098d2014-02-26 14:26:29 -080011namespace ndn {
12
Alexander Afanasyevd1b5c412014-03-27 15:03:51 -070013BOOST_AUTO_TEST_SUITE(UtilTestIo)
Yingdi Yuf50098d2014-02-26 14:26:29 -080014
Alexander Afanasyevd1b5c412014-03-27 15:03:51 -070015BOOST_AUTO_TEST_CASE(Basic)
Yingdi Yuf50098d2014-02-26 14:26:29 -080016{
17 KeyChainImpl<SecPublicInfoSqlite3, SecTpmFile> keychain;
18
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070019 Name identity("/TestIO/Basic");
20 identity.appendVersion();
21
Yingdi Yuf50098d2014-02-26 14:26:29 -080022 Name certName;
23 BOOST_REQUIRE_NO_THROW(certName = keychain.createIdentity(identity));
24 shared_ptr<IdentityCertificate> idCert;
25 BOOST_REQUIRE_NO_THROW(idCert = keychain.getCertificate(certName));
26
27 std::string file("/tmp/TestIO-Basic");
28 io::save(*idCert, file);
29 shared_ptr<IdentityCertificate> readCert = io::load<IdentityCertificate>(file);
30
31 BOOST_CHECK(static_cast<bool>(readCert));
32 BOOST_CHECK(idCert->getName() == readCert->getName());
33 keychain.deleteIdentity(identity);
34}
35
36BOOST_AUTO_TEST_SUITE_END()
37
38} // namespace ndn