From: Krzysztof Jackiewicz Date: Wed, 7 Nov 2018 13:14:31 +0000 (+0100) Subject: Update log formatter in tests X-Git-Tag: accepted/tizen/unified/20190220.071637~14 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e0d5bfde568340c163bfae0dd047162cdee0de24;p=platform%2Fcore%2Fsecurity%2Fkey-manager.git Update log formatter in tests Apparently the boost unit_test_log_formatter interface has changed. The colour_log_formatter has been updated to match the new version. Thanks to that it is now possible to properly observe uncaught exceptions in unit tests. As a result the assert wrapper is no longer necessary and it has been removed. Change-Id: Ifbf0b8b2f1234e1d77fa695b145c50d65e87624a --- diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index ba5153e..7b1feef 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -61,15 +61,14 @@ SET(GENERATOR_SOURCES ADD_EXECUTABLE(${TARGET_CKM_GENERATOR} ${GENERATOR_SOURCES} ${ENCRYPTION_SCHEME_SOURCES}) -TARGET_COMPILE_DEFINITIONS(${TARGET_CKM_GENERATOR} PRIVATE NO_BOOST) - SET(SCHEME_TEST_LIBRARIES ${ENCRYPTION_SCHEME_DEP_LIBRARIES} ${TARGET_KEY_MANAGER_CLIENT} ${TARGET_KEY_MANAGER_CONTROL_CLIENT} ${CMAKE_THREAD_LIBS_INIT} + boost_unit_test_framework -ldl - ) + ) TARGET_LINK_LIBRARIES(${TARGET_CKM_GENERATOR} ${SCHEME_TEST_LIBRARIES} ) @@ -185,7 +184,6 @@ TARGET_LINK_LIBRARIES(${TARGET_TEST_MERGED} ${KEY_MANAGER_DEP_LIBRARIES} ${TEST_LINK_EXTRA_DEPS} ${SCHEME_TEST_LIBRARIES} - boost_unit_test_framework ) INSTALL(TARGETS ${TARGET_TEST_MERGED} DESTINATION bin) diff --git a/tests/colour_log_formatter.cpp b/tests/colour_log_formatter.cpp index 81e9938..87e862b 100644 --- a/tests/colour_log_formatter.cpp +++ b/tests/colour_log_formatter.cpp @@ -193,7 +193,7 @@ colour_log_formatter::test_unit_skipped( //____________________________________________________________________________// void -colour_log_formatter::log_exception_start( +colour_log_formatter::log_exception( std::ostream &output, log_checkpoint_data const &checkpoint_data, boost::execution_exception const &ex) @@ -225,14 +225,6 @@ colour_log_formatter::log_exception_start( //____________________________________________________________________________// void -colour_log_formatter::log_exception_finish(std::ostream &os) -{ - (void)os; -} - -//____________________________________________________________________________// - -void colour_log_formatter::log_entry_start( std::ostream &output, log_entry_data const &entry_data, @@ -305,39 +297,6 @@ colour_log_formatter::log_entry_finish( //____________________________________________________________________________// -void -colour_log_formatter::entry_context_start(std::ostream& os, boost::unit_test::log_level l) -{ - (void)os; - (void)l; -} -void -colour_log_formatter::log_entry_context(std::ostream& os, boost::unit_test::const_string value) -{ - (void)os; - (void)value; -} - -void -colour_log_formatter::log_entry_context(std::ostream&, - boost::unit_test::log_level, - boost::unit_test::const_string) -{ -} - -void -colour_log_formatter::entry_context_finish(std::ostream& os) -{ - (void)os; -} - -void -colour_log_formatter::entry_context_finish(std::ostream&, - boost::unit_test::log_level) -{ -} -//____________________________________________________________________________// - //____________________________________________________________________________// } // namespace CKM diff --git a/tests/colour_log_formatter.h b/tests/colour_log_formatter.h index 233edc3..3c5dae0 100644 --- a/tests/colour_log_formatter.h +++ b/tests/colour_log_formatter.h @@ -37,11 +37,10 @@ public: std::ostream &, boost::unit_test::test_unit const &tu); - void log_exception_start( + void log_exception( std::ostream &, boost::unit_test::log_checkpoint_data const &, boost::execution_exception const &ex); - void log_exception_finish(std::ostream &os); void log_entry_start( std::ostream &, @@ -55,19 +54,6 @@ public: boost::unit_test::lazy_ostream const &value); void log_entry_finish(std::ostream &); - - void entry_context_start( - std::ostream& os, - boost::unit_test::log_level l); - void log_entry_context( - std::ostream& os, - boost::unit_test::const_string value); - void log_entry_context( - std::ostream& os, - boost::unit_test::log_level l, - boost::unit_test::const_string value); - void entry_context_finish(std::ostream& os); - void entry_context_finish(std::ostream& os, boost::unit_test::log_level l); private: bool m_isTestCaseFailed; }; diff --git a/tests/encryption-scheme/assert-wrapper.h b/tests/encryption-scheme/assert-wrapper.h deleted file mode 100644 index 7ec5b0c..0000000 --- a/tests/encryption-scheme/assert-wrapper.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License - */ -/* - * @file assert-wrapper.h - * @author Krzysztof Jackiewicz (k.jackiewicz@samsung.com) - * @version 1.0 - * @brief - */ - -#pragma once - -#ifdef NO_BOOST - #include - #include - - #define ASSERT_MSG(cond, msg) \ - do { \ - if (!(cond)) { \ - std::ostringstream oss; \ - oss << msg; \ - throw std::runtime_error(oss.str()); \ - } \ - } while (0) - - #define ASSERT_FAIL(msg) ASSERT_MSG(false, msg) - -#else - #include - - #define ASSERT_MSG(cond, msg) BOOST_REQUIRE_MESSAGE(cond, msg) - - #define ASSERT_FAIL(msg) BOOST_FAIL(msg) - -#endif diff --git a/tests/encryption-scheme/scheme-test.cpp b/tests/encryption-scheme/scheme-test.cpp index 66a9fa0..66afdbc 100644 --- a/tests/encryption-scheme/scheme-test.cpp +++ b/tests/encryption-scheme/scheme-test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2015 - 2018 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,6 +18,7 @@ * @author Krzysztof Jackiewicz (k.jackiewicz@samsung.com) * @version 1.0 */ +#include #include #include @@ -33,6 +34,10 @@ #include #include +#include + +#include + #include #include #include @@ -40,10 +45,6 @@ #include #include -#include -#include -#include - using namespace CKM; using namespace std; @@ -307,7 +308,7 @@ uid_t getUid(const char *name) std::vector buf(bufsize, 0); int ret = getpwnam_r(name, &pwd, buf.data(), bufsize, &result); - ASSERT_MSG(ret == 0 && result, "getpwnam_r failed"); + BOOST_REQUIRE_MESSAGE(ret == 0 && result, "getpwnam_r failed"); return pwd.pw_uid; } @@ -326,7 +327,7 @@ gid_t getGid(const char *name) std::vector buf(bufsize, 0); int ret = getgrnam_r(name, &grp, buf.data(), bufsize, &result); - ASSERT_MSG(ret == 0 && result, "getgrnam_r failed"); + BOOST_REQUIRE_MESSAGE(ret == 0 && result, "getgrnam_r failed"); return grp.gr_gid; } @@ -342,47 +343,50 @@ void restoreFile(const string &filename) int sourceFd = TEMP_FAILURE_RETRY(open(sourcePath.c_str(), O_RDONLY)); err = errno; - ASSERT_MSG(sourceFd > 0, "Opening " << sourcePath << " failed: " << GetErrnoString(err)); + BOOST_REQUIRE_MESSAGE(sourceFd > 0, + "Opening " << sourcePath << " failed: " << GetErrnoString(err)); FdPtr sourceFdPtr(&sourceFd); int targetFd = TEMP_FAILURE_RETRY(creat(targetPath.c_str(), 0644)); err = errno; - ASSERT_MSG(targetFd > 0, "Creating " << targetPath << " failed: " << GetErrnoString(err)); + BOOST_REQUIRE_MESSAGE(targetFd > 0, + "Creating " << targetPath << " failed: " << GetErrnoString(err)); ret = fchown(targetFd, CKM_UID, CKM_GID); err = errno; - ASSERT_MSG(ret != -1, "fchown() failed: " << GetErrnoString(err)); + BOOST_REQUIRE_MESSAGE(ret != -1, "fchown() failed: " << GetErrnoString(err)); FdPtr targetFdPtr(&targetFd); struct stat sourceStat; ret = fstat(sourceFd, &sourceStat); err = errno; - ASSERT_MSG(ret != -1, "fstat() failed: " << GetErrnoString(err)); + BOOST_REQUIRE_MESSAGE(ret != -1, "fstat() failed: " << GetErrnoString(err)); ret = sendfile(targetFd, sourceFd, 0, sourceStat.st_size); err = errno; - ASSERT_MSG(ret != -1, "sendfile() failed: " << GetErrnoString(err)); + BOOST_REQUIRE_MESSAGE(ret != -1, "sendfile() failed: " << GetErrnoString(err)); ret = fsync(targetFd); err = errno; - ASSERT_MSG(ret != -1, "fsync() failed: " << GetErrnoString(err)); + BOOST_REQUIRE_MESSAGE(ret != -1, "fsync() failed: " << GetErrnoString(err)); } void generateRandom(size_t random_bytes, unsigned char *output) { if (random_bytes <= 0 || !output) - ASSERT_FAIL("Invalid param"); + throw runtime_error("Invalid param"); std::ifstream is("/dev/urandom", std::ifstream::binary); - ASSERT_MSG(is, "Failed to read /dev/urandom"); + if (!is) + throw runtime_error("Failed to read /dev/urandom"); is.read(reinterpret_cast(output), random_bytes); - ASSERT_MSG(static_cast(random_bytes) == is.gcount(), - "Not enough bytes read from /dev/urandom"); + if (static_cast(random_bytes) != is.gcount()) + throw runtime_error("Not enough bytes read from /dev/urandom"); } RawBuffer createRandomBuffer(size_t random_bytes) @@ -416,9 +420,11 @@ SchemeTest::~SchemeTest() void SchemeTest::RemoveUserData() { - ASSERT_MSG(m_control->lockUserKey(UID) == CKM_API_SUCCESS, "lockUserKey failed"); + if (CKM_API_SUCCESS != m_control->lockUserKey(UID)) + throw runtime_error("lockUserKey failed"); - ASSERT_MSG(m_control->removeUserData(UID) == CKM_API_SUCCESS, "removeUserData failed"); + if (CKM_API_SUCCESS != m_control->removeUserData(UID)) + throw runtime_error("removeUserData failed"); } void SchemeTest::SwitchToUser() @@ -426,21 +432,26 @@ void SchemeTest::SwitchToUser() if (m_userChanged) return; - ASSERT_MSG(m_control->unlockUserKey(UID, DBPASS) == CKM_API_SUCCESS, "unlockUserKey failed"); + if (CKM_API_SUCCESS != m_control->unlockUserKey(UID, DBPASS)) + throw runtime_error("unlockUserKey failed"); // get calling label char *label = NULL; - ASSERT_MSG(smack_new_label_from_self(&label) > 0, "smack_new_label_from_self failed"); + if (smack_new_label_from_self(&label) <= 0) + throw runtime_error("smack_new_label_from_self failed"); m_origLabel = string(label); free(label); - ASSERT_MSG(smack_set_label_for_self(LABEL) == 0, "smack_set_label_for_self failed"); + if (0 > smack_set_label_for_self(LABEL)) + throw runtime_error("smack_set_label_for_self failed"); - ASSERT_MSG(setegid(GID) == 0, "setegid failed"); + if (0 > setegid(GID)) + throw runtime_error("setegid failed"); - ASSERT_MSG(seteuid(UID) == 0, "seteuid failed"); + if (0 > seteuid(UID)) + throw runtime_error("seteuid failed"); m_userChanged = true; } @@ -450,14 +461,17 @@ void SchemeTest::SwitchToRoot() if (!m_userChanged) return; - ASSERT_MSG(seteuid(0) == 0, "seteuid failed"); + if (0 > seteuid(0)) + throw runtime_error("seteuid failed"); - ASSERT_MSG(setegid(0) == 0, "setegid failed"); + if (0 > setegid(0)) + throw runtime_error("setegid failed"); - ASSERT_MSG(smack_set_label_for_self(m_origLabel.c_str()) == 0, - "smack_set_label_for_self failed"); + if (0 > smack_set_label_for_self(m_origLabel.c_str())) + throw runtime_error("smack_set_label_for_self failed"); - ASSERT_MSG(m_control->lockUserKey(UID) == CKM_API_SUCCESS, "lockUserKey failed"); + if (m_control->lockUserKey(UID) != CKM_API_SUCCESS) + throw runtime_error("lockUserKey failed"); } void SchemeTest::FillDb() @@ -465,13 +479,15 @@ void SchemeTest::FillDb() // pkcs ifstream is(DB_TEST_DIR "/encryption-scheme.p12"); - ASSERT_MSG(is, "Failed to read pkcs"); + if (!is) + throw runtime_error("Failed to read pkcs"); istreambuf_iterator begin(is), end; RawBuffer pkcsBuffer(begin, end); auto pkcs = PKCS12::create(pkcsBuffer, Password()); - ASSERT_MSG(!pkcs->empty(), "Empty pkcs"); + if (pkcs->empty()) + throw runtime_error("Empty pkcs"); SwitchToUser(); @@ -489,40 +505,42 @@ void SchemeTest::FillDb() for (const auto &g : GROUPS) { switch (g.type) { case Group::KEY_PAIR_RSA: - ASSERT_MSG(g.items.size() == 2, "Wrong number of keys"); + if (g.items.size() != 2) + throw runtime_error("Wrong number of keys"); if (g.items[0].type != DataType::KEY_RSA_PRIVATE || g.items[1].type != DataType::KEY_RSA_PUBLIC) - ASSERT_FAIL("Invalid item type"); + throw runtime_error("Invalid item type"); if (CKM_API_SUCCESS != m_mgr->createKeyPairRSA(1024, g.items[0].alias, g.items[1].alias, g.items[0].policy, g.items[1].policy)) - ASSERT_FAIL("createKeyPair failed"); + throw runtime_error("createKeyPair failed"); break; case Group::CERT_CHAIN: - ASSERT_MSG(g.items.size() == CHAIN_SIZE, "Wrong number of certificates"); + if (g.items.size() != CHAIN_SIZE) + throw runtime_error("Wrong number of certificates"); if (g.items[0].type != DataType::CERTIFICATE || g.items[1].type != DataType::CERTIFICATE || g.items[2].type != DataType::CERTIFICATE) - ASSERT_FAIL("Invalid item type"); + throw runtime_error("Invalid item type"); if (CKM_API_SUCCESS != m_mgr->saveCertificate(g.items[0].alias, rootCa, g.items[0].policy)) - ASSERT_FAIL("saveCertificate failed"); + throw runtime_error("saveCertificate failed"); if (CKM_API_SUCCESS != m_mgr->saveCertificate(g.items[1].alias, imCa, g.items[1].policy)) - ASSERT_FAIL("saveCertificate failed"); + throw runtime_error("saveCertificate failed"); if (CKM_API_SUCCESS != m_mgr->saveCertificate(g.items[2].alias, leaf, g.items[2].policy)) - ASSERT_FAIL("saveCertificate failed"); + throw runtime_error("saveCertificate failed"); break; @@ -531,24 +549,24 @@ void SchemeTest::FillDb() switch (i.type) { case DataType::BINARY_DATA: if (CKM_API_SUCCESS != m_mgr->saveData(i.alias, TEST_DATA, i.policy)) - ASSERT_FAIL("saveData failed"); + throw runtime_error("saveData failed"); break; case DataType::KEY_AES: if (CKM_API_SUCCESS != m_mgr->createKeyAES(256, i.alias, i.policy)) - ASSERT_FAIL("createKeyAES failed"); + throw runtime_error("createKeyAES failed"); break; case DataType::CHAIN_CERT_0: // PKCS if (CKM_API_SUCCESS != m_mgr->savePKCS12(i.alias, pkcs, i.policy, i.policy)) - ASSERT_FAIL("savePkcs12 failed"); + throw runtime_error("savePkcs12 failed"); break; default: - ASSERT_FAIL("unsupported data type"); + throw runtime_error("unsupported data type"); } } @@ -577,8 +595,8 @@ void SchemeTest::ReadAll(bool useWrongPass) case DataType::BINARY_DATA: { RawBuffer receivedData; ret = m_mgr->getData(i.alias, pass, receivedData); - ASSERT_MSG(useWrongPass || receivedData == TEST_DATA, - "Received data is different for " << i.alias); + BOOST_REQUIRE_MESSAGE(useWrongPass || receivedData == TEST_DATA, + "Received data is different for " << i.alias); break; } @@ -603,20 +621,20 @@ void SchemeTest::ReadAll(bool useWrongPass) } default: - ASSERT_FAIL("Unsupported data type " << i.type); + BOOST_FAIL("Unsupported data type " << i.type); } if (i.policy.extractable) { if (useWrongPass) - ASSERT_MSG(ret == CKM_API_ERROR_AUTHENTICATION_FAILED, - "Reading item " << i.alias << " should fail with " << - CKM_API_ERROR_AUTHENTICATION_FAILED << " got: " << ret); + BOOST_REQUIRE_MESSAGE(ret == CKM_API_ERROR_AUTHENTICATION_FAILED, + "Reading item " << i.alias << " should fail with " << + CKM_API_ERROR_AUTHENTICATION_FAILED << " got: " << ret); else - ASSERT_MSG(ret == CKM_API_SUCCESS, - "Reading item " << i.alias << " failed with " << ret); + BOOST_REQUIRE_MESSAGE(ret == CKM_API_SUCCESS, "Reading item " << i.alias << + " failed with " << ret); } else { - ASSERT_MSG(ret == CKM_API_ERROR_NOT_EXPORTABLE, - "Item " << i.alias << " should not be exportable"); + BOOST_REQUIRE_MESSAGE(ret == CKM_API_ERROR_NOT_EXPORTABLE, "Item " << i.alias << + " should not be exportable"); } } } @@ -628,9 +646,9 @@ void SchemeTest::SignVerify() for (const auto &g : GROUPS) { if (g.type == Group::KEY_PAIR_RSA) { - ASSERT_MSG(g.items.size() == 2, "Wrong number of keys"); - ASSERT_MSG(g.items[0].type == DataType::KEY_RSA_PRIVATE && - g.items[1].type == DataType::KEY_RSA_PUBLIC, "Wrong key"); + BOOST_REQUIRE_MESSAGE(g.items.size() == 2, "Wrong number of keys"); + BOOST_REQUIRE_MESSAGE(g.items[0].type == DataType::KEY_RSA_PRIVATE && + g.items[1].type == DataType::KEY_RSA_PUBLIC, "Wrong key"); SignVerifyItem(g.items[0], g.items[1]); } else { @@ -654,9 +672,9 @@ void SchemeTest::EncryptDecrypt() for (const auto &g : GROUPS) { if (g.type == Group::KEY_PAIR_RSA) { - ASSERT_MSG(g.items.size() == 2, "Wrong number of keys"); - ASSERT_MSG(g.items[0].type == DataType::KEY_RSA_PRIVATE && - g.items[1].type == DataType::KEY_RSA_PUBLIC, "Wrong key"); + BOOST_REQUIRE_MESSAGE(g.items.size() == 2, "Wrong number of keys"); + BOOST_REQUIRE_MESSAGE(g.items[0].type == DataType::KEY_RSA_PRIVATE && + g.items[1].type == DataType::KEY_RSA_PUBLIC, "Wrong key"); EncryptDecryptItem(g.items[0], g.items[1]); } else { @@ -684,10 +702,10 @@ void SchemeTest::CreateChain() for (const auto &g : GROUPS) { if (g.type == Group::CERT_CHAIN) { - ASSERT_MSG(g.items.size() == CHAIN_SIZE, "Not enough certificates"); + BOOST_REQUIRE_MESSAGE(g.items.size() == CHAIN_SIZE, "Not enough certificates"); for (const auto &c : g.items) - ASSERT_MSG(c.type == DataType::CERTIFICATE, "Wrong item type"); + BOOST_REQUIRE_MESSAGE(c.type == DataType::CERTIFICATE, "Wrong item type"); Items trusted(CHAIN_SIZE - 1); std::copy(g.items.begin(), g.items.begin() + CHAIN_SIZE - 1, trusted.begin()); @@ -710,8 +728,8 @@ void SchemeTest::RemoveAll() for (const auto &g : GROUPS) { for (const auto &i : g.items) { int ret = m_mgr->removeAlias(i.alias); - ASSERT_MSG(ret == CKM_API_SUCCESS, - "removeAlias() failed with " << ret << " for " << i.alias); + BOOST_REQUIRE_MESSAGE(ret == CKM_API_SUCCESS, + "removeAlias() failed with " << ret << " for " << i.alias); } } } @@ -753,12 +771,13 @@ void SchemeTest::CheckSchemeVersion(const ItemFilter &filter, int version) DB::RowVector rows; m_db->getRows(i.alias, OWNER, filter.typeFrom, filter.typeTo, rows); - ASSERT_MSG(rows.size() > 0, "No rows found for " << i.alias); + BOOST_REQUIRE_MESSAGE(rows.size() > 0, "No rows found for " << i.alias); for (const auto &r : rows) { - ASSERT_MSG((r.encryptionScheme >> ENC_SCHEME_OFFSET) == version, - "Wrong encryption scheme for " << i.alias << ". Expected " << version << - " got: " << (r.encryptionScheme >> ENC_SCHEME_OFFSET)); + BOOST_REQUIRE_MESSAGE( + (r.encryptionScheme >> ENC_SCHEME_OFFSET) == version, + "Wrong encryption scheme for " << i.alias << ". Expected " << version << + " got: " << (r.encryptionScheme >> ENC_SCHEME_OFFSET)); } } } @@ -795,16 +814,18 @@ void SchemeTest::SignVerifyItem(const Item &itemPrv, const Item &itemPub) HashAlgorithm::SHA512, RSAPaddingAlgorithm::X931, signature); - ASSERT_MSG(ret == CKM_API_SUCCESS, - "createSignature() failed with " << ret << " for " << itemPrv.alias); + BOOST_REQUIRE_MESSAGE(ret == CKM_API_SUCCESS, + "createSignature() failed with " << ret << + " for " << itemPrv.alias); ret = m_mgr->verifySignature(itemPub.alias, itemPub.policy.password, TEST_DATA, signature, HashAlgorithm::SHA512, RSAPaddingAlgorithm::X931); - ASSERT_MSG(ret == CKM_API_SUCCESS, - "verifySignature() failed with " << ret << " for " << itemPub.alias); + BOOST_REQUIRE_MESSAGE(ret == CKM_API_SUCCESS, + "verifySignature() failed with " << ret << + " for " << itemPub.alias); } void SchemeTest::EncryptDecryptItem(const Item &item) @@ -817,13 +838,20 @@ void SchemeTest::EncryptDecryptItem(const Item &item) algo.setParam(ParamName::ALGO_TYPE, AlgoType::AES_GCM); algo.setParam(ParamName::ED_IV, iv); - ret = m_mgr->encrypt(algo, item.alias, item.policy.password, TEST_DATA, encrypted); - ASSERT_MSG(ret == CKM_API_SUCCESS, "encrypt() failed iwth " << ret << " for " << item.alias); + ret = m_mgr->encrypt(algo, item.alias, item.policy.password, TEST_DATA, + encrypted); + BOOST_REQUIRE_MESSAGE(ret == CKM_API_SUCCESS, + "encrypt() failed iwth " << ret << " for " << + item.alias); - ret = m_mgr->decrypt(algo, item.alias, item.policy.password, encrypted, decrypted); - ASSERT_MSG(ret == CKM_API_SUCCESS, "decrypt() failed iwth " << ret << " for " << item.alias); + ret = m_mgr->decrypt(algo, item.alias, item.policy.password, encrypted, + decrypted); + BOOST_REQUIRE_MESSAGE(ret == CKM_API_SUCCESS, + "decrypt() failed iwth " << ret << " for " << + item.alias); - ASSERT_MSG(decrypted == TEST_DATA, "Decrypted data not equal to original"); + BOOST_REQUIRE_MESSAGE(decrypted == TEST_DATA, + "Decrypted data not equal to original"); } void SchemeTest::EncryptDecryptItem(const Item &itemPrv, const Item &itemPub) @@ -834,13 +862,20 @@ void SchemeTest::EncryptDecryptItem(const Item &itemPrv, const Item &itemPub) algo.setParam(ParamName::ALGO_TYPE, AlgoType::RSA_OAEP); - ret = m_mgr->encrypt(algo, itemPub.alias, itemPub.policy.password, TEST_DATA, encrypted); - ASSERT_MSG(ret == CKM_API_SUCCESS, "encrypt() failed iwth " << ret << " for " << itemPub.alias); + ret = m_mgr->encrypt(algo, itemPub.alias, itemPub.policy.password, TEST_DATA, + encrypted); + BOOST_REQUIRE_MESSAGE(ret == CKM_API_SUCCESS, + "encrypt() failed iwth " << ret << " for " << + itemPub.alias); - ret = m_mgr->decrypt(algo, itemPrv.alias, itemPrv.policy.password, encrypted, decrypted); - ASSERT_MSG(ret == CKM_API_SUCCESS, "decrypt() failed iwth " << ret << " for " << itemPrv.alias); + ret = m_mgr->decrypt(algo, itemPrv.alias, itemPrv.policy.password, encrypted, + decrypted); + BOOST_REQUIRE_MESSAGE(ret == CKM_API_SUCCESS, + "decrypt() failed iwth " << ret << " for " << + itemPrv.alias); - ASSERT_MSG(decrypted == TEST_DATA, "Decrypted data not equal to original"); + BOOST_REQUIRE_MESSAGE(decrypted == TEST_DATA, + "Decrypted data not equal to original"); } void SchemeTest::CreateChainItem(const Item &leaf, const Items &certs) @@ -860,10 +895,13 @@ void SchemeTest::CreateChainItem(const Item &leaf, const Items &certs) CertificateShPtr leafCrt; int ret = m_mgr->getCertificate(leaf.alias, leaf.policy.password, leafCrt); - ASSERT_MSG(ret == CKM_API_SUCCESS, - "getCertificate failed with " << ret << " for " << leaf.alias); + BOOST_REQUIRE_MESSAGE(ret == CKM_API_SUCCESS, + "getCertificate failed with " << ret << " for " << + leaf.alias); ret = m_mgr->getCertificateChain(leafCrt, AliasVector(), trusted, false, chain); - ASSERT_MSG(ret == CKM_API_SUCCESS, "getCertificateChain() failed with " << ret); - ASSERT_MSG(chain.size() == CHAIN_LEN, "Wrong chain length: " << chain.size()); + BOOST_REQUIRE_MESSAGE(ret == CKM_API_SUCCESS, + "getCertificateChain() failed with " << ret); + BOOST_REQUIRE_MESSAGE(chain.size() == CHAIN_LEN, + "Wrong chain length: " << chain.size()); } diff --git a/tests/encryption-scheme/smack-access.cpp b/tests/encryption-scheme/smack-access.cpp index 960ea12..41a8ec0 100644 --- a/tests/encryption-scheme/smack-access.cpp +++ b/tests/encryption-scheme/smack-access.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000 - 2015 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2000 - 2018 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,14 +20,16 @@ * @version 1.0 */ -#include +#include -#include #include +#include + SmackAccess::SmackAccess() : m_handle(nullptr) { - ASSERT_MSG(smack_accesses_new(&m_handle) == 0, "smack_accesses_new failed"); + if (0 != smack_accesses_new(&m_handle)) + throw std::runtime_error("smack_accesses_new failed"); } void SmackAccess::add( @@ -35,13 +37,15 @@ void SmackAccess::add( const std::string &object, const std::string &rights) { - ASSERT_MSG(smack_accesses_add(m_handle, subject.c_str(), object.c_str(), rights.c_str()) == 0, - "smack_accesses_add failed"); + if (0 != smack_accesses_add(m_handle, subject.c_str(), object.c_str(), + rights.c_str())) + throw std::runtime_error("smack_accesses_add failed"); } void SmackAccess::apply() { - ASSERT_MSG(smack_accesses_apply(m_handle) == 0, "smack_accesses_apply failed"); + if (0 != smack_accesses_apply(m_handle)) + throw std::runtime_error("smack_accesses_apply failed"); } SmackAccess::~SmackAccess()