Remove boost dependency
[platform/core/appfw/app-installers.git] / test / smoke_tests / common / smoke_utils.h
index 9e1369b..10fa019 100644 (file)
 #include <unistd.h>
 #include <tzplatform_config.h>
 
-#include <boost/filesystem/operations.hpp>
-#include <boost/range/iterator_range.hpp>
-#include <boost/format.hpp>
-#include <boost/program_options.hpp>
-#include <boost/system/error_code.hpp>
-
 #include <gtest/gtest.h>
 #include <gtest/gtest-death-test.h>
 
@@ -34,6 +28,7 @@
 #include <array>
 #include <cstdio>
 #include <cstdlib>
+#include <filesystem>
 #include <memory>
 #include <regex>
 #include <string>
@@ -66,8 +61,8 @@
 
 namespace smoke_test {
 
-extern const bf::path kSmokePackagesDirectory;
-extern const bf::path kSdkDirectory;
+extern const fs::path kSmokePackagesDirectory;
+extern const fs::path kSdkDirectory;
 extern const uid_t kGlobalUserUid;
 extern const uid_t kGlobalUserGid;
 extern const char kLegacyExtImageDir[];
@@ -90,7 +85,7 @@ enum class StorageType {
 class ScopedTzipInterface {
  public:
   explicit ScopedTzipInterface(const std::string& pkgid, uid_t test_user)
-      : pkg_path_(boost::filesystem::path(
+      : pkg_path_(std::filesystem::path(
           common_installer::GetRootAppPath(false, test_user)) / pkgid),
         interface_(common_installer::GetMountLocation(pkg_path_)),
         mounted_(true) {
@@ -110,7 +105,7 @@ class ScopedTzipInterface {
   }
 
  private:
-  boost::filesystem::path pkg_path_;
+  std::filesystem::path pkg_path_;
   common_installer::TzipInterface interface_;
   bool mounted_;
 };
@@ -154,26 +149,28 @@ struct TestParameters {
 
 class FileInfoCollector {
  public:
-  using FileInfo = std::tuple<bf::path, bf::file_type, bf::perms,
+  using FileInfo = std::tuple<fs::path, fs::file_type, fs::perms,
       std::string, std::string, std::string>;
 
   FileInfoCollector(std::string pkgid, TestParameters params) :
       pkgid_(pkgid), params_(params) {}
-  bool FileInfoToFile(const bf::path& path) const;
+  bool FileInfoToFile(const fs::path& path) const;
   bool Init();
   bool IsEqual(const FileInfoCollector& collector,
-      const std::vector<bf::path>* exception_list = nullptr) const;
-  bool LoadFromFile(const bf::path& path);
+      const std::vector<fs::path>* exception_list = nullptr) const;
+  bool LoadFromFile(const fs::path& path);
 
  private:
-  void AddPath(const bf::path& path);
+  void AddPath(const fs::path& path);
   bool CollectFileInfoRecursive();
-  bool GetFileListTraversal(const bf::path& cur);
+  bool GetFileListTraversal(const fs::path& cur);
+  std::string FileTypeToString(fs::file_type type) const;
+  int PermsToInt(fs::perms perms) const;
   std::string FileInfoToString(const FileInfo& file_info) const;
 
   std::string pkgid_;
   TestParameters params_;
-  std::vector<bf::path> root_paths_;
+  std::vector<fs::path> root_paths_;
   std::vector<FileInfo> FileInfos_;
 };
 
@@ -203,10 +200,10 @@ struct PackageAttributes {
 
 common_installer::RequestMode ParseRequestMode(int argc,  char** argv);
 
-bool TouchFile(const boost::filesystem::path& path);
+bool TouchFile(const std::filesystem::path& path);
 
 void AddDataFiles(const std::string& pkgid, uid_t uid,
-    std::vector<bf::path>* result = nullptr);
+    std::vector<fs::path>* result = nullptr);
 
 bool AddTestUser(User* test_user);
 
@@ -214,12 +211,12 @@ bool DeleteTestUser();
 
 void RemoveAllRecoveryFiles(const std::string& prefix, uid_t uid);
 
-boost::filesystem::path FindRecoveryFile(const std::string& prefix, uid_t uid);
+std::filesystem::path FindRecoveryFile(const std::string& prefix, uid_t uid);
 
-boost::filesystem::path GetPackageRoot(const std::string& pkgid, uid_t uid);
+std::filesystem::path GetPackageRoot(const std::string& pkgid, uid_t uid);
 
 std::unique_ptr<common_installer::recovery::RecoveryFile> GetRecoverFileInfo(
-    const bf::path& recovery_file_path);
+    const fs::path& recovery_file_path);
 
 bool ValidateFileContentInPackage(const std::string& pkgid,
                                   const std::string& relative,
@@ -248,7 +245,7 @@ bool CheckSharedDataExistance(const std::string& pkgid,
 bool CheckSharedDataNonExistance(const std::string& pkgid,
                                 const TestParameters& params);
 
-bool TouchFile(const boost::filesystem::path& path);
+bool TouchFile(const std::filesystem::path& path);
 
 class SmokeInstallerFactory {
  public:
@@ -285,15 +282,15 @@ class BackendInterface {
   void CrashAfterEachStep(std::vector<std::string>* args,
                           std::function<bool(int iter)> validator,
                           PackageType type) const;
-  CommandResult Install(const std::vector<bf::path>& paths) const;
-  CommandResult InstallSuccess(const std::vector<bf::path>& paths) const;
-  CommandResult Install(const boost::filesystem::path& path) const;
-  CommandResult InstallPreload(const boost::filesystem::path& path) const;
-  CommandResult InstallWithStorage(const boost::filesystem::path& path,
+  CommandResult Install(const std::vector<fs::path>& paths) const;
+  CommandResult InstallSuccess(const std::vector<fs::path>& paths) const;
+  CommandResult Install(const std::filesystem::path& path) const;
+  CommandResult InstallPreload(const std::filesystem::path& path) const;
+  CommandResult InstallWithStorage(const std::filesystem::path& path,
       StorageType type = StorageType::INTERNAL) const;
-  CommandResult InstallSuccess(const bf::path& path) const;
+  CommandResult InstallSuccess(const fs::path& path) const;
   CommandResult InstallPreloadSuccess(
-      const boost::filesystem::path& path) const;
+      const std::filesystem::path& path) const;
 
   CommandResult Uninstall(const std::vector<std::string>& pkgids) const;
   CommandResult Uninstall(const std::string& pkgid) const;
@@ -302,43 +299,43 @@ class BackendInterface {
   CommandResult EnablePackage(const std::string& pkgid) const;
   CommandResult DisablePackage(const std::string& pkgid) const;
 
-  CommandResult MountInstall(const boost::filesystem::path& path) const;
-  CommandResult MountInstallSuccess(const bf::path& path) const;
+  CommandResult MountInstall(const std::filesystem::path& path) const;
+  CommandResult MountInstallSuccess(const fs::path& path) const;
   CommandResult ManifestDirectInstall(const std::string& pkgid) const;
 
   CommandResult MigrateLegacyExternalImage(const std::string& pkgid,
-      const boost::filesystem::path& path,
-      const boost::filesystem::path& legacy_path) const;
+      const std::filesystem::path& path,
+      const std::filesystem::path& legacy_path) const;
 
-  CommandResult RDSUpdate(const boost::filesystem::path& path,
+  CommandResult RDSUpdate(const std::filesystem::path& path,
       const std::string& pkgid) const;
 
-  CommandResult Recover(const boost::filesystem::path& recovery_file) const;
+  CommandResult Recover(const std::filesystem::path& recovery_file) const;
 
-  SubProcessResult InstallWithSubprocess(const bf::path& path) const;
-  SubProcessResult MountInstallWithSubprocess(const bf::path& path) const;
-  SubProcessResult RecoverWithSubprocess(const bf::path& path) const;
+  SubProcessResult InstallWithSubprocess(const fs::path& path) const;
+  SubProcessResult MountInstallWithSubprocess(const fs::path& path) const;
+  SubProcessResult RecoverWithSubprocess(const fs::path& path) const;
   SubProcessResult UninstallWithSubprocess(const std::string& pkgid) const;
   SubProcessResult InstallPreloadWithSubprocess(
-      const boost::filesystem::path& path) const;
+      const std::filesystem::path& path) const;
   SubProcessResult InstallWithSubprocessAndKill(
-      const bf::path& path, useconds_t delay) const;
+      const fs::path& path, useconds_t delay) const;
   SubProcessResult MountInstallWithSubprocessAndKill(
-      const bf::path& path, useconds_t delay) const;
+      const fs::path& path, useconds_t delay) const;
   SubProcessResult UninstallWithSubprocessAndKill(
       const std::string& pkgid, useconds_t delay) const;
   SubProcessResult InstallPkgsWithSubprocess(
-      const std::vector<bf::path>& paths) const;
+      const std::vector<fs::path>& paths) const;
   SubProcessResult MountInstallPkgsWithSubprocess(
-      const std::vector<bf::path>& paths) const;
+      const std::vector<fs::path>& paths) const;
   SubProcessResult RecoverPkgsWithSubprocess(
-      const std::vector<bf::path>& paths) const;
+      const std::vector<fs::path>& paths) const;
   SubProcessResult UninstallPkgsWithSubprocess(
       const std::vector<std::string>& pkgids) const;
   SubProcessResult InstallPkgsWithSubprocessAndKill(
-      const std::vector<bf::path>& paths, useconds_t delay) const;
+      const std::vector<fs::path>& paths, useconds_t delay) const;
   SubProcessResult MountInstallPkgsWithSubprocessAndKill(
-      const std::vector<bf::path>& paths, useconds_t delay) const;
+      const std::vector<fs::path>& paths, useconds_t delay) const;
 
  protected:
   CommandResult CallBackend(int argc, const char* argv[]) const;
@@ -372,19 +369,19 @@ bool CheckAvailableExternalPath();
 
 bool CheckAvailableExtendedPath();
 
-bool BackupPathCopyAndRemove(const boost::filesystem::path& path);
+bool BackupPathCopyAndRemove(const std::filesystem::path& path);
 
-bool BackupPath(const boost::filesystem::path& path);
+bool BackupPath(const std::filesystem::path& path);
 
 void CreateDatabase();
 
-bool RestorePathCopyAndRemove(const boost::filesystem::path& path);
+bool RestorePathCopyAndRemove(const std::filesystem::path& path);
 
-bool RestorePath(const boost::filesystem::path& path);
+bool RestorePath(const std::filesystem::path& path);
 
-std::vector<boost::filesystem::path> SetupBackupDirectories(uid_t test_uid);
+std::vector<std::filesystem::path> SetupBackupDirectories(uid_t test_uid);
 
-void UninstallAllAppsInDirectory(boost::filesystem::path dir, bool is_preload,
+void UninstallAllAppsInDirectory(std::filesystem::path dir, bool is_preload,
     BackendInterface* backend);
 
 void UninstallAllSmokeApps(common_installer::RequestMode request_mode,
@@ -429,7 +426,7 @@ class StepCrash : public common_installer::Step {
 };
 
 bool CompareFileInfo(const std::string& pkgid, const TestParameters& params,
-    const bf::path& file);
+    const fs::path& file);
 
 }  // namespace smoke_test