Manifest testcase skeleton 34/60034/3
authorTomasz Iwanek <t.iwanek@samsung.com>
Mon, 22 Feb 2016 13:33:03 +0000 (14:33 +0100)
committerTomasz Iwanek <t.iwanek@samsung.com>
Mon, 29 Feb 2016 09:09:27 +0000 (01:09 -0800)
Testcase skeleton for tests which parse manifest and
set fields in manifest_x structure.

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

One of tests to pass requires change:
 - https://review.tizen.org/gerrit/60033

Change-Id: I79807551a5505d0924de7cd893039aec5edb3eda

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.ManifestElement_InvalidRootElement/tizen-manifest.xml [new file with mode: 0644]
src/unit_tests/test_samples/manifest/ManifestTest.ManifestElement_Valid/tizen-manifest.xml [new file with mode: 0644]

index 08b0642..10f540f 100644 (file)
@@ -27,6 +27,7 @@ SET(TARGET_TPK_BACKEND "tpk-backend")
 
 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 4a8d7e8..7e195a0 100644 (file)
@@ -9,8 +9,13 @@ 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)
 
@@ -18,12 +23,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_TPK} ${GTEST_MAIN_LIBRARIES})
 target_link_libraries(${TARGET_SMOKE_TEST_HELPER} PRIVATE ${TARGET_LIBNAME_TPK})
+target_link_libraries(${TARGET_MANIFEST_TEST} PRIVATE ${TARGET_LIBNAME_TPK} ${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..b7e9e55
--- /dev/null
@@ -0,0 +1,96 @@
+// 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/step/step_parse_manifest.h>
+#include <common/utils/glist_range.h>
+
+#include <glib.h>
+#include <gtest/gtest.h>
+
+#include <memory>
+#include <string>
+
+#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/tpk-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();
+    ci::parse::StepParseManifest step(context_.get(),
+        ci::parse::StepParseManifest::ManifestLocation::PACKAGE,
+        ci::parse::StepParseManifest::StoreLocation::NORMAL);
+    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_);
+  }
+
+  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, ManifestElement_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, ManifestElement_InvalidRootElement) {
+  StepParseRunner runner(GetMyName());
+  ASSERT_FALSE(runner.Run());
+}
diff --git a/src/unit_tests/test_samples/manifest/ManifestTest.ManifestElement_InvalidRootElement/tizen-manifest.xml b/src/unit_tests/test_samples/manifest/ManifestTest.ManifestElement_InvalidRootElement/tizen-manifest.xml
new file mode 100644 (file)
index 0000000..a24942c
--- /dev/null
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<widget xmlns="http://tizen.org/ns/packages" api-version="2.3" package="package0id" version="1.0.0">
+    <ui-application appid="package0id.appid" exec="testapp" type="capp">
+    </ui-application>
+</widget>
diff --git a/src/unit_tests/test_samples/manifest/ManifestTest.ManifestElement_Valid/tizen-manifest.xml b/src/unit_tests/test_samples/manifest/ManifestTest.ManifestElement_Valid/tizen-manifest.xml
new file mode 100644 (file)
index 0000000..f0bba4a
--- /dev/null
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<manifest xmlns="http://tizen.org/ns/packages" api-version="2.3" package="package0id" version="1.0.0">
+    <ui-application appid="package0id.appid" exec="testapp" type="capp">
+    </ui-application>
+</manifest>