Remove boost dependency
[platform/core/appfw/app-installers.git] / test / smoke_tests / libs / test_category_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* categories) {
26   if (!pkgid)
27     return std::string("Package id is null for category plugin");
28   if (!appid)
29     return std::string("Application id is null for category plugin");
30   if (strcmp(pkgid, ci::kTestPackageId) != 0)
31     return std::string("Package id doesn't match for category plugin");
32   if (strcmp(appid, ci::kTestApplicationId) != 0)
33     return std::string("Application id doesn't match for category plugin");
34   auto range = GListRange<__category_t*>(categories);
35   if (range.Size() != 3)
36     return std::string("Metadata Glist is wrong size for category plugin");
37   bool found = false;
38   for (__category_t* category : range) {
39     if (strcmp(category->name, "http://tizen.org/category/test_category") == 0)
40       found = true;
41   }
42   if (!found)
43     return std::string("Category value not found");
44   return {};
45 }
46
47 }  // namespace
48
49 extern "C" int PKGMGR_CATEGORY_PARSER_PLUGIN_INSTALL(
50     const char* pkgid,
51     const char* appid,
52     GList* categories) {
53   ci::TestAssessor::Instance().AddResult(std::make_tuple(
54       ci::kCategoryPluginName,
55       ci::Plugin::ActionType::Install,
56       ci::Plugin::ProcessType::Main),
57       CheckArgs(pkgid, appid, categories));
58   return 0;
59 }
60
61 extern "C" int PKGMGR_CATEGORY_PARSER_PLUGIN_UPGRADE(
62     const char* pkgid,
63     const char* appid,
64     GList* categories) {
65   ci::TestAssessor::Instance().AddResult(std::make_tuple(
66       ci::kCategoryPluginName,
67       ci::Plugin::ActionType::Upgrade,
68       ci::Plugin::ProcessType::Main),
69       CheckArgs(pkgid, appid, categories));
70   return 0;
71 }
72
73 extern "C" int PKGMGR_CATEGORY_PARSER_PLUGIN_UNINSTALL(
74     const char* pkgid,
75     const char* appid,
76     GList* categories) {
77   ci::TestAssessor::Instance().AddResult(std::make_tuple(
78       ci::kCategoryPluginName,
79       ci::Plugin::ActionType::Uninstall,
80       ci::Plugin::ProcessType::Main),
81       CheckArgs(pkgid, appid, categories));
82   return 0;
83 }