blob: 70ba72fdc72a744105587ab14ed2505fa804b8d1 [file] [log] [blame]
dmcoomese062a182017-06-12 11:10:31 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
Davide Pesavento47ce2ee2023-05-09 01:33:33 -04003 * Copyright (c) 2013-2023 Regents of the University of California.
dmcoomese062a182017-06-12 11:10:31 -05004 *
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
Davide Pesavento7e780642018-11-24 15:51:34 -050022#include "ndn-cxx/util/logger.hpp"
23#include "ndn-cxx/util/logging.hpp"
dmcoomese062a182017-06-12 11:10:31 -050024
Davide Pesavento7e780642018-11-24 15:51:34 -050025#include "tests/boost-test.hpp"
dmcoomese062a182017-06-12 11:10:31 -050026
Davide Pesavento47ce2ee2023-05-09 01:33:33 -040027namespace ndn::tests {
28
29using ndn::util::Logger;
30using ndn::util::Logging;
31using ndn::util::LogLevel;
dmcoomese062a182017-06-12 11:10:31 -050032
33BOOST_AUTO_TEST_SUITE(Util)
34BOOST_AUTO_TEST_SUITE(TestLogger)
35
36BOOST_AUTO_TEST_CASE(LegalAlphanumeric)
37{
38 Logger logger("ndnTest123");
39 auto mNames = Logging::getLoggerNames();
40 BOOST_CHECK_EQUAL(mNames.count("ndnTest123"), 1);
41 BOOST_CHECK(logger.isLevelEnabled(LogLevel::NONE));
42 Logging::get().removeLogger(logger);
43}
44
45BOOST_AUTO_TEST_CASE(AllLegalSymbols)
46{
47 Logger logger("ndn.~#%.test_<check>1-2-3");
48 auto mNames = Logging::getLoggerNames();
49 BOOST_CHECK_EQUAL(mNames.count("ndn.~#%.test_<check>1-2-3"), 1);
50 BOOST_CHECK(logger.isLevelEnabled(LogLevel::NONE));
51 Logging::get().removeLogger(logger);
52}
53
54BOOST_AUTO_TEST_CASE(EmptyLogger)
55{
56 BOOST_CHECK_THROW(Logger logger(""), std::invalid_argument);
57}
58
59BOOST_AUTO_TEST_CASE(InvalidSymbol)
60{
61 BOOST_CHECK_THROW(Logger logger("ndn.test.*"), std::invalid_argument);
62}
63
64BOOST_AUTO_TEST_CASE(StartsWithPeriod)
65{
66 BOOST_CHECK_THROW(Logger logger(".ndn.test"), std::invalid_argument);
67}
68
69BOOST_AUTO_TEST_CASE(EndsWithPeriod)
70{
71 BOOST_CHECK_THROW(Logger logger("ndn.test."), std::invalid_argument);
72}
73
74BOOST_AUTO_TEST_CASE(ConsecutivePeriods)
75{
76 BOOST_CHECK_THROW(Logger logger("ndn..test"), std::invalid_argument);
77}
78
79BOOST_AUTO_TEST_SUITE_END() // TestLogger
80BOOST_AUTO_TEST_SUITE_END() // Util
81
Davide Pesavento47ce2ee2023-05-09 01:33:33 -040082} // namespace ndn::tests