summaryrefslogtreecommitdiffstats
path: root/nsframework/framework_unified/client/include/native_service/XMLParser.h
blob: 36467ba420f86c76399c60cfa3d31e5343dbc1e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
/*
 * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

//////////////////////////////////////////////////////////////////////////////////////////////////
/// \ingroup MY 14 Platform Software Team
/// \brief   Xml parser used to extract and update data from Xml file
///
///
//////////////////////////////////////////////////////////////////////////////////////////////////

/**
 * @file XMLParser.h
 * @brief \~english Xml parser used to extract and update data from Xml file
 *
 */
/** @addtogroup BaseSystem
 *  @{
 */
/** @addtogroup native_service
 *  @ingroup BaseSystem
 *  @{
 */
/** @addtogroup framework_unified
 *  @ingroup native_service
 *  @{
 */
/** @addtogroup native
 *  @ingroup framework_unified
 *  @{
 */
#ifndef XMLPARSER_H_  // NOLINT  (build/header_guard)
#define XMLPARSER_H_

#include <libxml/tree.h>

#include <native_service/frameworkunified_types.h>
#include <native_service/ns_logger_if.h>

#include <vector>
#include <list>
#include <string>
#include <map>
#include <sstream>

////////////////////////////////////////////////////////////////////////
///   CTestCaseData : Class used to fill testcase data from XML
////////////////////////////////////////////////////////////////////////


class CTestCaseData {
 public:
  std::string key;

  // Delay for testCase
  SI_32 m_testDelaySec;
  SI_32 m_testDelayMSec;
  SI_32 m_testDelayUSec;
  // TestLoop Count
  SI_32 m_testLoop;

  SI_32 m_testReset;
  SI_32 m_testPrintResult;
  std::string m_testCategory;
  std::string m_testResultType;

  std::vector<std::string> macroVector;
  // Delay for TestMacros
  std::string m_macroDelaySecVal;
  std::string m_macroDelayMsecVal;
  std::string m_macroDelayUsecVal;

  std::list<std::string> expOut;


  CTestCaseData(const xmlChar *name, std::string testDelaySec, std::string testDelayMSec, std::string testDelayUSec,
                std::string testLoopVal, std::string testReset, std::string testPrintResult, std::string testCategory,
                std::string testResultType, std::vector<std::string> paramMacroVector, std::string macroDelaySecVal,
                std::string macroDelayMSecVal,  std::string macroDelayUSecVal,
                std::list<std::string> expOutputVector);

  CTestCaseData(const CTestCaseData &value);

  ~CTestCaseData();
};

class XMLParser {
 private:
  struct FindByName {
    std::string l_sName;
    FindByName(const std::string &name) : l_sName(name) {}  // NOLINT  (readability/nolint)
    bool operator()(const xmlNodePtr &xmlNode) {
      std::stringstream l_sStream;
      l_sStream << xmlNode->name;
      std::string l_sStr = l_sStream.str();
      return l_sStr == l_sName;
    }
  };

