Manifest testcase skeleton 30/59230/5
authorTomasz Iwanek <t.iwanek@samsung.com>
Thu, 11 Feb 2016 11:51:14 +0000 (12:51 +0100)
committerTomasz Iwanek <t.iwanek@samsung.com>
Wed, 2 Mar 2016 10:30:19 +0000 (02:30 -0800)
Testcase skeleton for tests which parse manifest and
set fields in manifest_x structure.

Verification: /usr/bin/wgt-backend-ut/manifest-test

Change-Id: I4fde4bdcdcf38b2fb23979d3c8eef67d40f92d9d

CMakeLists.txt
src/unit_tests/CMakeLists.txt
src/unit_tests/manifest_test.cc [new file with mode: 0644]
src/unit_tests/test_samples/manifest/ManifestTest.WidgetElement_InvalidNamespace/config.xml [new file with mode: 0644]
src/unit_tests/test_samples/manifest/ManifestTest.WidgetElement_Valid/config.xml [new file with mode: 0644]

index d520638f56e4bbd0b70d3eef71d6c262b3ee9c32..c7359f825c932c5a24c606a748730477af4a7320 100644 (file)
@@ -28,6 +28,7 @@ SET(TARGET_LIBNAME_HYBRID "hybrid-installer")
 
 SET(TARGET_SMOKE_TEST "smoke-test")
 SET(TARGET_SMOKE_TEST_HELPER "smoke-test-helper")
+SET(TARGET_MANIFEST_TEST "manifest-test")
 
 ADD_DEFINITIONS("-Wall")
 ADD_DEFINITIONS("-Wextra")
