Use std::string on test function param 32/73932/1
authorKyungwook Tak <k.tak@samsung.com>
Fri, 10 Jun 2016 05:51:52 +0000 (14:51 +0900)
committerKyungwook Tak <k.tak@samsung.com>
Fri, 10 Jun 2016 05:54:01 +0000 (14:54 +0900)
resource paths could be converted to std::string to support both of
platform v 2.4 & 3.0 by generate paths dynamically.
For this, test assertion functions need to receive std::string() param
for not to use '.c_str()' member function of std::string to all of
callers.

Change-Id: I3780673a757204fea7be1846726e8f15f14c449b
Signed-off-by: Kyungwook Tak <k.tak@samsung.com>
test/test-api-content-screening-async.cpp
test/test-api-content-screening.cpp
test/test-common.cpp
test/test-common.h
test/test-helper.cpp
test/test-helper.h

index c416232..8261c20 100644 (file)
@@ -83,7 +83,7 @@ void on_scanned(const char *file, void *userdata)
 void on_detected(csr_cs_malware_h detected, void *userdata)
 {
        Test::ScopedCstr file_name;
-       ASSERT_IF(csr_cs_malware_get_file_name(detected, &file_name.ptr), CSR_ERROR_NONE);
+       ASSERT_SUCCESS(csr_cs_malware_get_file_name(detected, &file_name.ptr));
        BOOST_MESSAGE("on_detected. file[" << file_name.ptr << "] detected!");
        auto ctx = reinterpret_cast<AsyncTestContext *>(userdata);
 
@@ -95,7 +95,8 @@ void on_detected(csr_cs_malware_h detected, void *userdata)
 
 void on_error(int ec, void *userdata)
 {
-       BOOST_MESSAGE("on_error. async request done with error code[" << ec << "]");
+       BOOST_MESSAGE("on_error. async request done with error: " <<
+                                 Test::capi_ec_to_string(static_cast<csr_error_e>(ec)));
        auto ctx = reinterpret_cast<AsyncTestContext *>(userdata);
 
        ctx->errorCnt++;
@@ -121,11 +122,11 @@ void on_cancelled(void *userdata)
 
 void set_default_callback(csr_cs_context_h context)
 {
-       ASSERT_IF(csr_cs_set_detected_cb(context, on_detected), CSR_ERROR_NONE);
-       ASSERT_IF(csr_cs_set_completed_cb(context, on_completed), CSR_ERROR_NONE);
-       ASSERT_IF(csr_cs_set_cancelled_cb(context, on_cancelled), CSR_ERROR_NONE);
-       ASSERT_IF(csr_cs_set_error_cb(context, on_error), CSR_ERROR_NONE);
-       ASSERT_IF(csr_cs_set_file_scanned_cb(context, on_scanned), CSR_ERROR_NONE);
+       ASSERT_SUCCESS(csr_cs_set_detected_cb(context, on_detected));
+       ASSERT_SUCCESS(csr_cs_set_completed_cb(context, on_completed));
+       ASSERT_SUCCESS(csr_cs_set_cancelled_cb(context, on_cancelled));
+       ASSERT_SUCCESS(csr_cs_set_error_cb(context, on_error));
+       ASSERT_SUCCESS(csr_cs_set_file_scanned_cb(context, on_scanned));
 }
 
 void install_test_files()
@@ -216,10 +217,7 @@ BOOST_AUTO_TEST_CASE(scan_files_async_positive)
 
        AsyncTestContext testCtx;
 
-       ASSERT_IF(
-               csr_cs_scan_files_async(context, files, sizeof(files) / sizeof(const char *),
-                                                               &testCtx),
-               CSR_ERROR_NONE);
+       ASSERT_SUCCESS(csr_cs_scan_files_async(context, files, 4, &testCtx));
 
        std::unique_lock<std::mutex> l(testCtx.m);
        testCtx.cv.wait(l);
@@ -229,18 +227,15 @@ BOOST_AUTO_TEST_CASE(scan_files_async_positive)
 
        ASSERT_DETECTED_IN_LIST(testCtx.detectedList,
                TEST_FILE_HIGH, MALWARE_HIGH_NAME, MALWARE_HIGH_SEVERITY, MALWARE_HIGH_DETAILED_URL);
-       ASSERT_DETECTED_IN_LIST_EXT(testCtx.detectedList,
-               TEST_FILE_HIGH, false, nullptr);
+       ASSERT_DETECTED_IN_LIST_EXT(testCtx.detectedList, TEST_FILE_HIGH, false, "");
 
        ASSERT_DETECTED_IN_LIST(testCtx.detectedList,
                TEST_FILE_MEDIUM, MALWARE_MEDIUM_NAME, MALWARE_MEDIUM_SEVERITY, MALWARE_MEDIUM_DETAILED_URL);
-       ASSERT_DETECTED_IN_LIST_EXT(testCtx.detectedList,
-               TEST_FILE_MEDIUM, false, nullptr);
+       ASSERT_DETECTED_IN_LIST_EXT(testCtx.detectedList, TEST_FILE_MEDIUM, false, "");
 
        ASSERT_DETECTED_IN_LIST(testCtx.detectedList,
                TEST_FILE_LOW, MALWARE_LOW_NAME, MALWARE_LOW_SEVERITY, MALWARE_LOW_DETAILED_URL);
-       ASSERT_DETECTED_IN_LIST_EXT(testCtx.detectedList,
-               TEST_FILE_LOW, false, nullptr);
+       ASSERT_DETECTED_IN_LIST_EXT(testCtx.detectedList, TEST_FILE_LOW, false, "");
 
        EXCEPTION_GUARD_END
 }
@@ -260,15 +255,8 @@ BOOST_AUTO_TEST_CASE(scan_files_async_negative)
 
        AsyncTestContext testCtx;
 
-       ASSERT_IF(
-               csr_cs_scan_files_async(nullptr, files, sizeof(files) / sizeof(const char *),
-                                                               nullptr),
-               CSR_ERROR_INVALID_HANDLE);
-
-       ASSERT_IF(
-               csr_cs_scan_files_async(context, nullptr, sizeof(files) / sizeof(const char *),
-                                                               nullptr),
-               CSR_ERROR_INVALID_PARAMETER);
+       ASSERT_IF(csr_cs_scan_files_async(nullptr, files, 3, nullptr), CSR_ERROR_INVALID_HANDLE);
+       ASSERT_IF(csr_cs_scan_files_async(context, nullptr, 3, nullptr), CSR_ERROR_INVALID_PARAMETER);
 
        EXCEPTION_GUARD_END
 }
