2 * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * @file ParsingMetadataTests.cpp
18 * @author Slawomir Pajak (s.pajak@partner.samsung.com)
20 * @brief metadata element installation tests
24 #include <dpl/test/test_runner.h>
25 #include <InstallerWrapper.h>
26 #include <ManifestFile.h>
27 #include <dpl/utils/wrt_utility.h>
29 #include <root_parser.h>
30 #include <widget_parser.h>
31 #include <parser_runner.h>
33 using namespace InstallerWrapper;
37 template<typename Exception, typename Function>
38 bool checkException(Function fun)
52 #define RUNNER_ASSERT_EXCEPTION(exceptionType, function) \
54 RUNNER_ASSERT(checkException<exceptionType>([&](){function})); \
59 ////////////////////////////////////////////////////////////////////////////////
61 RUNNER_TEST_GROUP_INIT(ParsingMetadata)
64 Name: InstallWidgetWithMetadata
65 Description: Tests if widget with metadata element is installed correctly
66 Expected: widget should be installed correctly and metadata info should be stored in manifest file
68 RUNNER_TEST(InstallWidgetWithMetadata)
71 std::string manifestPath = "/opt/share/packages/";
72 RUNNER_ASSERT(install(miscWidgetsStuff + "widgets/metadata.wgt", tizenId) == InstallerWrapper::Success);
74 RUNNER_ASSERT(WrtUtilFileExists(manifestPath.append(tizenId.substr(0, 10)).append(".xml")));
75 ManifestFile mf(manifestPath);
77 RUNNER_ASSERT(mf.getValueByXpath("/p:manifest/p:ui-application/p:metadata[1]/@key") == "key1");
78 RUNNER_ASSERT(mf.getValueByXpath("/p:manifest/p:ui-application/p:metadata[2]/@key") == "key2");
79 RUNNER_ASSERT(mf.getValueByXpath("/p:manifest/p:ui-application/p:metadata[2]/@value") == "value2");
80 RUNNER_ASSERT(mf.getValueByXpath("/p:manifest/p:ui-application/p:metadata[3]/@key") == "key3");
81 RUNNER_ASSERT(mf.getValueByXpath("/p:manifest/p:ui-application/p:metadata[3]/@value") == "value3");
88 Description: Tests parsing configuration file without metadata element
89 Expected: Element should be parsed correctly.
91 RUNNER_TEST(NoMetadata)
94 WrtDB::ConfigParserData widgetConfig;
96 parser.Parse(miscWidgetsStuff + "configs/NoMetadata.xml",
98 new RootParser<WidgetParser>(widgetConfig,
101 RUNNER_ASSERT(widgetConfig.metadataList.empty());
106 Description: Tests parsing configuration file with empty metadata element
107 Expected: Exception should be thrown
109 //TODO: Fix in parser needed
110 //RUNNER_TEST(MetadataEmpty)
112 // ParserRunner parser;
113 // WrtDB::ConfigParserData widgetConfig;
115 // RUNNER_ASSERT_EXCEPTION(ElementParser::Exception::ParseError,
116 // parser.Parse(miscWidgetsStuff + "configs/MetadataEmpty.xml",
117 // ElementParserPtr( new RootParser<WidgetParser>(widgetConfig, L"widget")));
122 Name: MultipleMetadata
123 Description: Tests parsing configuration file with multiple metadata element
124 Expected: Element should be parsed correctly. All values should be stored
126 RUNNER_TEST(MultipleMetadata)
129 WrtDB::ConfigParserData widgetConfig;
131 parser.Parse(miscWidgetsStuff + "configs/MultipleMetadata.xml",
133 new RootParser<WidgetParser>(widgetConfig,
136 RUNNER_ASSERT(3 == widgetConfig.metadataList.size());
138 RUNNER_ASSERT(1 == std::count(widgetConfig.metadataList.begin(), widgetConfig.metadataList.end(),
139 WrtDB::ConfigParserData::Metadata(DPL::OptionalString(L"key1"), DPL::OptionalString())));
140 RUNNER_ASSERT(1 == std::count(widgetConfig.metadataList.begin(), widgetConfig.metadataList.end(),
141 WrtDB::ConfigParserData::Metadata(DPL::OptionalString(L"key2"), DPL::OptionalString(L"value2"))));
142 RUNNER_ASSERT(1 == std::count(widgetConfig.metadataList.begin(), widgetConfig.metadataList.end(),
143 WrtDB::ConfigParserData::Metadata(DPL::OptionalString(L"key3"), DPL::OptionalString(L"value3"))));
148 Name: MetadataDuplicatedKey
149 Description: Tests parsing configuration file with duplicated key attribute value in metadata element
150 Expected: Exception should be thrown
152 //TODO: Fix in parser needed
153 //RUNNER_TEST(MetadataDuplicatedKey)
155 // ParserRunner parser;
156 // WrtDB::ConfigParserData widgetConfig;
158 // RUNNER_ASSERT_EXCEPTION(ElementParser::Exception::ParseError,
159 // parser.Parse(miscWidgetsStuff + "configs/MetadataDuplicatedKey.xml",
160 // ElementParserPtr( new RootParser<WidgetParser>(widgetConfig, L"widget")));