Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / cppuhelper / qa / misc / test_misc.cxx
blob0e4fdf9efb42eb254b6ddaf07856b85224ae1b82
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #include <cppunit/TestFixture.h>
11 #include <cppunit/extensions/HelperMacros.h>
12 #include <cppunit/plugin/TestPlugIn.h>
14 #include <cppuhelper/exc_hlp.hxx>
16 namespace
18 class Test : public ::CppUnit::TestFixture
20 public:
21 void testCatchThrow();
22 void testgetCaughtException();
24 CPPUNIT_TEST_SUITE(Test);
25 CPPUNIT_TEST(testCatchThrow);
26 CPPUNIT_TEST(testgetCaughtException);
27 CPPUNIT_TEST_SUITE_END();
30 void Test::testCatchThrow()
32 css::uno::Any aSavedException;
33 try
35 throw css::uno::RuntimeException("RuntimeException");
37 catch (const css::uno::RuntimeException&)
39 aSavedException = cppu::getCaughtException();
41 CPPUNIT_ASSERT(aSavedException.hasValue());
42 try
44 cppu::throwException(aSavedException);
46 catch (const css::uno::RuntimeException&)
48 // the expected case
50 catch (...)
52 CPPUNIT_ASSERT(false);
56 void Test::testgetCaughtException()
58 css::uno::Any aSavedExceptionAny;
59 std::exception_ptr
60 aSavedException; /// exception caught during unzipping is saved to be thrown during reading
61 try
63 throw css::uno::RuntimeException("RuntimeException");
65 catch (...)
67 aSavedException = std::current_exception();
69 CPPUNIT_ASSERT(bool(aSavedException));
70 try
72 std::rethrow_exception(aSavedException);
74 catch (const css::uno::RuntimeException&)
76 // the expected case
77 aSavedExceptionAny = cppu::getCaughtException();
79 catch (...)
81 CPPUNIT_ASSERT(false);
83 CPPUNIT_ASSERT(aSavedExceptionAny.hasValue());
86 CPPUNIT_TEST_SUITE_REGISTRATION(Test);
89 CPPUNIT_PLUGIN_IMPLEMENT();
91 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */