Fix failed test cases and make test common lib 03/69903/2
authorKyungwook Tak <k.tak@samsung.com>
Tue, 17 May 2016 08:38:35 +0000 (17:38 +0900)
committerKyungwook Tak <k.tak@samsung.com>
Tue, 17 May 2016 09:42:27 +0000 (18:42 +0900)
Test common library for all of test binaries

Change-Id: I41a72a170050e1c86662c5c75c0e1fc1b4ae131e
Signed-off-by: Kyungwook Tak <k.tak@samsung.com>
19 files changed:
CMakeLists.txt
packaging/csr-framework.spec
src/framework/service/app-deleter.cpp
src/framework/service/app-deleter.h
src/framework/service/cs-logic.cpp
src/framework/service/exception.h
src/framework/service/file-system.cpp
src/framework/service/file-system.h
test/CMakeLists.txt
test/internals/CMakeLists.txt
test/internals/test-file-system.cpp
test/popup/CMakeLists.txt
test/test-api-content-screening.cpp
test/test-api-engine-web-protection.cpp
test/test-api-web-protection.cpp
test/test-common.cpp
test/test-common.h
test/test-helper.cpp
test/test-helper.h

index 12bdbc8..bec7f1f 100644 (file)
@@ -60,6 +60,7 @@ SET(TARGET_CSR_POPUP ${SERVICE_NAME}-popup)
 SET(TARGET_CSR_CS_ENGINE_SAMPLE ${SERVICE_NAME}-cs-engine)
 SET(TARGET_CSR_WP_ENGINE_SAMPLE ${SERVICE_NAME}-wp-engine)
 SET(TARGET_CSR_TEST ${SERVICE_NAME}-test)
+SET(TARGET_CSR_TEST_COMMON ${SERVICE_NAME}-test-common)
 SET(TARGET_CSR_INTERNAL_TEST ${SERVICE_NAME}-internal-test)
 SET(TARGET_CSR_POPUP_TEST ${SERVICE_NAME}-popup-test)
 SET(TARGET_CSR_THREADPOOL_TEST ${SERVICE_NAME}-threadpool-test)
index 6878fd7..49d4969 100644 (file)
@@ -253,6 +253,7 @@ fi
 %manifest %{service_name}-test.manifest
 %{ro_data_dir}/license/%{name}-test
 %{ro_data_dir}/license/%{name}-test.BSL-1.0
+%{_libdir}/lib%{service_name}-test-common.so
 %attr(-, %{service_user}, %{service_group}) %{bin_dir}/%{service_name}-test
 %attr(-, %{service_user}, %{service_group}) %{bin_dir}/%{service_name}-internal-test
 %attr(-, %{service_user}, %{service_group}) %{bin_dir}/%{service_name}-popup-test
index c5c1f96..c8aaa0f 100644 (file)
@@ -82,7 +82,7 @@ static gboolean __app_uninstall_timeout(gpointer data)
 
 namespace Csr {
 
-bool AppDeleter::remove(const std::string &pkgid)
+void AppDeleter::remove(const std::string &pkgid)
 {
        if (pkgid.empty())
                ThrowExc(InternalError, "pkgid shouldn't be empty in AppDeleter");
@@ -98,17 +98,20 @@ bool AppDeleter::remove(const std::string &pkgid)
 
        LoopData data(loop.get(), pkgid);
 
-       if (pkgmgr_client_uninstall(client.get(), nullptr, pkgid.c_str(), PM_QUIET,
-                                                               ::__app_uninstall_cb, &data) <= PKGMGR_R_OK)
-               return false;
+       auto ret = pkgmgr_client_uninstall(client.get(), nullptr, pkgid.c_str(), PM_QUIET,
+                                                                          ::__app_uninstall_cb, &data);
+       if (ret <= PKGMGR_R_OK)
+               ThrowExc(RemoveFailed, "Failed to pkgmgr_client_uninstall for pkg: " << pkgid <<
+                                " ret: " << ret);
 
-       g_timeout_add_seconds(MAX_WAIT_SEC, __app_uninstall_timeout, &data);
+       g_timeout_add_seconds(MAX_WAIT_SEC, ::__app_uninstall_timeout, &data);
 
        g_main_loop_run(loop.get());
 
        DEBUG("App Removed. pkgid: " << pkgid);
 
-       return data.isDeleted;
+       if (!data.isDeleted)
+               ThrowExc(RemoveFailed, "Failed to remove app: " << pkgid);
 }
 
 } // namespace Csr
index 6b57cbe..750855d 100644 (file)
@@ -28,7 +28,7 @@ namespace Csr {
 class AppDeleter {
 public:
        AppDeleter() = delete;
-       static bool remove(const std::string &pkgid);
+       static void remove(const std::string &pkgid);
 };
 
 } // namespace Csr
