2
* Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
24
#include "precompiled.hpp"
25
#include "logging/logLevel.hpp"
26
#include "unittest.hpp"
28
TEST(LogLevel, from_string) {
31
// Verify each name defined in the LOG_LEVEL_LIST
32
#define LOG_LEVEL(lname, lstring) \
33
level = LogLevel::from_string(#lstring); \
34
EXPECT_EQ(level, LogLevel::lname);
38
// Verify a few invalid level strings
39
EXPECT_EQ(LogLevel::Invalid, LogLevel::from_string("bad level"));
40
EXPECT_EQ(LogLevel::Invalid, LogLevel::from_string("debugger"));
41
EXPECT_EQ(LogLevel::Invalid, LogLevel::from_string("inf"));
42
EXPECT_EQ(LogLevel::Invalid, LogLevel::from_string("info "));
43
EXPECT_EQ(LogLevel::Invalid, LogLevel::from_string(" info"));
44
EXPECT_EQ(LogLevel::Invalid, LogLevel::from_string("=info"));
45
EXPECT_EQ(LogLevel::Invalid, LogLevel::from_string("infodebugwarning"));
48
TEST(LogLevel, fuzzy_match) {
49
for (size_t i = 1; i < LogLevel::Count; i++) {
50
LogLevelType level = static_cast<LogLevelType>(i);
51
ASSERT_EQ(level, LogLevel::fuzzy_match(LogLevel::name(level)));
54
ASSERT_EQ(LogLevel::Warning, LogLevel::fuzzy_match("warn"));
55
ASSERT_EQ(LogLevel::Error, LogLevel::fuzzy_match("err"));
57
ASSERT_EQ(LogLevel::Invalid, LogLevel::fuzzy_match("unknown"));
61
// Use names from macro as reference
62
#define LOG_LEVEL(lname, lstring) \
63
EXPECT_STREQ(LogLevel::name(LogLevel::lname), #lstring);