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