author | mlarsson |
Mon, 26 Feb 2018 09:34:20 +0100 | |
changeset 49163 | 580bb0b85f63 |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
40656 | 1 |
/* |
49163
580bb0b85f63
8198554: Add fuzzy matching for log levels and tags when parsing -Xlog
mlarsson
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved. |
40656 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
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. |
|
8 |
* |
|
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). |
|
14 |
* |
|
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. |
|
18 |
* |
|
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 |
|
21 |
* questions. |
|
22 |
*/ |
|
41705
332239c052cc
8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents:
40656
diff
changeset
|
23 |
|
40656 | 24 |
#include "precompiled.hpp" |
25 |
#include "logging/logLevel.hpp" |
|
26 |
#include "unittest.hpp" |
|
27 |
||
28 |
TEST(LogLevel, from_string) { |
|
29 |
LogLevelType level; |
|
30 |
||
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); |
|
35 |
LOG_LEVEL_LIST |
|
36 |
#undef LOG_LEVEL |
|
37 |
||
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")); |
|
46 |
} |
|
47 |
||
49163
580bb0b85f63
8198554: Add fuzzy matching for log levels and tags when parsing -Xlog
mlarsson
parents:
47216
diff
changeset
|
48 |
TEST(LogLevel, fuzzy_match) { |
580bb0b85f63
8198554: Add fuzzy matching for log levels and tags when parsing -Xlog
mlarsson
parents:
47216
diff
changeset
|
49 |
for (size_t i = 1; i < LogLevel::Count; i++) { |
580bb0b85f63
8198554: Add fuzzy matching for log levels and tags when parsing -Xlog
mlarsson
parents:
47216
diff
changeset
|
50 |
LogLevelType level = static_cast<LogLevelType>(i); |
580bb0b85f63
8198554: Add fuzzy matching for log levels and tags when parsing -Xlog
mlarsson
parents:
47216
diff
changeset
|
51 |
ASSERT_EQ(level, LogLevel::fuzzy_match(LogLevel::name(level))); |
580bb0b85f63
8198554: Add fuzzy matching for log levels and tags when parsing -Xlog
mlarsson
parents:
47216
diff
changeset
|
52 |
} |
580bb0b85f63
8198554: Add fuzzy matching for log levels and tags when parsing -Xlog
mlarsson
parents:
47216
diff
changeset
|
53 |
|
580bb0b85f63
8198554: Add fuzzy matching for log levels and tags when parsing -Xlog
mlarsson
parents:
47216
diff
changeset
|
54 |
ASSERT_EQ(LogLevel::Warning, LogLevel::fuzzy_match("warn")); |
580bb0b85f63
8198554: Add fuzzy matching for log levels and tags when parsing -Xlog
mlarsson
parents:
47216
diff
changeset
|
55 |
ASSERT_EQ(LogLevel::Error, LogLevel::fuzzy_match("err")); |
580bb0b85f63
8198554: Add fuzzy matching for log levels and tags when parsing -Xlog
mlarsson
parents:
47216
diff
changeset
|
56 |
|
580bb0b85f63
8198554: Add fuzzy matching for log levels and tags when parsing -Xlog
mlarsson
parents:
47216
diff
changeset
|
57 |
ASSERT_EQ(LogLevel::Invalid, LogLevel::fuzzy_match("unknown")); |
580bb0b85f63
8198554: Add fuzzy matching for log levels and tags when parsing -Xlog
mlarsson
parents:
47216
diff
changeset
|
58 |
} |
580bb0b85f63
8198554: Add fuzzy matching for log levels and tags when parsing -Xlog
mlarsson
parents:
47216
diff
changeset
|
59 |
|
40656 | 60 |
TEST(LogLevel, name) { |
61 |
// Use names from macro as reference |
|
62 |
#define LOG_LEVEL(lname, lstring) \ |
|
63 |
EXPECT_STREQ(LogLevel::name(LogLevel::lname), #lstring); |
|
64 |
LOG_LEVEL_LIST |
|
65 |
#undef LOG_LEVEL |
|
66 |
} |