@@ -284,7 +272,7 @@ BOOST_AUTO_TEST_CASE(scan_dir_positive)
 
        AsyncTestContext testCtx;
 
-       ASSERT_IF(csr_cs_scan_dir_async(context, TEST_DIR_MALWARES, &testCtx), CSR_ERROR_NONE);
+       ASSERT_SUCCESS(csr_cs_scan_dir_async(context, TEST_DIR_MALWARES, &testCtx));
 
        std::unique_lock<std::mutex> l(testCtx.m);
        testCtx.cv.wait(l);
@@ -305,10 +293,8 @@ BOOST_AUTO_TEST_CASE(scan_dir_negative)
 
        AsyncTestContext testCtx;
 
-       ASSERT_IF(csr_cs_scan_dir_async(nullptr, TEST_DIR_MALWARES, nullptr),
-               CSR_ERROR_INVALID_HANDLE);
-       ASSERT_IF(csr_cs_scan_dir_async(context, nullptr, nullptr),
-               CSR_ERROR_INVALID_PARAMETER);
+       ASSERT_IF(csr_cs_scan_dir_async(nullptr, TEST_DIR_MALWARES, nullptr), CSR_ERROR_INVALID_HANDLE);
+       ASSERT_IF(csr_cs_scan_dir_async(context, nullptr, nullptr), CSR_ERROR_INVALID_PARAMETER);
 
        EXCEPTION_GUARD_END
 }
@@ -327,7 +313,7 @@ BOOST_AUTO_TEST_CASE(scan_dir_root)
 
        AsyncTestContext testCtx;
 
-       ASSERT_IF(csr_cs_scan_dir_async(context, TEST_DIR_ROOT, &testCtx), CSR_ERROR_NONE);
+       ASSERT_SUCCESS(csr_cs_scan_dir_async(context, TEST_DIR_ROOT, &testCtx));
 
        std::unique_lock<std::mutex> l(testCtx.m);
        testCtx.cv.wait(l);
@@ -341,43 +327,35 @@ BOOST_AUTO_TEST_CASE(scan_dir_root)
 
        ASSERT_DETECTED_IN_LIST(testCtx.detectedList,
                TEST_FILE_HIGH, MALWARE_HIGH_NAME, MALWARE_HIGH_SEVERITY, MALWARE_HIGH_DETAILED_URL);
-       ASSERT_DETECTED_IN_LIST_EXT(testCtx.detectedList,
-               TEST_FILE_HIGH, false, nullptr);
+       ASSERT_DETECTED_IN_LIST_EXT(testCtx.detectedList, TEST_FILE_HIGH, false, "");
 
        ASSERT_DETECTED_IN_LIST(testCtx.detectedList,
                TEST_FILE_MEDIUM, MALWARE_MEDIUM_NAME, MALWARE_MEDIUM_SEVERITY, MALWARE_MEDIUM_DETAILED_URL);
-       ASSERT_DETECTED_IN_LIST_EXT(testCtx.detectedList,
-               TEST_FILE_MEDIUM, false, nullptr);
+       ASSERT_DETECTED_IN_LIST_EXT(testCtx.detectedList, TEST_FILE_MEDIUM, false, "");
 
        ASSERT_DETECTED_IN_LIST(testCtx.detectedList,
                TEST_FILE_LOW, MALWARE_LOW_NAME, MALWARE_LOW_SEVERITY, MALWARE_LOW_DETAILED_URL);
-       ASSERT_DETECTED_IN_LIST_EXT(testCtx.detectedList,
-               TEST_FILE_LOW, false, nullptr);
+       ASSERT_DETECTED_IN_LIST_EXT(testCtx.detectedList, TEST_FILE_LOW, false, "");
 
        ASSERT_DETECTED_IN_LIST(testCtx.detectedList,
                TEST_FILE_MEDIA, MALWARE_HIGH_NAME, MALWARE_HIGH_SEVERITY, MALWARE_HIGH_DETAILED_URL);
-       ASSERT_DETECTED_IN_LIST_EXT(testCtx.detectedList,
-               TEST_FILE_MEDIA, false, nullptr);
+       ASSERT_DETECTED_IN_LIST_EXT(testCtx.detectedList, TEST_FILE_MEDIA, false, "");
 
        ASSERT_DETECTED_IN_LIST(testCtx.detectedList,
                TEST_FILE_TMP, MALWARE_HIGH_NAME, MALWARE_HIGH_SEVERITY, MALWARE_HIGH_DETAILED_URL);
-       ASSERT_DETECTED_IN_LIST_EXT(testCtx.detectedList,
-               TEST_FILE_TMP, false, nullptr);
+       ASSERT_DETECTED_IN_LIST_EXT(testCtx.detectedList, TEST_FILE_TMP, false, "");
 
        ASSERT_DETECTED_IN_LIST(testCtx.detectedList,
                TEST_WGT_APP_ROOT(), MALWARE_HIGH_NAME, MALWARE_HIGH_SEVERITY, MALWARE_HIGH_DETAILED_URL);
-       ASSERT_DETECTED_IN_LIST_EXT(testCtx.detectedList,
-               TEST_WGT_APP_ROOT(), true, TEST_WGT_PKG_ID);
+       ASSERT_DETECTED_IN_LIST_EXT(testCtx.detectedList, TEST_WGT_APP_ROOT(), true, TEST_WGT_PKG_ID);
 
        ASSERT_DETECTED_IN_LIST(testCtx.detectedList,
                TEST_TPK_APP_ROOT(), MALWARE_HIGH_NAME, MALWARE_HIGH_SEVERITY, MALWARE_HIGH_DETAILED_URL);