index 8c28b9e..5a0d543 100644 (file)
@@ -365,6 +365,19 @@ RawBuffer CsLogic::judgeStatus(const std::string &filepath, csr_cs_action_e acti
 {
        EXCEPTION_GUARD_START
 
+       // for file existence / status check. exception thrown.
+       FilePtr file;
+       try {
+               file = File::create(filepath);
+       } catch (const Exception &e) {
+               ERROR("file system related exception occured on file: " << filepath <<
+                         " let's refresh detected malware history...");
+
+               this->m_db.deleteDetectedMalware(filepath);
+
+               throw;
+       }
+
        auto history = this->m_db.getDetectedMalware(filepath);
 
        if (!history) {
@@ -372,31 +385,18 @@ RawBuffer CsLogic::judgeStatus(const std::string &filepath, csr_cs_action_e acti
                return BinaryQueue::Serialize(CSR_ERROR_INVALID_PARAMETER).pop();
        }
 
-       auto fileptr = File::create(filepath, static_cast<time_t>(history->ts));
-
-       if (fileptr) {
-               ERROR("Target modified since db delta inserted. name: " << filepath);
+       // TODO: make isModifiedSince member function to File class
+       //       not to regenerate like this.
+       if (File::create(filepath, static_cast<time_t>(history->ts))) {
                this->m_db.deleteDetectedMalware(filepath);
 
-               // TODO: is it okay to just refresh db and return success?
-               return BinaryQueue::Serialize(CSR_ERROR_NONE).pop();
+               ThrowExc(FileSystemError, "Target modified since db delta inserted. "
+                                "name: " << filepath);
        }
 
        switch (action) {
        case CSR_CS_ACTION_REMOVE:
-               try {
-                       auto file = File::create(filepath);
-
-                       if (!file && !file->remove()) {
-                               ERROR("Failed to remove filepath: " << filepath);
-                               return BinaryQueue::Serialize(CSR_ERROR_REMOVE_FAILED).pop();
-                       }
-               } catch (const FileDoNotExist &) {
-                       WARN("File already removed... : " << filepath);
-               } catch (const FileSystemError &) {
-                       WARN("File type is changed... it's considered as different file "
-                                "in same path: " << filepath);
-               }
+               file->remove();
 
                this->m_db.deleteDetectedMalware(filepath);
                break;
@@ -524,14 +524,11 @@ RawBuffer CsLogic::handleUserResponse(const CsDetected &d, FilePtr &&fileptr)
                        else
                                _fileptr = File::create(d.targetName);
 
-                       if (!_fileptr->remove()) {
-                               ERROR("Failed to remove file: " << d.targetName);
-                               return BinaryQueue::Serialize(CSR_ERROR_REMOVE_FAILED, d).pop();
-                       }
+                       _fileptr->remove();
                } catch (const FileDoNotExist &) {
                        WARN("File already removed.: " << d.targetName);
                } catch (const FileSystemError &) {
-                       WARN("File type is changed. it's considered as different file: " << d.targetName);
+                       WARN("File type is changed, considered as different file: " << d.targetName);
                }
 
                this->m_db.deleteDetectedMalware(d.targetName);
index 3feddee..c9a27b1 100644 (file)
@@ -30,5 +30,6 @@ using DbFailed           = DerivedException<CSR_ERROR_DB>;
 using EngineError        = DerivedException<CSR_ERROR_ENGINE_INTERNAL>;
 using EngineNotActivated = DerivedException<CSR_ERROR_ENGINE_NOT_ACTIVATED>;
 using EnginePermDenied   = DerivedException<CSR_ERROR_ENGINE_PERMISSION>;
+using RemoveFailed       = DerivedException<CSR_ERROR_REMOVE_FAILED>;
 
 }
index 76ba33d..3d9e234 100644 (file)
@@ -129,12 +129,16 @@ const std::string &File::getAppPkgPath() const
        return m_appPkgPath;
 }
 
-bool File::remove() const
+void File::remove() const
 {
-       if (m_inApp)
-               return AppDeleter::remove(m_appPkgId);
-       else
-               return ::remove(m_path.c_str()) == 0;
+       if (m_inApp) {
+               DEBUG("remove app: " << m_appPkgId);
+               AppDeleter::remove(m_appPkgId);
+       } else {
+               DEBUG("remove file: " << m_path);
+               if (::remove(m_path.c_str()) != 0)
+                       ThrowExc(RemoveFailed, "Failed to remove file: " << m_path);
+       }
 }
 
 FilePtr File::create(const std::string &fpath, time_t modifiedSince)
index 9fbff6e..a64997a 100644 (file)
@@ -47,7 +47,7 @@ public:
        const std::string &getAppUser() const;
        const std::string &getAppPkgPath() const;
 
-       bool remove() const;
+       void remove() const;
 
        // throws FileNotExist and FileSystemError
        static FilePtr create(const std::string &fpath, time_t modifiedSince = -1);
index a03d518..ee43719 100755 (executable)
@@ -20,15 +20,50 @@ FIND_PACKAGE(Threads REQUIRED)
 ADD_DEFINITIONS("-DBOOST_TEST_DYN_LINK")
 ADD_DEFINITIONS("-DTEST_TARGET=\"${TEST_TARGET}\"")
 
-PKG_CHECK_MODULES(${TARGET_CSR_TEST}_DEP
+################### make test common library ##################
+PKG_CHECK_MODULES(${TARGET_CSR_TEST_COMMON}_DEP
        REQUIRED
        glib-2.0
        pkgmgr
        pkgmgr-info
 )
 
-SET(${TARGET_CSR_TEST}_SRCS
+SET(${TARGET_CSR_TEST_COMMON}_SRCS
+       test-common.cpp
        colour_log_formatter.cpp
+)
+
+INCLUDE_DIRECTORIES(
+       SYSTEM
+       ${${TARGET_CSR_TEST_COMMON}_DEP_INCLUDE_DIRS}
+)
+
+INCLUDE_DIRECTORIES(
+       ${PROJECT_SOURCE_DIR}/src/include
+       .
+)
+
+ADD_LIBRARY(${TARGET_CSR_TEST_COMMON} SHARED ${${TARGET_CSR_TEST_COMMON}_SRCS})
+
+SET_TARGET_PROPERTIES(${TARGET_CSR_TEST_COMMON}
+       PROPERTIES
+               COMPILE_FLAGS "-D_GNU_SOURCE -fvisibility=default"
+)
+
+TARGET_LINK_LIBRARIES(${TARGET_CSR_TEST_COMMON}
+       ${${TARGET_CSR_TEST_COMMON}_DEP_LIBRARIES}
+       ${TARGET_CSR_CLIENT}
+)
+
+INSTALL(TARGETS ${TARGET_CSR_TEST_COMMON} DESTINATION ${LIB_INSTALL_DIR})
+#################################################################
+
+###################### make api test program ####################
+PKG_CHECK_MODULES(${TARGET_CSR_TEST}_DEP
+       REQUIRED
+)
+
+SET(${TARGET_CSR_TEST}_SRCS
        test-api-content-screening.cpp
        test-api-content-screening-async.cpp
        test-api-engine-manager.cpp
@@ -36,19 +71,23 @@ SET(${TARGET_CSR_TEST}_SRCS
        test-api-engine-content-screening.cpp
        test-api-engine-web-protection.cpp
        test-main.cpp
-       test-common.cpp
        test-helper.cpp
 )
 
 INCLUDE_DIRECTORIES(
-       ${PROJECT_SOURCE_DIR}/src/include
-       ./
+       SYSTEM
        ${${TARGET_CSR_TEST}_DEP_INCLUDE_DIRS}
 )
 
+INCLUDE_DIRECTORIES(
+       ${PROJECT_SOURCE_DIR}/src/include
+       .
+)
+
 ADD_EXECUTABLE(${TARGET_CSR_TEST} ${${TARGET_CSR_TEST}_SRCS})
 
 TARGET_LINK_LIBRARIES(${TARGET_CSR_TEST}
+       ${TARGET_CSR_TEST_COMMON}
        ${TARGET_CSR_CLIENT}
        ${TARGET_CSR_CS_ENGINE_SAMPLE}
        ${TARGET_CSR_WP_ENGINE_SAMPLE}
@@ -63,3 +102,4 @@ INSTALL(DIRECTORY resources/ DESTINATION ${TEST_DIR})
 ADD_SUBDIRECTORY(internals)
 ADD_SUBDIRECTORY(popup)
 ADD_SUBDIRECTORY(thread-pool)
+#################################################################
index 0932ae4..ce84411 100644 (file)
@@ -25,17 +25,10 @@ SET(CSR_FW_SRC_PATH ${PROJECT_SOURCE_DIR}/src/framework)
 PKG_CHECK_MODULES(${TARGET_CSR_INTERNAL_TEST}_DEP
        REQUIRED
        sqlite3
-       glib-2.0
-       pkgmgr
-       pkgmgr-info
 )
 
 SET(${TARGET_CSR_INTERNAL_TEST}_SRCS
-       ${CSR_TEST_SRC_PATH}/colour_log_formatter.cpp
-       ${CSR_TEST_SRC_PATH}/test-common.cpp
-
        ${CSR_FW_SRC_PATH}/common/exception.cpp
-
        ${CSR_FW_SRC_PATH}/db/connection.cpp
        ${CSR_FW_SRC_PATH}/db/statement.cpp
        ${CSR_FW_SRC_PATH}/db/manager.cpp
@@ -68,6 +61,7 @@ INCLUDE_DIRECTORIES(
 ADD_EXECUTABLE(${TARGET_CSR_INTERNAL_TEST} ${${TARGET_CSR_INTERNAL_TEST}_SRCS})
 
 TARGET_LINK_LIBRARIES(${TARGET_CSR_INTERNAL_TEST}
+       ${TARGET_CSR_TEST_COMMON}
        ${TARGET_CSR_COMMON}
        ${${TARGET_CSR_INTERNAL_TEST}_DEP_LIBRARIES}
        -lboost_unit_test_framework
index 6bdf1c3..2cdb95a 100644 (file)
@@ -47,37 +47,6 @@ using namespace Csr;
 
 namespace {
 
-bool installed;
-GMainLoop *mainLoop;
-int __app_install_cb(int req_id, const char *pkg_type, const char *pkgid,
-                                        const char *key, const char *val, const void *pmsg, void *data)
-{
-       (void) req_id;
-       (void) pkg_type;
-       (void) pkgid;
-       (void) pmsg;
-       (void) data;
-
-       installed = false;
-
-       if (key && strncmp(key, "end", strlen("end")) == 0) {
-               if (strncmp(val, "ok", strlen("ok")) == 0) {
-                       installed = true;
-                       g_main_loop_quit(mainLoop);
-                       g_main_loop_unref(mainLoop);
-               }
-       }
-
-       return 0;
-}
-
-gboolean __app_uninstall_timeout(gpointer)
-{
-       installed = false;
-
-       return TRUE;
-}
-
 void __assertFile(const File &file, const std::string &path,
                                  const std::string &user,
                                  const std::string &pkgId, const std::string &pkgPath, bool inApp)
@@ -163,48 +132,44 @@ BOOST_AUTO_TEST_CASE(check_in_app)
 
 BOOST_AUTO_TEST_CASE(remove_file)
 {
+       EXCEPTION_GUARD_START
+
        std::string fpath = "/tmp/test.txt";
 
        __createFile(fpath);
 
        auto file = File::create(fpath);
-       BOOST_REQUIRE_MESSAGE(file->remove(), "Faile to remove file. path=" << fpath);
+       BOOST_REQUIRE_NO_THROW(file->remove());
 
        bool isRemoved = access(fpath.c_str(), F_OK) != 0 && errno == ENOENT;
        __removeFile(fpath);
 
        BOOST_REQUIRE_MESSAGE(isRemoved, "file remove done but file still exist...");
+
+       EXCEPTION_GUARD_END
 }
 
 BOOST_AUTO_TEST_CASE(remove_app)
 {
+       EXCEPTION_GUARD_START
+
        std::string fpath =
                "/opt/usr/apps/org.example.maliciousapp/shared/res/maliciousapp.png";
-       std::string appPath = TEST_APP_PKG;
 
        // install the test app
-       auto pkgmgr = pkgmgr_client_new(PC_REQUEST);
-       CHECK_IS_NOT_NULL(pkgmgr);
-
-       int ret = pkgmgr_client_install(pkgmgr, nullptr, nullptr,
-                                                                       appPath.c_str(), nullptr, PM_QUIET, ::__app_install_cb, nullptr);
-       BOOST_REQUIRE_MESSAGE(ret > PKGMGR_R_OK,
-                                                 std::string("expected>") << PKGMGR_R_OK << ", actual=" << ret);
-       g_timeout_add_seconds(30, __app_uninstall_timeout, this);
-       mainLoop = g_main_loop_new(nullptr, false);
-       g_main_loop_run(mainLoop);
-       pkgmgr_client_free(pkgmgr);
-       BOOST_REQUIRE_MESSAGE(installed, "fail to install test app");
+       BOOST_REQUIRE(Test::install_app(TEST_APP_PKG, "TPK"));
 
        // remove the app
        auto app = File::create(fpath);
        CHECK_IS_NOT_NULL(app);
-       BOOST_REQUIRE_MESSAGE(app->remove(), "Faile to remove app. path=" << fpath);
+       BOOST_REQUIRE_NO_THROW(app->remove());
 
        // check if the app still exists
        pkgmgrinfo_pkginfo_h handle;
-       ret = pkgmgrinfo_pkginfo_get_pkginfo(app->getAppPkgId().c_str(), &handle);
-       BOOST_REQUIRE(ret < PKGMGR_R_OK);
+       BOOST_REQUIRE(pkgmgrinfo_pkginfo_get_pkginfo(app->getAppPkgId().c_str(), &handle)
+                                 < PKGMGR_R_OK);
+
+       EXCEPTION_GUARD_END
 }
 
 BOOST_AUTO_TEST_CASE(file_visitor_positive_existing)
index 4f2e7e2..c414fb9 100644 (file)
@@ -23,8 +23,6 @@ PKG_CHECK_MODULES(${TARGET_CSR_POPUP_TEST}_DEP
 SET(${TARGET_CSR_POPUP_TEST}_SRCS
        ${PROJECT_SOURCE_DIR}/src/framework/ui/askuser.cpp
        ${PROJECT_SOURCE_DIR}/src/framework/ui/common.cpp
-       ${PROJECT_SOURCE_DIR}/test/colour_log_formatter.cpp
-       ${PROJECT_SOURCE_DIR}/test/test-common.cpp
        test-main.cpp
        test-popup.cpp
 )
@@ -40,6 +38,7 @@ INCLUDE_DIRECTORIES(
 ADD_EXECUTABLE(${TARGET_CSR_POPUP_TEST} ${${TARGET_CSR_POPUP_TEST}_SRCS})
 
 TARGET_LINK_LIBRARIES(${TARGET_CSR_POPUP_TEST}
+       ${TARGET_CSR_TEST_COMMON}
        ${TARGET_CSR_COMMON}
        -lboost_unit_test_framework
        -ldl
index 7c3ca95..4d82bb5 100644 (file)
@@ -75,8 +75,7 @@ BOOST_AUTO_TEST_CASE(context_create_destroy)
 {
        EXCEPTION_GUARD_START
 
-       auto c = Test::Context<csr_cs_context_h>();
-       (void) c;
+       Test::Context<csr_cs_context_h>();
 
        EXCEPTION_GUARD_END
 }
@@ -88,17 +87,17 @@ BOOST_AUTO_TEST_CASE(set_values_to_context_positive)
        auto c = Test::Context<csr_cs_context_h>();
        auto context = c.get();
 
-       ASSERT_IF(csr_cs_set_ask_user(context, CSR_CS_NOT_ASK_USER), CSR_ERROR_NONE);
-       ASSERT_IF(csr_cs_set_ask_user(context, CSR_CS_ASK_USER), CSR_ERROR_NONE);
+       ASSERT_SUCCESS(csr_cs_set_ask_user(context, CSR_CS_NOT_ASK_USER));
+       ASSERT_SUCCESS(csr_cs_set_ask_user(context, CSR_CS_ASK_USER));
 
-       ASSERT_IF(csr_cs_set_popup_message(context, "Test popup message"), CSR_ERROR_NONE);
+       ASSERT_SUCCESS(csr_cs_set_popup_message(context, "Test popup message"));
 
-       ASSERT_IF(csr_cs_set_core_usage(context, CSR_CS_USE_CORE_DEFAULT), CSR_ERROR_NONE);
-       ASSERT_IF(csr_cs_set_core_usage(context, CSR_CS_USE_CORE_ALL), CSR_ERROR_NONE);
-       ASSERT_IF(csr_cs_set_core_usage(context, CSR_CS_USE_CORE_HALF), CSR_ERROR_NONE);
-       ASSERT_IF(csr_cs_set_core_usage(context, CSR_CS_USE_CORE_SINGLE), CSR_ERROR_NONE);
+       ASSERT_SUCCESS(csr_cs_set_core_usage(context, CSR_CS_USE_CORE_DEFAULT));
+       ASSERT_SUCCESS(csr_cs_set_core_usage(context, CSR_CS_USE_CORE_ALL));
+       ASSERT_SUCCESS(csr_cs_set_core_usage(context, CSR_CS_USE_CORE_HALF));
+       ASSERT_SUCCESS(csr_cs_set_core_usage(context, CSR_CS_USE_CORE_SINGLE));
 
-       ASSERT_IF(csr_cs_set_scan_on_cloud(context), CSR_ERROR_NONE);
+       ASSERT_SUCCESS(csr_cs_set_scan_on_cloud(context));
 
        EXCEPTION_GUARD_END
 }
@@ -133,7 +132,7 @@ BOOST_AUTO_TEST_CASE(scan_data_normal)
        unsigned char data[100] = {0, };
 
        // no malware detected
-       ASSERT_IF(csr_cs_scan_data(context, data, sizeof(data), &detected), CSR_ERROR_NONE);
+       ASSERT_SUCCESS(csr_cs_scan_data(context, data, sizeof(data), &detected));
 
        CHECK_IS_NULL(detected);
 
@@ -152,10 +151,11 @@ BOOST_AUTO_TEST_CASE(scan_data_high)
 
        // severity high detected
        memcpy(data, MALWARE_HIGH_SIGNATURE, strlen(MALWARE_HIGH_SIGNATURE));
-       ASSERT_IF(csr_cs_scan_data(context, data, sizeof(data), &detected), CSR_ERROR_NONE);
+       ASSERT_SUCCESS(csr_cs_scan_data(context, data, sizeof(data), &detected));
 
        CHECK_IS_NOT_NULL(detected);
-       ASSERT_DETECTED(detected, MALWARE_HIGH_NAME, MALWARE_HIGH_SEVERITY, MALWARE_HIGH_DETAILED_URL);
+       ASSERT_DETECTED(detected, MALWARE_HIGH_NAME, MALWARE_HIGH_SEVERITY,
+                                       MALWARE_HIGH_DETAILED_URL);
        ASSERT_DETECTED_EXT(detected, start_time, nullptr, false, nullptr);
 
        EXCEPTION_GUARD_END
@@ -173,10 +173,11 @@ BOOST_AUTO_TEST_CASE(scan_data_medium)
 
        // severity medium detected
        memcpy(data, MALWARE_MEDIUM_SIGNATURE, strlen(MALWARE_MEDIUM_SIGNATURE));
-       ASSERT_IF(csr_cs_scan_data(context, data, sizeof(data), &detected), CSR_ERROR_NONE);
+       ASSERT_SUCCESS(csr_cs_scan_data(context, data, sizeof(data), &detected));
 
        CHECK_IS_NOT_NULL(detected);
-       ASSERT_DETECTED(detected, MALWARE_MEDIUM_NAME, MALWARE_MEDIUM_SEVERITY, MALWARE_MEDIUM_DETAILED_URL);
+       ASSERT_DETECTED(detected, MALWARE_MEDIUM_NAME, MALWARE_MEDIUM_SEVERITY,
+                                       MALWARE_MEDIUM_DETAILED_URL);
        ASSERT_DETECTED_EXT(detected, start_time, nullptr, false, nullptr);
 
        EXCEPTION_GUARD_END
@@ -194,10 +195,11 @@ BOOST_AUTO_TEST_CASE(scan_data_low)
 
        // severity low detected
        memcpy(data, MALWARE_LOW_SIGNATURE, strlen(MALWARE_LOW_SIGNATURE));
-       ASSERT_IF(csr_cs_scan_data(context, data, sizeof(data), &detected), CSR_ERROR_NONE);
+       ASSERT_SUCCESS(csr_cs_scan_data(context, data, sizeof(data), &detected));
 
        CHECK_IS_NOT_NULL(detected);
-       ASSERT_DETECTED(detected, MALWARE_LOW_NAME, MALWARE_LOW_SEVERITY, MALWARE_LOW_DETAILED_URL);
+       ASSERT_DETECTED(detected, MALWARE_LOW_NAME, MALWARE_LOW_SEVERITY,
+                                       MALWARE_LOW_DETAILED_URL);
        ASSERT_DETECTED_EXT(detected, start_time, nullptr, false, nullptr);
 
        EXCEPTION_GUARD_END
@@ -212,11 +214,14 @@ BOOST_AUTO_TEST_CASE(scan_data_negative)
        csr_cs_detected_h detected;
        unsigned char data[100] = {0, };
 
-       ASSERT_IF(csr_cs_scan_data(nullptr, data, sizeof(data), &detected), CSR_ERROR_INVALID_HANDLE);
+       ASSERT_IF(csr_cs_scan_data(nullptr, data, sizeof(data), &detected),
+                         CSR_ERROR_INVALID_HANDLE);
 
-       ASSERT_IF(csr_cs_scan_data(context, nullptr, sizeof(data), &detected), CSR_ERROR_INVALID_PARAMETER);
+       ASSERT_IF(csr_cs_scan_data(context, nullptr, sizeof(data), &detected),
+                         CSR_ERROR_INVALID_PARAMETER);
 
-       ASSERT_IF(csr_cs_scan_data(context, data, sizeof(data), nullptr),  CSR_ERROR_INVALID_PARAMETER);
+       ASSERT_IF(csr_cs_scan_data(context, data, sizeof(data), nullptr),
+                         CSR_ERROR_INVALID_PARAMETER);
 
        EXCEPTION_GUARD_END
 }
@@ -229,7 +234,7 @@ BOOST_AUTO_TEST_CASE(scan_file_normal)
        auto context = c.get();
        csr_cs_detected_h detected;
 
-       ASSERT_IF(csr_cs_scan_file(context, TEST_FILE_NORMAL, &detected), CSR_ERROR_NONE);
+       ASSERT_SUCCESS(csr_cs_scan_file(context, TEST_FILE_NORMAL, &detected));
 
        // no malware detected
        CHECK_IS_NULL(detected);
@@ -246,12 +251,13 @@ BOOST_AUTO_TEST_CASE(scan_file_high)
        csr_cs_detected_h detected;
        time_t start_time = time(nullptr);
 
-       touch_file(TEST_FILE_HIGH);
+       Test::touch_file(TEST_FILE_HIGH);
 
-       ASSERT_IF(csr_cs_scan_file(context, TEST_FILE_HIGH, &detected), CSR_ERROR_NONE);
+       ASSERT_SUCCESS(csr_cs_scan_file(context, TEST_FILE_HIGH, &detected));
 
        CHECK_IS_NOT_NULL(detected);
-       ASSERT_DETECTED(detected, MALWARE_HIGH_NAME, MALWARE_HIGH_SEVERITY, MALWARE_HIGH_DETAILED_URL);
+       ASSERT_DETECTED(detected, MALWARE_HIGH_NAME, MALWARE_HIGH_SEVERITY,
+                                       MALWARE_HIGH_DETAILED_URL);
        ASSERT_DETECTED_EXT(detected, start_time, TEST_FILE_HIGH, false, nullptr);
 
        EXCEPTION_GUARD_END
@@ -266,12 +272,13 @@ BOOST_AUTO_TEST_CASE(scan_file_medium)
        csr_cs_detected_h detected;
        time_t start_time = time(nullptr);
 
-       touch_file(TEST_FILE_MEDIUM);
+       Test::touch_file(TEST_FILE_MEDIUM);
 
-       ASSERT_IF(csr_cs_scan_file(context, TEST_FILE_MEDIUM, &detected), CSR_ERROR_NONE);
+       ASSERT_SUCCESS(csr_cs_scan_file(context, TEST_FILE_MEDIUM, &detected));
 
        CHECK_IS_NOT_NULL(detected);
-       ASSERT_DETECTED(detected, MALWARE_MEDIUM_NAME, MALWARE_MEDIUM_SEVERITY, MALWARE_MEDIUM_DETAILED_URL);
+       ASSERT_DETECTED(detected, MALWARE_MEDIUM_NAME, MALWARE_MEDIUM_SEVERITY,
+                                       MALWARE_MEDIUM_DETAILED_URL);
        ASSERT_DETECTED_EXT(detected, start_time, TEST_FILE_MEDIUM, false, nullptr);
 
        EXCEPTION_GUARD_END
@@ -286,12 +293,13 @@ BOOST_AUTO_TEST_CASE(scan_file_low)
        csr_cs_detected_h detected;
        time_t start_time = time(nullptr);
 
-       touch_file(TEST_FILE_LOW);
+       Test::touch_file(TEST_FILE_LOW);
 
-       ASSERT_IF(csr_cs_scan_file(context, TEST_FILE_LOW, &detected), CSR_ERROR_NONE);
+       ASSERT_SUCCESS(csr_cs_scan_file(context, TEST_FILE_LOW, &detected));
 
        CHECK_IS_NOT_NULL(detected);
-       ASSERT_DETECTED(detected, MALWARE_LOW_NAME, MALWARE_LOW_SEVERITY, MALWARE_LOW_DETAILED_URL);
+       ASSERT_DETECTED(detected, MALWARE_LOW_NAME, MALWARE_LOW_SEVERITY,
+                                       MALWARE_LOW_DETAILED_URL);
        ASSERT_DETECTED_EXT(detected, start_time, TEST_FILE_LOW, false, nullptr);
 
        EXCEPTION_GUARD_END
@@ -306,12 +314,13 @@ BOOST_AUTO_TEST_CASE(scan_file_media_dir)
        csr_cs_detected_h detected;
        time_t start_time = time(nullptr);
 
-       copy_file(TEST_FILE_HIGH, TEST_FILE_MEDIA);
+       Test::copy_file(TEST_FILE_HIGH, TEST_FILE_MEDIA);
 
-       ASSERT_IF(csr_cs_scan_file(context, TEST_FILE_MEDIA, &detected), CSR_ERROR_NONE);
+       ASSERT_SUCCESS(csr_cs_scan_file(context, TEST_FILE_MEDIA, &detected));
 
        CHECK_IS_NOT_NULL(detected);
-       ASSERT_DETECTED(detected, MALWARE_HIGH_NAME, MALWARE_HIGH_SEVERITY, MALWARE_HIGH_DETAILED_URL);
+       ASSERT_DETECTED(detected, MALWARE_HIGH_NAME, MALWARE_HIGH_SEVERITY,
+                                       MALWARE_HIGH_DETAILED_URL);
        ASSERT_DETECTED_EXT(detected, start_time, TEST_FILE_MEDIA, false, nullptr);
 
        EXCEPTION_GUARD_END
@@ -326,12 +335,13 @@ BOOST_AUTO_TEST_CASE(scan_file_tmp_dir)
        csr_cs_detected_h detected;
        time_t start_time = time(nullptr);
 
-       copy_file(TEST_FILE_HIGH, TEST_FILE_TMP);
+       Test::copy_file(TEST_FILE_HIGH, TEST_FILE_TMP);
 
-       ASSERT_IF(csr_cs_scan_file(context, TEST_FILE_TMP, &detected), CSR_ERROR_NONE);
+       ASSERT_SUCCESS(csr_cs_scan_file(context, TEST_FILE_TMP, &detected));
 
        CHECK_IS_NOT_NULL(detected);
-       ASSERT_DETECTED(detected, MALWARE_HIGH_NAME, MALWARE_HIGH_SEVERITY, MALWARE_HIGH_DETAILED_URL);
+       ASSERT_DETECTED(detected, MALWARE_HIGH_NAME, MALWARE_HIGH_SEVERITY,
+                                       MALWARE_HIGH_DETAILED_URL);
        ASSERT_DETECTED_EXT(detected, start_time, TEST_FILE_TMP, false, nullptr);
 
        EXCEPTION_GUARD_END
@@ -347,16 +357,17 @@ BOOST_AUTO_TEST_CASE(scan_file_wgt_dir)
        csr_cs_detected_h detected;
        time_t start_time = time(nullptr);
 
-       uninstall_app(TEST_WGT_PKG_ID);
-       BOOST_REQUIRE_MESSAGE(install_app(TEST_WGT_PATH, TEST_WGT_TYPE) == true, "FAIL TO INSTALL.");
+       Test::uninstall_app(TEST_WGT_PKG_ID);
+       ASSERT_INSTALL_APP(TEST_WGT_PATH, TEST_WGT_TYPE);
 
-       ASSERT_IF(csr_cs_scan_file(context, TEST_WGT_MAL_FILE, &detected), CSR_ERROR_NONE);
+       ASSERT_SUCCESS(csr_cs_scan_file(context, TEST_WGT_MAL_FILE, &detected));
 
        CHECK_IS_NOT_NULL(detected);
-       ASSERT_DETECTED(detected, MALWARE_HIGH_NAME, MALWARE_HIGH_SEVERITY, MALWARE_HIGH_DETAILED_URL);
+       ASSERT_DETECTED(detected, MALWARE_HIGH_NAME, MALWARE_HIGH_SEVERITY,
+                                       MALWARE_HIGH_DETAILED_URL);
        ASSERT_DETECTED_EXT(detected, start_time, TEST_WGT_APP_ROOT, true, TEST_WGT_PKG_ID);
 
-       BOOST_REQUIRE_MESSAGE(uninstall_app(TEST_WGT_PKG_ID) == true, "FAIL TO UNINSTALL.");
+       ASSERT_UNINSTALL_APP(TEST_WGT_PKG_ID);
 
        EXCEPTION_GUARD_END
 }
@@ -371,16 +382,17 @@ BOOST_AUTO_TEST_CASE(scan_file_tpk_dir)
        csr_cs_detected_h detected;
        time_t start_time = time(nullptr);
 
-       uninstall_app(TEST_TPK_PKG_ID);
-       BOOST_REQUIRE_MESSAGE(install_app(TEST_TPK_PATH, TEST_TPK_TYPE) == true, "FAIL TO INSTALL.");
+       Test::uninstall_app(TEST_TPK_PKG_ID);
+       ASSERT_INSTALL_APP(TEST_TPK_PATH, TEST_TPK_TYPE);
 
-       ASSERT_IF(csr_cs_scan_file(context, TEST_TPK_MAL_FILE, &detected), CSR_ERROR_NONE);
+       ASSERT_SUCCESS(csr_cs_scan_file(context, TEST_TPK_MAL_FILE, &detected));
 
        CHECK_IS_NOT_NULL(detected);
-       ASSERT_DETECTED(detected, MALWARE_HIGH_NAME, MALWARE_HIGH_SEVERITY, MALWARE_HIGH_DETAILED_URL);
+       ASSERT_DETECTED(detected, MALWARE_HIGH_NAME, MALWARE_HIGH_SEVERITY,
+                                       MALWARE_HIGH_DETAILED_URL);
        ASSERT_DETECTED_EXT(detected, start_time, TEST_TPK_APP_ROOT, true, TEST_TPK_PKG_ID);
 
-       BOOST_REQUIRE_MESSAGE(uninstall_app(TEST_TPK_PKG_ID) == true, "FAIL TO UNINSTALL.");
+       ASSERT_UNINSTALL_APP(TEST_TPK_PKG_ID);
 
        EXCEPTION_GUARD_END
 }
@@ -394,11 +406,11 @@ BOOST_AUTO_TEST_CASE(scan_file_invalid_params)
        auto context = c.get();
        csr_cs_detected_h detected;
 
-       ASSERT_IF(csr_cs_scan_file(nullptr, TEST_FILE_NORMAL, &detected), CSR_ERROR_INVALID_HANDLE);
-
+       ASSERT_IF(csr_cs_scan_file(nullptr, TEST_FILE_NORMAL, &detected),
+                         CSR_ERROR_INVALID_HANDLE);
        ASSERT_IF(csr_cs_scan_file(context, nullptr, &detected), CSR_ERROR_INVALID_PARAMETER);
-
-       ASSERT_IF(csr_cs_scan_file(context, TEST_FILE_NORMAL, nullptr), CSR_ERROR_INVALID_PARAMETER);
+       ASSERT_IF(csr_cs_scan_file(context, TEST_FILE_NORMAL, nullptr),
+                         CSR_ERROR_INVALID_PARAMETER);
 
        EXCEPTION_GUARD_END
 }
@@ -411,7 +423,8 @@ BOOST_AUTO_TEST_CASE(scan_file_not_existing_file)
        auto context = c.get();
        csr_cs_detected_h detected;
 
-       ASSERT_IF(csr_cs_scan_file(context, TEST_FILE_NO_EXIST, &detected), CSR_ERROR_FILE_DO_NOT_EXIST);
+       ASSERT_IF(csr_cs_scan_file(context, TEST_FILE_NO_EXIST, &detected),
+                         CSR_ERROR_FILE_DO_NOT_EXIST);
 
        EXCEPTION_GUARD_END
 }
@@ -425,11 +438,10 @@ BOOST_AUTO_TEST_CASE(get_detected_malware)
        csr_cs_detected_h detected;
        csr_cs_detected_h stored;
 
-       ASSERT_IF(csr_cs_scan_file(context, TEST_FILE_MEDIUM, &detected), CSR_ERROR_NONE);
+       ASSERT_SUCCESS(csr_cs_scan_file(context, TEST_FILE_MEDIUM, &detected));
        CHECK_IS_NOT_NULL(detected);
 
-       ASSERT_IF(csr_cs_get_detected_malware(context, TEST_FILE_MEDIUM, &stored),
-                         CSR_ERROR_NONE);
+       ASSERT_SUCCESS(csr_cs_get_detected_malware(context, TEST_FILE_MEDIUM, &stored));
        CHECK_IS_NOT_NULL(stored);
 
        ASSERT_DETECTED_HANDLE(detected, stored);
@@ -445,9 +457,12 @@ BOOST_AUTO_TEST_CASE(get_detected_malware_invalid_param)
        auto context = c.get();
        csr_cs_detected_h stored;
 
-       ASSERT_IF(csr_cs_get_detected_malware(nullptr, TEST_FILE_MEDIUM, &stored), CSR_ERROR_INVALID_HANDLE);
-       ASSERT_IF(csr_cs_get_detected_malware(context, nullptr, &stored), CSR_ERROR_INVALID_PARAMETER);
-       ASSERT_IF(csr_cs_get_detected_malware(context, TEST_FILE_MEDIUM, nullptr), CSR_ERROR_INVALID_PARAMETER);
+       ASSERT_IF(csr_cs_get_detected_malware(nullptr, TEST_FILE_MEDIUM, &stored),
+                         CSR_ERROR_INVALID_HANDLE);
+       ASSERT_IF(csr_cs_get_detected_malware(context, nullptr, &stored),
+                         CSR_ERROR_INVALID_PARAMETER);
+       ASSERT_IF(csr_cs_get_detected_malware(context, TEST_FILE_MEDIUM, nullptr),
+                         CSR_ERROR_INVALID_PARAMETER);
 
        EXCEPTION_GUARD_END;
 }
@@ -460,7 +475,7 @@ BOOST_AUTO_TEST_CASE(get_detected_malware_not_existing_file)
        auto context = c.get();
        csr_cs_detected_h stored;
 
-       ASSERT_IF(csr_cs_get_detected_malware(context, TEST_FILE_NO_EXIST, &stored), CSR_ERROR_NONE);
+       ASSERT_SUCCESS(csr_cs_get_detected_malware(context, TEST_FILE_NO_EXIST, &stored));
        CHECK_IS_NULL(stored);
 
        EXCEPTION_GUARD_END
@@ -484,20 +499,20 @@ BOOST_AUTO_TEST_CASE(get_detected_malwares)
                TEST_DIR
        };
 
-       ASSERT_IF(csr_cs_scan_file(context, TEST_FILE_HIGH, &detected_high), CSR_ERROR_NONE);
+       ASSERT_SUCCESS(csr_cs_scan_file(context, TEST_FILE_HIGH, &detected_high));
        CHECK_IS_NOT_NULL(detected_high);
-       ASSERT_IF(csr_cs_scan_file(context, TEST_FILE_MEDIUM, &detected_medium), CSR_ERROR_NONE);
+       ASSERT_SUCCESS(csr_cs_scan_file(context, TEST_FILE_MEDIUM, &detected_medium));
        CHECK_IS_NOT_NULL(detected_medium);
 
-       ASSERT_IF(csr_cs_get_detected_malwares(context, dirs,
-                                                                                  sizeof(dirs) / sizeof(const char *),
-                                                                                  &detected_list, &cnt), CSR_ERROR_NONE);
+       ASSERT_SUCCESS(csr_cs_get_detected_malwares(context, dirs,
+                                                                                               sizeof(dirs) / sizeof(const char *),
+                                                                                               &detected_list, &cnt));
        CHECK_IS_NOT_NULL(detected_list);
 
        for (idx = 0; idx < cnt; idx++) {
-               ASSERT_IF(csr_cs_dlist_get_detected(detected_list, idx, &stored), CSR_ERROR_NONE);
+               ASSERT_SUCCESS(csr_cs_dlist_get_detected(detected_list, idx, &stored));
                CHECK_IS_NOT_NULL(stored);
-               ASSERT_IF(csr_cs_detected_get_file_name(stored, &file_path_actual), CSR_ERROR_NONE);
+               ASSERT_SUCCESS(csr_cs_detected_get_file_name(stored, &file_path_actual));
                if (strcmp(TEST_FILE_HIGH, file_path_actual) == 0) {
                        ASSERT_DETECTED_HANDLE(detected_high, stored);
                        compared_cnt++;
@@ -528,14 +543,23 @@ BOOST_AUTO_TEST_CASE(get_detected_malwares_invalid_params)
                TEST_DIR
        };
 
-       ASSERT_IF(csr_cs_get_detected_malwares(nullptr, dirs, sizeof(dirs) / sizeof(const char *),
-                                                                                  &detected_list, &cnt), CSR_ERROR_INVALID_HANDLE);
-       ASSERT_IF(csr_cs_get_detected_malwares(context, nullptr, sizeof(dirs) / sizeof(const char *),
-                                                                                  &detected_list, &cnt), CSR_ERROR_INVALID_PARAMETER);
-       ASSERT_IF(csr_cs_get_detected_malwares(context, dirs, sizeof(dirs) / sizeof(const char *),
-                                                                                  nullptr, &cnt), CSR_ERROR_INVALID_PARAMETER);
-       ASSERT_IF(csr_cs_get_detected_malwares(context, dirs, sizeof(dirs) / sizeof(const char *),
-                                                                                  &detected_list, nullptr), CSR_ERROR_INVALID_PARAMETER);
+       ASSERT_IF(csr_cs_get_detected_malwares(nullptr, dirs,
+                                                                                  sizeof(dirs) / sizeof(const char *),
+                                                                                  &detected_list, &cnt),
+                         CSR_ERROR_INVALID_HANDLE);
+
+       ASSERT_IF(csr_cs_get_detected_malwares(context, nullptr,
+                                                                                  sizeof(dirs) / sizeof(const char *),
+                                                                                  &detected_list, &cnt),
+                         CSR_ERROR_INVALID_PARAMETER);
+       ASSERT_IF(csr_cs_get_detected_malwares(context, dirs,
+                                                                                  sizeof(dirs) / sizeof(const char *),
+                                                                                  nullptr, &cnt),
+                         CSR_ERROR_INVALID_PARAMETER);
+       ASSERT_IF(csr_cs_get_detected_malwares(context, dirs,
+                                                                                  sizeof(dirs) / sizeof(const char *),
+                                                                                  &detected_list, nullptr),
+                         CSR_ERROR_INVALID_PARAMETER);
 
        EXCEPTION_GUARD_END
 }
@@ -553,8 +577,9 @@ BOOST_AUTO_TEST_CASE(get_detected_malwares_not_existing_dir)
                TEST_FILE_NO_EXIST
        };
 
-       ASSERT_IF(csr_cs_get_detected_malwares(context, dirs, sizeof(dirs) / sizeof(const char *),
-                                                                                  &detected_list, &cnt), CSR_ERROR_NONE);
+       ASSERT_SUCCESS(csr_cs_get_detected_malwares(context, dirs,
+                                                                                               sizeof(dirs) / sizeof(const char *),
+                                                                                               &detected_list, &cnt));
 
        ASSERT_IF(cnt, static_cast<size_t>(0));
 
@@ -569,19 +594,20 @@ BOOST_AUTO_TEST_CASE(get_ignored_malware)
        auto context = c.get();
        csr_cs_detected_h detected, stored;
 
-       ASSERT_IF(csr_cs_scan_file(context, TEST_FILE_HIGH, &detected), CSR_ERROR_NONE);
+       ASSERT_SUCCESS(csr_cs_scan_file(context, TEST_FILE_HIGH, &detected));
        CHECK_IS_NOT_NULL(detected);
 
-       ASSERT_IF(csr_cs_judge_detected_malware(context, detected, CSR_CS_ACTION_IGNORE),
-                         CSR_ERROR_NONE);
+       ASSERT_SUCCESS(csr_cs_judge_detected_malware(context, detected, CSR_CS_ACTION_IGNORE));
 
-       ASSERT_IF(csr_cs_get_ignored_malware(context, TEST_FILE_HIGH, &stored),
-                         CSR_ERROR_NONE);
+       ASSERT_SUCCESS(csr_cs_get_ignored_malware(context, TEST_FILE_HIGH, &stored));
 
        CHECK_IS_NOT_NULL(stored);
 
        ASSERT_DETECTED_HANDLE(detected, stored);
 
+       // rollback to unignore
+       ASSERT_SUCCESS(csr_cs_judge_detected_malware(context, detected, CSR_CS_ACTION_UNIGNORE));
+
        EXCEPTION_GUARD_END
 }
 
@@ -593,9 +619,12 @@ BOOST_AUTO_TEST_CASE(get_ignored_malware_invalid_param)
        auto context = c.get();
        csr_cs_detected_h stored;
 
-       ASSERT_IF(csr_cs_get_ignored_malware(nullptr, TEST_FILE_MEDIUM, &stored), CSR_ERROR_INVALID_HANDLE);
-       ASSERT_IF(csr_cs_get_ignored_malware(context, nullptr, &stored), CSR_ERROR_INVALID_PARAMETER);
-       ASSERT_IF(csr_cs_get_ignored_malware(context, TEST_FILE_MEDIUM, nullptr), CSR_ERROR_INVALID_PARAMETER);
+       ASSERT_IF(csr_cs_get_ignored_malware(nullptr, TEST_FILE_MEDIUM, &stored),
+                         CSR_ERROR_INVALID_HANDLE);
+       ASSERT_IF(csr_cs_get_ignored_malware(context, nullptr, &stored),
+                         CSR_ERROR_INVALID_PARAMETER);
+       ASSERT_IF(csr_cs_get_ignored_malware(context, TEST_FILE_MEDIUM, nullptr),
+                         CSR_ERROR_INVALID_PARAMETER);
 
        EXCEPTION_GUARD_END
 }
@@ -608,7 +637,7 @@ BOOST_AUTO_TEST_CASE(get_ignored_malware_not_existing_file)
        auto context = c.get();
        csr_cs_detected_h stored;
 
-       ASSERT_IF(csr_cs_get_ignored_malware(context, TEST_FILE_NO_EXIST, &stored), CSR_ERROR_NONE);
+       ASSERT_SUCCESS(csr_cs_get_ignored_malware(context, TEST_FILE_NO_EXIST, &stored));
        CHECK_IS_NULL(stored);
 
        EXCEPTION_GUARD_END
@@ -631,25 +660,25 @@ BOOST_AUTO_TEST_CASE(get_ignored_malwares)
                TEST_DIR
        };
 
-       ASSERT_IF(csr_cs_scan_file(context, TEST_FILE_HIGH, &detected_high),
-                         CSR_ERROR_NONE);
+       ASSERT_SUCCESS(csr_cs_scan_file(context, TEST_FILE_HIGH, &detected_high));
        CHECK_IS_NOT_NULL(detected_high);
-       ASSERT_IF(csr_cs_judge_detected_malware(context, detected_high, CSR_CS_ACTION_IGNORE),
-                         CSR_ERROR_NONE);
-       ASSERT_IF(csr_cs_scan_file(context, TEST_FILE_MEDIUM, &detected_medium),
-                         CSR_ERROR_NONE);
+       ASSERT_SUCCESS(csr_cs_judge_detected_malware(context, detected_high,
+                                                                                                CSR_CS_ACTION_IGNORE));
+
+       ASSERT_SUCCESS(csr_cs_scan_file(context, TEST_FILE_MEDIUM, &detected_medium));
        CHECK_IS_NOT_NULL(detected_medium);
-       ASSERT_IF(csr_cs_judge_detected_malware(context, detected_medium, CSR_CS_ACTION_IGNORE),
-                         CSR_ERROR_NONE);
+       ASSERT_SUCCESS(csr_cs_judge_detected_malware(context, detected_medium,
+                                                                                                CSR_CS_ACTION_IGNORE));
 
-       ASSERT_IF(csr_cs_get_ignored_malwares(context, dirs, sizeof(dirs) / sizeof(const char *),
-                                                                                 &ignored_list, &cnt), CSR_ERROR_NONE);
+       ASSERT_SUCCESS(csr_cs_get_ignored_malwares(context, dirs,
+                                                                                               sizeof(dirs) / sizeof(const char *),
+                                                                                               &ignored_list, &cnt));
        CHECK_IS_NOT_NULL(ignored_list);
 
        for (idx = 0; idx < cnt; idx++) {
-               ASSERT_IF(csr_cs_dlist_get_detected(ignored_list, idx, &stored), CSR_ERROR_NONE);
+               ASSERT_SUCCESS(csr_cs_dlist_get_detected(ignored_list, idx, &stored));
                CHECK_IS_NOT_NULL(stored);
-               ASSERT_IF(csr_cs_detected_get_file_name(stored, &file_path_actual), CSR_ERROR_NONE);
+               ASSERT_SUCCESS(csr_cs_detected_get_file_name(stored, &file_path_actual));
                if (strcmp(TEST_FILE_HIGH, file_path_actual) == 0) {
                        ASSERT_DETECTED_HANDLE(detected_high, stored);
                        compared_cnt++;
@@ -663,6 +692,12 @@ BOOST_AUTO_TEST_CASE(get_ignored_malwares)
 
        ASSERT_IF(compared_cnt, static_cast<size_t>(2));
 
+       // rollback to unignore
+       ASSERT_SUCCESS(csr_cs_judge_detected_malware(context, detected_high,
+                                                                                                CSR_CS_ACTION_UNIGNORE));
+       ASSERT_SUCCESS(csr_cs_judge_detected_malware(context, detected_medium,
+                                                                                                CSR_CS_ACTION_UNIGNORE));
+
        EXCEPTION_GUARD_END
 }
 
@@ -679,14 +714,22 @@ BOOST_AUTO_TEST_CASE(get_ignored_malwares_invalid_params)
                TEST_DIR
        };
 
-       ASSERT_IF(csr_cs_get_ignored_malwares(nullptr, dirs, sizeof(dirs) / sizeof(const char *),
-                                                                                 &ignored_list, &cnt), CSR_ERROR_INVALID_HANDLE);
-       ASSERT_IF(csr_cs_get_ignored_malwares(context, nullptr, sizeof(dirs) / sizeof(const char *),
-                                                                                 &ignored_list, &cnt), CSR_ERROR_INVALID_PARAMETER);
-       ASSERT_IF(csr_cs_get_ignored_malwares(context, dirs, sizeof(dirs) / sizeof(const char *),
-                                                                                 nullptr, &cnt), CSR_ERROR_INVALID_PARAMETER);
-       ASSERT_IF(csr_cs_get_ignored_malwares(context, dirs, sizeof(dirs) / sizeof(const char *),
-                                                                                 &ignored_list, nullptr), CSR_ERROR_INVALID_PARAMETER);
+       ASSERT_IF(csr_cs_get_ignored_malwares(nullptr, dirs,
+                                                                                 sizeof(dirs) / sizeof(const char *),
+                                                                                 &ignored_list, &cnt),
+                         CSR_ERROR_INVALID_HANDLE);
+       ASSERT_IF(csr_cs_get_ignored_malwares(context, nullptr,
+                                                                                 sizeof(dirs) / sizeof(const char *),
+                                                                                 &ignored_list, &cnt),
+                         CSR_ERROR_INVALID_PARAMETER);
+       ASSERT_IF(csr_cs_get_ignored_malwares(context, dirs,
+                                                                                 sizeof(dirs) / sizeof(const char *),
+                                                                                 nullptr, &cnt),
+                         CSR_ERROR_INVALID_PARAMETER);
+       ASSERT_IF(csr_cs_get_ignored_malwares(context, dirs,
+                                                                                 sizeof(dirs) / sizeof(const char *),
+                                                                                 &ignored_list, nullptr),
+                         CSR_ERROR_INVALID_PARAMETER);
 
        EXCEPTION_GUARD_END
 }
