Add a test for libprivilege_strerror.
authorDamian Chromejko <d.chromejko@samsung.com>
Tue, 19 Nov 2013 12:15:11 +0000 (13:15 +0100)
committerMarcin Niesluchowski <m.niesluchow@samsung.com>
Thu, 23 Jan 2014 14:19:10 +0000 (15:19 +0100)
[Issue#]       SSDWSSP-646
[Bug]          N/A
[Cause]        Changed API of libprivilege-control.
[Solution]     Test if proper error descriptions are returned for error codes.
[Verification] Run libprivilege-control-test.

Change-Id: I0a48348e707311f593aa4b6b7065a3956b1e375d

tests/libprivilege-control-tests/test_cases.cpp

index f784166e63a9930af0f5d951a497c303e75c13c7..0989e31fd3d43785b48354b6d79470dc3916b87e 100644 (file)
 
 #define SMACK_ACC_LEN            6
 
+// Error codes for test_libprivilege_strerror
+const std::vector<int> error_codes {
+    PC_OPERATION_SUCCESS, PC_ERR_FILE_OPERATION, PC_ERR_MEM_OPERATION, PC_ERR_NOT_PERMITTED,
+    PC_ERR_INVALID_PARAM, PC_ERR_INVALID_OPERATION, PC_ERR_DB_OPERATION, PC_ERR_DB_LABEL_TAKEN,
+    PC_ERR_DB_QUERY_PREP, PC_ERR_DB_QUERY_BIND, PC_ERR_DB_QUERY_STEP, PC_ERR_DB_CONNECTION,
+    PC_ERR_DB_NO_SUCH_APP, PC_ERR_DB_PERM_FORBIDDEN
+};
+
 namespace {
 
 std::vector<std::string> gen_names(std::string prefix, std::string suffix, size_t size)
@@ -1847,3 +1855,22 @@ RUNNER_TEST(privilege_control24c_av_privilege_public_ro)
     CheckAVPrivilege(APP_TYPE_OSP, APP_PATH_PUBLIC_RO);
     CheckAVPrivilege(APP_TYPE_EFL, APP_PATH_PUBLIC_RO);
 }
+
+RUNNER_TEST(privilege_control25_test_libprivilege_strerror) {
+    int POSITIVE_ERROR_CODE = 1;
+    int NONEXISTING_ERROR_CODE = -239042;
+    const char *result;
+
+    for (auto itr = error_codes.begin(); itr != error_codes.end(); ++itr) {
+        RUNNER_ASSERT_MSG(strcmp(perm_strerror(*itr), "Unknown error") != 0,
+                "Returned invalid error code description.");
+    }
+
+    result = perm_strerror(POSITIVE_ERROR_CODE);
+    RUNNER_ASSERT_MSG(strcmp(result, "Unknown error") == 0,
+            "Bad message returned for invalid error code: \"" << result << "\"");
+
+    result = perm_strerror(NONEXISTING_ERROR_CODE);
+    RUNNER_ASSERT_MSG(strcmp(result, "Unknown error") == 0,
+            "Bad message returned for invalid error code: \"" << result << "\"");
+}