2 * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
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 //////////////////////////////////////////////////////////////////////////////////////////////////
18 /// \ingroup MY 14 Platform Software Team
19 /// \brief Xml parser used to extract and update data from Xml file
22 //////////////////////////////////////////////////////////////////////////////////////////////////
26 * @brief \~english Xml parser used to extract and update data from Xml file
29 /** @addtogroup BaseSystem
32 /** @addtogroup native_service
36 /** @addtogroup framework_unified
37 * @ingroup native_service
40 /** @addtogroup native
41 * @ingroup framework_unified
44 #ifndef XMLPARSER_H_ // NOLINT (build/header_guard)
47 #include <libxml/tree.h>
49 #include <native_service/frameworkunified_types.h>
50 #include <native_service/ns_logger_if.h>
58 ////////////////////////////////////////////////////////////////////////
59 /// CTestCaseData : Class used to fill testcase data from XML
60 ////////////////////////////////////////////////////////////////////////
69 SI_32 m_testDelayMSec;
70 SI_32 m_testDelayUSec;
75 SI_32 m_testPrintResult;
76 std::string m_testCategory;
77 std::string m_testResultType;
79 std::vector<std::string> macroVector;
80 // Delay for TestMacros
81 std::string m_macroDelaySecVal;
82 std::string m_macroDelayMsecVal;
83 std::string m_macroDelayUsecVal;
85 std::list<std::string> expOut;
88 CTestCaseData(const xmlChar *name, std::string testDelaySec, std::string testDelayMSec, std::string testDelayUSec,
89 std::string testLoopVal, std::string testReset, std::string testPrintResult, std::string testCategory,
90 std::string testResultType, std::vector<std::string> paramMacroVector, std::string macroDelaySecVal,
91 std::string macroDelayMSecVal, std::string macroDelayUSecVal,
92 std::list<std::string> expOutputVector);
94 CTestCaseData(const CTestCaseData &value);
103 FindByName(const std::string &name) : l_sName(name) {} // NOLINT (readability/nolint)
104 bool operator()(const xmlNodePtr &xmlNode) {
105 std::stringstream l_sStream;
106 l_sStream << xmlNode->name;
107 std::string l_sStr = l_sStream.str();
108 return l_sStr == l_sName;
113 static std::string xmlCharToString(const xmlChar *value);
114 ////////////////////////////////////////////////////////////////////////////////////////////
116 /// Class Constructor
117 ////////////////////////////////////////////////////////////////////////////////////////////
119 ////////////////////////////////////////////////////////////////////////////////////////////
122 ////////////////////////////////////////////////////////////////////////////////////////////
124 ////////////////////////////////////////////////////////////////////////////////////////////
126 /// read all XML files from xmlInputFile
128 /// \param [in] xmlInputFile
133 ////////////////////////////////////////////////////////////////////////////////////////////
134 void readAllXml(const std::string &xmlInputFile, std::list<std::string> &xmlList); // NOLINT (readability/nolint)
135 ////////////////////////////////////////////////////////////////////////////////////////////
141 /// vector<xmlNodePtr>
143 ////////////////////////////////////////////////////////////////////////////////////////////
144 void getChildNodeList(xmlNodePtr node, std::vector<xmlNodePtr> &nodeVector); // NOLINT (readability/nolint)
145 ////////////////////////////////////////////////////////////////////////////////////////////
152 /// vector<xmlNodePtr>
156 /// list<std::string>
160 /// vector<std::string>
162 ////////////////////////////////////////////////////////////////////////////////////////////
163 void fillMacroVector(xmlDocPtr &xmlFileHandle, // NOLINT (readability/nolint)
164 std::vector<xmlNodePtr> ¯oNodeVector, // NOLINT (readability/nolint)
165 std::string &expOutValue, // NOLINT (readability/nolint)
166 std::list<std::string> &expOutputVector, // NOLINT (readability/nolint)
167 std::string ¯oSecDelayVal, // NOLINT (readability/nolint)
168 std::string ¯oMSecDelayVal, // NOLINT (readability/nolint)
169 std::string ¯oUSecDelayVal, // NOLINT (readability/nolint)
170 std::vector<std::string> ¶mMacroVector); // NOLINT (readability/nolint)
171 ////////////////////////////////////////////////////////////////////////////////////////////
173 /// Convert the string to number
179 /// \return number value
181 ////////////////////////////////////////////////////////////////////////////////////////////
182 static int StringToNumber(const std::string &Text) { // NOLINT (readability/nolint)
183 std::istringstream ss(Text, std::istringstream::in);
185 return ss >> result ? result : 0;
187 ////////////////////////////////////////////////////////////////////////////////////////////
188 /// createTestCaseVector
191 /// testCaseNodeVector
192 /// vector<xmlNodePtr>
195 /// testCaseDataVector
196 /// vector<CTestCaseData>
199 ////////////////////////////////////////////////////////////////////////////////////////////
200 void createTestCaseVector(std::vector<xmlNodePtr> &testCaseNodeVector, xmlDocPtr &xmlFileHandle, // NOLINT (readability/nolint)
201 std::vector<CTestCaseData> &testCaseDataVector); // NOLINT (readability/nolint)
202 ////////////////////////////////////////////////////////////////////////////////////////////
203 /// GetXmlNodeAttributeValueToString
214 ////////////////////////////////////////////////////////////////////////////////////////////
215 std::string GetXmlNodeAttributeValueToString(void *arg, const char *str, xmlDocPtr xmlFileHandle);
216 ////////////////////////////////////////////////////////////////////////////////////////////
217 /// populateTestCaseMap
220 /// testCaseDataVector
221 /// vector<CTestCaseData>
226 ////////////////////////////////////////////////////////////////////////////////////////////
227 void populateTestCaseMap(std::vector<CTestCaseData> &testCaseDataVector, xmlDocPtr xmlFileHandle) ; // NOLINT (readability/nolint)
228 ////////////////////////////////////////////////////////////////////////////////////////////
229 /// updateXmlActualOutput
238 ////////////////////////////////////////////////////////////////////////////////////////////
239 void updateXmlActualOutput(const std::string &xmlName, // NOLINT (readability/nolint)
240 std::string &testCaseName, // NOLINT (readability/nolint)
241 std::string &actualOutput); // NOLINT (readability/nolint)
242 ////////////////////////////////////////////////////////////////////////////////////////////
243 /// GetXmlExpectedOutput
252 ////////////////////////////////////////////////////////////////////////////////////////////
253 void GetXmlExpectedOutput(std::string pKey, std::string pValue);
256 xmlDocPtr m_xmlFileHandle;
257 static const std::string EXPECTEDOUTPUT;
258 static const std::string VALUE;
259 static const std::string DELAYSEC;
260 static const std::string DELAYMSEC;
261 static const std::string DELAYUSEC;
262 static const std::string TESTLOOP;
263 static const std::string TESTRESET;
264 static const std::string TESTPRINTRESULT;
265 static const std::string TESTCATEGORY;
266 static const std::string TESTCASEDATA;
267 static const std::string MACRODELAYSEC;
268 static const std::string MACRODELAYMSEC;
269 static const std::string MACRODELAYUSEC;
270 static const std::string LOOPPVAL;
271 static const std::string ACTUALOUTOUT;
272 static const std::string OUTPUT_SEPARATOR;
273 static const std::string ACCESS_OPERATOR;
274 static const std::string TERMINATE_STR;
275 static const SI_32 LOOP_DEFAULT_VALUE;
276 static const std::string DEFAULT_VALUE;
277 static const std::string PARAMETER_SEPARATOR;
278 static const std::string TESTRESULTTYPE;
279 static const std::string RESULT_AUTOMATIC;
280 static const std::string RESULT_MANUAL;
283 #endif /* XMLPARSER_H_ */ // NOLINT (build/header_guard)