@@ -704,8 +747,9 @@ BOOST_AUTO_TEST_CASE(get_ignored_malwares_not_existing_dir)
                TEST_FILE_NO_EXIST
        };
 
-       ASSERT_IF(csr_cs_get_ignored_malwares(context, dirs, sizeof(dirs) / sizeof(const char *),
-                                                                                 &ignored_list, &cnt), CSR_ERROR_NONE);
+       ASSERT_SUCCESS(csr_cs_get_ignored_malwares(context, dirs,
+                                                                                          sizeof(dirs) / sizeof(const char *),
+                                                                                          &ignored_list, &cnt));
 
        ASSERT_IF(cnt, static_cast<size_t>(0));
 
@@ -721,46 +765,46 @@ BOOST_AUTO_TEST_CASE(judge_detected_malware)
        csr_cs_detected_h detected, stored;
 
        // remove earlier test results
-       copy_file(TEST_FILE_HIGH, TEST_FILE_MEDIA);
-       ASSERT_IF(csr_cs_scan_file(context, TEST_FILE_MEDIA, &detected), CSR_ERROR_NONE);
-       csr_cs_judge_detected_malware(context, detected, CSR_CS_ACTION_REMOVE);
-       copy_file(TEST_FILE_HIGH, TEST_FILE_MEDIA);
+       Test::copy_file(TEST_FILE_HIGH, TEST_FILE_MEDIA);
+       ASSERT_SUCCESS(csr_cs_scan_file(context, TEST_FILE_MEDIA, &detected));
+       ASSERT_SUCCESS(csr_cs_judge_detected_malware(context, detected, CSR_CS_ACTION_REMOVE));
+       Test::copy_file(TEST_FILE_HIGH, TEST_FILE_MEDIA);
 
        // store detected malware