-       ASSERT_DETECTED_IN_LIST_EXT(testCtx.detectedList,
-               TEST_TPK_APP_ROOT(), true, TEST_TPK_PKG_ID);
+       ASSERT_DETECTED_IN_LIST_EXT(testCtx.detectedList, TEST_TPK_APP_ROOT(), true, TEST_TPK_PKG_ID);
 
        ASSERT_DETECTED_IN_LIST(testCtx.detectedList,
                TEST_FAKE_APP_FILE, MALWARE_HIGH_NAME, MALWARE_HIGH_SEVERITY, MALWARE_HIGH_DETAILED_URL);
-       ASSERT_DETECTED_IN_LIST_EXT(testCtx.detectedList,
-               TEST_FAKE_APP_FILE, false, nullptr);
+       ASSERT_DETECTED_IN_LIST_EXT(testCtx.detectedList, TEST_FAKE_APP_FILE, false, "");
 
        EXCEPTION_GUARD_END
 }
@@ -395,7 +373,7 @@ BOOST_AUTO_TEST_CASE(scan_dir_media)
 
        AsyncTestContext testCtx;
 
-       ASSERT_IF(csr_cs_scan_dir_async(context, TEST_DIR_MEDIA, &testCtx), CSR_ERROR_NONE);
+       ASSERT_SUCCESS(csr_cs_scan_dir_async(context, TEST_DIR_MEDIA, &testCtx));
 
        std::unique_lock<std::mutex> l(testCtx.m);
        testCtx.cv.wait(l);
@@ -406,8 +384,7 @@ BOOST_AUTO_TEST_CASE(scan_dir_media)
 
        ASSERT_DETECTED_IN_LIST(testCtx.detectedList,
                TEST_FILE_MEDIA, MALWARE_HIGH_NAME, MALWARE_HIGH_SEVERITY, MALWARE_HIGH_DETAILED_URL);
-       ASSERT_DETECTED_IN_LIST_EXT(testCtx.detectedList,
-               TEST_FILE_MEDIA, false, nullptr);
+       ASSERT_DETECTED_IN_LIST_EXT(testCtx.detectedList, TEST_FILE_MEDIA, false, "");
 
        EXCEPTION_GUARD_END
 }
@@ -425,7 +402,7 @@ BOOST_AUTO_TEST_CASE(scan_dir_tmp)
 
        AsyncTestContext testCtx;
 
-       ASSERT_IF(csr_cs_scan_dir_async(context, TEST_DIR_TMP, &testCtx), CSR_ERROR_NONE);
+       ASSERT_SUCCESS(csr_cs_scan_dir_async(context, TEST_DIR_TMP, &testCtx));
 
        std::unique_lock<std::mutex> l(testCtx.m);
        testCtx.cv.wait(l);
@@ -436,8 +413,7 @@ BOOST_AUTO_TEST_CASE(scan_dir_tmp)
 
        ASSERT_DETECTED_IN_LIST(testCtx.detectedList,
                TEST_FILE_TMP, MALWARE_HIGH_NAME, MALWARE_HIGH_SEVERITY, MALWARE_HIGH_DETAILED_URL);
-       ASSERT_DETECTED_IN_LIST_EXT(testCtx.detectedList,
-               TEST_FILE_TMP, false, nullptr);
+       ASSERT_DETECTED_IN_LIST_EXT(testCtx.detectedList, TEST_FILE_TMP, false, "");
 
        EXCEPTION_GUARD_END
 }
@@ -467,18 +443,15 @@ BOOST_AUTO_TEST_CASE(scan_dir_apps)
 
        ASSERT_DETECTED_IN_LIST(testCtx.detectedList,
                TEST_WGT_APP_ROOT(), MALWARE_HIGH_NAME, MALWARE_HIGH_SEVERITY, MALWARE_HIGH_DETAILED_URL);
-       ASSERT_DETECTED_IN_LIST_EXT(testCtx.detectedList,
-               TEST_WGT_APP_ROOT(), true, TEST_WGT_PKG_ID);
+       ASSERT_DETECTED_IN_LIST_EXT(testCtx.detectedList, TEST_WGT_APP_ROOT(), true, TEST_WGT_PKG_ID);
 
        ASSERT_DETECTED_IN_LIST(testCtx.detectedList,
                TEST_TPK_APP_ROOT(), MALWARE_HIGH_NAME, MALWARE_HIGH_SEVERITY, MALWARE_HIGH_DETAILED_URL);
-       ASSERT_DETECTED_IN_LIST_EXT(testCtx.detectedList,
-               TEST_TPK_APP_ROOT(), true, TEST_TPK_PKG_ID);
+       ASSERT_DETECTED_IN_LIST_EXT(testCtx.detectedList, TEST_TPK_APP_ROOT(), true, TEST_TPK_PKG_ID);
 
        ASSERT_DETECTED_IN_LIST(testCtx.detectedList,
                TEST_FAKE_APP_FILE, MALWARE_HIGH_NAME, MALWARE_HIGH_SEVERITY, MALWARE_HIGH_DETAILED_URL);
-       ASSERT_DETECTED_IN_LIST_EXT(testCtx.detectedList,
-               TEST_FAKE_APP_FILE, false, nullptr);
+       ASSERT_DETECTED_IN_LIST_EXT(testCtx.detectedList, TEST_FAKE_APP_FILE, false, "");
 
        uninstall_test_apps();
 
@@ -499,7 +472,7 @@ BOOST_AUTO_TEST_CASE(scan_dir_wgt)
 
        AsyncTestContext testCtx;
 
