2 * Copyright (c) 2000 - 2017 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/test/unit_test.hpp>
23 #define CHECK_EXCEPTION(exception, ec, isDebug) \
25 const std::string errmsg = "test exception string"; \
26 BOOST_REQUIRE_THROW(ThrowErr(exception, errmsg), exception); \
28 ThrowErr(exception, errmsg); \
29 } catch (const exception &e) { \
30 checkExceptionInternal(e, ec, isDebug ? std::string() : errmsg); \
36 void checkExceptionInternal(const Exc::Exception &e, int ec, const std::string &msg)
38 BOOST_REQUIRE_MESSAGE(e.error() == ec,
39 "ec(" << ec << ") not matched(" << e.error() << ")");
41 BOOST_REQUIRE_MESSAGE(msg == e.what(),
42 "msg(" << msg << ") isn't matched(" << e.what() << ")");
44 BOOST_REQUIRE_MESSAGE(e.message().find(msg) != std::string::npos,
45 "msg(" << msg << ") isn't contained from message("
46 << e.message() << ")");
49 } // namespace anonymous
51 BOOST_AUTO_TEST_SUITE(EXCEPTION_TEST)
53 BOOST_AUTO_TEST_CASE(internal_error)
55 CHECK_EXCEPTION(Exc::InternalError, CKM_API_ERROR_SERVER_ERROR, false);
58 BOOST_AUTO_TEST_CASE(database_locked)
60 CHECK_EXCEPTION(Exc::DatabaseLocked, CKM_API_ERROR_DB_LOCKED, false);
63 BOOST_AUTO_TEST_CASE(database_failed)
65 CHECK_EXCEPTION(Exc::DatabaseFailed, CKM_API_ERROR_DB_ERROR, false);
68 BOOST_AUTO_TEST_CASE(filesystem_failed)
70 CHECK_EXCEPTION(Exc::FileSystemFailed, CKM_API_ERROR_FILE_SYSTEM, false);
73 BOOST_AUTO_TEST_CASE(inputparam)
75 CHECK_EXCEPTION(Exc::InputParam, CKM_API_ERROR_INPUT_PARAM, true);
78 BOOST_AUTO_TEST_CASE(authentication_failed)
80 CHECK_EXCEPTION(Exc::AuthenticationFailed, CKM_API_ERROR_AUTHENTICATION_FAILED, true);
83 BOOST_AUTO_TEST_CASE(transaction_failed)
85 CHECK_EXCEPTION(Exc::TransactionFailed, CKM_API_ERROR_DB_ERROR, false);
88 BOOST_AUTO_TEST_SUITE_END()