view tests/src/irccdctl/cli-plugin-load/main.cpp @ 758:445c071e8efb

Irccd: Javascript API cleanup - Place all related code to `js` namespace, - Import duk.hpp and duk.cpp from libduk.
author David Demelier <markand@malikania.fr>
date Thu, 09 Aug 2018 13:07:19 +0200
parents 46a1877749ff
children 8c44bbcbbab9
line wrap: on
line source

/*
 * main.cpp -- test irccdctl plugin-load
 *
 * 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-load"
#include <boost/test/unit_test.hpp>

#include <irccd/test/cli_fixture.hpp>
#include <irccd/test/mock_plugin.hpp>

using namespace irccd::test;

namespace irccd {

namespace {

class custom_plugin_loader : public plugin_loader {
public:
    custom_plugin_loader()
        : plugin_loader({}, { "none" })
    {
    }

    auto find(std::string_view id) -> std::shared_ptr<plugin> override
    {
        return std::make_unique<mock_plugin>(std::string(id));
    }

    auto open(std::string_view id, std::string_view) -> std::shared_ptr<plugin> override
    {
        return std::make_unique<mock_plugin>(std::string(id));
    }
};

} // !namespace

BOOST_FIXTURE_TEST_SUITE(plugin_load_suite, cli_fixture)

BOOST_AUTO_TEST_CASE(simple)
{
    irccd_.plugins().add(std::make_unique<mock_plugin>("p1"));
    irccd_.plugins().add(std::make_unique<mock_plugin>("p2"));
    irccd_.plugins().add_loader(std::make_unique<custom_plugin_loader>());
    start();

    // Load a plugin first.
    {
        const auto [code, out, err] = exec({ "plugin-load", "test" });

        BOOST_TEST(!code);
        BOOST_TEST(out.size() == 0U);
        BOOST_TEST(err.size() == 0U);
    }

    // Get the new list of plugins.
    {
        const auto [code, out, err] = exec({ "plugin-list" });

        BOOST_TEST(!code);
        BOOST_TEST(out.size() == 3U);
        BOOST_TEST(err.size() == 0U);
        BOOST_TEST(out[0] == "p1");
        BOOST_TEST(out[1] == "p2");
        BOOST_TEST(out[2] == "test");
    }
}

BOOST_AUTO_TEST_SUITE_END()

} // !irccd