Remove compilation warnings from libprivilege-control tests
authorLukasz Kostyra <l.kostyra@partner.samsung.com>
Wed, 28 Aug 2013 08:31:53 +0000 (10:31 +0200)
committerMarcin Niesluchowski <m.niesluchow@samsung.com>
Thu, 23 Jan 2014 14:07:38 +0000 (15:07 +0100)
[Issue#]        SSDWSSP-482
[Bug]           Libprivilege-control tests displayed warnings during compilation.
[Cause]         N/A
[Solution]      Replace deprecated functions with their replacements, supress warnings for functions
                that have no replacements, remove other warnings.
[Verification]  Build package - no warnings should appear. Run libprivilege-control-tests, all tests
                should pass just as they did earlier.

Change-Id: I41e2f69ad7fb1ff38b04eb7bcdfefcb7248fc0a9

tests/libprivilege-control-tests/test_cases.cpp

index 0d63ba1..1ec9e85 100644 (file)
@@ -829,7 +829,7 @@ RUNNER_TEST_SMACK(privilege_control03_app_label_shared_dir)
  */
 RUNNER_TEST_SMACK(privilege_control04_add_permissions)
 {
-    int result = app_add_permissions(APP_ID, PRIVS);
+    int result = perm_app_enable_permissions(APP_ID, APP_TYPE_OTHER, PRIVS, 1);
     RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS,
         " Error adding app permissions. Result: " << result);
 
@@ -991,6 +991,10 @@ static void read_gids(std::set<unsigned> &set, const char *file_path)
     }
 }
 
+//Functions add_shared_dir_readers and app_register_av are deprecated and
+//have no replacement. Until those functions are deleted warnings for
+//tests using those functions are supressed.
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
 RUNNER_TEST_SMACK(privilege_control05_add_shared_dir_readers)
 {
 #define  TEST_OBJ            "TEST_OBJECT"
@@ -1113,7 +1117,7 @@ RUNNER_TEST_SMACK(privilege_control05_add_shared_dir_readers)
     free(path);
     fclose(file);
 }
-
+#pragma GCC diagnostic warning "-Wdeprecated-declarations"
 
 /**
  * Set APP privileges.
@@ -1601,6 +1605,7 @@ void checkOnlyAvAccess(const char *av_id, const char *app_id, const char *commen
  * Check app_register_av function
  * Notice that this test case may have no sense if previous would fail (privilege_control06_app_install)
  */
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
 RUNNER_TEST_SMACK(privilege_control10_app_register_av)
 {
     int result;
@@ -1655,6 +1660,7 @@ RUNNER_TEST_SMACK(privilege_control10_app_register_av)
     cleaning_smack_app_files();
     cleaning_smack_database_files();
 }
