dmcoomes | e062a18 | 2017-06-12 11:10:31 -0500 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /* |
Davide Pesavento | 74daf74 | 2018-11-23 18:14:13 -0500 | [diff] [blame] | 3 | * Copyright (c) 2013-2018 Regents of the University of California. |
dmcoomes | e062a18 | 2017-06-12 11:10:31 -0500 | [diff] [blame] | 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 "util/logger.hpp" |
| 23 | #include "util/logging.hpp" |
| 24 | |
| 25 | #include "boost-test.hpp" |
| 26 | |
| 27 | namespace ndn { |
| 28 | namespace util { |
| 29 | namespace tests { |
| 30 | |
| 31 | BOOST_AUTO_TEST_SUITE(Util) |
| 32 | BOOST_AUTO_TEST_SUITE(TestLogger) |
| 33 | |
| 34 | BOOST_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 | |
| 43 | BOOST_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 | |
| 52 | BOOST_AUTO_TEST_CASE(EmptyLogger) |
| 53 | { |
| 54 | BOOST_CHECK_THROW(Logger logger(""), std::invalid_argument); |
| 55 | } |
| 56 | |
| 57 | BOOST_AUTO_TEST_CASE(InvalidSymbol) |
| 58 | { |
| 59 | BOOST_CHECK_THROW(Logger logger("ndn.test.*"), std::invalid_argument); |
| 60 | } |
| 61 | |
| 62 | BOOST_AUTO_TEST_CASE(StartsWithPeriod) |
| 63 | { |
| 64 | BOOST_CHECK_THROW(Logger logger(".ndn.test"), std::invalid_argument); |
| 65 | } |
| 66 | |
| 67 | BOOST_AUTO_TEST_CASE(EndsWithPeriod) |
| 68 | { |
| 69 | BOOST_CHECK_THROW(Logger logger("ndn.test."), std::invalid_argument); |
| 70 | } |
| 71 | |
| 72 | BOOST_AUTO_TEST_CASE(ConsecutivePeriods) |
| 73 | { |
| 74 | BOOST_CHECK_THROW(Logger logger("ndn..test"), std::invalid_argument); |
| 75 | } |
| 76 | |
| 77 | BOOST_AUTO_TEST_SUITE_END() // TestLogger |
| 78 | BOOST_AUTO_TEST_SUITE_END() // Util |
| 79 | |
| 80 | } // namespace tests |
| 81 | } // namespace util |
| 82 | } // namespace ndn |