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