Test case for transaction rollback in libprivilege-control
authorPawel Broda <p.broda@partner.samsung.com>
Mon, 20 Jan 2014 14:03:01 +0000 (15:03 +0100)
committerMarcin Niesluchowski <m.niesluchow@samsung.com>
Wed, 5 Feb 2014 12:50:22 +0000 (13:50 +0100)
[Issue#]        SSDWSSP-609
[Feature]       Test case for new libprivilege-control API
                function: perm_rollback().
[Cause]         N/A
[Solution]      N/A
[Verification]  Build and run on the target.
                Build together with libprivilege-control package
                containing:
                http://slp-info.sec.samsung.net/gerrit/#/c/337121/

Change-Id: I1bd9f2de29276b2c6a2c5fbd3a457f800088fa79

tests/libprivilege-control-tests/test_cases.cpp

index 874dbd8..0cb300c 100644 (file)
@@ -656,44 +656,103 @@ RUNNER_TEST(privilege_control11_add_api_feature)
 }
 
 /*
- * Check perm_app_install function
+ * Check perm_app_uninstall function
  */
-RUNNER_TEST(privilege_control01_app_install)
+void check_perm_app_uninstall(const char* pkg_id)
 {
     int result;
 
     DB_BEGIN
 
-    perm_app_uninstall(APP_ID);
+    result = perm_app_uninstall(pkg_id);
+    RUNNER_ASSERT_MSG_BT(result == 0, "perm_app_uninstall returned: " << perm_strerror(result));
 
-    result = perm_app_install(APP_ID);
-    RUNNER_ASSERT_MSG_BT(result == 0, "perm_app_install returned " << result << ". Errno: " << strerror(errno));
+    DB_END
 
-    // try install second time app with the same ID - it should pass.
-    result = perm_app_install(APP_ID);
-    RUNNER_ASSERT_MSG_BT(result == 0, "perm_app_install returned " << result << ". Errno: " << strerror(errno));
+    TestLibPrivilegeControlDatabase db_test;
+    db_test.test_db_after__perm_app_uninstall(pkg_id);
+}
+
+RUNNER_TEST(privilege_control07_app_uninstall)
+{
+    check_perm_app_uninstall(APP_ID);
+}
+
+/*
+ * Check perm_app_install function
+ */
+void check_perm_app_install(const char* pkg_id)
+{
+    int result;
+
+    DB_BEGIN
+
+    result = perm_app_install(pkg_id);
+    RUNNER_ASSERT_MSG_BT(result == 0, "perm_app_install returned: " << perm_strerror(result));
 
     DB_END
+
+    TestLibPrivilegeControlDatabase db_test;
+    db_test.test_db_after__perm_app_install(pkg_id);
+}
+
+RUNNER_TEST(privilege_control01_app_install)
+{
+    check_perm_app_uninstall(APP_ID);
+    check_perm_app_install(APP_ID);
+    // try install second time app with the same ID - it should pass.
+    check_perm_app_install(APP_ID);
 }
 
 /*
- * Check perm_app_uninstall function
+ * Check perm_rollback function
  */
-RUNNER_TEST(privilege_control07_app_uninstall)
+RUNNER_TEST(privilege_control07_app_rollback)
 {
+    check_perm_app_uninstall(APP_ID);
+
     int result;
 
     DB_BEGIN
 
-    result = perm_app_uninstall(APP_ID);
-    RUNNER_ASSERT_MSG_BT(result == 0, "perm_app_uninstall returned " << result << ". Errno: " << strerror(errno));
+    result = perm_app_install(APP_ID);
+    RUNNER_ASSERT_MSG_BT(result == 0, "perm_app_install returned: " << perm_strerror(result));
+
+    // transaction rollback
+    result = perm_rollback();
+    RUNNER_ASSERT_MSG_BT(result == 0, "perm_rollback returned: " << perm_strerror(result));
 
     DB_END
 
     TestLibPrivilegeControlDatabase db_test;
     db_test.test_db_after__perm_app_uninstall(APP_ID);
+
 }
 
+RUNNER_TEST(privilege_control07_app_rollback_2)
+{
+    check_perm_app_uninstall(APP_ID);
+
+    int result;
+
+    DB_BEGIN
+
+    result = perm_app_install(APP_ID);
+    RUNNER_ASSERT_MSG_BT(result == 0, "perm_app_install returned: " << perm_strerror(result));
+
+    // transaction rollback
+    result = perm_rollback();
+    RUNNER_ASSERT_MSG_BT(result == 0, "perm_rollback returned: " << perm_strerror(result));
+
+    // install once again after the rollback
+    result = perm_app_install(APP_ID);
+    RUNNER_ASSERT_MSG_BT(result == 0, "perm_app_install returned: " << perm_strerror(result));
+
+    DB_END
+
+    TestLibPrivilegeControlDatabase db_test;
+    db_test.test_db_after__perm_app_install(APP_ID);
+}
 /*
  * Check app_register_av function
  * Notice that this test case may have no sense if previous would fail (privilege_control06_app_install)