• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef TEST_CONVERTXML_H
17 #define TEST_CONVERTXML_H
18 
19 #include "js_api_module/convertxml/js_convertxml.h"
20 
21 namespace OHOS::Xml {
22 class CxmlTest {
23 public:
24     CxmlTest() = default;
25     ~CxmlTest() = default;
26     static std::string Trim(napi_env env, std::string strXmltrim);
27     static std::string GetNodeType(napi_env env, const xmlElementType enumType);
28     static void GetPrevNodeList(napi_env env, xmlNodePtr curNode);
29     static void SetXmlElementType(napi_env env, xmlNodePtr curNode, const napi_value &elementsObject,
30                                   bool &bFlag, char *curContent);
31     static void SetNodeInfo(napi_env env, xmlNodePtr curNode, const napi_value &elementsObject);
32     static void DealSpaces(napi_env env, const napi_value napiObj);
33     static void SetDefaultKey(napi_env env, size_t i, const std::string strRecv);
34     static void DealSingleLine(napi_env env, std::string &strXml, const napi_value &object);
35     static void DealComplex(napi_env env, std::string &strXml, const napi_value &object);
36     static void Replace(napi_env env, std::string &str, const std::string src, const std::string dst);
37     static void DealCDataInfo(napi_env env, bool bCData, xmlNodePtr &curNode);
38     static void GetAnDSetPrevNodeList(napi_env env, xmlNodePtr curNode);
39 };
40 
Trim(napi_env env,std::string strXmltrim)41 std::string CxmlTest::Trim(napi_env env, std::string strXmltrim)
42 {
43     ConvertXml convert(env);
44     return convert.Trim(strXmltrim);
45 }
46 
GetNodeType(napi_env env,const xmlElementType enumType)47 std::string CxmlTest::GetNodeType(napi_env env, const xmlElementType enumType)
48 {
49     ConvertXml convert(env);
50     return convert.GetNodeType(enumType);
51 }
52 
GetPrevNodeList(napi_env env,xmlNodePtr curNode)53 void CxmlTest::GetPrevNodeList(napi_env env, xmlNodePtr curNode)
54 {
55     ConvertXml convert(env);
56     convert.GetPrevNodeList(env, curNode);
57 }
58 
SetXmlElementType(napi_env env,xmlNodePtr curNode,const napi_value & elementsObject,bool & bFlag,char * curContent)59 void CxmlTest::SetXmlElementType(napi_env env, xmlNodePtr curNode, const napi_value &elementsObject,
60                                  bool &bFlag, char *curContent)
61 {
62     ConvertXml convert(env);
63     convert.SetXmlElementType(env, curNode, elementsObject, bFlag, curContent);
64 }
65 
SetNodeInfo(napi_env env,xmlNodePtr curNode,const napi_value & elementsObject)66 void CxmlTest::SetNodeInfo(napi_env env, xmlNodePtr curNode, const napi_value &elementsObject)
67 {
68     ConvertXml convert(env);
69     convert.SetNodeInfo(env, curNode, elementsObject);
70 }
71 
DealSpaces(napi_env env,const napi_value napiObj)72 void CxmlTest::DealSpaces(napi_env env, const napi_value napiObj)
73 {
74     ConvertXml convert(env);
75     convert.DealSpaces(env, napiObj);
76 }
77 
SetDefaultKey(napi_env env,size_t i,const std::string strRecv)78 void CxmlTest::SetDefaultKey(napi_env env, size_t i, const std::string strRecv)
79 {
80     ConvertXml convert(env);
81     convert.SetDefaultKey(i, strRecv);
82 }
83 
DealSingleLine(napi_env env,std::string & strXml,const napi_value & object)84 void CxmlTest::DealSingleLine(napi_env env, std::string &strXml, const napi_value &object)
85 {
86     ConvertXml convert(env);
87     convert.DealSingleLine(env, strXml, object);
88 }
89 
DealComplex(napi_env env,std::string & strXml,const napi_value & object)90 void CxmlTest::DealComplex(napi_env env, std::string &strXml, const napi_value &object)
91 {
92     ConvertXml convert(env);
93     convert.DealComplex(env, strXml, object);
94 }
95 
Replace(napi_env env,std::string & str,const std::string src,const std::string dst)96 void CxmlTest::Replace(napi_env env, std::string &str, const std::string src, const std::string dst)
97 {
98     ConvertXml convert(env);
99     convert.Replace(str, src, dst);
100 }
101 
DealCDataInfo(napi_env env,bool bCData,xmlNodePtr & curNode)102 void CxmlTest::DealCDataInfo(napi_env env, bool bCData, xmlNodePtr &curNode)
103 {
104     ConvertXml convert(env);
105     convert.DealCDataInfo(bCData, curNode);
106 }
107 
GetAnDSetPrevNodeList(napi_env env,xmlNodePtr curNode)108 void CxmlTest::GetAnDSetPrevNodeList(napi_env env, xmlNodePtr curNode)
109 {
110     ConvertXml convert(env);
111     convert.GetPrevNodeList(env, curNode);
112     convert.GetPrevNodeList(env, curNode);
113 
114     napi_value recvElement = nullptr;
115     napi_create_array(env, &recvElement);
116     int32_t index = 0;
117     convert.SetPrevInfo(env, recvElement, 0, index);
118 }
119 }
120 #endif // TEST_CONVERTXML_H
121