-       ASSERT_IF(csr_cs_scan_file(context, TEST_FILE_MEDIA, &detected), CSR_ERROR_NONE);
+       ASSERT_SUCCESS(csr_cs_scan_file(context, TEST_FILE_MEDIA, &detected));
        CHECK_IS_NOT_NULL(detected);
 
-       ASSERT_IF(csr_cs_get_detected_malware(context, TEST_FILE_MEDIA, &stored), CSR_ERROR_NONE);
+       ASSERT_SUCCESS(csr_cs_get_detected_malware(context, TEST_FILE_MEDIA, &stored));
        CHECK_IS_NOT_NULL(stored);
 
-       ASSERT_IF(csr_cs_get_ignored_malware(context, TEST_FILE_MEDIA, &stored), CSR_ERROR_NONE);
+       ASSERT_SUCCESS(csr_cs_get_ignored_malware(context, TEST_FILE_MEDIA, &stored));
        CHECK_IS_NULL(stored);
 
-       // INGORE
-       ASSERT_IF(csr_cs_judge_detected_malware(context, detected, CSR_CS_ACTION_IGNORE), CSR_ERROR_NONE);
+       // IGNORE
+       ASSERT_SUCCESS(csr_cs_judge_detected_malware(context, detected, CSR_CS_ACTION_IGNORE));
 
