1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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/.
10 #include <cppunit/TestFixture.h>
11 #include <cppunit/extensions/HelperMacros.h>
12 #include <cppunit/plugin/TestPlugIn.h>
14 #include <cppuhelper/exc_hlp.hxx>
18 class Test
: public ::CppUnit::TestFixture
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
;
35 throw css::uno::RuntimeException("RuntimeException");
37 catch (const css::uno::RuntimeException
&)
39 aSavedException
= cppu::getCaughtException();
41 CPPUNIT_ASSERT(aSavedException
.hasValue());
44 cppu::throwException(aSavedException
);
46 catch (const css::uno::RuntimeException
&)
52 CPPUNIT_ASSERT(false);
56 void Test::testgetCaughtException()
58 css::uno::Any aSavedExceptionAny
;
60 aSavedException
; /// exception caught during unzipping is saved to be thrown during reading
63 throw css::uno::RuntimeException("RuntimeException");
67 aSavedException
= std::current_exception();
69 CPPUNIT_ASSERT(bool(aSavedException
));
72 std::rethrow_exception(aSavedException
);
74 catch (const css::uno::RuntimeException
&)
77 aSavedExceptionAny
= cppu::getCaughtException();
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: */