Add skeleton code
authorIlho Kim <ilho159.kim@samsung.com>
Thu, 24 Dec 2020 11:15:06 +0000 (20:15 +0900)
committerIlho Kim <ilho159.kim@samsung.com>
Mon, 28 Dec 2020 00:24:17 +0000 (09:24 +0900)
Signed-off-by: Ilho Kim <ilho159.kim@samsung.com>
22 files changed:
CMakeLists.txt
packaging/rpk-installer.spec
src/CMakeLists.txt
src/lib/CMakeLists.txt [new file with mode: 0644]
src/lib/rpk_archive_info.cc [new file with mode: 0644]
src/lib/rpk_archive_info.h [new file with mode: 0644]
src/lib/rpk_pkgmgr.cc [new file with mode: 0644]
src/rpk/CMakeLists.txt [new file with mode: 0644]
src/rpk/rpk-installer.pc.in [new file with mode: 0644]
src/rpk/rpk_app_query_interface.cc [new file with mode: 0644]
src/rpk/rpk_app_query_interface.h [new file with mode: 0644]
src/rpk/rpk_installer.cc [new file with mode: 0644]
src/rpk/rpk_installer.h [new file with mode: 0644]
src/rpk_manifest_handlers/CMakeLists.txt [new file with mode: 0644]
src/rpk_manifest_handlers/rpk-manifest-handlers.pc.in [new file with mode: 0644]
src/rpk_manifest_handlers/rpk_config_parser.cc [new file with mode: 0644]
src/rpk_manifest_handlers/rpk_config_parser.h [new file with mode: 0644]
test/CMakeLists.txt [new file with mode: 0644]
test/unit_tests/CMakeLists.txt [moved from src/unit_tests/CMakeLists.txt with 71% similarity]
test/unit_tests/main.cc [moved from src/unit_tests/main.cc with 100% similarity]
test/unit_tests/test_rpk_app_query_interface.cc [new file with mode: 0644]
test/unit_tests/test_rpk_manifest_handlers.cc [new file with mode: 0644]

index 8cd27fb..43eeb22 100755 (executable)
@@ -16,7 +16,9 @@ SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed,--gc-sections -pie")
 SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/")
 
 ## Targets
-SET(TARGET_RPK_INSTALLER "rpk-insatller")
+SET(TARGET_LIBNAME_RPK "rpk-installer")
+SET(TARGET_LIBNAME_RPK_ARCHIVE_INFO "rpk")
+SET(TARGET_LIBNAME_RPK_MANIFEST_HANDLERS "rpk-manifest-handlers")
 
 ENABLE_TESTING()
 SET(TARGET_RPK_INSTALLER_UNIT_TEST "rpk-installer-unit-test")
@@ -30,5 +32,10 @@ INCLUDE(ApplyPkgConfig)
 PKG_CHECK_MODULES(APP_INSTALLERS_DEPS REQUIRED app-installers)
 PKG_CHECK_MODULES(GMOCK_DEPS REQUIRED gmock)
 PKG_CHECK_MODULES(PKGMGR_DEPS REQUIRED pkgmgr)
+PKG_CHECK_MODULES(MANIFEST_PARSER_DEPS REQUIRED manifest-parser)
+PKG_CHECK_MODULES(MANIFEST_PARSER_UTILS_DEPS REQUIRED manifest-parser-utils)
 
-ADD_SUBDIRECTORY(src)
\ No newline at end of file
+FIND_PACKAGE(Boost REQUIRED COMPONENTS system filesystem)
+
+ADD_SUBDIRECTORY(src)
+ADD_SUBDIRECTORY(test)
index aa90e03..cab81f0 100755 (executable)
@@ -7,9 +7,11 @@ License:    Apache-2.0
 Source0:    %{name}-%{version}.tar.gz
 Source1001: %{name}.manifest
 BuildRequires:  cmake
+BuildRequires:  boost-devel
 BuildRequires:  pkgconfig(dlog)
 BuildRequires:  pkgconfig(gmock)
 BuildRequires:  pkgconfig(app-installers)
