Mercurial > irccd
diff tests/logger/main.cpp @ 115:9a8f321371f7
Irccd: add filter system in logging, #491
author | David Demelier <markand@malikania.fr> |
---|---|
date | Thu, 28 Apr 2016 20:48:23 +0200 |
parents | |
children | 6635b9187d71 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/logger/main.cpp Thu Apr 28 20:48:23 2016 +0200 @@ -0,0 +1,105 @@ +/* + * main.cpp -- test logger functions + * + * Copyright (c) 2013-2016 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. + */ + +#include <algorithm> + +#include <gtest/gtest.h> + +#include <irccd/logger.hpp> + +using namespace irccd; + +namespace { + +std::string lineDebug; +std::string lineInfo; +std::string lineWarning; + +} // !namespace + +class MyInterface : public log::Interface { +public: + void debug(const std::string &line) override + { + lineDebug = line; + } + + void info(const std::string &line) override + { + lineInfo = line; + } + + void warning(const std::string &line) override + { + lineWarning = line; + } +}; + +class MyFilter : public log::Filter { +public: + std::string preDebug(std::string input) const override + { + return std::reverse(input.begin(), input.end()), input; + } + + std::string preInfo(std::string input) const override + { + return std::reverse(input.begin(), input.end()), input; + } + + std::string preWarning(std::string input) const override + { + return std::reverse(input.begin(), input.end()), input; + } +}; + +#if !defined(NDEBUG) + +TEST(Logger, debug) +{ + log::debug("debug"); + + ASSERT_EQ("gubed", lineDebug); +} + +#endif + +TEST(Logger, info) +{ + log::info("info"); + + ASSERT_EQ("ofni", lineInfo); +} + +TEST(Logger, warning) +{ + log::warning("warning"); + + ASSERT_EQ("gninraw", lineWarning); +} + +int main(int argc, char **argv) +{ + log::setVerbose(true); + log::setInterface(std::make_unique<MyInterface>()); + log::setFilter(std::make_unique<MyFilter>()); + + testing::InitGoogleTest(&argc, argv); + + return RUN_ALL_TESTS(); +}