Add api wrappers to security-manager tests 60/31860/4
authorMarcin Niesluchowski <m.niesluchow@samsung.com>
Wed, 10 Dec 2014 13:35:55 +0000 (14:35 +0100)
committerMarcin Niesluchowski <m.niesluchow@samsung.com>
Mon, 15 Dec 2014 09:20:08 +0000 (10:20 +0100)
Change-Id: Ic558284e8d029b5450ff4126ef42c8029c38947d

tests/security-manager-tests/CMakeLists.txt
tests/security-manager-tests/common/sm_api.cpp [new file with mode: 0644]
tests/security-manager-tests/common/sm_api.h [new file with mode: 0644]

index dd8f049..88890e6 100644 (file)
@@ -36,6 +36,7 @@ SET(TARGET_SEC_MGR_TESTS "security-manager-tests")
 
 SET(SEC_MGR_SOURCES
     ${PROJECT_SOURCE_DIR}/tests/security-manager-tests/security_manager_tests.cpp
+    ${PROJECT_SOURCE_DIR}/tests/security-manager-tests/common/sm_api.cpp
     ${PROJECT_SOURCE_DIR}/tests/security-manager-tests/common/sm_db.cpp
     ${PROJECT_SOURCE_DIR}/tests/security-manager-tests/common/sm_request.cpp
     ${PROJECT_SOURCE_DIR}/tests/cynara-tests/common/cynara_test_client.cpp
diff --git a/tests/security-manager-tests/common/sm_api.cpp b/tests/security-manager-tests/common/sm_api.cpp
new file mode 100644 (file)
index 0000000..7ffe85b
--- /dev/null
@@ -0,0 +1,104 @@
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+
+#include <sm_api.h>
+
+#include <dpl/test/test_runner.h>
+
+namespace SecurityManagerTest {
+
+namespace Api {
+
+void install(const InstallRequest &request, lib_retcode expectedResult)
+{
+    int result = security_manager_app_install(request.get());
+    RUNNER_ASSERT_MSG((lib_retcode)result == expectedResult,
+                      "installing app returned wrong value."
+                          << " InstallRequest: [ " << request << "];"
+                          << " Result: " << result << ";"
+                          << " Expected result: " << expectedResult);
+}
+
+void uninstall(const InstallRequest &request, lib_retcode expectedResult)
+{
+    int result = security_manager_app_uninstall(request.get());
+    RUNNER_ASSERT_MSG((lib_retcode)result == expectedResult,
+                      "uninstalling app returned wrong value."
+                          << " InstallRequest: [ " << request << "];"
+                          << " Result: " << result << ";"
+                          << " Expected result: " << expectedResult);
+}
+
+std::string getPkgId(const char *appId, lib_retcode expectedResult)
+{
+    char *pkgId = nullptr;
+    int result = security_manager_get_app_pkgid(&pkgId, appId);
+    RUNNER_ASSERT_MSG((lib_retcode)result == expectedResult,
+                      "getting pkg id from app id returned wrong value."
+                          << " App id: " << appId << ";"
+                          << " Result: " << result << ";"
+                          << " Expected result: " << expectedResult);
+    if (expectedResult != SECURITY_MANAGER_SUCCESS)
+        return std::string();
+
+    RUNNER_ASSERT_MSG(pkgId != nullptr, "getting pkg id did not allocate memory");
+    std::string str(pkgId);
+    free(pkgId);
+    return str;
+}
+
+void setProcessLabel(const char *appId, lib_retcode expectedResult)
+{
+    int result = security_manager_set_process_label_from_appid(appId);
+    RUNNER_ASSERT_MSG((lib_retcode)result == expectedResult,
+                      "setting process label from app id returned wrong value."
+                          << " App id: " << appId << ";"
+                          << " Result: " << result << ";"
+                          << " Expected result: " << expectedResult);
+}
+
+void setProcessGroups(const char *appId, lib_retcode expectedResult)
+{
+    int result = security_manager_set_process_groups_from_appid(appId);
+    RUNNER_ASSERT_MSG((lib_retcode)result == expectedResult,
+                      "setting process groups from app id returned wrong value."
+                          << " App id: " << appId << ";"
+                          << " Result: " << result << ";"
+                          << " Expected result: " << expectedResult);
+}
+
+void dropProcessPrivileges(lib_retcode expectedResult)
+{
+    int result = security_manager_drop_process_privileges();
+    RUNNER_ASSERT_MSG((lib_retcode)result == expectedResult,
+                      "dropping process privileges returned wrong value."
+                          << " Result: " << result << ";"
+                          << " Expected result: " << expectedResult);
+}
+
+void prepareApp(const char *appId, lib_retcode expectedResult)
+{
+    int result = security_manager_prepare_app(appId);
+    RUNNER_ASSERT_MSG((lib_retcode)result == expectedResult,
+                      "preparing app returned wrong value."
+                          << " App id: " << appId << ";"
+                          << " Result: " << result << ";"
+                          << " Expected result: " << expectedResult);
+}
+
+} // namespace Api
+
+} // namespace SecurityManagerTest
diff --git a/tests/security-manager-tests/common/sm_api.h b/tests/security-manager-tests/common/sm_api.h
new file mode 100644 (file)
index 0000000..49e4088
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+
+#ifndef SECURITY_MANAGER_TEST_API
+#define SECURITY_MANAGER_TEST_API
+
+#include <sm_request.h>
+
+#include <security-manager.h>
+
+namespace SecurityManagerTest {
+
+namespace Api {
+
+void install(const InstallRequest &request, lib_retcode expectedResult = SECURITY_MANAGER_SUCCESS);
+void uninstall(const InstallRequest &request, lib_retcode expectedResult = SECURITY_MANAGER_SUCCESS);
+std::string getPkgId(const char *appId, lib_retcode expectedResult = SECURITY_MANAGER_SUCCESS);
+void setProcessLabel(const char *appId, lib_retcode expectedResult = SECURITY_MANAGER_SUCCESS);
+void setProcessGroups(const char *appId, lib_retcode expectedResult = SECURITY_MANAGER_SUCCESS);
+void dropProcessPrivileges(lib_retcode expectedResult = SECURITY_MANAGER_SUCCESS);
+void prepareApp(const char *appId, lib_retcode expectedResult = SECURITY_MANAGER_SUCCESS);
+
+} // namespace Api
+
+} // namespace SecurityManagerTest
+
+#endif // SECURITY_MANAGER_TEST_API