-       ASSERT_IF(csr_cs_get_detected_malware(context, TEST_FILE_MEDIA, &stored), CSR_ERROR_NONE);
+       ASSERT_SUCCESS(csr_cs_get_detected_malware(context, TEST_FILE_MEDIA, &stored));
        CHECK_IS_NULL(stored);
 
-       ASSERT_IF(csr_cs_get_ignored_malware(context, TEST_FILE_MEDIA, &stored), CSR_ERROR_NONE);
+       ASSERT_SUCCESS(csr_cs_get_ignored_malware(context, TEST_FILE_MEDIA, &stored));
        CHECK_IS_NOT_NULL(stored);
 
        // UNIGNORE
-       ASSERT_IF(csr_cs_judge_detected_malware(context, detected, CSR_CS_ACTION_UNIGNORE), CSR_ERROR_NONE);
+       ASSERT_SUCCESS(csr_cs_judge_detected_malware(context, detected, CSR_CS_ACTION_UNIGNORE));
 
-       ASSERT_IF(csr_cs_get_detected_malware(context, TEST_FILE_MEDIA, &stored), CSR_ERROR_NONE);
+       ASSERT_SUCCESS(csr_cs_get_detected_malware(context, TEST_FILE_MEDIA, &stored));
        CHECK_IS_NOT_NULL(stored);
 
-       ASSERT_IF(csr_cs_get_ignored_malware(context, TEST_FILE_MEDIA, &stored), CSR_ERROR_NONE);
+       ASSERT_SUCCESS(csr_cs_get_ignored_malware(context, TEST_FILE_MEDIA, &stored));
        CHECK_IS_NULL(stored);
 
        // REMOVE
-       ASSERT_IF(csr_cs_judge_detected_malware(context, detected, CSR_CS_ACTION_REMOVE), CSR_ERROR_NONE);
+       ASSERT_SUCCESS(csr_cs_judge_detected_malware(context, detected, CSR_CS_ACTION_REMOVE));
 
-       ASSERT_IF(csr_cs_get_detected_malware(context, TEST_FILE_MEDIA, &stored), CSR_ERROR_NONE);
+       ASSERT_SUCCESS(csr_cs_get_detected_malware(context, TEST_FILE_MEDIA, &stored));
        CHECK_IS_NULL(stored);
 
-       ASSERT_IF(csr_cs_get_ignored_malware(context, TEST_FILE_MEDIA, &stored), CSR_ERROR_NONE);
+       ASSERT_SUCCESS(csr_cs_get_ignored_malware(context, TEST_FILE_MEDIA, &stored));
        CHECK_IS_NULL(stored);
 
        EXCEPTION_GUARD_END
@@ -775,28 +819,31 @@ BOOST_AUTO_TEST_CASE(judge_detected_malware_ignored_rescan)
        csr_cs_detected_h detected, stored;
 
        // remove earlier test results
-       copy_file(TEST_FILE_HIGH, TEST_FILE_MEDIA);
-       ASSERT_IF(csr_cs_scan_file(context, TEST_FILE_MEDIA, &detected), CSR_ERROR_NONE);
+       Test::copy_file(TEST_FILE_HIGH, TEST_FILE_MEDIA);
+       ASSERT_SUCCESS(csr_cs_scan_file(context, TEST_FILE_MEDIA, &detected));
        csr_cs_judge_detected_malware(context, detected, CSR_CS_ACTION_REMOVE);
-       copy_file(TEST_FILE_HIGH, TEST_FILE_MEDIA);
+       Test::copy_file(TEST_FILE_HIGH, TEST_FILE_MEDIA);
 
        // store detected malware
-       ASSERT_IF(csr_cs_scan_file(context, TEST_FILE_MEDIA, &detected), CSR_ERROR_NONE);
+       ASSERT_SUCCESS(csr_cs_scan_file(context, TEST_FILE_MEDIA, &detected));
        CHECK_IS_NOT_NULL(detected);
 
        // ignore
-       ASSERT_IF(csr_cs_judge_detected_malware(context, detected, CSR_CS_ACTION_IGNORE), CSR_ERROR_NONE);
+       ASSERT_SUCCESS(csr_cs_judge_detected_malware(context, detected, CSR_CS_ACTION_IGNORE));
 
        // rescan
-       ASSERT_IF(csr_cs_scan_file(context, TEST_FILE_MEDIA, &detected), CSR_ERROR_NONE);
-       CHECK_IS_NOT_NULL(detected);
+       ASSERT_SUCCESS(csr_cs_scan_file(context, TEST_FILE_MEDIA, &detected));
+       CHECK_IS_NULL(detected);
 
-       ASSERT_IF(csr_cs_get_detected_malware(context, TEST_FILE_MEDIA, &stored), CSR_ERROR_NONE);
+       ASSERT_SUCCESS(csr_cs_get_detected_malware(context, TEST_FILE_MEDIA, &stored));
        CHECK_IS_NULL(stored);
 
-       ASSERT_IF(csr_cs_get_ignored_malware(context, TEST_FILE_MEDIA, &stored), CSR_ERROR_NONE);
+       ASSERT_SUCCESS(csr_cs_get_ignored_malware(context, TEST_FILE_MEDIA, &stored));
        CHECK_IS_NOT_NULL(stored);
 
+       // rollback to unignore
+       ASSERT_SUCCESS(csr_cs_judge_detected_malware(context, stored, CSR_CS_ACTION_UNIGNORE));
+
        EXCEPTION_GUARD_END
 }
 
@@ -809,48 +856,48 @@ BOOST_AUTO_TEST_CASE(judge_detected_malware_remove_file)
        csr_cs_detected_h detected, stored;
 
        // remove earlier test results
-       copy_file(TEST_FILE_HIGH, TEST_FILE_MEDIA);
-       ASSERT_IF(csr_cs_scan_file(context, TEST_FILE_MEDIA, &detected), CSR_ERROR_NONE);
+       Test::copy_file(TEST_FILE_HIGH, TEST_FILE_MEDIA);
+       ASSERT_SUCCESS(csr_cs_scan_file(context, TEST_FILE_MEDIA, &detected));
        csr_cs_judge_detected_malware(context, detected, CSR_CS_ACTION_REMOVE);
-       copy_file(TEST_FILE_HIGH, TEST_FILE_MEDIA);
+       Test::copy_file(TEST_FILE_HIGH, TEST_FILE_MEDIA);
 
        // store detected malware
-       ASSERT_IF(csr_cs_scan_file(context, TEST_FILE_MEDIA, &detected), CSR_ERROR_NONE);
+       ASSERT_SUCCESS(csr_cs_scan_file(context, TEST_FILE_MEDIA, &detected));
        CHECK_IS_NOT_NULL(detected);
 
        // remove detected malware file
-       ASSERT_IF(csr_cs_judge_detected_malware(context, detected, CSR_CS_ACTION_REMOVE), CSR_ERROR_NONE);
+       ASSERT_SUCCESS(csr_cs_judge_detected_malware(context, detected, CSR_CS_ACTION_REMOVE));
 
-       ASSERT_IF(csr_cs_get_detected_malware(context, TEST_FILE_MEDIA, &stored), CSR_ERROR_NONE);
+       ASSERT_SUCCESS(csr_cs_get_detected_malware(context, TEST_FILE_MEDIA, &stored));
        CHECK_IS_NULL(stored);
 
-       ASSERT_IF(csr_cs_get_ignored_malware(context, TEST_FILE_MEDIA, &stored), CSR_ERROR_NONE);
+       ASSERT_SUCCESS(csr_cs_get_ignored_malware(context, TEST_FILE_MEDIA, &stored));
        CHECK_IS_NULL(stored);
 
-       ASSERT_IF(is_file_exist(TEST_FILE_MEDIA), false);
+       ASSERT_IF(Test::is_file_exist(TEST_FILE_MEDIA), false);
 
        // make ignored
-       copy_file(TEST_FILE_HIGH, TEST_FILE_MEDIA);
-       ASSERT_IF(csr_cs_scan_file(context, TEST_FILE_MEDIA, &detected), CSR_ERROR_NONE);
-       ASSERT_IF(csr_cs_judge_detected_malware(context, detected, CSR_CS_ACTION_IGNORE), CSR_ERROR_NONE);
+       Test::copy_file(TEST_FILE_HIGH, TEST_FILE_MEDIA);
+       ASSERT_SUCCESS(csr_cs_scan_file(context, TEST_FILE_MEDIA, &detected));
+       ASSERT_SUCCESS(csr_cs_judge_detected_malware(context, detected, CSR_CS_ACTION_IGNORE));
 
        // remove ignored malware file
-       ASSERT_IF(csr_cs_judge_detected_malware(context, detected, CSR_CS_ACTION_REMOVE), CSR_ERROR_NONE);
-
-       ASSERT_IF(csr_cs_judge_detected_malware(context, detected, CSR_CS_ACTION_REMOVE), CSR_ERROR_NONE);
+       ASSERT_SUCCESS(csr_cs_judge_detected_malware(context, detected, CSR_CS_ACTION_REMOVE));
 
-       ASSERT_IF(csr_cs_get_detected_malware(context, TEST_FILE_MEDIA, &stored), CSR_ERROR_NONE);
+       ASSERT_SUCCESS(csr_cs_get_detected_malware(context, TEST_FILE_MEDIA, &stored));
        CHECK_IS_NULL(stored);
 
-       ASSERT_IF(csr_cs_get_ignored_malware(context, TEST_FILE_MEDIA, &stored), CSR_ERROR_NONE);
+       ASSERT_SUCCESS(csr_cs_get_ignored_malware(context, TEST_FILE_MEDIA, &stored));
        CHECK_IS_NULL(stored);
 
-       ASSERT_IF(is_file_exist(TEST_FILE_MEDIA), false);
+       ASSERT_IF(Test::is_file_exist(TEST_FILE_MEDIA), false);
 
        // remove not existing file
-       copy_file(TEST_FILE_HIGH, TEST_FILE_MEDIA);
-       ASSERT_IF(csr_cs_scan_file(context, TEST_FILE_MEDIA, &detected), CSR_ERROR_NONE);
-       ASSERT_IF(csr_cs_judge_detected_malware(context, detected, CSR_CS_ACTION_REMOVE), CSR_ERROR_NONE);
+       Test::copy_file(TEST_FILE_HIGH, TEST_FILE_MEDIA);
+       ASSERT_SUCCESS(csr_cs_scan_file(context, TEST_FILE_MEDIA, &detected));
+       CHECK_IS_NOT_NULL(detected);
+
+       ASSERT_SUCCESS(csr_cs_judge_detected_malware(context, detected, CSR_CS_ACTION_REMOVE));
 
        ASSERT_IF(csr_cs_judge_detected_malware(context, detected, CSR_CS_ACTION_REMOVE),
                          CSR_ERROR_FILE_DO_NOT_EXIST);
@@ -867,16 +914,17 @@ BOOST_AUTO_TEST_CASE(judge_detected_malware_remove_wgt)
        csr_cs_detected_h detected;
 
        // remove old test data
-       uninstall_app(TEST_WGT_PKG_ID);
-       BOOST_REQUIRE_MESSAGE(install_app(TEST_WGT_PATH, TEST_WGT_TYPE) == true, "FAIL TO INSTALL.");
+       Test::uninstall_app(TEST_WGT_PKG_ID);
+
+       ASSERT_INSTALL_APP(TEST_WGT_PATH, TEST_WGT_TYPE);
 
        // remove detected malware file
-       ASSERT_IF(csr_cs_scan_file(context, TEST_WGT_MAL_FILE, &detected), CSR_ERROR_NONE);
+       ASSERT_SUCCESS(csr_cs_scan_file(context, TEST_WGT_MAL_FILE, &detected));
        CHECK_IS_NOT_NULL(detected);
 
-       ASSERT_IF(csr_cs_judge_detected_malware(context, detected, CSR_CS_ACTION_REMOVE), CSR_ERROR_NONE);
+       ASSERT_SUCCESS(csr_cs_judge_detected_malware(context, detected, CSR_CS_ACTION_REMOVE));
 
-       ASSERT_IF(is_app_exist(TEST_WGT_PKG_ID), false);
+       ASSERT_IF(Test::is_app_exist(TEST_WGT_PKG_ID), false);
 
        EXCEPTION_GUARD_END
 }