index e09827f2a7cde704a4e947d91ec74460fe492527..7222f1e412434dcf6eaccb6e1ed56917291aea8a 100644 (file)
@@ -7,9 +7,13 @@ ADD_EXECUTABLE(${TARGET_SMOKE_TEST}
 ADD_EXECUTABLE(${TARGET_SMOKE_TEST_HELPER}
   smoke_test_helper.cc
 )
+ADD_EXECUTABLE(${TARGET_MANIFEST_TEST}
+  manifest_test.cc
+)
 
 TARGET_INCLUDE_DIRECTORIES(${TARGET_SMOKE_TEST} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../)
 TARGET_INCLUDE_DIRECTORIES(${TARGET_SMOKE_TEST_HELPER} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../)
+TARGET_INCLUDE_DIRECTORIES(${TARGET_MANIFEST_TEST} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../)
 
 INSTALL(DIRECTORY test_samples/ DESTINATION ${SHAREDIR}/${DESTINATION_DIR}/test_samples)
 
@@ -17,12 +21,18 @@ APPLY_PKG_CONFIG(${TARGET_SMOKE_TEST} PUBLIC
   Boost
   GTEST
 )
+APPLY_PKG_CONFIG(${TARGET_MANIFEST_TEST} PUBLIC
+  Boost
+  GTEST
+)
 
 # FindGTest module do not sets all needed libraries in GTEST_LIBRARIES and
 # GTest main libraries is still missing, so additional linking of
 # GTEST_MAIN_LIBRARIES is needed.
 target_link_libraries(${TARGET_SMOKE_TEST} PRIVATE ${TARGET_LIBNAME_WGT} ${TARGET_LIBNAME_HYBRID} ${GTEST_MAIN_LIBRARIES})
 target_link_libraries(${TARGET_SMOKE_TEST_HELPER} PRIVATE ${TARGET_LIBNAME_WGT})
+target_link_libraries(${TARGET_MANIFEST_TEST} PRIVATE ${TARGET_LIBNAME_WGT} ${GTEST_MAIN_LIBRARIES})
 
 INSTALL(TARGETS ${TARGET_SMOKE_TEST} DESTINATION ${BINDIR}/${DESTINATION_DIR})
 INSTALL(TARGETS ${TARGET_SMOKE_TEST_HELPER} DESTINATION ${BINDIR}/${DESTINATION_DIR})
+INSTALL(TARGETS ${TARGET_MANIFEST_TEST} DESTINATION ${BINDIR}/${DESTINATION_DIR})
diff --git a/src/unit_tests/manifest_test.cc b/src/unit_tests/manifest_test.cc
new file mode 100644 (file)
index 0000000..fb74852
--- /dev/null
@@ -0,0 +1,97 @@
+// Copyright (c) 2015 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 <boost/filesystem/path.hpp>
+
+#include <common/installer_context.h>
+#include <common/request.h>
+#include <common/utils/glist_range.h>
+
+#include <glib.h>
+#include <gtest/gtest.h>
+
+#include <memory>
+#include <string>
+
+#include "wgt/step/step_parse.h"
+#include "wgt/wgt_backend_data.h"
+
+#define ASSERT_CSTR_EQ(STR1, STR2)                                             \
+  ASSERT_EQ(strcmp(STR1, STR2), 0)                                             \
+
+namespace bf = boost::filesystem;
+namespace ci = common_installer;
+
+namespace {
+
+const char kManifestTestcaseData[] =
+    "/usr/share/wgt-backend-ut/test_samples/manifest/";
+
+template<typename T>
+gint Size(GListRange<T>* range) {
+  return std::distance(range->begin(), range->end());
+}
+
+class StepParseRunner {
+ public:
+  explicit StepParseRunner(const std::string& dir_suffix,
+                           bool ignore_start_files = true)
+      : dir_suffix_(dir_suffix),
+        ignore_start_files_(ignore_start_files),
+        context_(nullptr) {
+  }
+
+  bool Run() {
+    PrepareContext();
+    wgt::parse::StepParse step(context_.get(), !ignore_start_files_);
+    return step.process() == ci::Step::Status::OK;
+  }
+
+  manifest_x* GetManifest() const {
+    return context_->manifest_data.get();
+  }
+
+ private:
+  void PrepareContext() {
+    context_.reset(new ci::InstallerContext());
+    context_->root_application_path.set(ci::GetRootAppPath(false));
+    context_->unpacked_dir_path.set(
+        bf::path(kManifestTestcaseData) / dir_suffix_);
+    context_->backend_data.set(new wgt::WgtBackendData());
+  }
+
+  std::string dir_suffix_;
+  bool ignore_start_files_;
+  std::unique_ptr<ci::InstallerContext> context_;
+};
+
+}  // namespace
+
+class ManifestTest : public testing::Test {
+ public:
+  std::string GetMyName() const {
+    std::string suite =
+        testing::UnitTest::GetInstance()->current_test_info()->test_case_name();
+    std::string case_name =
+        testing::UnitTest::GetInstance()->current_test_info()->name();
+    return suite + '.' + case_name;
+  }
+};
+
+TEST_F(ManifestTest, WidgetElement_Valid) {
+  StepParseRunner runner(GetMyName());
+  ASSERT_TRUE(runner.Run());
+  manifest_x* m = runner.GetManifest();
+  ASSERT_NE(m, nullptr);
+  ASSERT_CSTR_EQ(m->package, "package0id");
+  auto apps = GListRange<application_x*>(m->application);
+  ASSERT_EQ(Size(&apps), 1);
+  application_x* app = *apps.begin();
+  ASSERT_CSTR_EQ(app->appid, "package0id.appid");
+}
+
+TEST_F(ManifestTest, WidgetElement_InvalidNamespace) {
+  StepParseRunner runner(GetMyName());
+  ASSERT_FALSE(runner.Run());
+}
diff --git a/src/unit_tests/test_samples/manifest/ManifestTest.WidgetElement_InvalidNamespace/config.xml b/src/unit_tests/test_samples/manifest/ManifestTest.WidgetElement_InvalidNamespace/config.xml
new file mode 100644 (file)
index 0000000..d4c2eef
--- /dev/null
@@ -0,0 +1,4 @@
+<?xml version="1.0"?>
+<widget xmlns="http://www.w3.org/ns/widgets/invalid" xmlns:tizen="http://tizen.org/ns/widgets">
+  <tizen:application id="package0id.appid" package="package0id" required_version="3.0"/>
+</widget>
diff --git a/src/unit_tests/test_samples/manifest/ManifestTest.WidgetElement_Valid/config.xml b/src/unit_tests/test_samples/manifest/ManifestTest.WidgetElement_Valid/config.xml
new file mode 100644 (file)
index 0000000..14d024a
--- /dev/null
@@ -0,0 +1,4 @@
+<?xml version="1.0"?>
+<widget xmlns="http://www.w3.org/ns/widgets" xmlns:tizen="http://tizen.org/ns/widgets">
+  <tizen:application id="package0id.appid" package="package0id" required_version="3.0"/>
+</widget>