-       ASSERT_IF(csr_cs_scan_dir_async(context, TEST_WGT_APP_ROOT().c_str(), &testCtx), CSR_ERROR_NONE);
+       ASSERT_SUCCESS(csr_cs_scan_dir_async(context, TEST_WGT_APP_ROOT().c_str(), &testCtx));
 
        std::unique_lock<std::mutex> l(testCtx.m);
        testCtx.cv.wait(l);
@@ -510,8 +483,7 @@ BOOST_AUTO_TEST_CASE(scan_dir_wgt)
 
        ASSERT_DETECTED_IN_LIST(testCtx.detectedList,
                TEST_WGT_APP_ROOT(), MALWARE_HIGH_NAME, MALWARE_HIGH_SEVERITY, MALWARE_HIGH_DETAILED_URL);
-       ASSERT_DETECTED_IN_LIST_EXT(testCtx.detectedList,
-               TEST_WGT_APP_ROOT(), true, TEST_WGT_PKG_ID);
+       ASSERT_DETECTED_IN_LIST_EXT(testCtx.detectedList, TEST_WGT_APP_ROOT(), true, TEST_WGT_PKG_ID);
 
        Test::uninstall_app(TEST_WGT_PKG_ID);
 
@@ -532,7 +504,7 @@ BOOST_AUTO_TEST_CASE(scan_dir_tpk)
 
        AsyncTestContext testCtx;
 
-       ASSERT_IF(csr_cs_scan_dir_async(context, TEST_TPK_APP_ROOT().c_str(), &testCtx), CSR_ERROR_NONE);
+       ASSERT_SUCCESS(csr_cs_scan_dir_async(context, TEST_TPK_APP_ROOT().c_str(), &testCtx));
 
        std::unique_lock<std::mutex> l(testCtx.m);
        testCtx.cv.wait(l);
@@ -543,8 +515,7 @@ BOOST_AUTO_TEST_CASE(scan_dir_tpk)
 
        ASSERT_DETECTED_IN_LIST(testCtx.detectedList,
                TEST_TPK_APP_ROOT(), MALWARE_HIGH_NAME, MALWARE_HIGH_SEVERITY, MALWARE_HIGH_DETAILED_URL);
-       ASSERT_DETECTED_IN_LIST_EXT(testCtx.detectedList,
-               TEST_TPK_APP_ROOT(), true, TEST_TPK_PKG_ID);
+       ASSERT_DETECTED_IN_LIST_EXT(testCtx.detectedList, TEST_TPK_APP_ROOT(), true, TEST_TPK_PKG_ID);
 
        Test::uninstall_app(TEST_TPK_PKG_ID);
 
@@ -566,10 +537,7 @@ BOOST_AUTO_TEST_CASE(scan_dirs_positive)
                TEST_DIR_MALWARES
        };
 
-       ASSERT_IF(
-               csr_cs_scan_dirs_async(context, dirs, sizeof(dirs) / sizeof(const char *),
-                                                          &testCtx),
-               CSR_ERROR_NONE);
+       ASSERT_SUCCESS(csr_cs_scan_dirs_async(context, dirs, 1, &testCtx));
 
        std::unique_lock<std::mutex> l(testCtx.m);
        testCtx.cv.wait(l);
@@ -592,15 +560,8 @@ BOOST_AUTO_TEST_CASE(scan_dirs_negative)
                TEST_DIR_MALWARES
        };
 
-       ASSERT_IF(
-               csr_cs_scan_dirs_async(nullptr, dirs, sizeof(dirs) / sizeof(const char *),
-                                                          nullptr),
-               CSR_ERROR_INVALID_HANDLE);
-
-       ASSERT_IF(
-               csr_cs_scan_dirs_async(context, nullptr, sizeof(dirs) / sizeof(const char *),
-                                                          nullptr),
-               CSR_ERROR_INVALID_PARAMETER);
+       ASSERT_IF(csr_cs_scan_dirs_async(nullptr, dirs, 1, nullptr), CSR_ERROR_INVALID_HANDLE);
+       ASSERT_IF(csr_cs_scan_dirs_async(context, nullptr, 1, nullptr), CSR_ERROR_INVALID_PARAMETER);
 
        EXCEPTION_GUARD_END
 }
@@ -624,15 +585,13 @@ BOOST_AUTO_TEST_CASE(scan_cancel_positiive)
        // touch a file : in case of no target file to scan, we cannot cancel to scan.
        Test::touch_file(TEST_FILE_HIGH);
 
-       ASSERT_IF(csr_cs_scan_dirs_async(context, dirs,
-                                                                        sizeof(dirs) / sizeof(const char *), &testCtx),
-                         CSR_ERROR_NONE);
+       ASSERT_SUCCESS(csr_cs_scan_dirs_async(context, dirs, 1, &testCtx));
 
        // TODO: check the reason
        // Without sleep, sometimes the first run of this TC fails with core dump.
        std::this_thread::sleep_for(std::chrono::milliseconds(100));
 
-       ASSERT_IF(csr_cs_cancel_scanning(context), CSR_ERROR_NONE);
+       ASSERT_SUCCESS(csr_cs_cancel_scanning(context));
 
        std::this_thread::sleep_for(std::chrono::milliseconds(100));
 
@@ -697,18 +656,15 @@ BOOST_AUTO_TEST_CASE(delta_scan_basic)
 
        ASSERT_DETECTED_IN_LIST(testRescanCtx.detectedList,
                TEST_WGT_APP_ROOT(), MALWARE_HIGH_NAME, MALWARE_HIGH_SEVERITY, MALWARE_HIGH_DETAILED_URL);
-       ASSERT_DETECTED_IN_LIST_EXT(testRescanCtx.detectedList,
-               TEST_WGT_APP_ROOT(), true, TEST_WGT_PKG_ID);
+       ASSERT_DETECTED_IN_LIST_EXT(testRescanCtx.detectedList, TEST_WGT_APP_ROOT(), true, TEST_WGT_PKG_ID);
 
        ASSERT_DETECTED_IN_LIST(testRescanCtx.detectedList,
                TEST_TPK_APP_ROOT(), MALWARE_HIGH_NAME, MALWARE_HIGH_SEVERITY, MALWARE_HIGH_DETAILED_URL);
