blob: 1db3aac8fa20f29022071102385566ce79e1ce80 [file] [log] [blame]
Alexander Afanasyev7e721412017-01-11 13:36:08 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesavento74daf742018-11-23 18:14:13 -05002/*
3 * Copyright (c) 2013-2018 Regents of the University of California.
Alexander Afanasyev7e721412017-01-11 13:36:08 -08004 *
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/v2/validation-error.hpp"
23
24#include "boost-test.hpp"
25#include <boost/lexical_cast.hpp>
26
27namespace ndn {
28namespace security {
29namespace v2 {
30namespace tests {
31
32BOOST_AUTO_TEST_SUITE(Security)
33BOOST_AUTO_TEST_SUITE(V2)
34BOOST_AUTO_TEST_SUITE(TestValidationError)
35
36BOOST_AUTO_TEST_CASE(Basic)
37{
38 ValidationError e1{ValidationError::Code::INVALID_SIGNATURE};
39 BOOST_CHECK_EQUAL(e1.getCode(), 1);
40 BOOST_CHECK_EQUAL(e1.getInfo(), "");
41 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(e1), "Invalid signature");
42
43 ValidationError e2{ValidationError::Code::NO_SIGNATURE, "message"};
44 BOOST_CHECK_EQUAL(e2.getCode(), 2);
45 BOOST_CHECK_EQUAL(e2.getInfo(), "message");
46 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(e2), "Missing signature (message)");
47
48 ValidationError e3{65535, "other message"};
49 BOOST_CHECK_EQUAL(e3.getCode(), 65535);
50 BOOST_CHECK_EQUAL(e3.getInfo(), "other message");
51 BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(e3), "Custom error code 65535 (other message)");
52}
53
54BOOST_AUTO_TEST_SUITE_END() // TestValidationError
55BOOST_AUTO_TEST_SUITE_END() // V2
56BOOST_AUTO_TEST_SUITE_END() // Security
57
58} // namespace tests
59} // namespace v2
60} // namespace security
61} // namespace ndn