blob: bc05ca9f8c8808c2f8e8089630b96b8e1aa3cbdf [file] [log] [blame]
Yingdi Yub8f8b342015-04-27 11:06:42 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2013-2015 Regents of the University of California.
4 *
5 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
6 *
7 * 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.
20 */
21
22#include "security/pib.hpp"
Yingdi Yu3bf91f52015-06-12 19:39:40 -070023#include "security/pib-memory.hpp"
Yingdi Yub8f8b342015-04-27 11:06:42 -070024#include "pib-data-fixture.hpp"
25
26#include "boost-test.hpp"
27
28namespace ndn {
29namespace security {
30namespace tests {
31
32BOOST_AUTO_TEST_SUITE(SecurityPib)
33
34BOOST_FIXTURE_TEST_CASE(ValidityChecking, PibDataFixture)
35{
Yingdi Yu3bf91f52015-06-12 19:39:40 -070036 auto pibImpl = make_shared<PibMemory>();
Yingdi Yub8f8b342015-04-27 11:06:42 -070037 Pib pib("pib-memory", "", pibImpl);
38
39 Identity id = pib.addIdentity(id1);
40
41 BOOST_CHECK_EQUAL(bool(id), true);
42 BOOST_CHECK_EQUAL(!id, false);
43
44 if (id)
45 BOOST_CHECK(true);
46 else
47 BOOST_CHECK(false);
48
49 // key
50 Key key = id.addKey(id1Key1, id1Key1Name.get(-1));
51
52 BOOST_CHECK_EQUAL(bool(key), true);
53 BOOST_CHECK_EQUAL(!key, false);
54
55 if (key)
56 BOOST_CHECK(true);
57 else
58 BOOST_CHECK(false);
59}
60
61BOOST_FIXTURE_TEST_CASE(TestIdentityOperation, PibDataFixture)
62{
Yingdi Yu3bf91f52015-06-12 19:39:40 -070063 auto pibImpl = make_shared<PibMemory>();
Yingdi Yub8f8b342015-04-27 11:06:42 -070064 Pib pib("pib-memory", "", pibImpl);
65
66 BOOST_CHECK_THROW(pib.getIdentity(id1), Pib::Error);
67 Identity identity1 = pib.addIdentity(id1);
68 BOOST_CHECK_NO_THROW(pib.getIdentity(id1));
69 pib.removeIdentity(id1);
70 BOOST_CHECK_THROW(pib.getIdentity(id1), Pib::Error);
71
72 BOOST_CHECK_THROW(pib.getDefaultIdentity(), Pib::Error);
73 BOOST_REQUIRE_NO_THROW(pib.setDefaultIdentity(id1));
74 BOOST_REQUIRE_NO_THROW(pib.getDefaultIdentity());
75 BOOST_CHECK_EQUAL(pib.getDefaultIdentity().getName(), id1);
76 pib.removeIdentity(id1);
77 BOOST_CHECK_THROW(pib.getIdentity(id1), Pib::Error);
78 BOOST_CHECK_THROW(pib.getDefaultIdentity(), Pib::Error);
79}
80
81BOOST_AUTO_TEST_SUITE_END()
82
83} // namespace tests
84} // namespace security
85} // namespace ndn