/* * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions.
*/
LogMessageTest::~LogMessageTest() { // Stop logging to the files and remove them. for (int i = 0; i < LogLevel::Count; i++) {
set_log_config(_level_filename[i], "all=off");
remove(_level_filename[i]);
}
}
// Verify that messages with multiple levels are written // to outputs configured for all the corresponding levels
TEST_VM_F(LogMessageTest, level_inclusion) { const size_t message_count = 10;
LogMessageBuffer msg[message_count];
// Fill in messages with the above lines for (size_t i = 0; i < ARRAY_SIZE(lines); i++) { switch (lines[i].level) { #define LOG_LEVEL(name, printname) \ case LogLevel::name: \
msg[lines[i].message_number].printname("msg[%d]: "#printname, lines[i].message_number); \ break;
LOG_LEVEL_LIST #undef LOG_LEVEL default: break;
}
}
for (size_t i = 0; i < message_count; i++) {
_log.write(msg[i]);
}
// Verify that lines are written to the expected log files for (size_t i = 0; i < ARRAY_SIZE(lines); i++) { char expected[256];
jio_snprintf(expected, sizeof(expected), "msg[%d]: %s",
lines[i].message_number, LogLevel::name(lines[i].level)); for (int level = lines[i].level; level > 0; level--) {
EXPECT_TRUE(file_contains_substring(_level_filename[level], expected))
<< "line #" << i << " missing from log file " << _level_filename[level];
} for (int level = lines[i].level + 1; level < LogLevel::Count; level++) {
EXPECT_FALSE(file_contains_substring(_level_filename[level], expected))
<< "line #" << i << " erroneously included in log file " << _level_filename[level];
}
}
}
// Verify that messages are logged in the order they are added to the log message
TEST_VM_F(LogMessageTest, line_order) {
LogMessageBuffer msg;
msg.info("info line").error("error line").trace("trace line")
.error("another error").warning("warning line").debug("debug line");
_log.write(msg);
TEST_VM_F(LogMessageTest, prefixing) {
LogMessageBuffer msg;
msg.set_prefix(dummy_prefixer); for (int i = 0; i < 3; i++) {
msg.info("test %d", i);
}
msg.set_prefix(NULL);
msg.info("test 3");
_log.write(msg);
constchar* expected[] = { "] some prefix: test 0", "] some prefix: test 1", "] some prefix: test 2", "] test 3",
NULL
};
EXPECT_TRUE(file_contains_substrings_in_order(_level_filename[LogLevel::Trace], expected))
<< "error in prefixed output";
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.