-       ASSERT_DETECTED_IN_LIST_EXT(testRescanCtx.detectedList,
-               TEST_TPK_APP_ROOT(), true, TEST_TPK_PKG_ID);
+       ASSERT_DETECTED_IN_LIST_EXT(testRescanCtx.detectedList, TEST_TPK_APP_ROOT(), true, TEST_TPK_PKG_ID);
 
        ASSERT_DETECTED_IN_LIST(testRescanCtx.detectedList,
                TEST_FAKE_APP_FILE, MALWARE_HIGH_NAME, MALWARE_HIGH_SEVERITY, MALWARE_HIGH_DETAILED_URL);
-       ASSERT_DETECTED_IN_LIST_EXT(testRescanCtx.detectedList,
-               TEST_FAKE_APP_FILE, false, nullptr);
+       ASSERT_DETECTED_IN_LIST_EXT(testRescanCtx.detectedList, TEST_FAKE_APP_FILE, false, "");
 
        // Rescan the sub dir
        AsyncTestContext testRescanSubCtx;
@@ -724,8 +680,7 @@ BOOST_AUTO_TEST_CASE(delta_scan_basic)
 
        ASSERT_DETECTED_IN_LIST(testRescanSubCtx.detectedList,
                TEST_WGT_APP_ROOT(), MALWARE_HIGH_NAME, MALWARE_HIGH_SEVERITY, MALWARE_HIGH_DETAILED_URL);
-       ASSERT_DETECTED_IN_LIST_EXT(testRescanSubCtx.detectedList,
-               TEST_WGT_APP_ROOT(), true, TEST_WGT_PKG_ID);
+       ASSERT_DETECTED_IN_LIST_EXT(testRescanSubCtx.detectedList, TEST_WGT_APP_ROOT(), true, TEST_WGT_PKG_ID);
 
        uninstall_test_apps();
 
@@ -778,18 +733,15 @@ BOOST_AUTO_TEST_CASE(delta_scan_changed_after_scan)
 
        ASSERT_DETECTED_IN_LIST(testRescanCtx.detectedList,
                TEST_WGT_APP_ROOT(), MALWARE_HIGH_NAME, MALWARE_HIGH_SEVERITY, MALWARE_HIGH_DETAILED_URL);
-       ASSERT_DETECTED_IN_LIST_EXT(testRescanCtx.detectedList,
-               TEST_WGT_APP_ROOT(), true, TEST_WGT_PKG_ID);
+       ASSERT_DETECTED_IN_LIST_EXT(testRescanCtx.detectedList, TEST_WGT_APP_ROOT(), true, TEST_WGT_PKG_ID);
 
        ASSERT_DETECTED_IN_LIST(testRescanCtx.detectedList,
                TEST_TPK_APP_ROOT(), MALWARE_HIGH_NAME, MALWARE_HIGH_SEVERITY, MALWARE_HIGH_DETAILED_URL);
-       ASSERT_DETECTED_IN_LIST_EXT(testRescanCtx.detectedList,
-               TEST_TPK_APP_ROOT(), true, TEST_TPK_PKG_ID);
+       ASSERT_DETECTED_IN_LIST_EXT(testRescanCtx.detectedList, TEST_TPK_APP_ROOT(), true, TEST_TPK_PKG_ID);
 
        ASSERT_DETECTED_IN_LIST(testRescanCtx.detectedList,
                TEST_FAKE_APP_FILE, MALWARE_HIGH_NAME, MALWARE_HIGH_SEVERITY, MALWARE_HIGH_DETAILED_URL);
-       ASSERT_DETECTED_IN_LIST_EXT(testRescanCtx.detectedList,
-               TEST_FAKE_APP_FILE, false, nullptr);
+       ASSERT_DETECTED_IN_LIST_EXT(testRescanCtx.detectedList, TEST_FAKE_APP_FILE, false, "");
 
        uninstall_test_apps();
 
@@ -819,8 +771,7 @@ BOOST_AUTO_TEST_CASE(canonicalize_files_absolute_path)
 
        AsyncTestContext testCtx;
 
-       ASSERT_SUCCESS(csr_cs_scan_files_async(context, files, sizeof(files) / sizeof(const char *),
-                                                                                  &testCtx));
+       ASSERT_SUCCESS(csr_cs_scan_files_async(context, files, 4, &testCtx));
 
        std::unique_lock<std::mutex> l(testCtx.m);
        testCtx.cv.wait(l);
@@ -858,8 +809,7 @@ BOOST_AUTO_TEST_CASE(canonicalize_files_relative_path)
 
        Test::ScopedChDir scopedCd(TEST_DIR);
 
-       ASSERT_SUCCESS(csr_cs_scan_files_async(context, files, sizeof(files) / sizeof(const char *),
-                                                                                  &testCtx));
+       ASSERT_SUCCESS(csr_cs_scan_files_async(context, files, 4, &testCtx));
 
        std::unique_lock<std::mutex> l(testCtx.m);
        testCtx.cv.wait(l);
@@ -895,8 +845,7 @@ BOOST_AUTO_TEST_CASE(multiple_async_dispatch_negative)
 
        // second call while first call is running in background. It should blocked because
        // only one operation can be running asynchronously on one handle.
-       ASSERT_IF(csr_cs_scan_dir_async(context, TEST_DIR_APPS, &testCtx2),
-                         CSR_ERROR_BUSY);
+       ASSERT_IF(csr_cs_scan_dir_async(context, TEST_DIR_APPS, &testCtx2), CSR_ERROR_BUSY);
 
        std::unique_lock<std::mutex> l(testCtx.m);
        testCtx.cv.wait(l);
@@ -927,12 +876,12 @@ BOOST_AUTO_TEST_CASE(get_malware_after_async)
        csr_cs_malware_h malware = nullptr;
        size_t count = 0;
 