@@ -890,16 +938,16 @@ BOOST_AUTO_TEST_CASE(judge_detected_malware_remove_tpk)
        csr_cs_detected_h detected;
 
        // remove old test data
-       uninstall_app(TEST_TPK_PKG_ID);
-       BOOST_REQUIRE_MESSAGE(install_app(TEST_TPK_PATH, TEST_TPK_TYPE) == true, "FAIL TO INSTALL.");
+       Test::uninstall_app(TEST_TPK_PKG_ID);
+       ASSERT_INSTALL_APP(TEST_TPK_PATH, TEST_TPK_TYPE);
 
        // remove detected malware file
-       ASSERT_IF(csr_cs_scan_file(context, TEST_TPK_MAL_FILE, &detected), CSR_ERROR_NONE);
+       ASSERT_SUCCESS(csr_cs_scan_file(context, TEST_TPK_MAL_FILE, &detected));
        CHECK_IS_NOT_NULL(detected);
 
-       ASSERT_IF(csr_cs_judge_detected_malware(context, detected, CSR_CS_ACTION_REMOVE), CSR_ERROR_NONE);
+       ASSERT_SUCCESS(csr_cs_judge_detected_malware(context, detected, CSR_CS_ACTION_REMOVE));
 
-       ASSERT_IF(is_app_exist(TEST_TPK_PKG_ID), false);
+       ASSERT_IF(Test::is_app_exist(TEST_TPK_PKG_ID), false);
 
        EXCEPTION_GUARD_END
 }
@@ -912,14 +960,15 @@ BOOST_AUTO_TEST_CASE(judge_detected_malware_invalid_params)
        auto context = c.get();
        csr_cs_detected_h detected;
 
-       ASSERT_IF(csr_cs_scan_file(context, TEST_FILE_HIGH, &detected), CSR_ERROR_NONE);
+       ASSERT_SUCCESS(csr_cs_scan_file(context, TEST_FILE_HIGH, &detected));
        CHECK_IS_NOT_NULL(detected);
 
        ASSERT_IF(csr_cs_judge_detected_malware(nullptr, detected, CSR_CS_ACTION_REMOVE),
                          CSR_ERROR_INVALID_HANDLE);
        ASSERT_IF(csr_cs_judge_detected_malware(context, nullptr, CSR_CS_ACTION_REMOVE),
                          CSR_ERROR_INVALID_PARAMETER);
-       ASSERT_IF(csr_cs_judge_detected_malware(context, detected, static_cast<csr_cs_action_e>(-1)),
+       ASSERT_IF(csr_cs_judge_detected_malware(context, detected,
+                                                                                       static_cast<csr_cs_action_e>(-1)),
                          CSR_ERROR_INVALID_PARAMETER);
 
        EXCEPTION_GUARD_END
index 9021746..7d150db 100644 (file)
@@ -35,19 +35,19 @@ struct Result {
        csre_wp_risk_level_e risk_level;
        std::string detailed_url;
 
-       Result(csre_wp_risk_level_e r, const char *durl) : risk_level(r),
-               detailed_url(durl) {}
+       Result(csre_wp_risk_level_e r, const char *durl) :
+               risk_level(r),
+               detailed_url(durl ? durl : std::string()) {}
 };
 
 std::unordered_map<std::string, Result> ExpectedResult = {
-       {"http://normal.test.com",      Result(CSRE_WP_RISK_UNVERIFIED, "")},
+       {"http://normal.test.com",      Result(CSRE_WP_RISK_UNVERIFIED, nullptr)},
        {"http://highrisky.test.com",   Result(CSRE_WP_RISK_HIGH, "http://high.risky.com")},
        {"http://mediumrisky.test.com", Result(CSRE_WP_RISK_MEDIUM, "http://medium.risky.com")},
-       {"http://lowrisky.test.com",    Result(CSRE_WP_RISK_LOW, "")}
+       {"http://lowrisky.test.com",    Result(CSRE_WP_RISK_LOW, "http://low.risky.com")}
 };
 
-inline void checkResult(const std::string &url, csre_wp_check_result_h &result,
-                                               const Result &expected)
+inline void checkResult(csre_wp_check_result_h &result, const Result &expected)
 {
        EXCEPTION_GUARD_START
 
@@ -55,16 +55,11 @@ inline void checkResult(const std::string &url, csre_wp_check_result_h &result,
 
        csre_wp_risk_level_e risk_level;
        ASSERT_IF(csre_wp_result_get_risk_level(result, &risk_level), CSRE_ERROR_NONE);
-       BOOST_REQUIRE_MESSAGE(risk_level == expected.risk_level,
-                                                 "url[" << url << "] risk level isn't expected value. "
-                                                 "val: " << risk_level << " expected: " << expected.risk_level);
+       ASSERT_IF(risk_level, expected.risk_level);
 
        const char *detailed_url = nullptr;
-       ASSERT_IF(csre_wp_result_get_detailed_url(result, &detailed_url),
-                         CSRE_ERROR_NONE);
-       BOOST_REQUIRE_MESSAGE(expected.detailed_url.compare(detailed_url) == 0,
-                                                 "url[" << url << "] detailed url isn't expected value. "
-                                                 "val: " << detailed_url << " expected: " << expected.detailed_url);
+       ASSERT_IF(csre_wp_result_get_detailed_url(result, &detailed_url), CSRE_ERROR_NONE);
+       ASSERT_IF(detailed_url, expected.detailed_url);
 
        EXCEPTION_GUARD_END
 }
@@ -77,8 +72,7 @@ BOOST_AUTO_TEST_CASE(context_create_destroy)
 {
        EXCEPTION_GUARD_START
 
-       auto c = Test::Context<csre_wp_context_h>();
-       (void) c;
+       Test::Context<csre_wp_context_h>();
 
        EXCEPTION_GUARD_END
 }
@@ -94,7 +88,8 @@ BOOST_AUTO_TEST_CASE(check_url)
                csre_wp_check_result_h result;
                ASSERT_IF(csre_wp_check_url(context, pair.first.c_str(), &result),
                                  CSRE_ERROR_NONE);
-               checkResult(pair.first, result, pair.second);
+               BOOST_MESSAGE("check result from url: " << pair.first);
+               checkResult(result, pair.second);
        }
 
        EXCEPTION_GUARD_END
index 57d3f31..930bd05 100644 (file)
@@ -52,17 +52,15 @@ void ASSERT_RESULT(csr_wp_check_result_h result,
        const char *a_detailed_url;
        csr_wp_user_response_e a_response;
 
-       BOOST_REQUIRE_MESSAGE(result != nullptr, "Result handle is null");
+       CHECK_IS_NOT_NULL(result);
 
-       ASSERT_IF(csr_wp_result_get_risk_level(result, &a_risk), CSR_ERROR_NONE);
-       ASSERT_IF(csr_wp_result_get_detailed_url(result, &a_detailed_url), CSR_ERROR_NONE);
-       ASSERT_IF(csr_wp_result_get_user_response(result, &a_response), CSR_ERROR_NONE);
+       ASSERT_SUCCESS(csr_wp_result_get_risk_level(result, &a_risk));
+       ASSERT_SUCCESS(csr_wp_result_get_detailed_url(result, &a_detailed_url));
+       ASSERT_SUCCESS(csr_wp_result_get_user_response(result, &a_response));
 
-       BOOST_REQUIRE_MESSAGE(risk == a_risk,
-               "RISK LEVEL CMP FAIL. EXP=" << risk <<", ACT=" << a_risk);
-       ASSERT_STRING(detailed_url, a_detailed_url, "DETAIL URL CMP FAIL.");
-       BOOST_REQUIRE_MESSAGE(response == a_response,
-               "USER RESPONSE CMP FAIL. EXP=" << response <<", ACT=" << a_response);
+       ASSERT_IF(a_risk, risk);
+       ASSERT_IF(a_detailed_url, detailed_url);
+       ASSERT_IF(a_response, response);
 }
 
 BOOST_AUTO_TEST_SUITE(API_WEB_PROTECTION)
@@ -71,8 +69,7 @@ BOOST_AUTO_TEST_CASE(context_create_destroy)
 {
        EXCEPTION_GUARD_START
 
-       auto c = Test::Context<csr_wp_context_h>();
-       (void) c;
+       Test::Context<csr_wp_context_h>();
 
        EXCEPTION_GUARD_END
 }
@@ -84,9 +81,8 @@ BOOST_AUTO_TEST_CASE(set_ask_user)
        auto c = Test::Context<csr_wp_context_h>();
        auto context = c.get();
 
-       ASSERT_IF(csr_wp_set_ask_user(context, CSR_WP_ASK_USER), CSR_ERROR_NONE);
-
-       ASSERT_IF(csr_wp_set_ask_user(context, CSR_WP_NOT_ASK_USER), CSR_ERROR_NONE);
+       ASSERT_SUCCESS(csr_wp_set_ask_user(context, CSR_WP_ASK_USER));
+       ASSERT_SUCCESS(csr_wp_set_ask_user(context, CSR_WP_NOT_ASK_USER));
 
        EXCEPTION_GUARD_END
 }
@@ -114,7 +110,7 @@ BOOST_AUTO_TEST_CASE(set_popup_message)
        auto context = c.get();
        const char *msg = "test popup message";
 
-       ASSERT_IF(csr_wp_set_popup_message(context, msg), CSR_ERROR_NONE);
+       ASSERT_SUCCESS(csr_wp_set_popup_message(context, msg));
 
        EXCEPTION_GUARD_END
 }
@@ -128,7 +124,6 @@ BOOST_AUTO_TEST_CASE(set_popup_message_invalid_param)
        const char *msg = "test popup message";
 
        ASSERT_IF(csr_wp_set_popup_message(nullptr, msg), CSR_ERROR_INVALID_HANDLE);
-
        ASSERT_IF(csr_wp_set_popup_message(context, nullptr), CSR_ERROR_INVALID_PARAMETER);
 
        EXCEPTION_GUARD_END
@@ -142,7 +137,7 @@ BOOST_AUTO_TEST_CASE(check_url_high)
        auto context = c.get();
 
        csr_wp_check_result_h result;
-       ASSERT_IF(csr_wp_check_url(context, RISK_HIGH_URL, &result), CSR_ERROR_NONE);
+       ASSERT_SUCCESS(csr_wp_check_url(context, RISK_HIGH_URL, &result));
 
        CHECK_IS_NOT_NULL(result);
 
@@ -159,7 +154,7 @@ BOOST_AUTO_TEST_CASE(check_url_medium)
        auto context = c.get();
 
        csr_wp_check_result_h result;
-       ASSERT_IF(csr_wp_check_url(context, RISK_MEDIUM_URL, &result), CSR_ERROR_NONE);
+       ASSERT_SUCCESS(csr_wp_check_url(context, RISK_MEDIUM_URL, &result));
 
        CHECK_IS_NOT_NULL(result);
 
@@ -176,7 +171,7 @@ BOOST_AUTO_TEST_CASE(check_url_low)
        auto context = c.get();
 
        csr_wp_check_result_h result;
-       ASSERT_IF(csr_wp_check_url(context, RISK_LOW_URL, &result), CSR_ERROR_NONE);
+       ASSERT_SUCCESS(csr_wp_check_url(context, RISK_LOW_URL, &result));
 
        CHECK_IS_NOT_NULL(result);
 
@@ -193,11 +188,12 @@ BOOST_AUTO_TEST_CASE(check_url_unverified)
        auto context = c.get();
 
        csr_wp_check_result_h result;
-       ASSERT_IF(csr_wp_check_url(context, RISK_UNVERIFIED_URL, &result), CSR_ERROR_NONE);
+       ASSERT_SUCCESS(csr_wp_check_url(context, RISK_UNVERIFIED_URL, &result));
 
        CHECK_IS_NOT_NULL(result);
 
-       ASSERT_RESULT(result, RISK_UNVERIFIED_RISK, RISK_UNVERIFIED_DETAILED_URL, CSR_WP_NO_ASK_USER);
+       ASSERT_RESULT(result, RISK_UNVERIFIED_RISK, RISK_UNVERIFIED_DETAILED_URL,
+                                 CSR_WP_NO_ASK_USER);
 
        EXCEPTION_GUARD_END
 }
@@ -212,7 +208,8 @@ BOOST_AUTO_TEST_CASE(check_url_invalid_param)
        csr_wp_check_result_h result;
        ASSERT_IF(csr_wp_check_url(nullptr, RISK_HIGH_URL, &result), CSR_ERROR_INVALID_HANDLE);
        ASSERT_IF(csr_wp_check_url(context, nullptr, &result), CSR_ERROR_INVALID_PARAMETER);
-       ASSERT_IF(csr_wp_check_url(context, RISK_HIGH_URL, nullptr), CSR_ERROR_INVALID_PARAMETER);
+       ASSERT_IF(csr_wp_check_url(context, RISK_HIGH_URL, nullptr),
+                         CSR_ERROR_INVALID_PARAMETER);
 
        EXCEPTION_GUARD_END
 }
@@ -226,12 +223,10 @@ BOOST_AUTO_TEST_CASE(get_risk_level)
        csr_wp_risk_level_e risk_level;
 
        csr_wp_check_result_h result;
-       ASSERT_IF(csr_wp_check_url(context, RISK_HIGH_URL, &result), CSR_ERROR_NONE);
-
-       ASSERT_IF(csr_wp_result_get_risk_level(result, &risk_level), CSR_ERROR_NONE);
+       ASSERT_SUCCESS(csr_wp_check_url(context, RISK_HIGH_URL, &result));
+       ASSERT_SUCCESS(csr_wp_result_get_risk_level(result, &risk_level));
 
-       BOOST_REQUIRE_MESSAGE( RISK_HIGH_RISK == risk_level,
-               "RISK LEVEL CMP FAIL. EXP=" << RISK_HIGH_RISK <<", ACT=" << risk_level);
+       ASSERT_IF(risk_level, RISK_HIGH_RISK);
 
        EXCEPTION_GUARD_END
 }
