1c178d8632e981f53457eacdd0e59a552e664bbf
[platform/core/appfw/app-installers.git] / test / smoke_tests / libs / test_metadata_plugin.cc
1 // Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
2 // Use of this source code is governed by an apache 2.0 license that can be
3 // found in the LICENSE file.
4
5 #include <boost/optional/optional.hpp>
6
7 #include <pkgmgr_parser.h>
8
9 #include <glib/glist.h>
10
11 #include <cstring>
12 #include <string>
13 #include <tuple>
14
15 #include "common/plugins/plugin.h"
16 #include "common/utils/glist_range.h"
17 #include "smoke_tests/libs/test_assessor.h"
18
19 namespace ci = common_installer;
20
21 namespace {
22
23 boost::optional<std::string> CheckArgs(
24     const char* pkgid,
25     const char* appid,
26     GList* metadata) {
27   if (!pkgid)
28     return std::string("Package id is null for metadata plugin");
29   if (!appid)
30     return std::string("Application id is null for metadata plugin");
31   if (strcmp(pkgid, ci::kTestPackageId) != 0)
32     return std::string("Package id doesn't match for metadata plugin");
33   if (strcmp(appid, ci::kTestApplicationId) != 0)
34     return std::string("Application id doesn't match for metadata plugin");
35   auto range = GListRange<__metadata_t*>(metadata);
36   if (range.Size() != 3)
37     return std::string("Metadata Glist is wrong size for metadata plugin");
38   bool found_a = false;
39   bool found_b = false;
40   bool found_c = false;
41   for (__metadata_t* meta : range) {
42     if (strcmp(meta->key,
43        "http://developer.samsung.com/tizen/metadata/test_metadata/key_a")
44        == 0 && strcmp(meta->value, "value_a") == 0) {
45       found_a = true;
46     }
47     if (strcmp(meta->key,
48        "http://developer.samsung.com/tizen/metadata/test_metadata/key_b")
49        == 0 && strcmp(meta->value, "value_b") == 0) {
50       found_b = true;
51     }
52     if (strcmp(meta->key,
53        "http://developer.samsung.com/tizen/metadata/test_metadata/key_c")
54        == 0 && strcmp(meta->value, "value_c") == 0) {
55       found_c = true;
56     }
57   }
58   if (!found_a)
59     return std::string("Metadata key_a incorrect or not found");
60   if (!found_b)
61     return std::string("Metadata key_b incorrect or not found");
62   if (!found_c)
63     return std::string("Metadata key_c incorrect or not found");
64   return {};
65 }
66
67 }  // namespace
68
69 extern "C" int PKGMGR_MDPARSER_PLUGIN_INSTALL(
70     const char* pkgid,
71     const char* appid,
72     GList* metadata) {
73   ci::TestAssessor::Instance().AddResult(std::make_tuple(
74       ci::kMetadataPluginName,
75       ci::Plugin::ActionType::Install,
76       ci::Plugin::ProcessType::Main),
77       CheckArgs(pkgid, appid, metadata));
78   return 0;
79 }
80
81 extern "C" int PKGMGR_MDPARSER_PLUGIN_UPGRADE(
82     const char* pkgid,
83     const char* appid,
84     GList* metadata) {
85   ci::TestAssessor::Instance().AddResult(std::make_tuple(
86       ci::kMetadataPluginName,
87       ci::Plugin::ActionType::Upgrade,
88       ci::Plugin::ProcessType::Main),
89       CheckArgs(pkgid, appid, metadata));
90   return 0;
91 }
92
93 extern "C" int PKGMGR_MDPARSER_PLUGIN_UNINSTALL(
94     const char* pkgid,
95     const char* appid,
96     GList* metadata) {
97   ci::TestAssessor::Instance().AddResult(std::make_tuple(
98       ci::kMetadataPluginName,
99       ci::Plugin::ActionType::Uninstall,
100       ci::Plugin::ProcessType::Main),
101       CheckArgs(pkgid, appid, metadata));
102   return 0;
103 }