Rewriting cleanup functions for libsmack test cases 52/19952/2
authorZofia Abramowska <z.abramowska@samsung.com>
Thu, 17 Apr 2014 12:51:00 +0000 (14:51 +0200)
committerZofia Abramowska <z.abramowska@samsung.com>
Thu, 24 Apr 2014 09:32:01 +0000 (11:32 +0200)
Simplifying cleanup functions.
This is a preparation commit for total refactoring
of cleanup mechanism in libsmack test cases

Change-Id: I1963b71188446b912f85ade0e9838eeb9f1af34f

tests/libsmack-tests/test_cases.cpp

index e2fac42766de38c45462f47e6851ac7c358ba6bd..6c7464a722bd6180457c01312f3ad95985b880db 100644 (file)
@@ -85,28 +85,13 @@ int files_compare(int fd1, int fd2)
     return result;
 }
 
-
 RUNNER_TEST_GROUP_INIT(libsmack)
 /**
  * Helper method to reset privileges at the begginning of tests.
  */
 void clean_up()
 {
-    struct smack_accesses *rules = NULL;
-    int result = smack_accesses_new(&rules);
-    RUNNER_ASSERT_MSG_BT(result == 0, "Unable to create smack_accesses instance");
-
-    // CLEAN UP
-    smack_accesses_add_modify(rules,TEST_SUBJECT, TEST_OBJECT,"","rwxat");
-    smack_accesses_apply(rules);
-    smack_accesses_free(rules);
-
-    // PREINIT CHECK.
-    RUNNER_ASSERT_MSG_BT(smack_have_access(TEST_SUBJECT, TEST_OBJECT,"r") != 1, "Rule has previous privileges after cleaning up!");
-    RUNNER_ASSERT_MSG_BT(smack_have_access(TEST_SUBJECT, TEST_OBJECT,"w") != 1, "Rule has previous privileges after cleaning up!");
-    RUNNER_ASSERT_MSG_BT(smack_have_access(TEST_SUBJECT, TEST_OBJECT,"x") != 1, "Rule has previous privileges after cleaning up!");
-    RUNNER_ASSERT_MSG_BT(smack_have_access(TEST_SUBJECT, TEST_OBJECT,"a") != 1, "Rule has previous privileges after cleaning up!");
-    RUNNER_ASSERT_MSG_BT(smack_have_access(TEST_SUBJECT, TEST_OBJECT,"t") != 1, "Rule has previous privileges after cleaning up!");
+    smack_revoke_subject(TEST_SUBJECT);
 }
 
 /**
@@ -115,51 +100,23 @@ void clean_up()
 bool checkNoAccesses(const char *subject, const char *object)
 {
     int result;
-    result = smack_have_access(subject, object,"r");
-    if (result == 1) {
-        return false;
-    }
-    result = smack_have_access(subject, object,"w");
-    if (result == 1) {
-        return false;
-    }
-    result = smack_have_access(subject, object,"x");
-    if (result == 1) {
-        return false;
-    }
-    result = smack_have_access(subject, object,"a");
-    if (result == 1) {
-        return false;
-    }
-    result = smack_have_access(subject, object,"t");
-    if (result == 1) {
-        return false;
+    for(const auto &perm : std::vector<std::string> () = {"r", "w", "a","t", "l"}) {
+        result = smack_have_access(subject, object, perm.c_str());
+        if (result == 1) {
+            return false;
+        }
     }
     return true;
 }
 
 void removeAccessesAll()
 {
-    struct smack_accesses *rules = NULL;
-    int result = smack_accesses_new(&rules);
-    RUNNER_ASSERT_MSG_BT(result == 0, "Unable to create smack_accesses instance");
-
-    result = smack_accesses_add_modify(rules, "test_subject_01", "test_object_01", "", "rxwat");
-    result = smack_accesses_add_modify(rules, "test_subject_01", "test_object_02", "", "rxwat");
-    result = smack_accesses_add_modify(rules, "test_subject_01", "test_object_03", "", "rxwat");
-    result = smack_accesses_add_modify(rules, "test_subject_02", "test_object_01", "", "rxwat");
-    result = smack_accesses_add_modify(rules, "test_subject_02", "test_object_02", "", "rxwat");
-    result = smack_accesses_add_modify(rules, "test_subject_02", "test_object_03", "", "rxwat");
-    result = smack_accesses_add_modify(rules, "test_subject_03", "test_object_01", "", "rxwat");
-    result = smack_accesses_add_modify(rules, "test_subject_03", "test_object_02", "", "rxwat");
-    result = smack_accesses_add_modify(rules, "test_subject_03", "test_object_03", "", "rxwat");
-
-    smack_accesses_apply(rules);
-    RUNNER_ASSERT_MSG_BT(result == 0, "Error while applying accesses. Result: " << result);
-    smack_accesses_free(rules);
+    for(int i = 1; i <=3; i++)
+        //smack_revoke_subject will fail, when subject does not exist in kernel
+        //as this function is called at test beginning we cannot check return value
+        smack_revoke_subject(("test_subject_0" + std::to_string(i)).c_str());
 }
 
-
 /**
  * Add a new access with smack_accesses_add_modify()
  */