jdk

Форк
0
/
test_logLevel.cpp 
66 строк · 2.4 Кб
1
/*
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.
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
 */
23

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

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)));
52
  }
53

54
  ASSERT_EQ(LogLevel::Warning, LogLevel::fuzzy_match("warn"));
55
  ASSERT_EQ(LogLevel::Error, LogLevel::fuzzy_match("err"));
56

57
  ASSERT_EQ(LogLevel::Invalid, LogLevel::fuzzy_match("unknown"));
58
}
59

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
}
67

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.