+#pragma GCC diagnostic warning "-Wdeprecated-declarations"
 
 /**
  * Grant SMACK permissions based on permissions list.
@@ -2768,7 +2774,7 @@ int test_have_nosmack_accesses(const std::vector< std::vector<std::string> > &ru
 RUNNER_TEST_NOSMACK(privilege_control04_add_permissions_nosmack)
 {
     //Add permissions
-    auto result = app_add_permissions(APP_ID, PRIVS);
+    auto result = perm_app_enable_permissions(APP_ID, APP_TYPE_OTHER, PRIVS, 1);
     RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS,
             "Error adding app permissions. Result: " << result);
 
@@ -2791,18 +2797,18 @@ RUNNER_TEST_NOSMACK(privilege_control04_add_permissions_nosmack)
  * This test is very similar to it's SMACK version - only difference is different result expected
  * from smack_have_access.
  */
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
 RUNNER_TEST_NOSMACK(privilege_control05_add_shared_dir_readers_nosmack)
 {
-#define  TEST_OBJ            "TEST_OBJECT"
-#define  TEST_OBJ_SOME_OTHER "TEST_OBJA"
-#define test_string_01       "TEST_raz TEST_OBJECT r-x--- ------"
-#define test_string_21       "TEST_trzy TEST_OBJA -wx---"
-#define test_string_22       "TEST_trzy TEST_OBJECT r-x--- ------"
+    const char* test_obj = "TEST_OBJECT";
+    const char* test_obj_some_other = "TEST_OBJA";
+    const char* test_str_01 = "TEST_raz TEST_OBJECT r-x--- ------";
+    const char* test_str_21 = "TEST_trzy TEST_OBJA -wx---";
+    const char* test_str_22 = "TEST_trzy TEST_OBJECT r-x--- ------";
 
     int result;
     int i;
     int fd = -1;
-    char* path_ref;
 
     const char* app_labels_wrong[] = {"-TEST_raz", NULL};
     const char* app_labels[] = {"TEST_raz", "TEST_dwa", "TEST_trzy", NULL};
@@ -2815,11 +2821,10 @@ RUNNER_TEST_NOSMACK(privilege_control05_add_shared_dir_readers_nosmack)
     cleaning_smack_database_files();
 
     //test what happens when the label is not correct SMACK label
-    result = add_shared_dir_readers(TEST_OBJ,app_labels_wrong);
+    result = add_shared_dir_readers(test_obj,app_labels_wrong);
     RUNNER_ASSERT_MSG(result == PC_ERR_INVALID_PARAM,
             "add_shared_dir_readers should fail here. Result: " << result);
-
-    result = smack_have_access(app_labels_wrong[0],TEST_OBJ,"rx");
+    result = smack_have_access(app_labels_wrong[0],test_obj,"rx");
     RUNNER_ASSERT_MSG(result != 1,
             "add_shared_dir_readers should not grant permission here. Result: " << result);
 
@@ -2850,7 +2855,7 @@ RUNNER_TEST_NOSMACK(privilege_control05_add_shared_dir_readers_nosmack)
         RUNNER_ASSERT_MSG(fd != -1, "Error in opening file");
 
         if (i == 1) {
-            result = smack_accesses_add(rules.get(), app_labels[i], TEST_OBJ, "wt");
+            result = smack_accesses_add(rules.get(), app_labels[i], test_obj, "wt");
             RUNNER_ASSERT_MSG(result == 0,
                     "smack_accesses_add failed. Result: " << result);
         }
@@ -2863,7 +2868,7 @@ RUNNER_TEST_NOSMACK(privilege_control05_add_shared_dir_readers_nosmack)
             rules.reset(tmp);
 
             result = smack_accesses_add(rules.get(), app_labels[i],
-                    TEST_OBJ_SOME_OTHER, "wx");
+                    test_obj_some_other, "wx");
             RUNNER_ASSERT_MSG(result == 0,
                     "smack_accesses_add failed. Result: " << result);
         }
@@ -2881,26 +2886,26 @@ RUNNER_TEST_NOSMACK(privilege_control05_add_shared_dir_readers_nosmack)
     }
 
     //Use add_shared_dir_readers and check if smack_have_access still fails
-    result = add_shared_dir_readers(TEST_OBJ,app_labels);
+    result = add_shared_dir_readers(test_obj,app_labels);
     RUNNER_ASSERT_MSG(result == 0, "add_shared_dir_readers failed. Result: " << result);
 
-    result = smack_have_access(app_labels[0],TEST_OBJ,"rx");
+    result = smack_have_access(app_labels[0],test_obj,"rx");
     RUNNER_ASSERT_MSG(result == -1,
             "smack_have_access should return error (SMACK is off). Result: " << result);
 
-    result = smack_have_access(app_labels[1],TEST_OBJ,"rx");
+    result = smack_have_access(app_labels[1],test_obj,"rx");
     RUNNER_ASSERT_MSG(result == -1,
             "smack_have_access should return error (SMACK is off). Result: " << result);
 
-    result = smack_have_access(app_labels[2],TEST_OBJ,"rx");
+    result = smack_have_access(app_labels[2],test_obj,"rx");
     RUNNER_ASSERT_MSG(result == -1,
             "smack_have_access should return error (SMACK is off). Result: " << result);
 
-    result = smack_have_access(app_labels[1],TEST_OBJ,"rwxt");
+    result = smack_have_access(app_labels[1],test_obj,"rwxt");
     RUNNER_ASSERT_MSG(result == -1,
             "smack_have_access should return error (SMACK is off). Result: " << result);
 