-       ASSERT_SUCCESS(csr_cs_get_detected_malwares(context, dirs, sizeof(dirs) / sizeof(const char *), &malwares, &count));
+       ASSERT_SUCCESS(csr_cs_get_detected_malwares(context, dirs, 4, &malwares, &count));
        BOOST_MESSAGE("detected malware exist count before scanning: " << count);
 
        AsyncTestContext testCtx;
 
-       ASSERT_SUCCESS(csr_cs_scan_dirs_async(context, dirs, sizeof(dirs) / sizeof(const char *), &testCtx));
+       ASSERT_SUCCESS(csr_cs_scan_dirs_async(context, dirs, 4, &testCtx));
 
        std::unique_lock<std::mutex> l(testCtx.m);
        testCtx.cv.wait(l);
@@ -944,7 +893,7 @@ BOOST_AUTO_TEST_CASE(get_malware_after_async)
        BOOST_MESSAGE("cancelled count: " << testCtx.cancelledCnt);
        BOOST_MESSAGE("error count: " << testCtx.errorCnt);
 
-       ASSERT_SUCCESS(csr_cs_get_detected_malwares(context, dirs, sizeof(dirs) / sizeof(const char *), &malwares, &count));
+       ASSERT_SUCCESS(csr_cs_get_detected_malwares(context, dirs, 4, &malwares, &count));
 
        CHECK_IS_NOT_NULL(malwares);
 
index 0040c20..67599f1 100644 (file)
@@ -151,7 +151,7 @@ BOOST_AUTO_TEST_CASE(scan_data_high)
        auto context = c.get();
        csr_cs_malware_h detected;
        unsigned char data[100] = {0, };
-       time_t start_time = time(nullptr);
+       auto start_time = ::time(nullptr);
 
        // severity high detected
        memcpy(data, MALWARE_HIGH_SIGNATURE, strlen(MALWARE_HIGH_SIGNATURE));
@@ -160,7 +160,7 @@ BOOST_AUTO_TEST_CASE(scan_data_high)
        CHECK_IS_NOT_NULL(detected);
        ASSERT_DETECTED(detected, MALWARE_HIGH_NAME, MALWARE_HIGH_SEVERITY,
                                        MALWARE_HIGH_DETAILED_URL);
-       ASSERT_DETECTED_EXT(detected, start_time, nullptr, false, nullptr);
+       ASSERT_DETECTED_EXT(detected, start_time, "", false, "");
 
        EXCEPTION_GUARD_END
 }
@@ -173,7 +173,7 @@ BOOST_AUTO_TEST_CASE(scan_data_medium)
        auto context = c.get();
        csr_cs_malware_h detected;
        unsigned char data[100] = {0, };
-       time_t start_time = time(nullptr);
+       auto start_time = ::time(nullptr);
 
        // severity medium detected
        memcpy(data, MALWARE_MEDIUM_SIGNATURE, strlen(MALWARE_MEDIUM_SIGNATURE));
@@ -182,7 +182,7 @@ BOOST_AUTO_TEST_CASE(scan_data_medium)
        CHECK_IS_NOT_NULL(detected);
        ASSERT_DETECTED(detected, MALWARE_MEDIUM_NAME, MALWARE_MEDIUM_SEVERITY,
                                        MALWARE_MEDIUM_DETAILED_URL);
-       ASSERT_DETECTED_EXT(detected, start_time, nullptr, false, nullptr);
+       ASSERT_DETECTED_EXT(detected, start_time, "", false, "");
 
        EXCEPTION_GUARD_END
 }
@@ -195,7 +195,7 @@ BOOST_AUTO_TEST_CASE(scan_data_low)
        auto context = c.get();
        csr_cs_malware_h detected;
        unsigned char data[100] = {0, };
-       time_t start_time = time(nullptr);
+       auto start_time = ::time(nullptr);
 
        // severity low detected
        memcpy(data, MALWARE_LOW_SIGNATURE, strlen(MALWARE_LOW_SIGNATURE));
@@ -204,7 +204,7 @@ BOOST_AUTO_TEST_CASE(scan_data_low)
        CHECK_IS_NOT_NULL(detected);
        ASSERT_DETECTED(detected, MALWARE_LOW_NAME, MALWARE_LOW_SEVERITY,
                                        MALWARE_LOW_DETAILED_URL);
-       ASSERT_DETECTED_EXT(detected, start_time, nullptr, false, nullptr);
+       ASSERT_DETECTED_EXT(detected, start_time, "", false, "");
 
        EXCEPTION_GUARD_END
 }
@@ -253,7 +253,7 @@ BOOST_AUTO_TEST_CASE(scan_file_high)
        auto c = Test::Context<csr_cs_context_h>();
        auto context = c.get();
        csr_cs_malware_h detected;
-       time_t start_time = time(nullptr);
+       auto start_time = ::time(nullptr);
 
        Test::touch_file(TEST_FILE_HIGH);
 
@@ -262,7 +262,7 @@ BOOST_AUTO_TEST_CASE(scan_file_high)
        CHECK_IS_NOT_NULL(detected);
        ASSERT_DETECTED(detected, MALWARE_HIGH_NAME, MALWARE_HIGH_SEVERITY,
                                        MALWARE_HIGH_DETAILED_URL);
-       ASSERT_DETECTED_EXT(detected, start_time, TEST_FILE_HIGH, false, nullptr);
+       ASSERT_DETECTED_EXT(detected, start_time, TEST_FILE_HIGH, false, "");
 
        EXCEPTION_GUARD_END
 }
@@ -274,7 +274,7 @@ BOOST_AUTO_TEST_CASE(scan_file_medium)
        auto c = Test::Context<csr_cs_context_h>();
        auto context = c.get();
        csr_cs_malware_h detected;
-       time_t start_time = time(nullptr);
+       auto start_time = ::time(nullptr);
 
        Test::touch_file(TEST_FILE_MEDIUM);
 
@@ -283,7 +283,7 @@ BOOST_AUTO_TEST_CASE(scan_file_medium)
        CHECK_IS_NOT_NULL(detected);
        ASSERT_DETECTED(detected, MALWARE_MEDIUM_NAME, MALWARE_MEDIUM_SEVERITY,
                                        MALWARE_MEDIUM_DETAILED_URL);
