blob: ad742bb589a8b6dc32c18af2767c1faff1f54b40 [file] [log] [blame]
dmcoomese062a182017-06-12 11:10:31 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
Davide Pesavento74daf742018-11-23 18:14:13 -05003 * Copyright (c) 2013-2018 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
27namespace ndn {
28namespace util {
29namespace tests {
30
31BOOST_AUTO_TEST_SUITE(Util)
32BOOST_AUTO_TEST_SUITE(TestLogger)
33
34BOOST_AUTO_TEST_CASE(LegalAlphanumeric)
35{
36 Logger logger("ndnTest123");
37 auto mNames = Logging::getLoggerNames();
38 BOOST_CHECK_EQUAL(mNames.count("ndnTest123"), 1);
39 BOOST_CHECK(logger.isLevelEnabled(LogLevel::NONE));
40 Logging::get().removeLogger(logger);
41}
42
43BOOST_AUTO_TEST_CASE(AllLegalSymbols)
44{
45 Logger logger("ndn.~#%.test_<check>1-2-3");
46 auto mNames = Logging::getLoggerNames();
47 BOOST_CHECK_EQUAL(mNames.count("ndn.~#%.test_<check>1-2-3"), 1);
48 BOOST_CHECK(logger.isLevelEnabled(LogLevel::NONE));
49 Logging::get().removeLogger(logger);
50}
51
52BOOST_AUTO_TEST_CASE(EmptyLogger)
53{
54 BOOST_CHECK_THROW(Logger logger(""), std::invalid_argument);
55}
56
57BOOST_AUTO_TEST_CASE(InvalidSymbol)
58{
59 BOOST_CHECK_THROW(Logger logger("ndn.test.*"), std::invalid_argument);
60}
61
62BOOST_AUTO_TEST_CASE(StartsWithPeriod)
63{
64 BOOST_CHECK_THROW(Logger logger(".ndn.test"), std::invalid_argument);
65}
66
67BOOST_AUTO_TEST_CASE(EndsWithPeriod)
68{
69 BOOST_CHECK_THROW(Logger logger("ndn.test."), std::invalid_argument);
70}
71
72BOOST_AUTO_TEST_CASE(ConsecutivePeriods)
73{
74 BOOST_CHECK_THROW(Logger logger("ndn..test"), std::invalid_argument);
75}
76
77BOOST_AUTO_TEST_SUITE_END() // TestLogger
78BOOST_AUTO_TEST_SUITE_END() // Util
79
80} // namespace tests
81} // namespace util
82} // namespace ndn