Mercurial > irccd
changeset 170:28080933bac6
Irccd: unbreak test-js-logger
author | David Demelier <markand@malikania.fr> |
---|---|
date | Wed, 25 May 2016 22:34:35 +0200 |
parents | f2099005b23d |
children | a02756832959 |
files | tests/js-logger/empty.js tests/js-logger/main.cpp |
diffstat | 1 files changed, 36 insertions(+), 39 deletions(-) [+] |
line wrap: on
line diff
--- a/tests/js-logger/main.cpp Wed May 25 22:30:44 2016 +0200 +++ b/tests/js-logger/main.cpp Wed May 25 22:34:35 2016 +0200 @@ -18,12 +18,14 @@ #include <gtest/gtest.h> +#include <irccd/irccd.hpp> +#include <irccd/logger.hpp> +#include <irccd/mod-irccd.hpp> +#include <irccd/mod-logger.hpp> +#include <irccd/plugin-js.hpp> +#include <irccd/service-module.hpp> #include <irccd/sysconfig.hpp> -#include <irccd/js-irccd.hpp> -#include <irccd/js-logger.hpp> -#include <irccd/logger.hpp> - using namespace irccd; namespace { @@ -34,7 +36,7 @@ } // !namespace -class TestLogger : public log::Interface { +class LoggerIfaceTest : public log::Interface { public: void info(const std::string &line) override { @@ -52,19 +54,26 @@ } }; -TEST(TestJsLogger, info) -{ - duk::Context ctx; - - loadJsIrccd(ctx); - loadJsLogger(ctx); +class TestJsLogger : public testing::Test { +protected: + Irccd m_irccd; + std::shared_ptr<JsPlugin> m_plugin; - try { - duk::putGlobal(ctx, "\xff""\xff""name", "test"); + TestJsLogger() + : m_plugin(std::make_shared<JsPlugin>("empty", SOURCEDIR "/empty.js")) + { + m_irccd.moduleService().get("Irccd")->load(m_irccd, *m_plugin); + m_irccd.moduleService().get("Irccd.Logger")->load(m_irccd, *m_plugin); + } +}; - if (duk::pevalString(ctx, "Irccd.Logger.info(\"hello!\");") != 0) { - throw duk::error(ctx, -1); - } +TEST_F(TestJsLogger, info) +{ + try { + duk::putGlobal(m_plugin->context(), "\xff""\xff""name", "test"); + + if (duk::pevalString(m_plugin->context(), "Irccd.Logger.info(\"hello!\");") != 0) + throw duk::error(m_plugin->context(), -1); ASSERT_EQ("plugin test: hello!", lineInfo); } catch (const std::exception &ex) { @@ -72,19 +81,13 @@ } } -TEST(TestJsLogger, warning) +TEST_F(TestJsLogger, warning) { - duk::Context ctx; - - loadJsIrccd(ctx); - loadJsLogger(ctx); + try { + duk::putGlobal(m_plugin->context(), "\xff""\xff""name", "test"); - try { - duk::putGlobal(ctx, "\xff""\xff""name", "test"); - - if (duk::pevalString(ctx, "Irccd.Logger.warning(\"FAIL!\");") != 0) { - throw duk::error(ctx, -1); - } + if (duk::pevalString(m_plugin->context(), "Irccd.Logger.warning(\"FAIL!\");") != 0) + throw duk::error(m_plugin->context(), -1); ASSERT_EQ("plugin test: FAIL!", lineWarning); } catch (const std::exception &ex) { @@ -94,19 +97,13 @@ #if !defined(NDEBUG) -TEST(TestJsLogger, debug) +TEST_F(TestJsLogger, debug) { - duk::Context ctx; - - loadJsIrccd(ctx); - loadJsLogger(ctx); + try { + duk::putGlobal(m_plugin->context(), "\xff""\xff""name", "test"); - try { - duk::putGlobal(ctx, "\xff""\xff""name", "test"); - - if (duk::pevalString(ctx, "Irccd.Logger.debug(\"starting\");") != 0) { - throw duk::error(ctx, -1); - } + if (duk::pevalString(m_plugin->context(), "Irccd.Logger.debug(\"starting\");") != 0) + throw duk::error(m_plugin->context(), -1); ASSERT_EQ("plugin test: starting", lineDebug); } catch (const std::exception &ex) { @@ -121,7 +118,7 @@ testing::InitGoogleTest(&argc, argv); log::setVerbose(true); - log::setInterface(std::make_unique<TestLogger>()); + log::setInterface(std::make_unique<LoggerIfaceTest>()); return RUN_ALL_TESTS(); }