Path: blob/master/test/hotspot/gtest/logging/test_logLevel.cpp
41145 views
/*1* Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223#include "precompiled.hpp"24#include "logging/logLevel.hpp"25#include "unittest.hpp"2627TEST(LogLevel, from_string) {28LogLevelType level;2930// Verify each name defined in the LOG_LEVEL_LIST31#define LOG_LEVEL(lname, lstring) \32level = LogLevel::from_string(#lstring); \33EXPECT_EQ(level, LogLevel::lname);34LOG_LEVEL_LIST35#undef LOG_LEVEL3637// Verify a few invalid level strings38EXPECT_EQ(LogLevel::Invalid, LogLevel::from_string("bad level"));39EXPECT_EQ(LogLevel::Invalid, LogLevel::from_string("debugger"));40EXPECT_EQ(LogLevel::Invalid, LogLevel::from_string("inf"));41EXPECT_EQ(LogLevel::Invalid, LogLevel::from_string("info "));42EXPECT_EQ(LogLevel::Invalid, LogLevel::from_string(" info"));43EXPECT_EQ(LogLevel::Invalid, LogLevel::from_string("=info"));44EXPECT_EQ(LogLevel::Invalid, LogLevel::from_string("infodebugwarning"));45}4647TEST(LogLevel, fuzzy_match) {48for (size_t i = 1; i < LogLevel::Count; i++) {49LogLevelType level = static_cast<LogLevelType>(i);50ASSERT_EQ(level, LogLevel::fuzzy_match(LogLevel::name(level)));51}5253ASSERT_EQ(LogLevel::Warning, LogLevel::fuzzy_match("warn"));54ASSERT_EQ(LogLevel::Error, LogLevel::fuzzy_match("err"));5556ASSERT_EQ(LogLevel::Invalid, LogLevel::fuzzy_match("unknown"));57}5859TEST(LogLevel, name) {60// Use names from macro as reference61#define LOG_LEVEL(lname, lstring) \62EXPECT_STREQ(LogLevel::name(LogLevel::lname), #lstring);63LOG_LEVEL_LIST64#undef LOG_LEVEL65}666768