Update pingcheck to work with cmake 3.28
[pingcheck] / test / test_loglevel.cpp
CommitLineData
7ca853fe
GMF
1/*
2The software in this package is distributed under the GNU General
3Public License version 2 (with a special exception described below).
4
5A copy of GNU General Public License (GPL) is included in this distribution,
6in the file COPYING.GPL.
7
8As a special exception, if other files instantiate templates or use macros
9or inline functions from this file, or you compile this file and link it
10with other works to produce a work based on this file, this file
11does not by itself cause the resulting work to be covered
12by the GNU General Public License.
13
14However the source code for this file must still be made available
15in accordance with section (3) of the GNU General Public License.
16
17This exception does not invalidate any other reasons why a work based
18on this file might be covered by the GNU General Public License.
19*/
20
21#define BOOST_TEST_MAIN
22#define BOOST_TEST_DYN_LINK
23
24#include <boost/test/unit_test.hpp>
25
c67aeed7
GMF
26#include <logfunc.hpp>
27
7ca853fe
GMF
28#include "host/loglevel.h"
29
f3c09c5a
GMF
30using I2n::Logger::LogLevel;
31
7ca853fe
GMF
32BOOST_AUTO_TEST_SUITE( TestLogLevel )
33
34BOOST_AUTO_TEST_CASE( lowercase )
35{
d9ce1ade
GMF
36 BOOST_CHECK_EQUAL( static_cast<int>(get_log_level_from_string( "debug" )), static_cast<int>(LogLevel::Debug) );
37 BOOST_CHECK_EQUAL( static_cast<int>(get_log_level_from_string( "info" )), static_cast<int>(LogLevel::Info) );
38 BOOST_CHECK_EQUAL( static_cast<int>(get_log_level_from_string( "notice" )), static_cast<int>(LogLevel::Notice) );
39 BOOST_CHECK_EQUAL( static_cast<int>(get_log_level_from_string( "warning" )), static_cast<int>(LogLevel::Warning) );
40 BOOST_CHECK_EQUAL( static_cast<int>(get_log_level_from_string( "error" )), static_cast<int>(LogLevel::Error) );
41 BOOST_CHECK_EQUAL( static_cast<int>(get_log_level_from_string( "critical" )), static_cast<int>(LogLevel::Critical) );
42 BOOST_CHECK_EQUAL( static_cast<int>(get_log_level_from_string( "alert" )), static_cast<int>(LogLevel::Alert) );
43 BOOST_CHECK_EQUAL( static_cast<int>(get_log_level_from_string( "emergency" )), static_cast<int>(LogLevel::Emergency) );
7ca853fe
GMF
44}
45
46BOOST_AUTO_TEST_CASE( uppercase )
47{
d9ce1ade
GMF
48 BOOST_CHECK_EQUAL( static_cast<int>(get_log_level_from_string( "DEBUG" )), static_cast<int>(LogLevel::Debug) );
49 BOOST_CHECK_EQUAL( static_cast<int>(get_log_level_from_string( "INFO" )), static_cast<int>(LogLevel::Info) );
50 BOOST_CHECK_EQUAL( static_cast<int>(get_log_level_from_string( "NOTICE" )), static_cast<int>(LogLevel::Notice) );
51 BOOST_CHECK_EQUAL( static_cast<int>(get_log_level_from_string( "WARNING" )), static_cast<int>(LogLevel::Warning) );
52 BOOST_CHECK_EQUAL( static_cast<int>(get_log_level_from_string( "ERROR" )), static_cast<int>(LogLevel::Error) );
53 BOOST_CHECK_EQUAL( static_cast<int>(get_log_level_from_string( "CRITICAL" )), static_cast<int>(LogLevel::Critical) );
54 BOOST_CHECK_EQUAL( static_cast<int>(get_log_level_from_string( "ALERT" )), static_cast<int>(LogLevel::Alert) );
55 BOOST_CHECK_EQUAL( static_cast<int>(get_log_level_from_string( "EMERGENCY" )), static_cast<int>(LogLevel::Emergency) );
7ca853fe
GMF
56}
57
58BOOST_AUTO_TEST_CASE( mixed_case )
59{
d9ce1ade
GMF
60 BOOST_CHECK_EQUAL( static_cast<int>(get_log_level_from_string( "DeBuG" )), static_cast<int>(LogLevel::Debug) );
61 BOOST_CHECK_EQUAL( static_cast<int>(get_log_level_from_string( "InfO" )), static_cast<int>(LogLevel::Info) );
62 BOOST_CHECK_EQUAL( static_cast<int>(get_log_level_from_string( "NoTicE" )), static_cast<int>(LogLevel::Notice) );
63 BOOST_CHECK_EQUAL( static_cast<int>(get_log_level_from_string( "warNing" )), static_cast<int>(LogLevel::Warning) );
64 BOOST_CHECK_EQUAL( static_cast<int>(get_log_level_from_string( "errOR" )), static_cast<int>(LogLevel::Error) );
65 BOOST_CHECK_EQUAL( static_cast<int>(get_log_level_from_string( "critiCaL" )), static_cast<int>(LogLevel::Critical) );
66 BOOST_CHECK_EQUAL( static_cast<int>(get_log_level_from_string( "aleRt" )), static_cast<int>(LogLevel::Alert) );
67 BOOST_CHECK_EQUAL( static_cast<int>(get_log_level_from_string( "EmerGENCy" )), static_cast<int>(LogLevel::Emergency) );
7ca853fe
GMF
68}
69
70BOOST_AUTO_TEST_CASE( misspelled )
71{
d9ce1ade
GMF
72 BOOST_CHECK_EQUAL( static_cast<int>(get_log_level_from_string( "when" )), static_cast<int>(LogLevel::Warning) );
73 BOOST_CHECK_EQUAL( static_cast<int>(get_log_level_from_string( "the" )), static_cast<int>(LogLevel::Warning) );
74 BOOST_CHECK_EQUAL( static_cast<int>(get_log_level_from_string( "word" )), static_cast<int>(LogLevel::Warning) );
75 BOOST_CHECK_EQUAL( static_cast<int>(get_log_level_from_string( "is" )), static_cast<int>(LogLevel::Warning) );
76 BOOST_CHECK_EQUAL( static_cast<int>(get_log_level_from_string( "wrong" )), static_cast<int>(LogLevel::Warning) );
77 BOOST_CHECK_EQUAL( static_cast<int>(get_log_level_from_string( "stick" )), static_cast<int>(LogLevel::Warning) );
78 BOOST_CHECK_EQUAL( static_cast<int>(get_log_level_from_string( "to" )), static_cast<int>(LogLevel::Warning) );
79 BOOST_CHECK_EQUAL( static_cast<int>(get_log_level_from_string( "WARNING" )), static_cast<int>(LogLevel::Warning) );
7ca853fe
GMF
80}
81
82BOOST_AUTO_TEST_SUITE_END()