Add new smoke tests
[platform/core/appfw/wgt-backend.git] / src / unit_tests / manifest_test.cc
1 // Copyright (c) 2015 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/filesystem/path.hpp>
6
7 #include <common/installer_context.h>
8 #include <common/request.h>
9 #include <common/utils/glist_range.h>
10
11 #include <wgt_manifest_handlers/setting_handler.h>
12
13 #include <glib.h>
14 #include <gtest/gtest.h>
15
16 #include <map>
17 #include <memory>
18 #include <string>
19 #include <vector>
20
21 #include "wgt/step/configuration/step_parse.h"
22 #include "wgt/wgt_backend_data.h"
23
24 #define ASSERT_CSTR_EQ(STR1, STR2)                                             \
25   ASSERT_EQ(strcmp(STR1, STR2), 0)                                             \
26
27 namespace bf = boost::filesystem;
28 namespace ci = common_installer;
29
30 namespace {
31
32 const char kManifestTestcaseData[] =
33     "/usr/share/wgt-backend-ut/test_samples/manifest/";
34
35 template<typename T>
36 gint Size(GListRange<T>* range) {
37   return std::distance(range->begin(), range->end());
38 }
39
40 class StepParseRunner {
41  public:
42   explicit StepParseRunner(const std::string& dir_suffix,
43                            bool ignore_start_files = true)
44       : dir_suffix_(dir_suffix),
45         ignore_start_files_(ignore_start_files),
46         context_(nullptr) {
47   }
48
49   bool Run() {
50     PrepareContext();
51     wgt::configuration::StepParse step(context_.get(),
52         wgt::configuration::StepParse::ConfigLocation::PACKAGE,
53         !ignore_start_files_);
54     return step.process() == ci::Step::Status::OK;
55   }
56
57   wgt::WgtBackendData* GetBackendData() const {
58     return static_cast<wgt::WgtBackendData*>(context_->backend_data.get());
59   }
60
61   manifest_x* GetManifest() const {
62     return context_->manifest_data.get();
63   }
64
65  private:
66   void PrepareContext() {
67     context_.reset(new ci::InstallerContext());
68     context_->root_application_path.set(ci::GetRootAppPath(false, getuid()));
69     context_->unpacked_dir_path.set(
70         bf::path(kManifestTestcaseData) / dir_suffix_);
71     context_->backend_data.set(new wgt::WgtBackendData());
72   }
73
74   std::string dir_suffix_;
75   bool ignore_start_files_;
76   std::unique_ptr<ci::InstallerContext> context_;
77 };
78
79 }  // namespace
80
81 class ManifestTest : public testing::Test {
82  public:
83   std::string GetMyName() const {
84     std::string suite =
85         testing::UnitTest::GetInstance()->current_test_info()->test_case_name();
86     std::string case_name =
87         testing::UnitTest::GetInstance()->current_test_info()->name();
88     return suite + '.' + case_name;
89   }
90 };
91
92 TEST_F(ManifestTest, WidgetElement_Valid) {
93   StepParseRunner runner(GetMyName());
94   ASSERT_TRUE(runner.Run());
95   manifest_x* m = runner.GetManifest();
96   ASSERT_NE(m, nullptr);
97   ASSERT_CSTR_EQ(m->package, "package0id");
98   auto apps = GListRange<application_x*>(m->application);
99   ASSERT_EQ(Size(&apps), 1);
100   application_x* app = *apps.begin();
101   ASSERT_CSTR_EQ(app->appid, "package0id.appid");
102 }
103
104 TEST_F(ManifestTest, WidgetElement_InvalidNamespace) {
105   StepParseRunner runner(GetMyName());
106   ASSERT_FALSE(runner.Run());
107 }
108
109 TEST_F(ManifestTest, WidgetElement_MissingNamespace) {
110   StepParseRunner runner(GetMyName());
111   ASSERT_FALSE(runner.Run());
112 }
113
114 TEST_F(ManifestTest, WidgetElement_ManyNamespaces) {
115   StepParseRunner runner(GetMyName());
116   ASSERT_FALSE(runner.Run());
117 }
118
119 TEST_F(ManifestTest, ApplicationElement_ManyElements) {
120   StepParseRunner runner(GetMyName());
121   ASSERT_FALSE(runner.Run());
122 }
123
124 TEST_F(ManifestTest, ApplicationElement_ValidAppId) {
125   StepParseRunner runner(GetMyName());
126   ASSERT_TRUE(runner.Run());
127   manifest_x* m = runner.GetManifest();
128   ASSERT_NE(m, nullptr);
129   auto apps = GListRange<application_x*>(m->application);
130   application_x* app = *apps.begin();
131   ASSERT_NE(app, nullptr);
132   ASSERT_CSTR_EQ(app->appid, "package0id.appid");
133 }
134
135 TEST_F(ManifestTest, ApplicationElement_MissingAppId) {
136   StepParseRunner runner(GetMyName());
137   ASSERT_FALSE(runner.Run());
138 }
139
140 TEST_F(ManifestTest, ApplicationElement_InvalidAppId) {
141   StepParseRunner runner(GetMyName());
142   ASSERT_FALSE(runner.Run());
143 }
144
145 TEST_F(ManifestTest, ApplicationElement_ValidPackage) {
146   StepParseRunner runner(GetMyName());
147   ASSERT_TRUE(runner.Run());
148   manifest_x* m = runner.GetManifest();
149   ASSERT_NE(m, nullptr);
150   ASSERT_CSTR_EQ(m->package, "package0id");
151 }
152
153 TEST_F(ManifestTest, ApplicationElement_InvalidPackage) {
154   StepParseRunner runner(GetMyName());
155   ASSERT_FALSE(runner.Run());
156 }
157
158 TEST_F(ManifestTest, ApplicationElement_MissingPackage) {
159   StepParseRunner runner(GetMyName());
160   ASSERT_FALSE(runner.Run());
161 }
162
163 TEST_F(ManifestTest, ApplicationElement_ValidVersion) {
164   StepParseRunner runner(GetMyName());
165   ASSERT_TRUE(runner.Run());
166   manifest_x* m = runner.GetManifest();
167   ASSERT_NE(m, nullptr);
168   ASSERT_CSTR_EQ(m->api_version, "3.0");
169 }
170
171 TEST_F(ManifestTest, ApplicationElement_InvalidVersion) {
172   StepParseRunner runner(GetMyName());
173   ASSERT_FALSE(runner.Run());
174 }
175
176 TEST_F(ManifestTest, ApplicationElement_MissingVersion) {
177   StepParseRunner runner(GetMyName());
178   ASSERT_FALSE(runner.Run());
179 }
180
181 TEST_F(ManifestTest, PrivilegeElement_ValidName) {
182   StepParseRunner runner(GetMyName());
183   ASSERT_TRUE(runner.Run());
184   manifest_x* m = runner.GetManifest();
185   ASSERT_NE(m, nullptr);
186   std::vector<std::string> priv_vec;
187   for (privilege_x* priv : GListRange<privilege_x*>(m->privileges)) {
188     priv_vec.push_back(priv->value);
189   }
190   ASSERT_FALSE(priv_vec.empty());
191   const char* expected_name = "http://tizen.org/privilege/application.launch";
192   ASSERT_CSTR_EQ(priv_vec[0].c_str(), expected_name);
193 }
194
195 TEST_F(ManifestTest, PrivilegeElement_ManyElements) {
196   StepParseRunner runner(GetMyName());
197   ASSERT_TRUE(runner.Run());
198   manifest_x* m = runner.GetManifest();
199   ASSERT_NE(m, nullptr);
200   std::vector<std::string> priv_vec;
201   for (privilege_x* priv : GListRange<privilege_x*>(m->privileges)) {
202     priv_vec.push_back(priv->value);
203   }
204   ASSERT_EQ(priv_vec.size(), 2);
205   const char* first_priv = "http://tizen.org/privilege/application.close";
206   ASSERT_CSTR_EQ(priv_vec[0].c_str(), first_priv);
207   const char* second_priv = "http://tizen.org/privilege/application.launch";
208   ASSERT_CSTR_EQ(priv_vec[1].c_str(), second_priv);
209 }
210
211 TEST_F(ManifestTest, PrivilegeElement_InvalidName) {
212   StepParseRunner runner(GetMyName());
213   ASSERT_FALSE(runner.Run());
214 }
215
216 TEST_F(ManifestTest, PrivilegeElement_MissingName) {
217   StepParseRunner runner(GetMyName());
218   ASSERT_FALSE(runner.Run());
219 }
220
221 TEST_F(ManifestTest, AppDefinedPrivilegeElement_Invalid_NotURI) {
222   StepParseRunner runner(GetMyName());
223   ASSERT_FALSE(runner.Run());
224 }
225
226 TEST_F(ManifestTest, AppDefinedPrivilegeElement_Invalid_NoPKGID) {
227   StepParseRunner runner(GetMyName());
228   ASSERT_FALSE(runner.Run());
229 }
230
231 TEST_F(ManifestTest, AppDefinedPrivilegeElement_Invalid_OverLength) {
232   StepParseRunner runner(GetMyName());
233   ASSERT_FALSE(runner.Run());
234 }
235
236 TEST_F(ManifestTest, AppDefinedPrivilegeElement_ValidName) {
237   StepParseRunner runner(GetMyName());
238   ASSERT_TRUE(runner.Run());
239   manifest_x* m = runner.GetManifest();
240   ASSERT_NE(m, nullptr);
241   std::vector<std::string> priv_vec;
242   for (appdefined_privilege_x* priv :
243       GListRange<appdefined_privilege_x*>(m->appdefined_privileges)) {
244     priv_vec.push_back(priv->value);
245   }
246   ASSERT_FALSE(priv_vec.empty());
247   const char* expected_name = "http://package0id/appdefined/test.read";
248   ASSERT_CSTR_EQ(priv_vec[0].c_str(), expected_name);
249 }
250
251 TEST_F(ManifestTest, AppDefinedPrivilegeElement_ManyElements) {
252   StepParseRunner runner(GetMyName());
253   ASSERT_TRUE(runner.Run());
254   manifest_x* m = runner.GetManifest();
255   ASSERT_NE(m, nullptr);
256   std::vector<std::string> priv_vec;
257   for (appdefined_privilege_x* priv :
258       GListRange<appdefined_privilege_x*>(m->appdefined_privileges)) {
259     priv_vec.push_back(priv->value);
260   }
261   ASSERT_EQ(priv_vec.size(), 2);
262   const char* first_priv = "http://package0id/appdefined/test.read";
263   ASSERT_CSTR_EQ(priv_vec[0].c_str(), first_priv);
264   const char* second_priv = "http://package0id/appdefined/test.write";
265   ASSERT_CSTR_EQ(priv_vec[1].c_str(), second_priv);
266 }
267
268 TEST_F(ManifestTest, AppDefinedPrivilegeElement_WithLicenseValidName) {
269   StepParseRunner runner(GetMyName());
270   ASSERT_TRUE(runner.Run());
271   manifest_x* m = runner.GetManifest();
272   ASSERT_NE(m, nullptr);
273   std::vector<std::string> priv_vec;
274   std::vector<std::string> license_vec;
275   for (appdefined_privilege_x* priv :
276       GListRange<appdefined_privilege_x*>(m->appdefined_privileges)) {
277     priv_vec.push_back(priv->value);
278     license_vec.push_back(priv->license);
279   }
280   ASSERT_FALSE(priv_vec.empty());
281   const char* expected_name = "http://package0id/appdefined/test.read";
282   ASSERT_CSTR_EQ(priv_vec[0].c_str(), expected_name);
283   ASSERT_FALSE(license_vec.empty());
284   bf::path path(m->root_path);
285   path /= "res/cert";
286   ASSERT_CSTR_EQ(license_vec[0].c_str(), path.c_str());
287 }
288
289 TEST_F(ManifestTest, AppDefinedPrivilegeElement_WithLicenseManyElements) {
290   StepParseRunner runner(GetMyName());
291   ASSERT_TRUE(runner.Run());
292   manifest_x* m = runner.GetManifest();
293   ASSERT_NE(m, nullptr);
294   std::vector<std::string> priv_vec;
295   std::vector<std::string> license_vec;
296   for (appdefined_privilege_x* priv :
297       GListRange<appdefined_privilege_x*>(m->appdefined_privileges)) {
298     priv_vec.push_back(priv->value);
299     license_vec.push_back(priv->license);
300   }
301   ASSERT_EQ(priv_vec.size(), 2);
302   const char* first_priv = "http://package0id/appdefined/test.read";
303   ASSERT_CSTR_EQ(priv_vec[0].c_str(), first_priv);
304   const char* second_priv = "http://package0id/appdefined/test.write";
305   ASSERT_CSTR_EQ(priv_vec[1].c_str(), second_priv);
306   ASSERT_EQ(license_vec.size(), 2);
307   bf::path path(m->root_path);
308   path /= "res/cert";
309   ASSERT_CSTR_EQ(license_vec[0].c_str(), path.c_str());
310   ASSERT_CSTR_EQ(license_vec[1].c_str(), path.c_str());
311 }
312
313 TEST_F(ManifestTest, AppDefinedPrivilegeElement_InvalidName) {
314   StepParseRunner runner(GetMyName());
315   ASSERT_FALSE(runner.Run());
316 }
317
318 TEST_F(ManifestTest, AppDefinedPrivilegeElement_MissingName) {
319   StepParseRunner runner(GetMyName());
320   ASSERT_FALSE(runner.Run());
321 }
322
323 TEST_F(ManifestTest, ProvidesAppDefinedPrivilegeElement_Invalid_NotURI) {
324   StepParseRunner runner(GetMyName());
325   ASSERT_FALSE(runner.Run());
326 }
327
328 TEST_F(ManifestTest, ProvidesAppDefinedPrivilegeElement_Invalid_NoPKGID) {
329   StepParseRunner runner(GetMyName());
330   ASSERT_FALSE(runner.Run());
331 }
332
333 TEST_F(ManifestTest, ProvidesAppDefinedPrivilegeElement_Invalid_OverLength) {
334   StepParseRunner runner(GetMyName());
335   ASSERT_FALSE(runner.Run());
336 }
337
338 TEST_F(ManifestTest, ProvidesAppDefinedPrivilegeElement_ValidName) {
339   StepParseRunner runner(GetMyName());
340   ASSERT_TRUE(runner.Run());
341   manifest_x* m = runner.GetManifest();
342   ASSERT_NE(m, nullptr);
343   std::vector<std::string> priv_vec;
344   for (appdefined_privilege_x* priv : GListRange<appdefined_privilege_x*>(
345       m->provides_appdefined_privileges)) {
346     priv_vec.push_back(priv->value);
347   }
348   ASSERT_FALSE(priv_vec.empty());
349   const char* expected_name = "http://package0id/appdefined/test.read";
350   ASSERT_CSTR_EQ(priv_vec[0].c_str(), expected_name);
351 }
352
353 TEST_F(ManifestTest, ProvidesAppDefinedPrivilegeElement_ManyElements) {
354   StepParseRunner runner(GetMyName());
355   ASSERT_TRUE(runner.Run());
356   manifest_x* m = runner.GetManifest();
357   ASSERT_NE(m, nullptr);
358   std::vector<std::string> priv_vec;
359   for (appdefined_privilege_x* priv : GListRange<appdefined_privilege_x*>(
360       m->provides_appdefined_privileges)) {
361     priv_vec.push_back(priv->value);
362   }
363   ASSERT_EQ(priv_vec.size(), 2);
364   const char* first_priv = "http://package0id/appdefined/test.read";
365   ASSERT_CSTR_EQ(priv_vec[0].c_str(), first_priv);
366   const char* second_priv = "http://package0id/appdefined/test.write";
367   ASSERT_CSTR_EQ(priv_vec[1].c_str(), second_priv);
368 }
369
370 TEST_F(ManifestTest, ProvidesAppDefinedPrivilegeElement_WithLicenseValidName) {
371   StepParseRunner runner(GetMyName());
372   ASSERT_TRUE(runner.Run());
373   manifest_x* m = runner.GetManifest();
374   ASSERT_NE(m, nullptr);
375   std::vector<std::string> priv_vec;
376   std::vector<std::string> license_vec;
377   for (appdefined_privilege_x* priv : GListRange<appdefined_privilege_x*>(
378       m->provides_appdefined_privileges)) {
379     priv_vec.push_back(priv->value);
380     license_vec.push_back(priv->license);
381   }
382   ASSERT_FALSE(priv_vec.empty());
383   const char* expected_name = "http://package0id/appdefined/test.read";
384   ASSERT_CSTR_EQ(priv_vec[0].c_str(), expected_name);
385   ASSERT_FALSE(license_vec.empty());
386   bf::path path(m->root_path);
387   path /= "res/cert";
388   ASSERT_CSTR_EQ(license_vec[0].c_str(), path.c_str());
389 }
390
391 TEST_F(ManifestTest,
392        ProvidesAppDefinedPrivilegeElement_WithLicenseManyElements) {
393   StepParseRunner runner(GetMyName());
394   ASSERT_TRUE(runner.Run());
395   manifest_x* m = runner.GetManifest();
396   ASSERT_NE(m, nullptr);
397   std::vector<std::string> priv_vec;
398   std::vector<std::string> license_vec;
399   for (appdefined_privilege_x* priv : GListRange<appdefined_privilege_x*>(
400       m->provides_appdefined_privileges)) {
401     priv_vec.push_back(priv->value);
402     license_vec.push_back(priv->license);
403   }
404   ASSERT_EQ(priv_vec.size(), 2);
405   const char* first_priv = "http://package0id/appdefined/test.read";
406   ASSERT_CSTR_EQ(priv_vec[0].c_str(), first_priv);
407   const char* second_priv = "http://package0id/appdefined/test.write";
408   ASSERT_CSTR_EQ(priv_vec[1].c_str(), second_priv);
409   ASSERT_EQ(license_vec.size(), 2);
410   bf::path path(m->root_path);
411   path /= "res/cert";
412   ASSERT_CSTR_EQ(license_vec[0].c_str(), path.c_str());
413   ASSERT_CSTR_EQ(license_vec[1].c_str(), path.c_str());
414 }
415
416 TEST_F(ManifestTest, ProvidesAppDefinedPrivilegeElement_InvalidName) {
417   StepParseRunner runner(GetMyName());
418   ASSERT_FALSE(runner.Run());
419 }
420
421 TEST_F(ManifestTest, ProvidesAppDefinedPrivilegeElement_MissingName) {
422   StepParseRunner runner(GetMyName());
423   ASSERT_FALSE(runner.Run());
424 }
425
426 TEST_F(ManifestTest, AppControlElement_Valid) {
427   StepParseRunner runner(GetMyName());
428   ASSERT_TRUE(runner.Run());
429   manifest_x* m = runner.GetManifest();
430   ASSERT_NE(m, nullptr);
431   auto apps = GListRange<application_x*>(m->application);
432   application_x* app = *apps.begin();
433   ASSERT_NE(app, nullptr);
434   std::vector<appcontrol_x*> app_controls;
435   for (appcontrol_x* app_control : GListRange<appcontrol_x*>(app->appcontrol)) {
436     app_controls.push_back(app_control);
437   }
438   ASSERT_EQ(app_controls.size(), 1);
439   ASSERT_CSTR_EQ(app_controls[0]->mime, "image/jpg");
440   ASSERT_CSTR_EQ(app_controls[0]->operation,
441                  "http://tizen.org/appcontrol/operation/edit");
442   ASSERT_CSTR_EQ(app_controls[0]->uri, "myapp");
443 }
444
445 TEST_F(ManifestTest, AppControlElement_MissingMIME) {
446   StepParseRunner runner(GetMyName());
447   ASSERT_TRUE(runner.Run());
448   manifest_x* m = runner.GetManifest();
449   ASSERT_NE(m, nullptr);
450   auto apps = GListRange<application_x*>(m->application);
451   application_x* app = *apps.begin();
452   ASSERT_NE(app, nullptr);
453   std::vector<appcontrol_x*> app_controls;
454   for (appcontrol_x* app_control : GListRange<appcontrol_x*>(app->appcontrol)) {
455     app_controls.push_back(app_control);
456   }
457   ASSERT_CSTR_EQ(app_controls[0]->mime, "");
458 }
459
460 TEST_F(ManifestTest, AppControlElement_MissingOperation) {
461   StepParseRunner runner(GetMyName());
462   ASSERT_FALSE(runner.Run());
463 }
464
465 TEST_F(ManifestTest, AppControlElement_MissingSrc) {
466   StepParseRunner runner(GetMyName());
467   ASSERT_FALSE(runner.Run());
468 }
469
470 TEST_F(ManifestTest, AppControlElement_MissingURI) {
471   StepParseRunner runner(GetMyName());
472   ASSERT_TRUE(runner.Run());
473   manifest_x* m = runner.GetManifest();
474   ASSERT_NE(m, nullptr);
475   auto apps = GListRange<application_x*>(m->application);
476   application_x* app = *apps.begin();
477   ASSERT_NE(app, nullptr);
478   std::vector<appcontrol_x*> app_controls;
479   for (appcontrol_x* app_control : GListRange<appcontrol_x*>(app->appcontrol)) {
480     app_controls.push_back(app_control);
481   }
482   ASSERT_CSTR_EQ(app_controls[0]->uri, "");
483 }
484
485 TEST_F(ManifestTest, SettingsElement_Valid) {
486   StepParseRunner runner(GetMyName());
487   ASSERT_TRUE(runner.Run());
488   manifest_x* m = runner.GetManifest();
489   ASSERT_NE(m, nullptr);
490   auto backend_data = runner.GetBackendData();
491   auto settings = backend_data->settings.get();
492
493   ASSERT_EQ(settings.background_support_enabled(), true);
494   ASSERT_EQ(settings.context_menu_enabled(), false);
495   ASSERT_EQ(settings.encryption_enabled(), true);
496   ASSERT_EQ(settings.screen_orientation(),
497             wgt::parse::SettingInfo::ScreenOrientation::LANDSCAPE);
498   ASSERT_EQ(settings.install_location(),
499             wgt::parse::SettingInfo::InstallLocation::INTERNAL);
500   ASSERT_EQ(settings.hwkey_enabled(), true);
501   ASSERT_EQ(settings.background_vibration(), true);
502 }
503
504 TEST_F(ManifestTest, SettingsElement_BackgroundSupportEnabled) {
505   StepParseRunner runner(GetMyName());
506   ASSERT_TRUE(runner.Run());
507   manifest_x* m = runner.GetManifest();
508   ASSERT_NE(m, nullptr);
509   auto backend_data = runner.GetBackendData();
510   auto settings = backend_data->settings.get();
511   ASSERT_EQ(settings.background_support_enabled(), true);
512 }
513
514 TEST_F(ManifestTest, SettingsElement_BackgroundSupportDisabled) {
515   StepParseRunner runner(GetMyName());
516   ASSERT_TRUE(runner.Run());
517   manifest_x* m = runner.GetManifest();
518   ASSERT_NE(m, nullptr);
519   auto backend_data = runner.GetBackendData();
520   auto settings = backend_data->settings.get();
521   ASSERT_EQ(settings.background_support_enabled(), false);
522 }
523
524 TEST_F(ManifestTest, SettingsElement_MissingBackgroundSupport) {
525   StepParseRunner runner(GetMyName());
526   ASSERT_TRUE(runner.Run());
527   manifest_x* m = runner.GetManifest();
528   ASSERT_NE(m, nullptr);
529   auto backend_data = runner.GetBackendData();
530   auto settings = backend_data->settings.get();
531   ASSERT_EQ(settings.background_support_enabled(), false);
532 }
533
534 TEST_F(ManifestTest, SettingsElement_BackgroundVibrationEnabled) {
535   StepParseRunner runner(GetMyName());
536   ASSERT_TRUE(runner.Run());
537   manifest_x* m = runner.GetManifest();
538   ASSERT_NE(m, nullptr);
539   auto backend_data = runner.GetBackendData();
540   auto settings = backend_data->settings.get();
541   ASSERT_EQ(settings.background_vibration(), true);
542 }
543
544 TEST_F(ManifestTest, SettingsElement_BackgroundVibrationDisabled) {
545   StepParseRunner runner(GetMyName());
546   ASSERT_TRUE(runner.Run());
547   manifest_x* m = runner.GetManifest();
548   ASSERT_NE(m, nullptr);
549   auto backend_data = runner.GetBackendData();
550   auto settings = backend_data->settings.get();
551   ASSERT_EQ(settings.background_vibration(), false);
552 }
553
554 TEST_F(ManifestTest, SettingsElement_MissingBackgroundVibration) {
555   StepParseRunner runner(GetMyName());
556   ASSERT_TRUE(runner.Run());
557   manifest_x* m = runner.GetManifest();
558   ASSERT_NE(m, nullptr);
559   auto backend_data = runner.GetBackendData();
560   auto settings = backend_data->settings.get();
561   ASSERT_EQ(settings.background_vibration(), false);
562 }
563
564 TEST_F(ManifestTest, SettingsElement_ContextMenuEnabled) {
565   StepParseRunner runner(GetMyName());
566   ASSERT_TRUE(runner.Run());
567   manifest_x* m = runner.GetManifest();
568   ASSERT_NE(m, nullptr);
569   auto backend_data = runner.GetBackendData();
570   auto settings = backend_data->settings.get();
571   ASSERT_EQ(settings.context_menu_enabled(), true);
572 }
573
574 TEST_F(ManifestTest, SettingsElement_ContextMenuDisabled) {
575   StepParseRunner runner(GetMyName());
576   ASSERT_TRUE(runner.Run());
577   manifest_x* m = runner.GetManifest();
578   ASSERT_NE(m, nullptr);
579   auto backend_data = runner.GetBackendData();
580   auto settings = backend_data->settings.get();
581   ASSERT_EQ(settings.context_menu_enabled(), false);
582 }
583
584 TEST_F(ManifestTest, SettingsElement_MissingContextMenu) {
585   StepParseRunner runner(GetMyName());
586   ASSERT_TRUE(runner.Run());
587   manifest_x* m = runner.GetManifest();
588   ASSERT_NE(m, nullptr);
589   auto backend_data = runner.GetBackendData();
590   auto settings = backend_data->settings.get();
591   ASSERT_EQ(settings.context_menu_enabled(), true);
592 }
593
594 TEST_F(ManifestTest, SettingsElement_EncryptionEnabled) {
595   StepParseRunner runner(GetMyName());
596   ASSERT_TRUE(runner.Run());
597   manifest_x* m = runner.GetManifest();
598   ASSERT_NE(m, nullptr);
599   auto backend_data = runner.GetBackendData();
600   auto settings = backend_data->settings.get();
601   ASSERT_EQ(settings.encryption_enabled(), true);
602 }
603
604 TEST_F(ManifestTest, SettingsElement_EncryptionDisabled) {
605   StepParseRunner runner(GetMyName());
606   ASSERT_TRUE(runner.Run());
607   manifest_x* m = runner.GetManifest();
608   ASSERT_NE(m, nullptr);
609   auto backend_data = runner.GetBackendData();
610   auto settings = backend_data->settings.get();
611   ASSERT_EQ(settings.encryption_enabled(), false);
612 }
613
614 TEST_F(ManifestTest, SettingsElement_MissingEncryption) {
615   StepParseRunner runner(GetMyName());
616   ASSERT_TRUE(runner.Run());
617   manifest_x* m = runner.GetManifest();
618   ASSERT_NE(m, nullptr);
619   auto backend_data = runner.GetBackendData();
620   auto settings = backend_data->settings.get();
621   ASSERT_EQ(settings.encryption_enabled(), false);
622 }
623
624 TEST_F(ManifestTest, SettingsElement_HwKeyEnabled) {
625   StepParseRunner runner(GetMyName());
626   ASSERT_TRUE(runner.Run());
627   manifest_x* m = runner.GetManifest();
628   ASSERT_NE(m, nullptr);
629   auto backend_data = runner.GetBackendData();
630   auto settings = backend_data->settings.get();
631   ASSERT_EQ(settings.hwkey_enabled(), true);
632 }
633
634 TEST_F(ManifestTest, SettingsElement_HwKeyDisabled) {
635   StepParseRunner runner(GetMyName());
636   ASSERT_TRUE(runner.Run());
637   manifest_x* m = runner.GetManifest();
638   ASSERT_NE(m, nullptr);
639   auto backend_data = runner.GetBackendData();
640   auto settings = backend_data->settings.get();
641   ASSERT_EQ(settings.hwkey_enabled(), false);
642 }
643
644 TEST_F(ManifestTest, SettingsElement_MissingHwKeyEvent) {
645   StepParseRunner runner(GetMyName());
646   ASSERT_TRUE(runner.Run());
647   manifest_x* m = runner.GetManifest();
648   ASSERT_NE(m, nullptr);
649   auto backend_data = runner.GetBackendData();
650   auto settings = backend_data->settings.get();
651   ASSERT_EQ(settings.hwkey_enabled(), true);
652 }
653
654 TEST_F(ManifestTest, SettingsElement_MissingInstallLocation) {
655   StepParseRunner runner(GetMyName());
656   ASSERT_TRUE(runner.Run());
657   manifest_x* m = runner.GetManifest();
658   ASSERT_NE(m, nullptr);
659   auto backend_data = runner.GetBackendData();
660   auto settings = backend_data->settings.get();
661   ASSERT_EQ(settings.install_location(),
662             wgt::parse::SettingInfo::InstallLocation::AUTO);
663 }
664
665 TEST_F(ManifestTest, SettingsElement_MissingScreenOrientation) {
666   StepParseRunner runner(GetMyName());
667   ASSERT_TRUE(runner.Run());
668   manifest_x* m = runner.GetManifest();
669   ASSERT_NE(m, nullptr);
670   auto backend_data = runner.GetBackendData();
671   auto settings = backend_data->settings.get();
672   ASSERT_EQ(settings.screen_orientation(),
673             wgt::parse::SettingInfo::ScreenOrientation::AUTO);
674 }
675
676 TEST_F(ManifestTest, MetadataElement_Valid) {
677   StepParseRunner runner(GetMyName());
678   ASSERT_TRUE(runner.Run());
679   manifest_x* m = runner.GetManifest();
680   ASSERT_NE(m, nullptr);
681   auto apps = GListRange<application_x*>(m->application);
682   application_x* app = *apps.begin();
683
684   std::map<std::string, std::string> meta_data_map;
685   for (metadata_x* meta_data : GListRange<metadata_x*>(app->metadata)) {
686     if (meta_data->value)
687       meta_data_map[meta_data->key] = meta_data->value;
688     else
689       meta_data_map[meta_data->key] = std::string();
690   }
691   ASSERT_EQ(meta_data_map.size(), 2);
692   ASSERT_CSTR_EQ(meta_data_map["key1"].c_str(), "");
693   ASSERT_CSTR_EQ(meta_data_map["key2"].c_str(), "value2");
694 }
695
696 TEST_F(ManifestTest, MetadataElement_DuplicateKey) {
697   StepParseRunner runner(GetMyName());
698   ASSERT_TRUE(runner.Run());
699   manifest_x* m = runner.GetManifest();
700   ASSERT_NE(m, nullptr);
701   auto apps = GListRange<application_x*>(m->application);
702   application_x* app = *apps.begin();
703
704   std::map<std::string, std::string> meta_data_map;
705   for (metadata_x* meta_data : GListRange<metadata_x*>(app->metadata)) {
706     meta_data_map[meta_data->key] = meta_data->value;
707   }
708   ASSERT_EQ(meta_data_map.size(), 2);
709   ASSERT_CSTR_EQ(meta_data_map["key1"].c_str(), "key1value");
710   ASSERT_CSTR_EQ(meta_data_map["key2"].c_str(), "key2value");
711 }
712
713 TEST_F(ManifestTest, MetadataElement_MissingValue) {
714   StepParseRunner runner(GetMyName());
715   ASSERT_TRUE(runner.Run());
716   manifest_x* m = runner.GetManifest();
717   ASSERT_NE(m, nullptr);
718   auto apps = GListRange<application_x*>(m->application);
719   application_x* app = *apps.begin();
720
721   std::map<std::string, std::string> meta_data_map;
722   for (metadata_x* meta_data : GListRange<metadata_x*>(app->metadata)) {
723     if (meta_data->value)
724       meta_data_map[meta_data->key] = meta_data->value;
725     else
726       meta_data_map[meta_data->key] = std::string();
727   }
728   ASSERT_EQ(meta_data_map.size(), 2);
729   ASSERT_CSTR_EQ(meta_data_map["key1"].c_str(), "");
730   ASSERT_CSTR_EQ(meta_data_map["key2"].c_str(), "");
731 }
732
733 TEST_F(ManifestTest, MetadataElement_MissingKey) {
734   StepParseRunner runner(GetMyName());
735   ASSERT_FALSE(runner.Run());
736 }
737
738 TEST_F(ManifestTest, CategoryElement_Valid) {
739   StepParseRunner runner(GetMyName());
740   ASSERT_TRUE(runner.Run());
741   manifest_x* m = runner.GetManifest();
742   ASSERT_NE(m, nullptr);
743   auto apps = GListRange<application_x*>(m->application);
744   application_x* app = *apps.begin();
745
746   std::vector<std::string> categories;
747   for (const char* category : GListRange<char*>(app->category)) {
748     categories.push_back(category);
749   }
750   ASSERT_EQ(categories.size(), 1);
751   ASSERT_CSTR_EQ(categories[0].c_str(),
752                  "http://tizen.org/category/wearable_clock");
753 }
754
755 TEST_F(ManifestTest, CategoryElement_MissingName) {
756   StepParseRunner runner(GetMyName());
757   ASSERT_FALSE(runner.Run());
758 }
759
760 TEST_F(ManifestTest, CategoryElement_MultipleElements) {
761   StepParseRunner runner(GetMyName());
762   ASSERT_TRUE(runner.Run());
763   manifest_x* m = runner.GetManifest();
764   ASSERT_NE(m, nullptr);
765   auto apps = GListRange<application_x*>(m->application);
766   application_x* app = *apps.begin();
767
768   std::vector<std::string> categories;
769   for (const char* category : GListRange<char*>(app->category)) {
770     categories.push_back(category);
771   }
772   ASSERT_EQ(categories.size(), 3);
773   ASSERT_CSTR_EQ(categories[0].c_str(),
774                  "http://tizen.org/category/category_0");
775   ASSERT_CSTR_EQ(categories[1].c_str(),
776                  "http://tizen.org/category/category_1");
777   ASSERT_CSTR_EQ(categories[2].c_str(),
778                  "http://tizen.org/category/category_2");
779 }