 public:
  static std::string xmlCharToString(const xmlChar *value);
  ////////////////////////////////////////////////////////////////////////////////////////////
  /// XMLParser
  /// Class Constructor
  ////////////////////////////////////////////////////////////////////////////////////////////
  XMLParser();
  ////////////////////////////////////////////////////////////////////////////////////////////
  /// XMLParser
  /// Class Destructor
  ////////////////////////////////////////////////////////////////////////////////////////////
  ~XMLParser();
  ////////////////////////////////////////////////////////////////////////////////////////////
  /// readAllXml
  ///   read all XML files from xmlInputFile
  ///
  /// \param [in] xmlInputFile
  ///       string
  ///       xmlList
  ///       string
  /// \return none
  ////////////////////////////////////////////////////////////////////////////////////////////
  void readAllXml(const std::string &xmlInputFile, std::list<std::string> &xmlList);  // NOLINT  (readability/nolint)
  ////////////////////////////////////////////////////////////////////////////////////////////
  /// getChildNodeList
  ///
  /// \param [in] node
  ///       xmlNodePtr
  ///       nodeVector
  ///       vector<xmlNodePtr>
  /// \return none
  ////////////////////////////////////////////////////////////////////////////////////////////
  void getChildNodeList(xmlNodePtr node, std::vector<xmlNodePtr> &nodeVector);  // NOLINT  (readability/nolint)
  ////////////////////////////////////////////////////////////////////////////////////////////
  /// fillMacroVector
  ///
  /// \param [in] node
  ///         xmlFileHandle
  ///         xmlDocPtr
  ///         macroNodeVector
  ///         vector<xmlNodePtr>
  ///         expOutValue
  ///         string
  ///         expOutputVector
  ///         list<std::string>
  ///         macroDelayVal
  ///         string
  ///         paramMacroVector
  ///         vector<std::string>
  /// \return none
  ////////////////////////////////////////////////////////////////////////////////////////////
  void fillMacroVector(xmlDocPtr &xmlFileHandle,  // NOLINT  (readability/nolint)
                       std::vector<xmlNodePtr> &macroNodeVector,  // NOLINT  (readability/nolint)
                       std::string &expOutValue,  // NOLINT  (readability/nolint)
                       std::list<std::string> &expOutputVector,  // NOLINT  (readability/nolint)
                       std::string &macroSecDelayVal,  // NOLINT  (readability/nolint)
                       std::string &macroMSecDelayVal,  // NOLINT  (readability/nolint)
                       std::string &macroUSecDelayVal,  // NOLINT  (readability/nolint)
                       std::vector<std::string> &paramMacroVector);  // NOLINT  (readability/nolint)
  ////////////////////////////////////////////////////////////////////////////////////////////
  ///  StringToNumber
  ///        Convert the string to number
  ///
  /// \param [in]
  ///      Text
  ///      string
  ///
  /// \return number value
  ///
  ////////////////////////////////////////////////////////////////////////////////////////////
  static int StringToNumber(const std::string &Text) {  // NOLINT  (readability/nolint)
    std::istringstream ss(Text, std::istringstream::in);
    int result;
    return ss >> result ? result : 0;
  }
  ////////////////////////////////////////////////////////////////////////////////////////////
  /// createTestCaseVector
  ///
  /// \param [in]
  ///      testCaseNodeVector
  ///      vector<xmlNodePtr>
  ///      xmlFileHandle
  ///      xmlDocPtr
  ///      testCaseDataVector
  ///      vector<CTestCaseData>
  ///
  /// \return none
  ////////////////////////////////////////////////////////////////////////////////////////////
  void createTestCaseVector(std::vector<xmlNodePtr> &testCaseNodeVector, xmlDocPtr &xmlFileHandle,  // NOLINT  (readability/nolint)
                            std::vector<CTestCaseData> &testCaseDataVector);  // NOLINT  (readability/nolint)
  ////////////////////////////////////////////////////////////////////////////////////////////
  /// GetXmlNodeAttributeValueToString
  ///
  /// \param [in]
  ///      arg
  ///      void *
  ///      str
  ///      const char *
  ///      xmlFileHandle
  ///      xmlDocPtr
  ///
  /// \return none
  ////////////////////////////////////////////////////////////////////////////////////////////
  std::string GetXmlNodeAttributeValueToString(void *arg, const char *str, xmlDocPtr xmlFileHandle);
  ////////////////////////////////////////////////////////////////////////////////////////////
  /// populateTestCaseMap
  ///
  /// \param [in]
  ///      testCaseDataVector
  ///      vector<CTestCaseData>
  ///      xmlFileHandle
  ///      xmlDocPtr
  ///
  /// \return none
  ////////////////////////////////////////////////////////////////////////////////////////////
  void   populateTestCaseMap(std::vector<CTestCaseData> &testCaseDataVector, xmlDocPtr xmlFileHandle) ;  // NOLINT  (readability/nolint)
  ////////////////////////////////////////////////////////////////////////////////////////////
  /// updateXmlActualOutput
  ///
  /// \param [in]
  ///      xmlName
  ///      string
  ///      testCaseName
  ///      string
  ///
  /// \return none
  ////////////////////////////////////////////////////////////////////////////////////////////
  void   updateXmlActualOutput(const std::string &xmlName,  // NOLINT  (readability/nolint)
                               std::string &testCaseName,  // NOLINT  (readability/nolint)
                               std::string &actualOutput);  // NOLINT  (readability/nolint)
  ////////////////////////////////////////////////////////////////////////////////////////////
  /// GetXmlExpectedOutput
  ///
  /// \param [in]
  ///      pKey
  ///      string
  ///      pValue
  ///      string
  ///
  /// \return none
  ////////////////////////////////////////////////////////////////////////////////////////////
  void   GetXmlExpectedOutput(std::string  pKey, std::string pValue);

 private:
  xmlDocPtr m_xmlFileHandle;
  static const std::string EXPECTEDOUTPUT;
  static const std::string VALUE;
  static const std::string DELAYSEC;
  static const std::string DELAYMSEC;
  static const std::string DELAYUSEC;
  static const std::string TESTLOOP;
  static const std::string TESTRESET;
  static const std::string TESTPRINTRESULT;
  static const std::string TESTCATEGORY;
  static const std::string TESTCASEDATA;
  static const std::string MACRODELAYSEC;
  static const std::string MACRODELAYMSEC;
  static const std::string MACRODELAYUSEC;
  static const std::string LOOPPVAL;
  static const std::string ACTUALOUTOUT;
  static const std::string OUTPUT_SEPARATOR;
  static const std::string ACCESS_OPERATOR;
  static const std::string TERMINATE_STR;
  static const SI_32     LOOP_DEFAULT_VALUE;
  static const std::string DEFAULT_VALUE;
  static const std::string PARAMETER_SEPARATOR;
  static const std::string TESTRESULTTYPE;
  static const std::string RESULT_AUTOMATIC;
  static const std::string RESULT_MANUAL;
};

#endif /* XMLPARSER_H_ */  // NOLINT  (build/header_guard)

// EOF
/** @}*/
/** @}*/
/** @}*/
/** @}*/