2 * Copyright (c) 2014 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 ParserRunnerTests.cpp
18 * @author Adrian Szafranek (a.szafranek@samsung.com)
20 * @brief Perform ParserRunner test's.
23 #include <parser_runner.h>
24 #include <dpl/scope_guard.h>
25 #include <dpl/test/test_runner.h>
26 #include <dpl/utils/path.h>
28 #include <installer_log.h>
35 RUNNER_TEST_GROUP_INIT(ParserRunner)
37 using namespace DPL::Utils;
40 const std::string rootTest = "/tmp/";
41 const std::string schemaFile = "/usr/etc/wrt-installer/widgets.xsd";
42 const std::string configFile = "/usr/lib/wrt-plugins/tizen-content/config.xml";
43 const std::string installConfigFile = "/opt/share/widget/tests/installer/configs/InstallConfig.xml";
46 class StreamRedirector
49 StreamRedirector(FILE* src, std::string dest)
50 : source(src), file_dest(dest)
52 fd = dup(fileno(source));
53 if ((fd < 0) || (freopen(file_dest.c_str(), "w", source) == NULL))
55 _D("Error catching stream.");
60 if (TEMP_FAILURE_RETRY(fflush(source)) == 0)
62 if (dup2(fd, fileno(source)) >= 0)
69 _D("Error returning stream.");
74 _D("Error returning stream.");
80 std::string file_dest;
87 Description: Tests validation and parsing functionality.
88 Test performed for proper files existing in system, wrong files or empty parameters.
90 RUNNER_TEST(parserRunner01)
94 std::unique_ptr<StreamRedirector> sd(new StreamRedirector(stderr, "/dev/null"));
97 if (Path(installConfigFile).Exists() && Path(schemaFile).Exists()) {
98 RUNNER_ASSERT(parser.Validate(installConfigFile, schemaFile) == true);
101 if (Path(configFile).Exists() && Path(schemaFile).Exists()) {
102 RUNNER_ASSERT(parser.Validate(configFile, schemaFile) == false);
105 RUNNER_ASSERT(parser.Validate("", "") == false);
110 Description: Tests validation and parsing functionality.
111 Test performed for wrong 'xml', empty 'xsd' file and wrong 'xml', non empty 'xsd' file.
113 RUNNER_TEST(parserRunner02)
117 std::unique_ptr<StreamRedirector> sd(new StreamRedirector(stderr, "/dev/null"));
120 Path pathF1 = Path(rootTest + "testFile1.xml");
121 if (!pathF1.Exists()) {
122 MakeEmptyFile(pathF1);
124 DPL_SCOPE_EXIT(&pathF1) { TryRemove(pathF1); };
127 ofs1.open(pathF1.Fullpath(), std::ofstream::out);
129 RUNNER_ASSERT_MSG(false, "Error creating file");
131 ofs1 << "wrongContent";
134 RUNNER_ASSERT(parser.Validate(pathF1.Fullpath(), "") == false);
135 if (Path(schemaFile).Exists()) {
136 RUNNER_ASSERT(parser.Validate(pathF1.Fullpath(), schemaFile) == false);
143 Description: Tests validation and parsing functionality.
144 Test performed for empty 'xml', wrong 'xsd' file and non empty 'xml', wrong 'xsd' file.
146 RUNNER_TEST(parserRunner03)
150 std::unique_ptr<StreamRedirector> sd(new StreamRedirector(stderr, "/dev/null"));
153 Path pathF2 = Path(rootTest + "testFile2.xsd");
154 if (!pathF2.Exists()) {
155 MakeEmptyFile(pathF2);
157 DPL_SCOPE_EXIT(&pathF2) { TryRemove(pathF2); };
160 ofs2.open(pathF2.Fullpath(), std::ofstream::out);
162 RUNNER_ASSERT_MSG(false, "Error creating file");
164 ofs2 << "<element name=\"Test\" type=\"ds:TransformType\"/>";
167 RUNNER_ASSERT(parser.Validate("", pathF2.Fullpath()) == false);
168 if (Path(configFile).Exists()) {
169 RUNNER_ASSERT(parser.Validate(configFile, pathF2.Fullpath()) == false);