SM : Add ScopedInstaller and ScopedPathRemover classes 21/88521/6
authorMateusz Forc <m.forc@samsung.com>
Mon, 19 Sep 2016 10:57:26 +0000 (12:57 +0200)
committerZofia Abramowska <z.abramowska@samsung.com>
Wed, 21 Sep 2016 13:20:51 +0000 (15:20 +0200)
Classes enable proper app installation per test
and sharedRO path cleanup for multiple apps in one package

Change-Id: Ib33d2e6e45b78a3841e88e8d7046231e6b2ba93c

src/security-manager-tests/common/scoped_installer.h [new file with mode: 0644]
src/security-manager-tests/common/scoped_path_remover.h [new file with mode: 0644]

diff --git a/src/security-manager-tests/common/scoped_installer.h b/src/security-manager-tests/common/scoped_installer.h
new file mode 100644 (file)
index 0000000..88d7915
--- /dev/null
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2016 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.
+ */
+
+#pragma once
+
+#include <ftw.h>
+#include <string>
+#include <sys/capability.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <vector>
+
+#include <security-manager-types.h>
+
+#include <app_install_helper.h>
+#include <memory.h>
+#include <sm_db.h>
+#include <sm_request.h>
+#include <sm_api.h>
+#include <temp_test_user.h>
+#include <synchronization_pipe.h>
+
+class ScopedInstaller {
+public:
+    ScopedInstaller(const AppInstallHelper &appInstallHelper)
+        : m_appInstallHelper(appInstallHelper)
+    {
+        SecurityManagerTest::InstallRequest instReq;
+        instReq.setAppId(m_appInstallHelper.getAppId());
+        instReq.setPkgId(m_appInstallHelper.getPkgId());
+        instReq.setUid(m_appInstallHelper.getUID());
+        instReq.setAppTizenVersion(m_appInstallHelper.getVersion());
+
+        for (const auto& typePaths : m_appInstallHelper.getDirsMap())
+            for (const auto& path : typePaths.second)
+                instReq.addPath(path, typePaths.first);
+        for (const auto& typePaths : m_appInstallHelper.getFilesMap())
+            for (const auto& path : typePaths.second)
+                instReq.addPath(path, typePaths.first);
+
+        SecurityManagerTest::Api::install(instReq);
+    }
+
+    virtual ~ScopedInstaller() {
+        uninstallApp();
+    }
+
+    void uninstallApp() {
+        SecurityManagerTest::InstallRequest uninstReq;
+        uninstReq.setAppId(m_appInstallHelper.getAppId());
+        uninstReq.setUid(m_appInstallHelper.getUID());
+
+        SecurityManagerTest::Api::uninstall(uninstReq);
+    }
+
+    AppInstallHelper& getAIH() {
+        return m_appInstallHelper;
+    }
+
+protected:
+    AppInstallHelper m_appInstallHelper;
+};
diff --git a/src/security-manager-tests/common/scoped_path_remover.h b/src/security-manager-tests/common/scoped_path_remover.h
new file mode 100644 (file)
index 0000000..1e56e4a
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2014-2016 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.
+ */
+#pragma once
+
+#include <vector>
+#include <utility>
+
+class ScopedPathRemover {
+public:
+    ScopedPathRemover(std::initializer_list<std::string> &&vec)
+        : m_dirVec(std::move(vec))
+    {}
+
+    ~ScopedPathRemover() {
+        // FIXME : Properly remove files and not empty directories
+        for (const auto &dir : m_dirVec)
+            rmdir(dir.c_str());
+    }
+
+protected:
+    std::vector<std::string> m_dirVec;
+};