@@ -245,10 +240,11 @@ BOOST_AUTO_TEST_CASE(get_risk_level_invalid_param)
        csr_wp_risk_level_e risk_level;
 
        csr_wp_check_result_h result;
-       ASSERT_IF(csr_wp_check_url(context, RISK_HIGH_URL, &result), CSR_ERROR_NONE);
+       ASSERT_SUCCESS(csr_wp_check_url(context, RISK_HIGH_URL, &result));
 
-       ASSERT_IF(csr_wp_result_get_risk_level(nullptr, &risk_level), CSR_ERROR_INVALID_HANDLE);
        ASSERT_IF(csr_wp_result_get_risk_level(result, nullptr), CSR_ERROR_INVALID_PARAMETER);
+       ASSERT_IF(csr_wp_result_get_risk_level(nullptr, &risk_level),
+                         CSR_ERROR_INVALID_HANDLE);
 
        EXCEPTION_GUARD_END
 }
@@ -262,10 +258,10 @@ BOOST_AUTO_TEST_CASE(get_detailed_url)
        const char *detailed_url;
 
        csr_wp_check_result_h result;
-       ASSERT_IF(csr_wp_check_url(context, RISK_HIGH_URL, &result), CSR_ERROR_NONE);
+       ASSERT_SUCCESS(csr_wp_check_url(context, RISK_HIGH_URL, &result));
 
-       ASSERT_IF(csr_wp_result_get_detailed_url(result, &detailed_url), CSR_ERROR_NONE);
-       ASSERT_STRING(RISK_HIGH_DETAILED_URL, detailed_url, "DETAILED URL not same");
+       ASSERT_SUCCESS(csr_wp_result_get_detailed_url(result, &detailed_url));
+       ASSERT_IF(detailed_url, RISK_HIGH_DETAILED_URL);
 
        EXCEPTION_GUARD_END
 }
@@ -279,10 +275,12 @@ BOOST_AUTO_TEST_CASE(get_detailed_url_invalid_param)
        const char *detailed_url;
 
        csr_wp_check_result_h result;
-       ASSERT_IF(csr_wp_check_url(context, RISK_HIGH_URL, &result), CSR_ERROR_NONE);
+       ASSERT_SUCCESS(csr_wp_check_url(context, RISK_HIGH_URL, &result));
 
-       ASSERT_IF(csr_wp_result_get_detailed_url(nullptr, &detailed_url), CSR_ERROR_INVALID_HANDLE);
-       ASSERT_IF(csr_wp_result_get_detailed_url(result, nullptr), CSR_ERROR_INVALID_PARAMETER);
+       ASSERT_IF(csr_wp_result_get_detailed_url(nullptr, &detailed_url),
+                         CSR_ERROR_INVALID_HANDLE);
+       ASSERT_IF(csr_wp_result_get_detailed_url(result, nullptr),
+                         CSR_ERROR_INVALID_PARAMETER);
 
        EXCEPTION_GUARD_END
 }
index faedd18..3d21a0b 100644 (file)
  */
 #include "test-common.h"
 
+#include <iostream>
+#include <fstream>
+#include <unistd.h>
+#include <utime.h>
+
+#include <package-manager.h>
+#include <pkgmgr-info.h>
+
 namespace Test {
 
+namespace {
+
+bool installed;
+GMainLoop *installMainLoop;
+int __app_install_cb(int req_id, const char *pkg_type, const char *pkgid,
+                                        const char *key, const char *val, const void *pmsg, void *data)
+{
+       (void) req_id;
+       (void) pkg_type;
+       (void) pkgid;
+       (void) pmsg;
+       (void) data;
+
+       installed = false;
+
+       if (key && strncmp(key, "end", strlen("end")) == 0) {
+               if (strncmp(val, "ok", strlen("ok")) == 0) {
+                       installed = true;
+                       g_main_loop_quit(installMainLoop);
+                       g_main_loop_unref(installMainLoop);
+               }
+       }
+
+       return 0;
+}
+
+gboolean __app_install_timeout(gpointer)
+{
+       installed = false;
+       return TRUE;
+}
+
+bool uninstalled;
+GMainLoop *uninstallMainLoop;
+int __app_uninstall_cb(int req_id, const char *pkg_type, const char *pkgid,
+                                          const char *key, const char *val, const void *pmsg, void *data)
+{
+       (void) req_id;
+       (void) pkg_type;
+       (void) pkgid;
+       (void) pmsg;
+       (void) data;
+
+       uninstalled = false;
+
+       if (key && strncmp(key, "end", strlen("end")) == 0) {
+               if (strncmp(val, "ok", strlen("ok")) == 0) {
+                       uninstalled = true;
+                       g_main_loop_quit(uninstallMainLoop);
+                       g_main_loop_unref(uninstallMainLoop);
+               }
+       }
+
+       return 0;
+}
+
+gboolean __app_uninstall_timeout(gpointer)
+{
+       uninstalled = false;
+       return TRUE;
+}
+
+#define ERRORDESCRIBE(name) case name: return #name
+std::string capi_ec_to_string(csr_error_e ec)
+{
+       switch (ec) {
+       ERRORDESCRIBE(CSR_ERROR_NONE);
+       ERRORDESCRIBE(CSR_ERROR_INVALID_PARAMETER);
+       ERRORDESCRIBE(CSR_ERROR_OUT_OF_MEMORY);
+       ERRORDESCRIBE(CSR_ERROR_PERMISSION_DENIED);
+       ERRORDESCRIBE(CSR_ERROR_SOCKET);
+       ERRORDESCRIBE(CSR_ERROR_INVALID_HANDLE);
+       ERRORDESCRIBE(CSR_ERROR_SERVER);
+       ERRORDESCRIBE(CSR_ERROR_NO_TASK);
+       ERRORDESCRIBE(CSR_ERROR_DB);
+       ERRORDESCRIBE(CSR_ERROR_REMOVE_FAILED);
+       ERRORDESCRIBE(CSR_ERROR_FILE_DO_NOT_EXIST);
+       ERRORDESCRIBE(CSR_ERROR_FILE_SYSTEM);
+       ERRORDESCRIBE(CSR_ERROR_ENGINE_PERMISSION);
+       ERRORDESCRIBE(CSR_ERROR_ENGINE_NOT_EXIST);
+       ERRORDESCRIBE(CSR_ERROR_ENGINE_DIASABLED);
+       ERRORDESCRIBE(CSR_ERROR_ENGINE_NOT_ACTIVATED);
+       ERRORDESCRIBE(CSR_ERROR_ENGINE_INTERNAL);
+       ERRORDESCRIBE(CSR_ERROR_UNKNOWN);
+       default: return std::string("Undefined capi error code: ")
+                                               + std::to_string(static_cast<int>(ec));
+       }
+}
+#undef ERRORDESCRIBE
+
+} // namespace anonymous
+
+template <>
+void _assert<csr_error_e, csr_error_e>(const csr_error_e &value,
+                                                                          const csr_error_e &expected,
+                                                                          const std::string &filename,
+                                                                          const std::string &funcname,
+                                                                          unsigned int line)
+{
+       BOOST_REQUIRE_MESSAGE(value == expected,
+                                                 "[" << filename << " > " << funcname << " : " << line << "]" <<
+                                                 " returned[" << capi_ec_to_string(value) <<
+                                                 "] expected[" << capi_ec_to_string(expected) << "]");
+}
+
+template <>
+void _assert<csr_error_e, int>(const csr_error_e &value,
+                                                          const int &expected,
+                                                          const std::string &filename,
+                                                          const std::string &funcname,
+                                                          unsigned int line)
+{
+       BOOST_REQUIRE_MESSAGE(value == expected,
+                                                 "[" << filename << " > " << funcname << " : " << line << "]" <<
+                                                 " returned[" << capi_ec_to_string(value) << "] expected[" <<
+                                                 capi_ec_to_string(static_cast<csr_error_e>(expected)) << "]");
+}
+
+template <>
+void _assert<int, csr_error_e>(const int &value,
+                                                          const csr_error_e &expected,
+                                                          const std::string &filename,
+                                                          const std::string &funcname,
+                                                          unsigned int line)
+{
+       BOOST_REQUIRE_MESSAGE(value == expected,
+                                                 "[" << filename << " > " << funcname << " : " << line << "]" <<
+                                                 " returned[" <<
+                                                 capi_ec_to_string(static_cast<csr_error_e>(value)) <<
+                                                 "] expected[" << capi_ec_to_string(expected) << "]");
+}
+
+void _assert(const char *value, const char *expected, const std::string &filename,
+                        const std::string &funcname, unsigned int line)
+{
+       if (value == nullptr && expected == nullptr)
+               BOOST_REQUIRE(true);
+       else if (value != nullptr && expected != nullptr)
+               _assert(std::string(value), expected, filename, funcname, line);
+       else if (value == nullptr && expected != nullptr)
+               BOOST_REQUIRE_MESSAGE(std::string(expected).empty(),
+                                                         "[" << filename << " > " << funcname << " : " << line <<
+                                                         "] returned[nullptr] expected[" << expected << "]");
+       else
+               BOOST_REQUIRE_MESSAGE(std::string(value).empty(),
+                                                         "[" << filename << " > " << funcname << " : " << line <<
+                                                         "] returned[" << value << "] expected[nullptr]");
+}
+
+void _assert(const char *value, const std::string &expected, const std::string &filename,
+                        const std::string &funcname, unsigned int line)
+{
+       _assert((value == nullptr) ? std::string() : std::string(value),
+                       expected, filename, funcname, line);
+}
+
 void exceptionGuard(const std::function<void()> &f)
 {
        try {
@@ -34,4 +198,76 @@ void exceptionGuard(const std::function<void()> &f)
        }
 }
 
+void copy_file(const char *src_file, const char *dest_file)
+{
+       std::ifstream srce(src_file, std::ios::binary);
+       std::ofstream dest(dest_file, std::ios::binary);
+       dest << srce.rdbuf();
+}
+
+void touch_file(const char *file)
+{
+       struct utimbuf new_times;
+       time_t now = time(nullptr);
+
+       new_times.actime = now;
+       new_times.modtime = now;
+
+       utime(file, &new_times);
+}
+
+bool is_file_exist(const char *file)
+{
+       return (access(file, F_OK) != -1);
+}
+
+bool uninstall_app(const char *pkg_id)
+{
+       auto pkgmgr = pkgmgr_client_new(PC_REQUEST);
+       CHECK_IS_NOT_NULL(pkgmgr);
+
+       uninstalled = false;
+       int ret = pkgmgr_client_uninstall(pkgmgr, nullptr, pkg_id, PM_QUIET,
+                                                                         __app_uninstall_cb, nullptr);
+       if (ret <= PKGMGR_R_OK)
+               return false;
+
+       g_timeout_add_seconds(30, __app_uninstall_timeout, nullptr);
+       uninstallMainLoop = g_main_loop_new(nullptr, false);
+       g_main_loop_run(uninstallMainLoop);
+       pkgmgr_client_free(pkgmgr);
+
+       return uninstalled;
+}
+
+bool is_app_exist(const char *pkg_id)
+{
+       pkgmgrinfo_pkginfo_h handle;
+
+       if (pkgmgrinfo_pkginfo_get_pkginfo(pkg_id, &handle) != PMINFO_R_OK)
+               return false;
+
+       pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
+       return true;
+}
+
+bool install_app(const char *app_path, const char *pkg_type)
+{
+       auto pkgmgr = pkgmgr_client_new(PC_REQUEST);
+       CHECK_IS_NOT_NULL(pkgmgr);
+
+       installed = false;
+       int ret = pkgmgr_client_install(pkgmgr, pkg_type, nullptr, app_path, nullptr, PM_QUIET,
+                                                                       __app_install_cb, nullptr);
+       if (ret <= PKGMGR_R_OK)
+               return false;
+
+       g_timeout_add_seconds(30, __app_install_timeout, nullptr);
+       installMainLoop = g_main_loop_new(nullptr, false);
+       g_main_loop_run(installMainLoop);
+       pkgmgr_client_free(pkgmgr);
+
+       return installed;
+}
+
 } // namespace Test
index 5af38e5..4a875b9 100644 (file)
 #define __FILENAME__ (::strrchr(__FILE__, '/') ? ::strrchr(__FILE__, '/') + 1 : __FILE__)
 #endif
 
-#define ASSERT_IF_(value, expected, file, f, l) \
-       Test::_assert(value, expected, file, f, l)
-
 #define ASSERT_IF(value, expected) \
-       ASSERT_IF_(value, expected, __FILENAME__, __func__, __LINE__)
+       Test::_assert(value, expected, __FILENAME__, __func__, __LINE__)
+
+#define ASSERT_SUCCESS(value) \
+       Test::_assert(value, CSR_ERROR_NONE, __FILENAME__, __func__, __LINE__)
+
+#define ASSERT_INSTALL_APP(path, type)                       \
+       BOOST_REQUIRE_MESSAGE(Test::install_app(path, type),     \
+                                                 "Failed to install app: " << path)
+
+#define ASSERT_UNINSTALL_APP(path)                             \
+       BOOST_REQUIRE_MESSAGE(Test::uninstall_app(path),           \
+                                                 "Failed to uninstall app: " << path)
 
 #define EXCEPTION_GUARD_START Test::exceptionGuard([&] {
 #define EXCEPTION_GUARD_END   });
@@ -60,13 +68,45 @@ void _assert(const T &value, const U &expected, const std::string &filename,
                         const std::string &funcname, unsigned int line)
 {
        BOOST_REQUIRE_MESSAGE(value == expected,
-                                                 "[" << filename << " > " << funcname << " : " << line << "]"
-                                                 << " returned code: " << value
-                                                 << " expected: " << expected);
+                                                 "[" << filename << " > " << funcname << " : " << line << "]" <<
+                                                 " returned[" << value << "] expected[" << expected << "]");
 }
 