-       ASSERT_DETECTED_EXT(detected, start_time, TEST_FILE_MEDIUM, false, nullptr);
+       ASSERT_DETECTED_EXT(detected, start_time, TEST_FILE_MEDIUM, false, "");
 
        EXCEPTION_GUARD_END
 }
@@ -295,7 +295,7 @@ BOOST_AUTO_TEST_CASE(scan_file_low)
        auto c = Test::Context<csr_cs_context_h>();
        auto context = c.get();
        csr_cs_malware_h detected;
-       time_t start_time = time(nullptr);
+       auto start_time = ::time(nullptr);
 
        Test::touch_file(TEST_FILE_LOW);
 
@@ -304,7 +304,7 @@ BOOST_AUTO_TEST_CASE(scan_file_low)
        CHECK_IS_NOT_NULL(detected);
        ASSERT_DETECTED(detected, MALWARE_LOW_NAME, MALWARE_LOW_SEVERITY,
                                        MALWARE_LOW_DETAILED_URL);
-       ASSERT_DETECTED_EXT(detected, start_time, TEST_FILE_LOW, false, nullptr);
+       ASSERT_DETECTED_EXT(detected, start_time, TEST_FILE_LOW, false, "");
 
        EXCEPTION_GUARD_END
 }
@@ -316,7 +316,7 @@ BOOST_AUTO_TEST_CASE(scan_file_media_dir)
        auto c = Test::Context<csr_cs_context_h>();
        auto context = c.get();
        csr_cs_malware_h detected;
-       time_t start_time = time(nullptr);
+       auto start_time = ::time(nullptr);
 
        Test::copy_file(TEST_FILE_HIGH, TEST_FILE_MEDIA);
 
@@ -325,7 +325,7 @@ BOOST_AUTO_TEST_CASE(scan_file_media_dir)
        CHECK_IS_NOT_NULL(detected);
        ASSERT_DETECTED(detected, MALWARE_HIGH_NAME, MALWARE_HIGH_SEVERITY,
                                        MALWARE_HIGH_DETAILED_URL);
-       ASSERT_DETECTED_EXT(detected, start_time, TEST_FILE_MEDIA, false, nullptr);
+       ASSERT_DETECTED_EXT(detected, start_time, TEST_FILE_MEDIA, false, "");
 
        EXCEPTION_GUARD_END
 }
@@ -337,7 +337,7 @@ BOOST_AUTO_TEST_CASE(scan_file_tmp_dir)
        auto c = Test::Context<csr_cs_context_h>();
        auto context = c.get();
        csr_cs_malware_h detected;
-       time_t start_time = time(nullptr);
+       auto start_time = ::time(nullptr);
 
        Test::copy_file(TEST_FILE_HIGH, TEST_FILE_TMP);
 
@@ -346,7 +346,7 @@ BOOST_AUTO_TEST_CASE(scan_file_tmp_dir)
        CHECK_IS_NOT_NULL(detected);
        ASSERT_DETECTED(detected, MALWARE_HIGH_NAME, MALWARE_HIGH_SEVERITY,
                                        MALWARE_HIGH_DETAILED_URL);
-       ASSERT_DETECTED_EXT(detected, start_time, TEST_FILE_TMP, false, nullptr);
+       ASSERT_DETECTED_EXT(detected, start_time, TEST_FILE_TMP, false, "");
 
        EXCEPTION_GUARD_END
 }
@@ -359,7 +359,7 @@ BOOST_AUTO_TEST_CASE(scan_file_wgt_dir)
        auto c = Test::Context<csr_cs_context_h>();
        auto context = c.get();
        csr_cs_malware_h detected;
-       time_t start_time = time(nullptr);
+       auto start_time = ::time(nullptr);
 
        Test::uninstall_app(TEST_WGT_PKG_ID);
        ASSERT_INSTALL_APP(TEST_WGT_PATH, TEST_WGT_TYPE);
@@ -384,7 +384,7 @@ BOOST_AUTO_TEST_CASE(scan_file_tpk_dir)
        auto c = Test::Context<csr_cs_context_h>();
        auto context = c.get();
        csr_cs_malware_h detected;
-       time_t start_time = time(nullptr);
+       auto start_time = ::time(nullptr);
 
        Test::uninstall_app(TEST_TPK_PKG_ID);
        ASSERT_INSTALL_APP(TEST_TPK_PATH, TEST_TPK_TYPE);
index a397a09..ffad409 100644 (file)
@@ -102,6 +102,8 @@ bool pkgmgr_request(const std::function<int(pkgmgr_client *, PkgEventData *)> &r
        return data.isSuccess;
 }
 
+} // namespace anonymous
+
 #define ERRORDESCRIBE(name) case name: return #name
 std::string capi_ec_to_string(csr_error_e ec)
 {
@@ -133,8 +135,6 @@ std::string capi_ec_to_string(csr_error_e ec)
 }
 #undef ERRORDESCRIBE
 