+BuildRequires:  pkgconfig(manifest-parser)
 BuildRequires:  pkgconfig(pkgmgr)
 
 %if 0%{?gcov:1}
@@ -20,6 +22,13 @@ BuildRequires:  zip
 %description
 This package contains rpk-installer library
 
+%package -n rpk-installer-devel
+Summary:    Rpk-installer development files
+Group:      Application Framework/Package Management
+Requires:   %{name} = %{version}
+
+%description devel
+This package contains header files of rpk-installer library
 
 %prep
 %setup -q
@@ -47,6 +56,7 @@ find . -name '*.gcno' -exec cp '{}' gcov-obj ';'
 %endif
 
 %check
+export LD_LIBRARY_PATH=../../src/rpk:../../src/rpk_manifest_handlers
 ctest -V
 %if 0%{?gcov:1}
 lcov -c --ignore-errors graph --no-external -q -d . -o rpk-insatller.info
@@ -72,6 +82,17 @@ install -m 0644 gcov-obj/* %{buildroot}%{_datadir}/gcov/obj
 %defattr(-,root,root,-)
 %{_libdir}/*
 %{_bindir}/*
+%{_sysconfdir}/package-manager/backendlib/librpk.so
+
+#%files -n rpk-installer-devel
+%files devel
+%{_includedir}/app-installers/rpk/*.h
+#%{_includedir}/app-installers/rpk/*/*/*.h
+%{_includedir}/rpk_manifest_handlers/*.h
+%{_libdir}/librpk-manifest-handlers.so
+%{_libdir}/pkgconfig/rpk-installer.pc
+%{_libdir}/pkgconfig/rpk-manifest-handlers.pc
+
 
 #################################################
 # rpk-installer-gcov
index c90fac8..31be19f 100755 (executable)
@@ -1 +1,3 @@
-ADD_SUBDIRECTORY(unit_tests)
+ADD_SUBDIRECTORY(lib)
+ADD_SUBDIRECTORY(rpk)
+ADD_SUBDIRECTORY(rpk_manifest_handlers)
diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt
new file mode 100644 (file)
index 0000000..1484721
--- /dev/null
@@ -0,0 +1,13 @@
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} LIB_SRCS)
+ADD_LIBRARY(${TARGET_LIBNAME_RPK_ARCHIVE_INFO} SHARED ${LIB_SRCS})
+
+TARGET_INCLUDE_DIRECTORIES(${TARGET_LIBNAME_RPK_ARCHIVE_INFO} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../)
+
+APPLY_PKG_CONFIG(${TARGET_LIBNAME_RPK_ARCHIVE_INFO} PUBLIC
+  APP_INSTALLERS_DEPS
+  PKGMGR_DEPS
+  MANIFEST_PARSER_DEPS
+)
+
+INSTALL(TARGETS ${TARGET_LIBNAME_RPK_ARCHIVE_INFO} DESTINATION ${SYSCONF_INSTALL_DIR}/package-manager/backendlib)
+INSTALL(FILES rpk_archive_info.h DESTINATION ${INCLUDEDIR}/app-installers/rpk/)
\ No newline at end of file
diff --git a/src/lib/rpk_archive_info.cc b/src/lib/rpk_archive_info.cc
new file mode 100644 (file)
index 0000000..f400219
--- /dev/null
@@ -0,0 +1,9 @@
+// Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by a apache 2.0 license that can be
+// found in the LICENSE file.
+
+#include "lib/rpk_archive_info.h"
+
+bool RpkArchiveInfo::LoadArchiveInfo() {
+  return true;
+}
diff --git a/src/lib/rpk_archive_info.h b/src/lib/rpk_archive_info.h
new file mode 100644 (file)
index 0000000..7dd2b0f
--- /dev/null
@@ -0,0 +1,26 @@
+// Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by a apache 2.0 license that can be
+// found in the LICENSE file.
+
+#ifndef LIB_RPK_ARCHIVE_INFO_H_
+#define LIB_RPK_ARCHIVE_INFO_H_
+
+#include <boost/filesystem/path.hpp>
+
+#include <common/archive_info.h>
+#include <manifest_parser/utils/logging.h>
+
+#include <string>
+
+namespace bf = boost::filesystem;
+
+class RpkArchiveInfo : public common_installer::ArchiveInfo {
+ public:
+  explicit RpkArchiveInfo(std::string path)
+      : common_installer::ArchiveInfo(path) { }
+  bool LoadArchiveInfo() override;
+
+  SCOPE_LOG_TAG(RpkArchiveInfo)
+};
+
+#endif  // LIB_RPK_ARCHIVE_INFO_H_
diff --git a/src/lib/rpk_pkgmgr.cc b/src/lib/rpk_pkgmgr.cc
new file mode 100644 (file)
index 0000000..cb668b3
--- /dev/null
@@ -0,0 +1,35 @@
+// Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by a apache 2.0 license that can be
+// found in the LICENSE file.
+
+#include <package-manager-plugin.h>
+
+#include "lib/rpk_archive_info.h"
+
+namespace {
+
+int GetPackageArchiveInfo(const char* path,
+    package_manager_pkg_detail_info_t* info) {
+  RpkArchiveInfo archive_info(path);
+  if (!archive_info.LoadArchiveInfo())
+    return -1;
+  if (!archive_info.GetPkgDetailInfo(info))
+    return -1;
+  return 0;
+}
+
+void PluginOnUnload() {
+}
+
+}  // namespace
+
+extern "C" int pkg_plugin_on_load(pkg_plugin_set* set) {
+  if (set == nullptr)
+    return -1;
+  set->plugin_on_unload = PluginOnUnload;
+  set->pkg_is_installed = nullptr;
+  set->get_installed_pkg_list = nullptr;
+  set->get_pkg_detail_info = nullptr;
+  set->get_pkg_detail_info_from_package = GetPackageArchiveInfo;
+  return 0;
+}
diff --git a/src/rpk/CMakeLists.txt b/src/rpk/CMakeLists.txt
new file mode 100644 (file)
index 0000000..8920a25
--- /dev/null
@@ -0,0 +1,29 @@
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} RPK_SRCS)
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/step/configuration RPK_STEP_CONFIGURATION_SRCS)
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/step/filesystem RPK_STEP_FILESYSTEM_SRCS)
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/step/pkgmgr RPK_STEP_PKGMGR_SRCS)
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/step/security RPK_STEP_SECURITY_SRCS)
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../lib LIB_SRCS)
+
+ADD_LIBRARY(${TARGET_LIBNAME_RPK} SHARED
+       ${RPK_SRCS}
+       ${RPK_STEP_CONFIGURATION_SRCS}
+       ${RPK_STEP_FILESYSTEM_SRCS}
+       ${RPK_STEP_PKGMGR_SRCS}
+       ${RPK_STEP_SECURITY_SRCS}
+       ${LIB_SRCS})
+
+TARGET_INCLUDE_DIRECTORIES(${TARGET_LIBNAME_RPK} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../")
+
+APPLY_PKG_CONFIG(${TARGET_LIBNAME_RPK} PUBLIC
+  APP_INSTALLERS_DEPS
+  PKGMGR_DEPS
+)
+
+INSTALL(TARGETS ${TARGET_LIBNAME_RPK} DESTINATION ${LIB_INSTALL_DIR})
+
+# Export devel package
+CONFIGURE_FILE(rpk-installer.pc.in rpk-installer.pc @ONLY)
+INSTALL(FILES rpk-installer.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
+INSTALL(DIRECTORY ./ DESTINATION ${INCLUDEDIR}/app-installers/rpk/
+        FILES_MATCHING PATTERN "*.h")
diff --git a/src/rpk/rpk-installer.pc.in b/src/rpk/rpk-installer.pc.in
new file mode 100644 (file)
index 0000000..0639c01
--- /dev/null
@@ -0,0 +1,11 @@
+prefix=@PREFIX@
+exec_prefix=@PREFIX@
+libdir=@LIBDIR@
+includedir=@INCLUDEDIR@
+
+Name: rpk-installer
+Description: Rpk-installer library
+Version: @FULLVER@
+Requires: app-installers pkgmgr manifest-parser
+Libs: -L${libdir} -lrpk-installer
+Cflags: -I${includedir}/app-installers/
diff --git a/src/rpk/rpk_app_query_interface.cc b/src/rpk/rpk_app_query_interface.cc
new file mode 100644 (file)
index 0000000..e9220f3
--- /dev/null
@@ -0,0 +1,20 @@
+// Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by an apache-2.0 license that can be
+// found in the LICENSE file.
+
+#include "rpk/rpk_app_query_interface.h"
+
+#include <string>
+
+namespace rpk {
+
+std::string RpkAppQueryInterface::GetManifestFileName() const {
+  return {};
+}
+
+std::string RpkAppQueryInterface::GetPkgIdFromPath(
+    const std::string& path) const {
+  return {};
+}
+
+}  // namespace rpk
diff --git a/src/rpk/rpk_app_query_interface.h b/src/rpk/rpk_app_query_interface.h
new file mode 100644 (file)
index 0000000..7caca33
--- /dev/null
@@ -0,0 +1,22 @@
+// Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by an apache-2.0 license that can be
+// found in the LICENSE file.
+
+#ifndef RPK_RPK_APP_QUERY_INTERFACE_H_
+#define RPK_RPK_APP_QUERY_INTERFACE_H_
+
+#include <common/app_query_interface.h>
+
+#include <string>
+
+namespace rpk {
+
+class RpkAppQueryInterface : public common_installer::AppQueryInterface {
+ private:
+  std::string GetPkgIdFromPath(const std::string& path) const override;
+  std::string GetManifestFileName() const override;
+};
+
+}  // namespace rpk
+
+#endif  // RPK_RPK_APP_QUERY_INTERFACE_H_
diff --git a/src/rpk/rpk_installer.cc b/src/rpk/rpk_installer.cc
new file mode 100644 (file)
index 0000000..b9d28b5
--- /dev/null
@@ -0,0 +1,77 @@
+/* Copyright 2020 Samsung Electronics, license APACHE-2.0, see LICENSE file */
+#include "rpk/rpk_installer.h"
+
+#include <common/installer/app_installer.h>
+
+//#include "lib/rpk_archive_info.h"
+
+namespace ci = common_installer;
+
+namespace {
+
+const char kPkgType[] = "rpk";
+
+}  // namespace
+
+namespace rpk {
+
+RpkInstaller::RpkInstaller(common_installer::PkgMgrPtr pkgmgr)
+    : AppInstaller(kPkgType, pkgmgr) {
+}
+
+RpkInstaller::~RpkInstaller() {
+}
+
+std::unique_ptr<ci::ArchiveInfo> RpkInstaller::GetArchiveInfo() {
+  return nullptr;
+}
+
+void RpkInstaller::InstallSteps() {
+  AppInstaller::InstallSteps();
+}
+
+void RpkInstaller::UpdateSteps() {
+  AppInstaller::UpdateSteps();
+}
+
+void RpkInstaller::UninstallSteps() {
+  AppInstaller::UninstallSteps();
+}
+
+void RpkInstaller::RecoverySteps() {
+  AppInstaller::RecoverySteps();
+}
+
+void RpkInstaller::ManifestDirectInstallSteps() {
+  AppInstaller::ManifestDirectInstallSteps();
+}
+
+void RpkInstaller::ManifestDirectUpdateSteps() {
+  AppInstaller::ManifestDirectUpdateSteps();
+}
+
+void RpkInstaller::ManifestPartialInstallSteps() {
+  AppInstaller::ManifestPartialInstallSteps();
+}
+
+void RpkInstaller::ManifestPartialUpdateSteps() {
+  AppInstaller::ManifestPartialUpdateSteps();
+}
+
+void RpkInstaller::PartialUninstallSteps() {
+  AppInstaller::PartialUninstallSteps();
+}
+
+void RpkInstaller::ReadonlyUpdateInstallSteps() {
+  AppInstaller::ReadonlyUpdateInstallSteps();
+}
+
+void RpkInstaller::ReadonlyUpdateUninstallSteps() {
+  AppInstaller::ReadonlyUpdateUninstallSteps();
+}
+
+void RpkInstaller::RecoverDBSteps() {
+  AppInstaller::RecoverDBSteps();
+}
+
+}  // namespace rpk
diff --git a/src/rpk/rpk_installer.h b/src/rpk/rpk_installer.h
new file mode 100644 (file)
index 0000000..e1b77de
--- /dev/null
@@ -0,0 +1,46 @@
+/* Copyright 2020 Samsung Electronics, license APACHE-2.0, see LICENSE file */
+
+#ifndef RPK_RPK_INSTALLER_H_
+#define RPK_RPK_INSTALLER_H_
+
+#include <common/installer/app_installer.h>
+#include <common/pkgmgr_interface.h>
+#include <manifest_parser/utils/logging.h>
+
+namespace rpk {
+
+/**
+ * @brief The RpkInstaller class
+ *        Handles request of rpk packages.
+ *
+ * This class is main class for installation/update/deinstallation of rpk
+ * packages. Pkgmgr request is parsed within and sequence of steps is built to
+ * be run.
+ */
+class RpkInstaller : public common_installer::AppInstaller {
+ public:
+  explicit RpkInstaller(common_installer::PkgMgrPtr pkgmgr);
+  ~RpkInstaller();
+  std::unique_ptr<common_installer::ArchiveInfo> GetArchiveInfo() override;
+
+ protected:
+  void InstallSteps() override;
+  void UpdateSteps() override;
+  void UninstallSteps() override;
+  void RecoverySteps() override;
+  void ManifestDirectInstallSteps() override;
+  void ManifestDirectUpdateSteps() override;
+  void ManifestPartialInstallSteps() override;
+  void ManifestPartialUpdateSteps() override;
+  void PartialUninstallSteps() override;
+  void ReadonlyUpdateInstallSteps() override;
+  void ReadonlyUpdateUninstallSteps() override;
+  void RecoverDBSteps() override;
+
+ private:
+  SCOPE_LOG_TAG(RpkInstaller)
+};
+
+}  // namespace rpk
+
+#endif  // RPK_RPK_INSTALLER_H_
diff --git a/src/rpk_manifest_handlers/CMakeLists.txt b/src/rpk_manifest_handlers/CMakeLists.txt
new file mode 100644 (file)
index 0000000..282b2ef
--- /dev/null
@@ -0,0 +1,31 @@
+# Target - sources
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} SRCS)
+
+# Target - definition
+ADD_LIBRARY(${TARGET_LIBNAME_RPK_MANIFEST_HANDLERS} SHARED
+       ${SRCS}
+)
+
+# Target - includes
+TARGET_INCLUDE_DIRECTORIES(${TARGET_LIBNAME_RPK_MANIFEST_HANDLERS} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../")
+
+# Target - deps
+APPLY_PKG_CONFIG(${TARGET_LIBNAME_RPK_MANIFEST_HANDLERS} PUBLIC
+  Boost
+  MANIFEST_PARSER_UTILS_DEPS
+)
+
+# Extra
+SET_TARGET_PROPERTIES(${TARGET_LIBNAME_RPK_MANIFEST_HANDLERS} PROPERTIES VERSION ${FULLVER})
+SET_TARGET_PROPERTIES(${TARGET_LIBNAME_RPK_MANIFEST_HANDLERS} PROPERTIES SOVERSION ${MAJORVER})
+
+# Install
+INSTALL(TARGETS ${TARGET_LIBNAME_RPK_MANIFEST_HANDLERS} DESTINATION ${LIB_INSTALL_DIR})
+
+# Install includes
+INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} DESTINATION ${INCLUDEDIR}
+        FILES_MATCHING PATTERN "*.h")
+
+# Configure and install pkgconfig file
+CONFIGURE_FILE(rpk-manifest-handlers.pc.in rpk-manifest-handlers.pc @ONLY)
+INSTALL(FILES rpk-manifest-handlers.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
diff --git a/src/rpk_manifest_handlers/rpk-manifest-handlers.pc.in b/src/rpk_manifest_handlers/rpk-manifest-handlers.pc.in
new file mode 100644 (file)
index 0000000..a83d008
--- /dev/null
@@ -0,0 +1,11 @@
+prefix=@PREFIX@
+exec_prefix=@PREFIX@
+libdir=@LIBDIR@
+includedir=@INCLUDEDIR@
+
+Name: rpk-manifest-handlers
+Description: Manifest handlers for rpk manifest file parser
+Version: @FULLVER@
+Requires: manifest-parser
+Libs: -L${libdir} -lrpk-manifest-handlers
+Cflags: -I${includedir}
diff --git a/src/rpk_manifest_handlers/rpk_config_parser.cc b/src/rpk_manifest_handlers/rpk_config_parser.cc
new file mode 100644 (file)
index 0000000..1020f5f
--- /dev/null
@@ -0,0 +1,47 @@
+// Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by an apache 2.0 license that can be
+// found in the LICENSE file.
+
+#include "rpk_manifest_handlers/rpk_config_parser.h"
+
+#include <utility>
+#include <string>
+#include <vector>
+
+#include "manifest_parser/manifest_handler.h"
+#include "manifest_parser/utils/iri_util.h"
+#include "manifest_parser/utils/logging.h"
+
+namespace rpk {
+namespace parse {
+
+RPKConfigParser::RPKConfigParser() {
+  std::vector<std::shared_ptr<parser::ManifestHandler>> handlers = {
+  };
+
+  std::unique_ptr<parser::ManifestHandlerRegistry> registry(
+      new parser::ManifestHandlerRegistry(handlers));
+
+  parser_.reset(new parser::ManifestParser(std::move(registry)));
+}
+
+std::shared_ptr<const parser::ManifestData> RPKConfigParser::GetManifestData(
+    const std::string& key) const {
+  return parser_->GetManifestData(key);
+}
+
+const std::string& RPKConfigParser::GetErrorMessage() const {
+  if (!error_.empty())
+    return error_;
+  return parser_->GetErrorMessage();
+}
+
+bool RPKConfigParser::ParseManifest(const boost::filesystem::path& path) {
+  if (!parser_->ParseManifest(path))
+    return false;
+
+  return true;
+}
+
+}  // namespace parse
+}  // namespace rpk
diff --git a/src/rpk_manifest_handlers/rpk_config_parser.h b/src/rpk_manifest_handlers/rpk_config_parser.h
new file mode 100644 (file)
index 0000000..a4ee096
--- /dev/null
@@ -0,0 +1,51 @@
+// Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by an apache 2.0 license that can be
+// found in the LICENSE file.
+
+#ifndef RPK_MANIFEST_HANDLERS_RPK_CONFIG_PARSER_H_
+#define RPK_MANIFEST_HANDLERS_RPK_CONFIG_PARSER_H_
+
+#include <boost/filesystem/path.hpp>
+
+#include <memory>
+#include <string>
+
+#include "manifest_parser/manifest_parser.h"
+
+namespace rpk {
+namespace parse {
+
+/**
+ * @brief The RPKConfigParser class
+ *        Parser class of rpk package tizen-manifest.xml manifest file.
+ *
+ * Instance of this class may be used to parse single configuration file.
+ * Depending on boolean result of @ref ParseManifest method, client code may
+ * call:
+ *  - on success -> @ref GetManifestData(), passing the key of ManifestData
+ *                  instance that it is interested in.
+ *  - on failure -> @ref GetErrorMessage(), to get value of error which was set
+ *                  during the processing of config.xml
+ *
+ * To investigate which key do you need to get certain parsed piece of data,
+ * check the key reported by handler's @ref ManifestHandler::Key() method.
+ * Key returned by this method is the key to access data set by handler.
+ */
+class RPKConfigParser {
+ public:
+  RPKConfigParser();
+
+  std::shared_ptr<const parser::ManifestData> GetManifestData(
+      const std::string& key) const;
+  const std::string& GetErrorMessage() const;
+  bool ParseManifest(const boost::filesystem::path& path);
+
+ private:
+  std::unique_ptr<parser::ManifestParser> parser_;
+  std::string error_;
+};
+
+}  // namespace parse
+}  // namespace rpk
+
+#endif  // RPK_MANIFEST_HANDLERS_RPK_CONFIG_PARSER_H_
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
new file mode 100644 (file)
index 0000000..c90fac8
--- /dev/null
@@ -0,0 +1 @@
+ADD_SUBDIRECTORY(unit_tests)
similarity index 71%
rename from src/unit_tests/CMakeLists.txt
rename to test/unit_tests/CMakeLists.txt
index fbf4ba2..9c639b5 100755 (executable)
@@ -3,13 +3,14 @@ ADD_EXECUTABLE(${TARGET_RPK_INSTALLER_UNIT_TEST}
   ${UNIT_TESTS_SRCS}
 )
 
-TARGET_INCLUDE_DIRECTORIES(${TARGET_RPK_INSTALLER_UNIT_TEST} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../")
-
 APPLY_PKG_CONFIG(${TARGET_RPK_INSTALLER_UNIT_TEST} PUBLIC
   GMOCK_DEPS
+  MANIFEST_PARSER_DEPS
 )
 
-#TARGET_LINK_LIBRARIES(${TARGET_RPK_INSTALLER_UNIT_TEST} PUBLIC ${TARGET_RPK_INSTALLER} )
+TARGET_LINK_LIBRARIES(${TARGET_RPK_INSTALLER_UNIT_TEST} PUBLIC ${TARGET_LIBNAME_RPK})
+TARGET_LINK_LIBRARIES(${TARGET_RPK_INSTALLER_UNIT_TEST} PUBLIC ${TARGET_LIBNAME_RPK_MANIFEST_HANDLERS})
+
 SET_TARGET_PROPERTIES(${TARGET_RPK_INSTALLER_UNIT_TEST} PROPERTIES COMPILE_FLAGS "-fPIE")
 SET_TARGET_PROPERTIES(${TARGET_RPK_INSTALLER_UNIT_TEST} PROPERTIES LINK_FLAGS "-pie")
 
diff --git a/test/unit_tests/test_rpk_app_query_interface.cc b/test/unit_tests/test_rpk_app_query_interface.cc
new file mode 100644 (file)
index 0000000..2c70720
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ *
+ * 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 <gtest/gtest.h>
+
+#include <common/app_query_interface.h>
+
+#include <cstdio>
+
+#include "rpk/rpk_app_query_interface.h"
+
+class RpkAppQueryInterfaceTest : public ::testing::Test {
+ public:
+  virtual void SetUp() {
+  }
+
+  virtual void TearDown() {
+  }
+};
+
+TEST_F(RpkAppQueryInterfaceTest, DummyTest) {
+  std::unique_ptr<common_installer::AppQueryInterface> ptr =
+      std::make_unique<rpk::RpkAppQueryInterface>();
+  EXPECT_EQ(ptr->GetPkgId(""), "");
+}
diff --git a/test/unit_tests/test_rpk_manifest_handlers.cc b/test/unit_tests/test_rpk_manifest_handlers.cc
new file mode 100644 (file)
index 0000000..69ddb95
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ *
+ * 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 <gtest/gtest.h>
+
+#include <cstdio>
+
+#include "rpk_manifest_handlers/rpk_config_parser.h"
+
+class RpkManifestHandlersTest : public ::testing::Test {
+ public:
+  virtual void SetUp() {
+  }
+
+  virtual void TearDown() {
+  }
+};
+
+TEST_F(RpkManifestHandlersTest, DummyTest) {
+  rpk::parse::RPKConfigParser config_parser;
+  EXPECT_EQ(config_parser.GetManifestData(""), nullptr);
+}