+template <>
+void _assert<csr_error_e, csr_error_e>(const csr_error_e &value,
+                                                                          const csr_error_e &expected,
+                                                                          const std::string &filename,
+                                                                          const std::string &funcname,
+                                                                          unsigned int line);
+
+template <>
+void _assert<csr_error_e, int>(const csr_error_e &value,
+                                                          const int &expected,
+                                                          const std::string &filename,
+                                                          const std::string &funcname,
+                                                          unsigned int line);
+
+template <>
+void _assert<int, csr_error_e>(const int &value,
+                                                          const csr_error_e &expected,
+                                                          const std::string &filename,
+                                                          const std::string &funcname,
+                                                          unsigned int line);
+
+void _assert(const char *value, const char *expected, const std::string &filename,
+                        const std::string &funcname, unsigned int line);
+void _assert(const char *value, const std::string &expected, const std::string &filename,
+                        const std::string &funcname, unsigned int line);
+
 void exceptionGuard(const std::function<void()> &);
 
+void copy_file(const char *src_file, const char *dest_file);
+void touch_file(const char *file);
+bool is_file_exist(const char *file);
+bool install_app(const char *app_path, const char *app_type);
+bool uninstall_app(const char *pkg_id);
+bool is_app_exist(const char *pkg_id);
+
 template <typename T>
 class Context {
 public:
index 1fcb177..d89c340 100644 (file)
  * @version     1.0
  * @brief       CSR API test helper
  */
-
 #include <string>
-#include <iostream>
-#include <fstream>
-#include <boost/test/unit_test.hpp>
 
 #include <time.h>
 #include <utime.h>
 #include <unistd.h>
 
-#include <package-manager.h>
-#include <pkgmgr-info.h>
+#include <boost/test/unit_test.hpp>
 
 #include "test-common.h"
 
-void ASSERT_STRING(const char *expected, const char *actual, const char *msg)
+void ASSERT_DETECTED(csr_cs_detected_h detected, const char *e_malware_name,
+                                        int e_severity, const char *e_detailed_url)
 {
-       if (expected == actual)  // true including nullptr
-               return;
+       csr_cs_severity_level_e a_severity;
+       const char *a_malware_name;
+       const char *a_detailed_url;
 
-       // null string and empty string are same
-       if ((expected == nullptr) && (actual != nullptr) && (strlen(actual) == 0))
-               return;
-       if ((actual == nullptr) && (expected != nullptr) && (strlen(expected) == 0))
-               return;
+       ASSERT_IF(csr_cs_detected_get_severity(detected, &a_severity), CSR_ERROR_NONE);
+       ASSERT_IF(csr_cs_detected_get_malware_name(detected, &a_malware_name), CSR_ERROR_NONE);
+       ASSERT_IF(csr_cs_detected_get_detailed_url(detected, &a_detailed_url), CSR_ERROR_NONE);
 
-       BOOST_REQUIRE_MESSAGE((expected != nullptr) && (actual != nullptr) && (strcmp(expected, actual) == 0),
-                                                 std::string((msg == nullptr) ? "NULL" : msg)
-                                                 << ", EXPECTED=" << std::string((expected == nullptr) ? "NULL" : expected)
-                                                 << ", ACTUAL=" << std::string((actual == nullptr) ? "NULL" : actual));
+       ASSERT_IF(a_severity, e_severity);
+       ASSERT_IF(a_malware_name, e_malware_name);
+       ASSERT_IF(a_detailed_url, e_detailed_url);
 }
 
-void ASSERT_DETECTED(csr_cs_detected_h detected, const char *name, int severity, const char *detailed_url)
+void ASSERT_DETECTED_EXT(csr_cs_detected_h detected, time_t e_timestamp,
+                                                const char *e_file_name, bool e_is_app, const char *e_pkg_id)
 {
-       csr_cs_severity_level_e d_severity;
-       const char *d_malware_name;
-       const char *d_detailed_url;
-
-       ASSERT_IF(csr_cs_detected_get_severity(detected, &d_severity), CSR_ERROR_NONE);
-       ASSERT_IF(csr_cs_detected_get_malware_name(detected, &d_malware_name), CSR_ERROR_NONE);
-       ASSERT_IF(csr_cs_detected_get_detailed_url(detected, &d_detailed_url), CSR_ERROR_NONE);
-
-       BOOST_REQUIRE_MESSAGE(severity == d_severity,
-                                                 "EXPECTED=" << severity << ", ACTUAL=" << d_severity);
-       ASSERT_STRING(name, d_malware_name, "MALWARE NAME CMP FAIL");
-       ASSERT_STRING(detailed_url, d_detailed_url, "DETAILED ULR CMP FAIL");
-}
-
-void ASSERT_DETECTED_EXT(csr_cs_detected_h detected, time_t time, const char *file_name, bool is_app, const char *pkg_id)
-{
-       time_t d_timestamp;
-       const char *d_file_name;
-       bool d_is_app;
-       const char *d_pkg_id;
-
-       ASSERT_IF(csr_cs_detected_get_timestamp(detected, &d_timestamp), CSR_ERROR_NONE);
-       ASSERT_IF(csr_cs_detected_get_file_name(detected, &d_file_name), CSR_ERROR_NONE);
-       ASSERT_IF(csr_cs_detected_is_app(detected, &d_is_app), CSR_ERROR_NONE);
-       ASSERT_IF(csr_cs_detected_get_pkg_id(detected, &d_pkg_id), CSR_ERROR_NONE);
-
-       BOOST_REQUIRE_MESSAGE(time <= d_timestamp,
-                                                 "TIMESTAMP CMP FAIL. EXPECTED should be smaller than ACTUAL, EXPECTED="
-                                                 << time << ", ACTUAL=" << d_timestamp);
-       ASSERT_STRING(file_name, d_file_name, "NAME CMP FAIL");
-       BOOST_REQUIRE_MESSAGE(is_app == d_is_app,
-                                                 "IS_APP CMP FAIL. EXPECTED=" << is_app << ", ACTUAL=" << d_is_app);
-       ASSERT_STRING(pkg_id, d_pkg_id, "PKGID CMP FAIL");
+       time_t a_timestamp;
+       const char *a_file_name;
+       bool a_is_app;
+       const char *a_pkg_id;
+
+       ASSERT_IF(csr_cs_detected_get_timestamp(detected, &a_timestamp), CSR_ERROR_NONE);
+       ASSERT_IF(csr_cs_detected_get_file_name(detected, &a_file_name), CSR_ERROR_NONE);
+       ASSERT_IF(csr_cs_detected_is_app(detected, &a_is_app), CSR_ERROR_NONE);
+       ASSERT_IF(csr_cs_detected_get_pkg_id(detected, &a_pkg_id), CSR_ERROR_NONE);
+
+       ASSERT_IF(a_file_name, e_file_name);
+       ASSERT_IF(a_is_app, e_is_app);
+       ASSERT_IF(a_pkg_id, e_pkg_id);
+
+       BOOST_CHECK_MESSAGE(e_timestamp <= a_timestamp,
+                                               "Actual detected item's time stamp is later than expected time "
+                                               "stamp (which is start time before scan_file maybe..). this case "
+                                               "should be the returned detected item comes from history which is "
+                                               "scanned in the past. actual time: " << a_timestamp <<
+                                               " expected(started) time: " << e_timestamp);
 }
 
 void ASSERT_DETECTED_HANDLE(csr_cs_detected_h expected, csr_cs_detected_h actual)
@@ -114,147 +96,11 @@ void ASSERT_DETECTED_HANDLE(csr_cs_detected_h expected, csr_cs_detected_h actual
        ASSERT_IF(csr_cs_detected_is_app(actual, &a_is_app), CSR_ERROR_NONE);
        ASSERT_IF(csr_cs_detected_get_pkg_id(actual, &a_pkg_id), CSR_ERROR_NONE);
 
-       BOOST_REQUIRE_MESSAGE(e_severity == a_severity,
-                                                 "EXPECTED=" << e_severity << ", ACTUAL=" << a_severity);
-       ASSERT_STRING(e_malware_name, a_malware_name, "MALWARE NAME CMP FAIL");
-       ASSERT_STRING(e_detailed_url, a_detailed_url, "DETAILED ULR CMP FAIL");
-       BOOST_REQUIRE_MESSAGE(e_timestamp == a_timestamp,
-                                                 "EXPECTED=" << e_timestamp << ", ACTUAL=" << a_timestamp);
-       ASSERT_STRING(e_file_name, a_file_name, "FILE NAME CMP FAIL");
-       BOOST_REQUIRE_MESSAGE(e_is_app == a_is_app,
-                                                 "EXPECTED=" << e_is_app << ", ACTUAL=" << a_is_app);
-       ASSERT_STRING(e_pkg_id, a_pkg_id, "PKG ID CMP FAIL");
-}
-
-
-void copy_file(const char *src_file, const char *dest_file)
-{
-       std::ifstream srce(src_file, std::ios::binary) ;
-       std::ofstream dest(dest_file, std::ios::binary) ;
-       dest << srce.rdbuf() ;
-}
-
-void touch_file(const char *file)
-{
-       struct utimbuf new_times;
-       time_t now = time(nullptr);
-
-       new_times.actime = now;
-       new_times.modtime = now;
-
-       utime(file, &new_times);
-}
-
-bool is_file_exist(const char *file)
-{
-       return (access(file, F_OK) != -1);
-}
-
-bool installed;
-GMainLoop *installMainLoop;
-int __app_install_cb(int req_id, const char *pkg_type, const char *pkgid,
-                                        const char *key, const char *val, const void *pmsg, void *data)
-{
-       (void) req_id;
-       (void) pkg_type;
-       (void) pkgid;
-       (void) pmsg;
-       (void) data;
-
-       installed = false;
-
-       if (key && strncmp(key, "end", strlen("end")) == 0) {
-               if (strncmp(val, "ok", strlen("ok")) == 0) {
-                       installed = true;
-                       g_main_loop_quit(installMainLoop);
-                       g_main_loop_unref(installMainLoop);
-               }
-       }
-
-       return 0;
-}
-
-gboolean __app_install_timeout(gpointer)
-{
-       installed = false;
-       return TRUE;
-}
-
-bool install_app(const char *app_path, const char *pkg_type)
-{
-       auto pkgmgr = pkgmgr_client_new(PC_REQUEST);
-       CHECK_IS_NOT_NULL(pkgmgr);
-
-       installed = false;
-       int ret = pkgmgr_client_install(pkgmgr, pkg_type, nullptr, app_path, nullptr, PM_QUIET,
-                                                                       __app_install_cb, nullptr);
-       if (ret <= PKGMGR_R_OK)
-               return false;
-
-       g_timeout_add_seconds(30, __app_install_timeout, nullptr);
-       installMainLoop = g_main_loop_new(nullptr, false);
-       g_main_loop_run(installMainLoop);
-       pkgmgr_client_free(pkgmgr);
-
-       return installed;
-}
-
-
-bool uninstalled;
-GMainLoop *uninstallMainLoop;
-int __app_uninstall_cb(int req_id, const char *pkg_type, const char *pkgid, const char *key,
-                                          const char *val, const void *pmsg, void *data)
-{
-       (void) req_id;
-       (void) pkg_type;
-       (void) pkgid;
-       (void) pmsg;
-       (void) data;
-
-       uninstalled = false;
-
-       if (key && strncmp(key, "end", strlen("end")) == 0) {
-               if (strncmp(val, "ok", strlen("ok")) == 0) {
-                       uninstalled = true;
-                       g_main_loop_quit(uninstallMainLoop);
-                       g_main_loop_unref(uninstallMainLoop);
-               }
-       }
-
-       return 0;
-}
-
-gboolean __app_uninstall_timeout(gpointer)
-{
-       uninstalled = false;
-       return TRUE;
-}
-
-bool uninstall_app(const char *pkg_id)
-{
-       auto pkgmgr = pkgmgr_client_new(PC_REQUEST);
-       CHECK_IS_NOT_NULL(pkgmgr);
-
-       uninstalled = false;
-       int ret = pkgmgr_client_uninstall(pkgmgr, nullptr, pkg_id, PM_QUIET, __app_uninstall_cb, nullptr);
-       if (ret <= PKGMGR_R_OK)
-               return false;
-
-       g_timeout_add_seconds(30, __app_uninstall_timeout, nullptr);
-       uninstallMainLoop = g_main_loop_new(nullptr, false);
-       g_main_loop_run(uninstallMainLoop);
-       pkgmgr_client_free(pkgmgr);
-
-       return uninstalled;
-}
-
-bool is_app_exist(const char *pkg_id)
-{
-       pkgmgrinfo_pkginfo_h handle;
-
-       if (pkgmgrinfo_pkginfo_get_pkginfo(pkg_id, &handle) != PMINFO_R_OK)
-               return false;
-
-       pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
-       return true;
+       ASSERT_IF(a_severity, e_severity);
+       ASSERT_IF(a_malware_name, e_malware_name);
+       ASSERT_IF(a_detailed_url, e_detailed_url);
+       ASSERT_IF(a_file_name, e_file_name);
+       ASSERT_IF(a_is_app, e_is_app);
+       ASSERT_IF(a_pkg_id, e_pkg_id);
+       ASSERT_IF(a_timestamp, e_timestamp);
 }
index eab62ec..03f96d9 100644 (file)
  */
 #include <csr/content-screening.h>
 
-void ASSERT_STRING(const char *expected, const char *actual, const char *msg);
-
 void ASSERT_DETECTED(csr_cs_detected_h detected, const char *name, int severity, const char *detailed_url);
 
 void ASSERT_DETECTED_EXT(csr_cs_detected_h detected, time_t time, const char *file_name, bool is_app, const char *pkg_id);
 
 void ASSERT_DETECTED_HANDLE(csr_cs_detected_h expected, csr_cs_detected_h actual);
-
-void copy_file(const char *src_file, const char *dest_file);
-
-void touch_file(const char *file);
-
-bool is_file_exist(const char *file);
-
-bool install_app(const char *app_path, const char *app_type);
-
-bool uninstall_app(const char *pkg_id);
-
-bool is_app_exist(const char *pkg_id);