Initialize Tizen 2.3
[framework/web/wrt-installer.git] / tests / general / ManifestTests.cpp
1 /*
2  * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *    Licensed under the Apache License, Version 2.0 (the "License");
5  *    you may not use this file except in compliance with the License.
6  *    You may obtain a copy of the License at
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *    Unless required by applicable law or agreed to in writing, software
11  *    distributed under the License is distributed on an "AS IS" BASIS,
12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *    See the License for the specific language governing permissions and
14  *    limitations under the License.
15  */
16 /**
17  * @file    TestCases.cpp
18  * @author  Karol Pawlowski (k.pawlowski@samsung.com)
19  * @author  Tomasz Iwanek (t.iwanek@samsung.com)
20  * @version 1.0
21  * @brief   Manifest installation test's bodies
22  */
23
24 #include <string>
25 #include <dpl/utils/wrt_utility.h>
26 #include <dpl/test/test_runner.h>
27 #include <InstallerWrapper.h>
28 #include <ManifestFile.h>
29 #include <installer_log.h>
30 #include <dpl/wrt-dao-ro/global_config.h>
31
32 using namespace InstallerWrapper;
33
34 ////////////////////////////////////////////////////////////////////////////////
35
36 RUNNER_TEST_GROUP_INIT(Manifest)
37
38 /*
39 Name: creatingManifestFile
40 Description: Creation of manifest file by wrt-installer test
41 Expected: file should be created and installed by wrt-installer. Content should
42  match expected values
43 */
44 RUNNER_TEST(creatingManifestFile)
45 {
46     std::string manifestPath = "/opt/share/packages/";
47     /* This widget removal should stay here in case previous test run failed
48      * (so widget has not been uninstalled) */
49     std::string tizenId;
50
51     if(install(miscWidgetsStuff + "widgets/manifest.wgt", tizenId)
52             != InstallerWrapper::Success)
53     {
54         uninstall(tizenId);
55         RUNNER_ASSERT(install(miscWidgetsStuff + "widgets/manifest.wgt", tizenId)
56                 == InstallerWrapper::Success);
57     }
58
59     RUNNER_ASSERT(WrtUtilFileExists(manifestPath.append(tizenId.substr(0,10)).append(".xml")));
60     ManifestFile mf(manifestPath);
61
62     Try
63     {
64         _D("Package %s", mf.getValueByXpath("/p:manifest/@package").c_str());
65         RUNNER_ASSERT(mf.getValueByXpath("/p:manifest/@package")
66                       == tizenId.substr(0,10));
67         _D("type %s", mf.getValueByXpath("/p:manifest/@type").c_str());
68         RUNNER_ASSERT(mf.getValueByXpath("/p:manifest/@type")
69                       == "wgt");
70         _D("version %s", mf.getValueByXpath("/p:manifest/@version").c_str());
71         RUNNER_ASSERT(mf.getValueByXpath("/p:manifest/@version")
72                       == "1.0");
73         _D("label %s", mf.getValueByXpath("/p:manifest/p:label").c_str());
74         RUNNER_ASSERT(mf.getValueByXpath("/p:manifest/p:label")
75                       == "Manifest Example");
76
77         _D("email %s", mf.getValueByXpath("/p:manifest/p:author/@email").c_str());
78         RUNNER_ASSERT(mf.getValueByXpath("/p:manifest/p:author/@email")
79                       == "manifest@misc.test.create.desktop.com");
80         _D("href %s", mf.getValueByXpath("/p:manifest/p:author/@href").c_str());
81         RUNNER_ASSERT(mf.getValueByXpath("/p:manifest/p:author/@href")
82                       == "http://misc.test.create.desktop.com");
83         _D("author %s", mf.getValueByXpath("/p:manifest/p:author").c_str());
84         RUNNER_ASSERT(mf.getValueByXpath("/p:manifest/p:author")
85                       == "Manifest");
86
87         _D("appid %s", mf.getValueByXpath("/p:manifest/p:ui-application/@appid").c_str());
88         RUNNER_ASSERT(mf.getValueByXpath("/p:manifest/p:ui-application/@appid")
89                       == tizenId);
90         _D("type %s", mf.getValueByXpath("/p:manifest/p:ui-application/@type").c_str());
91         RUNNER_ASSERT(mf.getValueByXpath("/p:manifest/p:ui-application/@type")
92                       == "webapp");
93         _D("extraid %s", mf.getValueByXpath("/p:manifest/p:ui-application/@extraid").c_str());
94         RUNNER_ASSERT(mf.getValueByXpath("/p:manifest/p:ui-application/@extraid")
95                       == "http://test.samsung.com/widget/manifestTest");
96         _D("icon %s", mf.getValueByXpath("/p:manifest/p:ui-application/p:icon").c_str());
97         RUNNER_ASSERT(mf.getValueByXpath("/p:manifest/p:ui-application/p:icon")
98                       == (std::string(WrtDB::GlobalConfig::GetUserInstalledWidgetPath()) + "/" + tizenId.substr(0,10) + WrtDB::GlobalConfig::GetWidgetSharedPath() + WrtDB::GlobalConfig::GetWidgetResPath() + "/" + tizenId + ".png"));
99
100         RUNNER_ASSERT(mf.getValueByXpath("/p:manifest/p:ui-application/p:label[not(@xml:lang)]")
101                       == "Manifest Example");
102         RUNNER_ASSERT(mf.getValueByXpath("/p:manifest/p:ui-application/p:label[@xml:lang='de-de']")
103                       == "Manifest Beispiel");
104         RUNNER_ASSERT(mf.getValueByXpath("/p:manifest/p:ui-application/p:label[@xml:lang='en-us']")
105                       == "Manifest Example");
106         RUNNER_ASSERT(mf.getValueByXpath("/p:manifest/p:ui-application/p:label[@xml:lang='pl']")
107                       == "PrzykĹ‚ad Manifest");
108         RUNNER_ASSERT(mf.getValueByXpath("/p:manifest/p:ui-application/p:label[@xml:lang='pt-pt']")
109                       == "Exemplo manifesto");
110     }
111     Catch(ManifestFile::ManifestParseError)
112     {
113         RUNNER_ASSERT_MSG(false,DPL::Exception::KnownExceptionToString(_rethrown_exception));
114     }
115     /* If test finished sucessfully than uninstall test widget */
116     uninstall(tizenId);
117 }