2017-04-23 17:14:04 +10:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <test/bootstrapfixture.hxx>
|
|
|
|
#include <cppunit/TestAssert.h>
|
|
|
|
#include <cppunit/TestFixture.h>
|
|
|
|
|
|
|
|
#include <vcl/errinf.hxx>
|
|
|
|
|
|
|
|
class MockErrorHandler : private ErrorHandler
|
|
|
|
{
|
|
|
|
friend class ErrorHandlerTest;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual bool CreateString(const ErrorInfo *pErrInfo, OUString &rErrString) const override
|
|
|
|
{
|
2017-02-09 08:52:13 +02:00
|
|
|
if (pErrInfo->GetErrorCode().IsDynamic())
|
2017-04-23 17:14:04 +10:00
|
|
|
rErrString = "Dynamic error";
|
2017-02-09 08:52:13 +02:00
|
|
|
else
|
|
|
|
rErrString = "Non-dynamic error";
|
2017-04-23 17:14:04 +10:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class ErrorHandlerTest : public test::BootstrapFixture
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ErrorHandlerTest() : BootstrapFixture(true, false) {}
|
|
|
|
|
|
|
|
void testGetErrorString();
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE(ErrorHandlerTest);
|
|
|
|
CPPUNIT_TEST(testGetErrorString);
|
|
|
|
CPPUNIT_TEST_SUITE_END();
|
|
|
|
};
|
|
|
|
|
|
|
|
void ErrorHandlerTest::testGetErrorString()
|
|
|
|
{
|
|
|
|
MockErrorHandler aErrHdlr;
|
2017-04-30 15:38:17 +01:00
|
|
|
std::unique_ptr<ErrorInfo> xErrorInfo;
|
2017-04-23 17:14:04 +10:00
|
|
|
OUString aErrStr;
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_MESSAGE("GetErrorString(ERRCODE_ABORT, aErrStr) should return false",
|
2017-04-26 14:10:36 +02:00
|
|
|
!ErrorHandler::GetErrorString(ERRCODE_ABORT, aErrStr));
|
2017-04-23 17:14:04 +10:00
|
|
|
// normally protected, but MockErrorHandler is a friend of this class
|
2017-04-30 15:38:17 +01:00
|
|
|
xErrorInfo.reset(ErrorInfo::GetErrorInfo(ERRCODE_ABORT));
|
|
|
|
aErrHdlr.CreateString(xErrorInfo.get(), aErrStr);
|
2017-04-28 14:22:53 +02:00
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE("error message should be non-dynamic", OUString("Non-dynamic error"), aErrStr);
|
2017-04-23 17:14:04 +10:00
|
|
|
|
|
|
|
CPPUNIT_ASSERT_MESSAGE("GetErrorString(ERRCODE_NONE, aErrStr) should return false",
|
2017-04-26 14:10:36 +02:00
|
|
|
!ErrorHandler::GetErrorString(ERRCODE_NONE, aErrStr));
|
2017-04-30 15:38:17 +01:00
|
|
|
xErrorInfo.reset(ErrorInfo::GetErrorInfo(ERRCODE_NONE));
|
|
|
|
aErrHdlr.CreateString(xErrorInfo.get(), aErrStr);
|
2017-04-28 14:22:53 +02:00
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE("error message should be non-dynamic", OUString("Non-dynamic error"), aErrStr);
|
2017-04-23 17:14:04 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION(ErrorHandlerTest);
|
|
|
|
|
|
|
|
CPPUNIT_PLUGIN_IMPLEMENT();
|
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|