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_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, bool &bFlag);
30     static void SetNodeInfo(napi_env env, xmlNodePtr curNode, const napi_value &elementsObject);
31     static void DealSpaces(napi_env env, const napi_value napiObj);
32     static void SetDefaultKey(napi_env env, size_t i, const std::string strRecv);
33     static void DealSingleLine(napi_env env, std::string &strXml, const napi_value &object);
34     static void DealComplex(napi_env env, std::string &strXml, const napi_value &object);
35     static void Replace(napi_env env, std::string &str, const std::string src, const std::string dst);
36     static void DealCDataInfo(napi_env env, bool bCData, xmlNodePtr &curNode);
37     static void GetAnDSetPrevNodeList(napi_env env, xmlNodePtr curNode);
38 };
39 
Trim(napi_env env,std::string strXmltrim)40 std::string CxmlTest::Trim(napi_env env, std::string strXmltrim)
41 {
42     ConvertXml convert(env);
43     return convert.Trim(strXmltrim);
44 }
45 
GetNodeType(napi_env env,const xmlElementType enumType)46 std::string CxmlTest::GetNodeType(napi_env env, const xmlElementType enumType)
47 {
48     ConvertXml convert(env);
49     return convert.GetNodeType(enumType);
50 }
51 
GetPrevNodeList(napi_env env,xmlNodePtr curNode)52 void CxmlTest::GetPrevNodeList(napi_env env, xmlNodePtr curNode)
53 {
54     ConvertXml convert(env);
55     convert.GetPrevNodeList(env, curNode);
56 }
57 
SetXmlElementType(napi_env env,xmlNodePtr curNode,const napi_value & elementsObject,bool & bFlag)58 void CxmlTest::SetXmlElementType(napi_env env, xmlNodePtr curNode, const napi_value &elementsObject, bool &bFlag)
59 {
60     ConvertXml convert(env);
61     convert.SetXmlElementType(env, curNode, elementsObject, bFlag);
62 }
63 
SetNodeInfo(napi_env env,xmlNodePtr curNode,const napi_value & elementsObject)64 void CxmlTest::SetNodeInfo(napi_env env, xmlNodePtr curNode, const napi_value &elementsObject)
65 {
66     ConvertXml convert(env);
67     convert.SetNodeInfo(env, curNode, elementsObject);
68 }
69 
DealSpaces(napi_env env,const napi_value napiObj)70 void CxmlTest::DealSpaces(napi_env env, const napi_value napiObj)
71 {
72     ConvertXml convert(env);
73     convert.DealSpaces(env, napiObj);
74 }
75 
SetDefaultKey(napi_env env,size_t i,const std::string strRecv)76 void CxmlTest::SetDefaultKey(napi_env env, size_t i, const std::string strRecv)
77 {
78     ConvertXml convert(env);
79     convert.SetDefaultKey(i, strRecv);
80 }
81 
DealSingleLine(napi_env env,std::string & strXml,const napi_value & object)82 void CxmlTest::DealSingleLine(napi_env env, std::string &strXml, const napi_value &object)
83 {
84     ConvertXml convert(env);
85     convert.DealSingleLine(env, strXml, object);
86 }
87 
DealComplex(napi_env env,std::string & strXml,const napi_value & object)88 void CxmlTest::DealComplex(napi_env env, std::string &strXml, const napi_value &object)
89 {
90     ConvertXml convert(env);
91     convert.DealComplex(env, strXml, object);
92 }
93 
Replace(napi_env env,std::string & str,const std::string src,const std::string dst)94 void CxmlTest::Replace(napi_env env, std::string &str, const std::string src, const std::string dst)
95 {
96     ConvertXml convert(env);
97     convert.Replace(str, src, dst);
98 }
99 
DealCDataInfo(napi_env env,bool bCData,xmlNodePtr & curNode)100 void CxmlTest::DealCDataInfo(napi_env env, bool bCData, xmlNodePtr &curNode)
101 {
102     ConvertXml convert(env);
103     convert.DealCDataInfo(bCData, curNode);
104 }
105 
GetAnDSetPrevNodeList(napi_env env,xmlNodePtr curNode)106 void CxmlTest::GetAnDSetPrevNodeList(napi_env env, xmlNodePtr curNode)
107 {
108     ConvertXml convert(env);
109     convert.GetPrevNodeList(env, curNode);
110     convert.GetPrevNodeList(env, curNode);
111 
112     napi_value recvElement = nullptr;
113     napi_create_array(env, &recvElement);
114     int32_t index = 0;
115     convert.SetPrevInfo(env, recvElement, 0, index);
116 }
117 }
118 #endif // TEST_CONVERTXML_H
119