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 21namespace OHOS::Xml { 22class CxmlTest { 23public: 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 40std::string CxmlTest::Trim(napi_env env, std::string strXmltrim) 41{ 42 ConvertXml convert(env); 43 return convert.Trim(strXmltrim); 44} 45 46std::string CxmlTest::GetNodeType(napi_env env, const xmlElementType enumType) 47{ 48 ConvertXml convert(env); 49 return convert.GetNodeType(enumType); 50} 51 52void CxmlTest::GetPrevNodeList(napi_env env, xmlNodePtr curNode) 53{ 54 ConvertXml convert(env); 55 convert.GetPrevNodeList(env, curNode); 56} 57 58void 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 64void CxmlTest::SetNodeInfo(napi_env env, xmlNodePtr curNode, const napi_value &elementsObject) 65{ 66 ConvertXml convert(env); 67 convert.SetNodeInfo(env, curNode, elementsObject); 68} 69 70void CxmlTest::DealSpaces(napi_env env, const napi_value napiObj) 71{ 72 ConvertXml convert(env); 73 convert.DealSpaces(env, napiObj); 74} 75 76void CxmlTest::SetDefaultKey(napi_env env, size_t i, const std::string strRecv) 77{ 78 ConvertXml convert(env); 79 convert.SetDefaultKey(i, strRecv); 80} 81 82void 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 88void 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 94void 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 100void CxmlTest::DealCDataInfo(napi_env env, bool bCData, xmlNodePtr &curNode) 101{ 102 ConvertXml convert(env); 103 convert.DealCDataInfo(bCData, curNode); 104} 105 106void 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