command_socket_factory_unittests.cc 2.59 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// Copyright (C) 2015 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 <gtest/gtest.h>

#include <cc/data.h>
#include <config/command_mgr.h>
Tomek Mrugalski's avatar
Tomek Mrugalski committed
19
#include <config/command_socket.h>
20
#include <config/command_socket_factory.h>
21
#include <cstdio>
22
23
24
25
26
27
28
29
30
31

using namespace isc::config;
using namespace isc::data;

// Test class for Command Manager
class CommandSocketFactoryTest : public ::testing::Test {
public:

    /// Default constructor
    CommandSocketFactoryTest() {
32
33
        // Remove any stale socket files
        remove(SOCKET_NAME.c_str());
34
35
36
37
    }

    /// Default destructor
    ~CommandSocketFactoryTest() {
38
39
40

        // Remove any stale socket files
        remove(SOCKET_NAME.c_str());
41
42
    }

43
    static const std::string SOCKET_NAME;
44
45
};

46
const std::string CommandSocketFactoryTest::SOCKET_NAME =
47
    std::string(TEST_DATA_BUILDDIR) + "/test-socket";
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68

TEST_F(CommandSocketFactoryTest, unixCreate) {
    // Null pointer is obviously a bad idea.
    EXPECT_THROW(CommandSocketFactory::create(ConstElementPtr()),
                 isc::config::BadSocketInfo);

    // So is passing no parameters.
    ElementPtr socket_info = Element::createMap();
    EXPECT_THROW(CommandSocketFactory::create(socket_info),
                 isc::config::BadSocketInfo);

    // We don't support ipx sockets
    socket_info->set("socket-type", Element::create("ipx"));
    EXPECT_THROW(CommandSocketFactory::create(socket_info),
                 isc::config::BadSocketInfo);

    socket_info->set("socket-type", Element::create("unix"));
    EXPECT_THROW(CommandSocketFactory::create(socket_info),
                 isc::config::BadSocketInfo);

    socket_info->set("socket-name", Element::create(SOCKET_NAME));
Tomek Mrugalski's avatar
Tomek Mrugalski committed
69
70
71
72
    CommandSocketPtr sock;
    EXPECT_NO_THROW(sock = CommandSocketFactory::create(socket_info));
    ASSERT_TRUE(sock);
    EXPECT_NE(-1, sock->getFD());
73
74

    // It should be possible to close the socket.
Tomek Mrugalski's avatar
Tomek Mrugalski committed
75
    EXPECT_NO_THROW(sock->close());
76
}
77