view tests/src/irccdctl/cli-plugin-reload/main.cpp @ 678:a4082de4e94e

Tests: rework cli_test to spawn irccd daemon in a thread, continue #785 Instead of spawning irccd executable, use the irccd class for better flexibility in test code. For example, for server tests we will need to use journal_server to see if commands have been called instead of checking a real IRC server. While here, add rule-cli-remove test that was forgotten.
author David Demelier <markand@malikania.fr>
date Thu, 12 Apr 2018 20:14:07 +0200
parents e9153b85b9bd
children 3e816cebed2c
line wrap: on
line source

/*
 * main.cpp -- test irccdctl plugin-reload
 *
 * Copyright (c) 2013-2018 David Demelier <markand@malikania.fr>
 *
 * 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 THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR 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.
 */

#define BOOST_TEST_MODULE "irccdctl plugin-reload"
#include <boost/test/unit_test.hpp>

#include <irccd/test/plugin_cli_test.hpp>

namespace irccd {

namespace {

class custom_plugin : public plugin {
public:
    bool reloaded_{false};

    custom_plugin()
        : plugin("p", "local")
    {
    }

    void handle_reload(irccd&) override
    {
        reloaded_ = true;
    }
};

} // !namespace

BOOST_FIXTURE_TEST_SUITE(plugin_reload_suite, plugin_cli_test)

BOOST_AUTO_TEST_CASE(simple)
{
    const auto plugin = std::make_shared<custom_plugin>();

    irccd_.plugins().add(plugin);
    start();

    const auto result = exec({ "plugin-reload", "p" });

    BOOST_TEST(result.first.size() == 0U);
    BOOST_TEST(result.second.size() == 0U);
    BOOST_TEST(plugin->reloaded_);
}

BOOST_AUTO_TEST_SUITE_END()

} // !irccd