-    result = smack_have_access(app_labels[2],TEST_OBJ_SOME_OTHER,"wx");
+    result = smack_have_access(app_labels[2],test_obj_some_other,"wx");
     RUNNER_ASSERT_MSG(result == -1,
             "smack_have_access should return error (SMACK is off). Result: " << result);
 
@@ -2912,7 +2917,7 @@ RUNNER_TEST_NOSMACK(privilege_control05_add_shared_dir_readers_nosmack)
     RUNNER_ASSERT_MSG(fs.good(), "Opening file stream failed. Error: " << strerror(errno));
 
     fs.get(buf, READ_BUF_SIZE);
-    result = strcmp(buf, test_string_01);
+    result = strcmp(buf, test_str_01);
     RUNNER_ASSERT_MSG(result == 0,
                 "add_shared_dir_readers ERROR, file not formatted " << path.str().c_str() <<
                 ". Result: " << result);
@@ -2928,17 +2933,19 @@ RUNNER_TEST_NOSMACK(privilege_control05_add_shared_dir_readers_nosmack)
     RUNNER_ASSERT_MSG(fs.good(), "fopen failed, errno:" << strerror(errno));
 
     fs.getline(buf, READ_BUF_SIZE);
-    result = strcmp(buf, test_string_21);
+    result = strcmp(buf, test_str_21);
     RUNNER_ASSERT_MSG( result == 0,
                 "add_shared_dir_readers ERROR, file not formatted " << path.str().c_str()
                 << ". Result: " << result);
 
     fs.getline(buf, READ_BUF_SIZE);
-    result = strcmp(buf, test_string_22);
+    result = strcmp(buf, test_str_22);
     RUNNER_ASSERT_MSG( result == 0,
                 "add_shared_dir_readers ERROR, file not formatted " << path.str().c_str()
                 << ". Result: " << result);
 }
+#pragma GCC diagnostic warning "-Wdeprecated-declarations"
+
 
 /**
  * NOSMACK version of privilege_control05_set_app_privilege test.
@@ -3169,13 +3176,16 @@ void checkOnlyAvAccessNosmack(const char *av_id, const char *app_id, const char
     int result;
     result = smack_have_access(av_id, app_id, "rwx");
     RUNNER_ASSERT_MSG(result == -1,
-            "smack_have_access should return error (SMACK is off). Result: " << result);
+            "smack_have_access should return error (SMACK is off). Result: " << result
+            << " when testing " << comment);
     result = smack_have_access(av_id, app_id, "a");
     RUNNER_ASSERT_MSG(result == -1,
-            "smack_have_access should return error (SMACK is off). Result: " << result);
+            "smack_have_access should return error (SMACK is off). Result: " << result
+            << " when testing " << comment);
     result = smack_have_access(av_id, app_id, "t");
     RUNNER_ASSERT_MSG(result == -1,
-            "smack_have_access should return error (SMACK is off). Result: " << result);
+            "smack_have_access should return error (SMACK is off). Result: " << result
+            << " when testing " << comment);
 }
 
 /*
@@ -3184,6 +3194,7 @@ void checkOnlyAvAccessNosmack(const char *av_id, const char *app_id, const char
  * Uses NOSMACK version of checkOnlyAvAccess (mentioned above), rest of the test is identical to
  * it's SMACK version.
  */
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
 RUNNER_TEST_NOSMACK(privilege_control10_app_register_av_nosmack)
 {
     int result;
@@ -3243,6 +3254,7 @@ RUNNER_TEST_NOSMACK(privilege_control10_app_register_av_nosmack)
     cleaning_smack_app_files();
     cleaning_smack_database_files();
 }
+#pragma GCC diagnostic warning "-Wdeprecated-declarations"
 
 /**
  * NOSMACK version of privilege_control11_app_enable_permissions test.
@@ -3255,7 +3267,6 @@ RUNNER_TEST_NOSMACK(privilege_control10_app_register_av_nosmack)
 RUNNER_TEST_NOSMACK(privilege_control11_app_enable_permissions_nosmack)
 {
     int result;
-    int smack_file_length;
     std::fstream fs;
 
     result = perm_app_revoke_permissions(APP_ID);