2 * Copyright (c) 2017 - 2020 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License
16 #include <exception.h>
18 #include <boost_macros_wrapper.h>
25 template <int Error, bool IsDebug, typename Before, typename After>
26 void verifyCatched(const Exc::DefineException<Error, IsDebug, Before, After>& e,
27 const std::string errmsg)
29 BOOST_REQUIRE_MESSAGE(e.error() == Error,
30 "ec(" << Error << ") not matched(" << e.error() << ")");
33 BOOST_REQUIRE_MESSAGE(std::string() == e.what(),
34 "expected empty e.what(), got(" << e.what() << ")");
36 BOOST_REQUIRE_MESSAGE(errmsg == e.what(),
37 "msg(" << errmsg << ") isn't matched(" << e.what() << ")");
39 BOOST_REQUIRE_MESSAGE(e.message().find(errmsg) != std::string::npos,
40 "msg(" << errmsg << ") isn't contained from message("
41 << e.message() << ")");
45 template <typename Exc>
48 const std::string errmsg = "test exception string";
50 ThrowErr(Exc, errmsg);
51 BOOST_FAIL("No exception thrown");
52 } catch (const Exc &e) {
53 verifyCatched(e ,errmsg);
57 } // namespace anonymous
59 BOOST_AUTO_TEST_SUITE(EXCEPTION_TEST)
61 POSITIVE_TEST_CASE(check_exceptions)
63 checkException<Exc::InternalError>();
64 checkException<Exc::DatabaseLocked>();
65 checkException<Exc::DatabaseFailed>();
66 checkException<Exc::FileSystemFailed>();
67 checkException<Exc::InputParam>();
68 checkException<Exc::AuthenticationFailed>();
69 checkException<Exc::VerificationFailed>();
70 checkException<Exc::InvalidFormat>();
71 checkException<Exc::BadResponse>();
72 checkException<Exc::TransactionFailed>();
75 BOOST_AUTO_TEST_SUITE_END()