Commit 18964f93 authored by Stephen Morris's avatar Stephen Morris
Browse files

[trac438] Extended logging API tests

Added an explicit test for logging up a non-existent or invalid
symbol in the dictionary.  Also added a test to ensure that multiple
MessageInitializer objects will all contribute their messages to
the global dictionary.
parent f70d352d
......@@ -20,6 +20,7 @@ run_unittests_SOURCES += logger_unittest.cc
run_unittests_SOURCES += message_dictionary_unittest.cc
run_unittests_SOURCES += message_reader_unittest.cc
run_unittests_SOURCES += message_initializer_unittest.cc
run_unittests_SOURCES += message_initializer_unittest_2.cc
run_unittests_SOURCES += strutil_unittest.cc
run_unittests_SOURCES += xdebuglevel_unittest.cc
run_unittests_SOURCES += run_unittests.cc
......
......@@ -145,3 +145,29 @@ TEST_F(MessageDictionaryTest, LoadTest) {
EXPECT_EQ(string(""), dictionary2.getText(data2[4]));
EXPECT_EQ(0, duplicates.size());
}
// Check for some non-existent items
TEST_F(MessageDictionaryTest, Lookups) {
static const char* data[] = {
"ALPHA", "This is alpha",
"BETA", "This is beta",
"GAMMA", "This is gamma",
NULL
};
MessageDictionary dictionary;
vector<MessageID> duplicates = dictionary.load(data);
EXPECT_EQ(3, dictionary.size());
EXPECT_EQ(0, duplicates.size());
// Valid lookups
EXPECT_EQ(string("This is alpha"), dictionary.getText("ALPHA"));
EXPECT_EQ(string("This is beta"), dictionary.getText("BETA"));
EXPECT_EQ(string("This is gamma"), dictionary.getText("GAMMA"));
// ... and invalid ones
EXPECT_EQ(string(""), dictionary.getText("XYZZY"));
EXPECT_EQ(string(""), dictionary.getText(""));
EXPECT_EQ(string(""), dictionary.getText("\n\n\n"));
}
......@@ -27,16 +27,26 @@ using namespace std;
// Declare a set of messages to go into the global dictionary.
namespace {
const char* values[] = {
const char* values1[] = {
"GLOBAL1", "global message one",
"GLOBAL2", "global message two",
NULL
};
const char* values2[] = {
"GLOBAL3", "global message three",
"GLOBAL4", "global message four",
NULL
};
}
// Statically initialize the global dictionary with those messages.
MessageInitializer init_message_initializer_unittest(values);
// Statically initialize the global dictionary with those messages. Three sets
// are used to check that the declaration of separate initializer objects really// does combine the messages. (The third set is declared in the separately-
// compiled file message_identifier_initializer_unittest_2.cc.)
MessageInitializer init_message_initializer_unittest_1(values1);
MessageInitializer init_message_initializer_unittest_2(values2);
class MessageInitializerTest : public ::testing::Test {
......@@ -55,5 +65,8 @@ TEST_F(MessageInitializerTest, MessageTest) {
EXPECT_EQ(string("global message one"), global->getText("GLOBAL1"));
EXPECT_EQ(string("global message two"), global->getText("GLOBAL2"));
EXPECT_EQ(string(""), global->getText(""));
EXPECT_EQ(string("global message three"), global->getText("GLOBAL3"));
EXPECT_EQ(string("global message four"), global->getText("GLOBAL4"));
EXPECT_EQ(string("global message five"), global->getText("GLOBAL5"));
EXPECT_EQ(string("global message six"), global->getText("GLOBAL6"));
}
// Copyright (C) 2010 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
// $Id: base64_unittest.cc 2549 2010-07-20 19:09:37Z jinmei $
// The sole purpose of this file is to provide a set of message definitions
// in a separate compilation unit from the one in which their presence is
// checked. This tests that merely declaring the MessageInitializer object
// is enough to include the definitions in the global dictionary.
#include <log/message_initializer.h>
using namespace isc::log;
// Declare a set of messages to go into the global dictionary.
namespace {
const char* values3[] = {
"GLOBAL5", "global message five",
"GLOBAL6", "global message six",
NULL
};
}
// Statically initialize the global dictionary with those messages.
// Three sets are used to check that the declaration of separate
// initializer objects really does combine the messages.
MessageInitializer init_message_initializer_unittest_3(values3);
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment