1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2025-01-31 09:57:14 +01:00
SqMod/vendor/POCO/Foundation/testsuite/src/LoggingFactoryTest.cpp
Sandu Liviu Catalin 4a6bfc086c Major plugin refactor and cleanup.
Switched to POCO library for unified platform/library interface.
Deprecated the external module API. It was creating more problems than solving.
Removed most built-in libraries in favor of system libraries for easier maintenance.
Cleaned and secured code with help from static analyzers.
2021-01-30 08:51:39 +02:00

157 lines
3.5 KiB
C++

//
// LoggingFactoryTest.cpp
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#include "LoggingFactoryTest.h"
#include "CppUnit/TestCaller.h"
#include "CppUnit/TestSuite.h"
#include "Poco/LoggingFactory.h"
#include "Poco/Instantiator.h"
#include "Poco/Channel.h"
#include "Poco/ConsoleChannel.h"
#if defined(_WIN32)
#include "Poco/WindowsConsoleChannel.h"
#endif
#ifndef POCO_NO_FILECHANNEL
#include "Poco/FileChannel.h"
#include "Poco/SimpleFileChannel.h"
#endif
#include "Poco/SplitterChannel.h"
#include "Poco/Formatter.h"
#include "Poco/PatternFormatter.h"
#include "Poco/Message.h"
#include "Poco/AutoPtr.h"
#include "Poco/Exception.h"
#include <memory>
using Poco::LoggingFactory;
using Poco::Channel;
using Poco::ConsoleChannel;
#ifndef POCO_NO_FILECHANNEL
using Poco::FileChannel;
using Poco::SimpleFileChannel;
#endif
using Poco::SplitterChannel;
using Poco::Formatter;
using Poco::PatternFormatter;
using Poco::Message;
using Poco::AutoPtr;
using Poco::Instantiator;
namespace
{
class CustomChannel: public Channel
{
public:
void log(const Message& msg)
{
}
};
class CustomFormatter: public Formatter
{
void format(const Message& msg, std::string& text)
{
}
};
}
LoggingFactoryTest::LoggingFactoryTest(const std::string& name): CppUnit::TestCase(name)
{
}
LoggingFactoryTest::~LoggingFactoryTest()
{
}
void LoggingFactoryTest::testBuiltins()
{
LoggingFactory& fact = LoggingFactory::defaultFactory();
Channel::Ptr pConsoleChannel = fact.createChannel("ConsoleChannel");
#if defined(_WIN32) && !defined(_WIN32_WCE)
assertTrue (!pConsoleChannel.cast<Poco::WindowsConsoleChannel>().isNull());
#else
assertTrue (!pConsoleChannel.cast<ConsoleChannel>().isNull());
#endif
#ifndef POCO_NO_FILECHANNEL
Channel::Ptr pFileChannel = fact.createChannel("FileChannel");
assertTrue (!pFileChannel.cast<FileChannel>().isNull());
Channel::Ptr pSimpleFileChannel = fact.createChannel("SimpleFileChannel");
assertTrue(!pSimpleFileChannel.cast<SimpleFileChannel>().isNull());
#endif
Channel::Ptr pSplitterChannel = fact.createChannel("SplitterChannel");
assertTrue (!pSplitterChannel.cast<SplitterChannel>().isNull());
try
{
Channel::Ptr pUnknownChannel = fact.createChannel("UnknownChannel");
fail("unknown class - must throw");
}
catch (Poco::NotFoundException&)
{
}
Formatter::Ptr pPatternFormatter = fact.createFormatter("PatternFormatter");
assertTrue (!pPatternFormatter.isNull());
try
{
Formatter::Ptr pUnknownFormatter = fact.createFormatter("UnknownFormatter");
fail("unknown class - must throw");
}
catch (Poco::NotFoundException&)
{
}
}
void LoggingFactoryTest::testCustom()
{
std::unique_ptr<LoggingFactory> fact(new LoggingFactory);
fact->registerChannelClass("CustomChannel", new Instantiator<CustomChannel, Channel>);
fact->registerFormatterClass("CustomFormatter", new Instantiator<CustomFormatter, Formatter>);
Channel::Ptr pCustomChannel = fact->createChannel("CustomChannel");
assertTrue (dynamic_cast<CustomChannel*>(pCustomChannel.get()) != 0);
Formatter::Ptr pCustomFormatter = fact->createFormatter("CustomFormatter");
assertTrue (!pCustomFormatter.isNull());
}
void LoggingFactoryTest::setUp()
{
}
void LoggingFactoryTest::tearDown()
{
}
CppUnit::Test* LoggingFactoryTest::suite()
{
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("LoggingFactoryTest");
CppUnit_addTest(pSuite, LoggingFactoryTest, testBuiltins);
CppUnit_addTest(pSuite, LoggingFactoryTest, testCustom);
return pSuite;
}