Remove unused directories and files in video_in_hal
[staging/basesystem.git] / service / native / framework_unified / client / include / native_service / XMLParser.h
1 /*
2  * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
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 //////////////////////////////////////////////////////////////////////////////////////////////////
18 /// \ingroup MY 14 Platform Software Team
19 /// \brief   Xml parser used to extract and update data from Xml file
20 ///
21 ///
22 //////////////////////////////////////////////////////////////////////////////////////////////////
23
24 /**
25  * @file XMLParser.h
26  * @brief \~english Xml parser used to extract and update data from Xml file
27  *
28  */
29 /** @addtogroup BaseSystem
30  *  @{
31  */
32 /** @addtogroup native_service
33  *  @ingroup BaseSystem
34  *  @{
35  */
36 /** @addtogroup framework_unified
37  *  @ingroup native_service
38  *  @{
39  */
40 /** @addtogroup native
41  *  @ingroup framework_unified
42  *  @{
43  */
44 #ifndef XMLPARSER_H_  // NOLINT  (build/header_guard)
45 #define XMLPARSER_H_
46
47 #include <libxml/tree.h>
48
49 #include <native_service/frameworkunified_types.h>
50 #include <native_service/ns_logger_if.h>
51
52 #include <vector>
53 #include <list>
54 #include <string>
55 #include <map>
56 #include <sstream>
57
58 ////////////////////////////////////////////////////////////////////////
59 ///   CTestCaseData : Class used to fill testcase data from XML
60 ////////////////////////////////////////////////////////////////////////
61
62
63 class CTestCaseData {
64  public:
65   std::string key;
66
67   // Delay for testCase
68   SI_32 m_testDelaySec;
69   SI_32 m_testDelayMSec;
70   SI_32 m_testDelayUSec;
71   // TestLoop Count
72   SI_32 m_testLoop;
73
74   SI_32 m_testReset;
75   SI_32 m_testPrintResult;
76   std::string m_testCategory;
77   std::string m_testResultType;
78
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;
84
85   std::list<std::string> expOut;
86
87
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);
93
94   CTestCaseData(const CTestCaseData &value);
95
96   ~CTestCaseData();
97 };
98
99 class XMLParser {
100  private:
101   struct FindByName {
102     std::string l_sName;
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;
109     }
110   };
111
112  public:
113   static std::string xmlCharToString(const xmlChar *value);
114   ////////////////////////////////////////////////////////////////////////////////////////////
115   /// XMLParser
116   /// Class Constructor
117   ////////////////////////////////////////////////////////////////////////////////////////////
118   XMLParser();
119   ////////////////////////////////////////////////////////////////////////////////////////////
120   /// XMLParser
121   /// Class Destructor
122   ////////////////////////////////////////////////////////////////////////////////////////////
123   ~XMLParser();
124   ////////////////////////////////////////////////////////////////////////////////////////////
125   /// readAllXml
126   ///   read all XML files from xmlInputFile
127   ///
128   /// \param [in] xmlInputFile
129   ///       string
130   ///       xmlList
131   ///       string
132   /// \return none
133   ////////////////////////////////////////////////////////////////////////////////////////////
134   void readAllXml(const std::string &xmlInputFile, std::list<std::string> &xmlList);  // NOLINT  (readability/nolint)
135   ////////////////////////////////////////////////////////////////////////////////////////////
136   /// getChildNodeList
137   ///
138   /// \param [in] node
139   ///       xmlNodePtr
140   ///       nodeVector
141   ///       vector<xmlNodePtr>
142   /// \return none
143   ////////////////////////////////////////////////////////////////////////////////////////////
144   void getChildNodeList(xmlNodePtr node, std::vector<xmlNodePtr> &nodeVector);  // NOLINT  (readability/nolint)
145   ////////////////////////////////////////////////////////////////////////////////////////////
146   /// fillMacroVector
147   ///
148   /// \param [in] node
149   ///         xmlFileHandle
150   ///         xmlDocPtr
151   ///         macroNodeVector
152   ///         vector<xmlNodePtr>
153   ///         expOutValue
154   ///         string
155   ///         expOutputVector
156   ///         list<std::string>
157   ///         macroDelayVal
158   ///         string
159   ///         paramMacroVector
160   ///         vector<std::string>
161   /// \return none
162   ////////////////////////////////////////////////////////////////////////////////////////////
163   void fillMacroVector(xmlDocPtr &xmlFileHandle,  // NOLINT  (readability/nolint)
164                        std::vector<xmlNodePtr> &macroNodeVector,  // NOLINT  (readability/nolint)
165                        std::string &expOutValue,  // NOLINT  (readability/nolint)
166                        std::list<std::string> &expOutputVector,  // NOLINT  (readability/nolint)
167                        std::string &macroSecDelayVal,  // NOLINT  (readability/nolint)
168                        std::string &macroMSecDelayVal,  // NOLINT  (readability/nolint)
169                        std::string &macroUSecDelayVal,  // NOLINT  (readability/nolint)
170                        std::vector<std::string> &paramMacroVector);  // NOLINT  (readability/nolint)
171   ////////////////////////////////////////////////////////////////////////////////////////////
172   ///  StringToNumber
173   ///        Convert the string to number
174   ///
175   /// \param [in]
176   ///      Text
177   ///      string
178   ///
179   /// \return number value
180   ///
181   ////////////////////////////////////////////////////////////////////////////////////////////
182   static int StringToNumber(const std::string &Text) {  // NOLINT  (readability/nolint)
183     std::istringstream ss(Text, std::istringstream::in);
184     int result;
185     return ss >> result ? result : 0;
186   }
187   ////////////////////////////////////////////////////////////////////////////////////////////
188   /// createTestCaseVector
189   ///
190   /// \param [in]
191   ///      testCaseNodeVector
192   ///      vector<xmlNodePtr>
193   ///      xmlFileHandle
194   ///      xmlDocPtr
195   ///      testCaseDataVector
196   ///      vector<CTestCaseData>
197   ///
198   /// \return none
199   ////////////////////////////////////////////////////////////////////////////////////////////
200   void createTestCaseVector(std::vector<xmlNodePtr> &testCaseNodeVector, xmlDocPtr &xmlFileHandle,  // NOLINT  (readability/nolint)
201                             std::vector<CTestCaseData> &testCaseDataVector);  // NOLINT  (readability/nolint)
202   ////////////////////////////////////////////////////////////////////////////////////////////
203   /// GetXmlNodeAttributeValueToString
204   ///
205   /// \param [in]
206   ///      arg
207   ///      void *
208   ///      str
209   ///      const char *
210   ///      xmlFileHandle
211   ///      xmlDocPtr
212   ///
213   /// \return none
214   ////////////////////////////////////////////////////////////////////////////////////////////
215   std::string GetXmlNodeAttributeValueToString(void *arg, const char *str, xmlDocPtr xmlFileHandle);
216   ////////////////////////////////////////////////////////////////////////////////////////////
217   /// populateTestCaseMap
218   ///
219   /// \param [in]
220   ///      testCaseDataVector
221   ///      vector<CTestCaseData>
222   ///      xmlFileHandle
223   ///      xmlDocPtr
224   ///
225   /// \return none
226   ////////////////////////////////////////////////////////////////////////////////////////////
227   void   populateTestCaseMap(std::vector<CTestCaseData> &testCaseDataVector, xmlDocPtr xmlFileHandle) ;  // NOLINT  (readability/nolint)
228   ////////////////////////////////////////////////////////////////////////////////////////////
229   /// updateXmlActualOutput
230   ///
231   /// \param [in]
232   ///      xmlName
233   ///      string
234   ///      testCaseName
235   ///      string
236   ///
237   /// \return none
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
244   ///
245   /// \param [in]
246   ///      pKey
247   ///      string
248   ///      pValue
249   ///      string
250   ///
251   /// \return none
252   ////////////////////////////////////////////////////////////////////////////////////////////
253   void   GetXmlExpectedOutput(std::string  pKey, std::string pValue);
254
255  private:
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;
281 };
282
283 #endif /* XMLPARSER_H_ */  // NOLINT  (build/header_guard)
284
285 // EOF
286 /** @}*/
287 /** @}*/
288 /** @}*/
289 /** @}*/