daemon_unittest.cc 2.83 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
// Copyright (C) 2014 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.

#include <config.h>
#include <exceptions/exceptions.h>
#include <dhcpsrv/daemon.h>
18 19
#include <dhcpsrv/logging.h>
#include <cc/data.h>
20 21 22 23
#include <gtest/gtest.h>

using namespace isc;
using namespace isc::dhcp;
24
using namespace isc::data;
25

Tomek Mrugalski's avatar
Tomek Mrugalski committed
26 27 28 29 30 31 32 33
std::string isc::dhcp::Daemon::getVersion(bool extended) {
    if (extended) {
        return (std::string("EXTENDED"));
    } else {
        return (std::string("BASIC"));
    }
}

34 35
namespace {

Tomek Mrugalski's avatar
Tomek Mrugalski committed
36

Tomek Mrugalski's avatar
Tomek Mrugalski committed
37 38
// Very simple test. Checks whether Daemon can be instantiated and its
// default parameters are sane
Tomek Mrugalski's avatar
Tomek Mrugalski committed
39 40
TEST(DaemonTest, constructor) {
    EXPECT_NO_THROW(Daemon instance1);
Tomek Mrugalski's avatar
Tomek Mrugalski committed
41 42

    // Check that the verbose mode is not set by default.
Tomek Mrugalski's avatar
Tomek Mrugalski committed
43 44
    Daemon instance2;
    EXPECT_FALSE(instance2.getVerbose());
45 46
}

47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
// Checks that configureLogger method is behaving properly.
// More dedicated tests are availablef for LogConfigParser class.
// See logger_unittest.cc
TEST(DaemonTest, parsingConsoleOutput) {

    // Storage - parsed configuration will be stored here
    ConfigurationPtr storage(new Configuration());

    const char* config_txt =
    "{ \"loggers\": ["
    "    {"
    "        \"name\": \"kea\","
    "        \"output_options\": ["
    "            {"
    "                \"output\": \"stdout\""
    "            }"
    "        ],"
    "        \"debuglevel\": 99,"
    "        \"severity\": \"DEBUG\""
    "    }"
    "]}";
    ConstElementPtr config = Element::fromJSON(config_txt);

    // Spawn a daemon and tell it to configure logger
    Daemon x;
Tomek Mrugalski's avatar
Tomek Mrugalski committed
72
    EXPECT_NO_THROW(x.configureLogger(config, storage, false));
73 74 75 76 77 78 79 80 81 82 83 84 85 86

    // The parsed configuration should be processed by the daemon and
    // stored in configuration storage.
    ASSERT_EQ(1, storage->logging_info_.size());

    EXPECT_EQ("kea", storage->logging_info_[0].name_);
    EXPECT_EQ(99, storage->logging_info_[0].debuglevel_);
    EXPECT_EQ(isc::log::DEBUG, storage->logging_info_[0].severity_);

    ASSERT_EQ(1, storage->logging_info_[0].destinations_.size());
    EXPECT_EQ("stdout" , storage->logging_info_[0].destinations_[0].output_);
}


87
// More tests will appear here as we develop Daemon class.
88 89

};