-} // namespace anonymous
-
 template <>
 void _assert<csr_error_e, csr_error_e>(const csr_error_e &value,
                                                                           const csr_error_e &expected,
index d49819e..76fa328 100644 (file)
@@ -182,6 +182,8 @@ void _assert<char *, std::string>(char * const &value,
 
 void exceptionGuard(const std::function<void()> &);
 
+std::string capi_ec_to_string(csr_error_e ec);
+
 void make_dir(const char *dir);
 void make_dir_assert(const char *dir);
 void copy_file(const char *src_file, const char *dest_file);
@@ -261,13 +263,13 @@ class Context<csr_cs_context_h> {
 public:
        Context() : m_context(nullptr)
        {
-               ASSERT_IF(csr_cs_context_create(&m_context), CSR_ERROR_NONE);
+               ASSERT_SUCCESS(csr_cs_context_create(&m_context));
                BOOST_REQUIRE(m_context != nullptr);
        }
 
        virtual ~Context()
        {
-               ASSERT_IF(csr_cs_context_destroy(m_context), CSR_ERROR_NONE);
+               ASSERT_SUCCESS(csr_cs_context_destroy(m_context));
        }
 
        csr_cs_context_h get(void) const
@@ -284,13 +286,13 @@ class Context<csr_wp_context_h> {
 public:
        Context() : m_context(nullptr)
        {
-               ASSERT_IF(csr_wp_context_create(&m_context), CSR_ERROR_NONE);
+               ASSERT_SUCCESS(csr_wp_context_create(&m_context));
                BOOST_REQUIRE(m_context != nullptr);
        }
 
        virtual ~Context()
        {
-               ASSERT_IF(csr_wp_context_destroy(m_context), CSR_ERROR_NONE);
+               ASSERT_SUCCESS(csr_wp_context_destroy(m_context));
        }
 
        csr_wp_context_h get(void) const
@@ -307,13 +309,13 @@ class Context<csre_cs_context_h> {
 public:
        Context() : m_context(nullptr)
        {
-               ASSERT_IF(csre_cs_context_create(&m_context), CSRE_ERROR_NONE);
+               ASSERT_SUCCESS(csre_cs_context_create(&m_context));
                BOOST_REQUIRE(m_context != nullptr);
        }
 
        virtual ~Context()
        {
-               ASSERT_IF(csre_cs_context_destroy(m_context), CSRE_ERROR_NONE);
+               ASSERT_SUCCESS(csre_cs_context_destroy(m_context));
        }
 
        csre_cs_context_h get(void) const
@@ -330,13 +332,13 @@ class Context<csre_wp_context_h> {
 public:
        Context() : m_context(nullptr)
        {
-               ASSERT_IF(csre_wp_context_create(&m_context), CSRE_ERROR_NONE);
+               ASSERT_SUCCESS(csre_wp_context_create(&m_context));
                BOOST_REQUIRE(m_context != nullptr);
        }
 
        virtual ~Context()
        {
-               ASSERT_IF(csre_wp_context_destroy(m_context), CSRE_ERROR_NONE);
+               ASSERT_SUCCESS(csre_wp_context_destroy(m_context));
        }
 
        csre_wp_context_h get(void) const
index 6e51c12..4a9b677 100644 (file)
@@ -29,8 +29,8 @@
 
 #include "test-common.h"
 
-void ASSERT_DETECTED(csr_cs_malware_h detected, const char *e_malware_name,
-                                        csr_cs_severity_level_e e_severity, const char *e_detailed_url)
+void ASSERT_DETECTED(csr_cs_malware_h detected, const std::string &e_malware_name,
+                                        csr_cs_severity_level_e e_severity, const std::string &e_detailed_url)
 {
        csr_cs_severity_level_e a_severity;
        Test::ScopedCstr a_malware_name, a_detailed_url;
@@ -45,7 +45,8 @@ void ASSERT_DETECTED(csr_cs_malware_h detected, const char *e_malware_name,
 }
 
 void ASSERT_DETECTED_EXT(csr_cs_malware_h detected, time_t e_timestamp,
-                                                const std::string &e_file_name, bool e_is_app, const char *e_pkg_id)
+                                                const std::string &e_file_name, bool e_is_app,
+                                                const std::string &e_pkg_id)
 {
        time_t a_timestamp;
        bool a_is_app;
@@ -102,8 +103,8 @@ void ASSERT_DETECTED_HANDLE(csr_cs_malware_h expected, csr_cs_malware_h actual)
 }
 
 void ASSERT_DETECTED_IN_LIST(const std::vector<csr_cs_malware_h> &detectedList,
-                                                        const std::string &file_name, const char *name,
-                                                        csr_cs_severity_level_e severity, const char *detailed_url)
+                                                        const std::string &file_name, const std::string &name,
+                                                        csr_cs_severity_level_e severity, const std::string &detailed_url)
 {
        csr_cs_severity_level_e a_severity;
        Test::ScopedCstr a_file_name, a_name, a_detailed_url;
@@ -131,7 +132,7 @@ void ASSERT_DETECTED_IN_LIST(const std::vector<csr_cs_malware_h> &detectedList,
 
 void ASSERT_DETECTED_IN_LIST_EXT(const std::vector<csr_cs_malware_h> &detectedList,
                                                                 const std::string &file_name, bool is_app,
-                                                                const char *pkg_id)
+                                                                const std::string &pkg_id)
 {
        bool a_is_app;
        Test::ScopedCstr a_file_name, a_pkg_id;
index 2d2b742..f76366f 100644 (file)
 
 #include <string>
 
-void ASSERT_DETECTED(csr_cs_malware_h detected, const char *name,
-                                        csr_cs_severity_level_e severity, const char *detailed_url);
+void ASSERT_DETECTED(csr_cs_malware_h detected, const std::string &name,
+                                        csr_cs_severity_level_e severity, const std::string &detailed_url);
 
 void ASSERT_DETECTED_EXT(csr_cs_malware_h detected, time_t time, const std::string &file_name,
-                                                bool is_app, const char *pkg_id);
+                                                bool is_app, const std::string &pkg_id);
 
 void ASSERT_DETECTED_HANDLE(csr_cs_malware_h expected, csr_cs_malware_h actual);
 
 void ASSERT_DETECTED_IN_LIST(const std::vector<csr_cs_malware_h> &detectedList,
-                                                        const std::string &file_name, const char *name,
-                                                        csr_cs_severity_level_e severity, const char *detailed_url);
+                                                        const std::string &file_name, const std::string &name,
+                                                        csr_cs_severity_level_e severity, const std::string &detailed_url);
 
 void ASSERT_DETECTED_IN_LIST_EXT(const std::vector<csr_cs_malware_h> &detectedList,
-                                                                const std::string &file_name, bool is_app, const char *pkg_id);
+                                                                const std::string &file_name, bool is_app,
+                                                                const std::string &pkg_id);