[Libreoffice-commits] core.git: vcl/CppunitTest_vcl_errorhandler.mk vcl/Module_vcl.mk vcl/qa
Chris Sherlock
chris.sherlock79 at gmail.com
Wed Apr 26 07:33:25 UTC 2017
vcl/CppunitTest_vcl_errorhandler.mk | 50 +++++++++++++++++++++++++++
vcl/Module_vcl.mk | 1
vcl/qa/cppunit/errorhandler.cxx | 66 ++++++++++++++++++++++++++++++++++++
3 files changed, 117 insertions(+)
New commits:
commit 8a23c68f58307b7cf2842cd4ce5a9eb93f8b244c
Author: Chris Sherlock <chris.sherlock79 at gmail.com>
Date: Sun Apr 23 17:14:04 2017 +1000
vcl: add ErrorHandler unit tests
Change-Id: I62f7d948522676ae2bed1a425c2f038929fb00b8
Reviewed-on: https://gerrit.libreoffice.org/36848
Reviewed-by: Chris Sherlock <chris.sherlock79 at gmail.com>
Tested-by: Chris Sherlock <chris.sherlock79 at gmail.com>
diff --git a/vcl/CppunitTest_vcl_errorhandler.mk b/vcl/CppunitTest_vcl_errorhandler.mk
new file mode 100644
index 000000000000..6b318f994f93
--- /dev/null
+++ b/vcl/CppunitTest_vcl_errorhandler.mk
@@ -0,0 +1,50 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#
+# 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/.
+#
+
+$(eval $(call gb_CppunitTest_CppunitTest,vcl_errorhandler))
+
+$(eval $(call gb_CppunitTest_set_include,vcl_errorhandler,\
+ $$(INCLUDE) \
+ -I$(SRCDIR)/vcl/inc \
+))
+
+$(eval $(call gb_CppunitTest_add_exception_objects,vcl_errorhandler, \
+ vcl/qa/cppunit/errorhandler \
+))
+
+$(eval $(call gb_CppunitTest_use_externals,vcl_errorhandler,boost_headers))
+
+$(eval $(call gb_CppunitTest_use_libraries,vcl_errorhandler, \
+ comphelper \
+ cppu \
+ cppuhelper \
+ sal \
+ svt \
+ test \
+ tl \
+ tk \
+ unotest \
+ vcl \
+ $(gb_UWINAPI) \
+))
+
+$(eval $(call gb_CppunitTest_use_sdk_api,vcl_errorhandler))
+
+$(eval $(call gb_CppunitTest_use_ure,vcl_errorhandler))
+$(eval $(call gb_CppunitTest_use_vcl,vcl_errorhandler))
+
+$(eval $(call gb_CppunitTest_use_components,vcl_errorhandler,\
+ configmgr/source/configmgr \
+ i18npool/util/i18npool \
+ ucb/source/core/ucb1 \
+))
+
+$(eval $(call gb_CppunitTest_use_configuration,vcl_errorhandler))
+
+# vim: set noet sw=4 ts=4:
diff --git a/vcl/Module_vcl.mk b/vcl/Module_vcl.mk
index 99e8374e5418..bb678740e9a0 100644
--- a/vcl/Module_vcl.mk
+++ b/vcl/Module_vcl.mk
@@ -152,6 +152,7 @@ $(eval $(call gb_Module_add_check_targets,vcl,\
CppunitTest_vcl_jpeg_read_write_test \
CppunitTest_vcl_svm_test \
CppunitTest_vcl_pdfexport \
+ CppunitTest_vcl_errorhandler \
))
diff --git a/vcl/qa/cppunit/errorhandler.cxx b/vcl/qa/cppunit/errorhandler.cxx
new file mode 100644
index 000000000000..f68035239839
--- /dev/null
+++ b/vcl/qa/cppunit/errorhandler.cxx
@@ -0,0 +1,66 @@
+/* -*- 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
+ {
+ if (!(pErrInfo->GetErrorCode() & ERRCODE_DYNAMIC_MASK))
+ rErrString = "Non-dynamic error";
+ else
+ rErrString = "Dynamic error";
+
+ 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;
+ OUString aErrStr;
+
+ CPPUNIT_ASSERT_MESSAGE("GetErrorString(ERRCODE_ABORT, aErrStr) should return false",
+ ErrorHandler::GetErrorString(ERRCODE_ABORT, aErrStr) == false);
+ // normally protected, but MockErrorHandler is a friend of this class
+ aErrHdlr.CreateString(ErrorInfo::GetErrorInfo(ERRCODE_ABORT), aErrStr);
+ CPPUNIT_ASSERT_MESSAGE("error message should be non-dynamic", aErrStr == "Non-dynamic error");
+
+ CPPUNIT_ASSERT_MESSAGE("GetErrorString(ERRCODE_NONE, aErrStr) should return false",
+ ErrorHandler::GetErrorString(ERRCODE_NONE, aErrStr) == false);
+ aErrHdlr.CreateString(ErrorInfo::GetErrorInfo(ERRCODE_NONE), aErrStr);
+ CPPUNIT_ASSERT_MESSAGE("error message should be non-dynamic", aErrStr == "Non-dynamic error");
+}
+
+CPPUNIT_TEST_SUITE_REGISTRATION(ErrorHandlerTest);
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
More information about the Libreoffice-commits
mailing list