diff --git a/convertxml/BUILD.gn b/convertxml/BUILD.gn index a2ac7c536b7250ae16d2459827d607085065270f..ebace8736b09cf77214256938bf52d4d4212ca67 100755 --- a/convertxml/BUILD.gn +++ b/convertxml/BUILD.gn @@ -11,16 +11,50 @@ # See the License for the specific language governing permissions and # limitations under the License. +import("//ark/ts2abc/ts2panda/ts2abc_config.gni") import("//build/ohos.gni") import("//build/ohos/ace/ace.gni") +import("//foundation/ace/ace_engine/ace_config.gni") + +# compile .js to .abc. +action("gen_convertxml_abc") { + visibility = [ ":*" ] + script = "//ark/ts2abc/ts2panda/scripts/generate_js_bytecode.py" + + args = [ + "--src-js", + rebase_path("//base/compileruntime/js_api_module/convertxml/js_convertxml.js"), + "--dst-file", + rebase_path(target_out_dir + "/convertxml.abc"), + "--node", + rebase_path("${node_path}"), + "--frontend-tool-path", + rebase_path("${ts2abc_build_path}"), + "--node-modules", + rebase_path("${node_modules}"), + ] + deps = [ "//ark/ts2abc/ts2panda:ark_ts2abc_build" ] + + inputs = [ "//base/compileruntime/js_api_module/convertxml/js_convertxml.js" ] + outputs = [ target_out_dir + "/convertxml.abc" ] +} base_output_path = get_label_info(":js_convertxml", "target_out_dir") js_xml_obj_path = base_output_path + "/convertxml.o" + gen_js_obj("js_convertxml") { input = "//base/compileruntime/js_api_module/convertxml/js_convertxml.js" output = js_xml_obj_path } +abc_output_path = get_label_info(":convertxml_abc", "target_out_dir") +convertxml_abc_obj_path = abc_output_path + "/convertxml_abc.o" +gen_js_obj("convertxml_abc") { + input = "$target_out_dir/convertxml.abc" + output = convertxml_abc_obj_path + dep = ":gen_convertxml_abc" +} + ohos_shared_library("convertxml") { include_dirs = [ "//third_party/icu/icu4c/source/common", @@ -36,6 +70,7 @@ ohos_shared_library("convertxml") { ] deps = [ + ":convertxml_abc", ":js_convertxml", "//base/compileruntime/js_api_module/convertxml/:js_convertxml", "//foundation/ace/napi/:ace_napi", diff --git a/convertxml/js_convertxml.cpp b/convertxml/js_convertxml.cpp index 727565fbfb941d4e75a6feea024641ce787c9ef3..65a409449cc5d6fbc39227e9b032f7c44c4e0005 100755 --- a/convertxml/js_convertxml.cpp +++ b/convertxml/js_convertxml.cpp @@ -114,12 +114,16 @@ void ConvertXml::GetPrevNodeList(xmlNodePtr curNode) if (curNode->type == xmlElementType::XML_PI_NODE && !m_Options.ignoreInstruction) { SetKeyValue(elementsObject, m_Options.type, GetNodeType(curNode->type)); SetKeyValue(elementsObject, m_Options.name, (char*)curNode->name); - SetKeyValue(elementsObject, m_Options.instruction, (const char*)xmlNodeGetContent(curNode)); + if (xmlNodeGetContent(curNode) != nullptr) { + SetKeyValue(elementsObject, m_Options.instruction, (const char*)xmlNodeGetContent(curNode)); + } m_prevObj.push_back(elementsObject); } if (curNode->type == xmlElementType::XML_COMMENT_NODE && !m_Options.ignoreComment) { SetKeyValue(elementsObject, m_Options.type, GetNodeType(curNode->type)); - SetKeyValue(elementsObject, m_Options.comment, (const char*)xmlNodeGetContent(curNode)); + if (xmlNodeGetContent(curNode) != nullptr) { + SetKeyValue(elementsObject, m_Options.comment, (const char*)xmlNodeGetContent(curNode)); + } m_prevObj.push_back(elementsObject); } if (curNode->type == xmlElementType::XML_DTD_NODE && !m_Options.ignoreDoctype) { @@ -147,34 +151,44 @@ void ConvertXml::SetAttributes(xmlNodePtr curNode, napi_value &elementsObject) void ConvertXml::SetXmlElementType(xmlNodePtr curNode, napi_value &elementsObject, bool &bFlag) { if (curNode->type == xmlElementType::XML_PI_NODE && !m_Options.ignoreInstruction) { - SetKeyValue(elementsObject, m_Options.instruction.c_str(), (const char*)xmlNodeGetContent(curNode)); - bFlag = true; + if (xmlNodeGetContent(curNode) != nullptr) { + SetKeyValue(elementsObject, m_Options.instruction.c_str(), (const char*)xmlNodeGetContent(curNode)); + bFlag = true; + } } else if (curNode->type == xmlElementType::XML_COMMENT_NODE && !m_Options.ignoreComment) { - SetKeyValue(elementsObject, m_Options.comment.c_str(), (const char*)xmlNodeGetContent(curNode)); - bFlag = true; + if (xmlNodeGetContent(curNode) != nullptr) { + SetKeyValue(elementsObject, m_Options.comment.c_str(), (const char*)xmlNodeGetContent(curNode)); + bFlag = true; + } } else if (curNode->type == xmlElementType::XML_CDATA_SECTION_NODE && !m_Options.ignoreCdata) { - SetKeyValue(elementsObject, m_Options.cdata, (const char*)xmlNodeGetContent(curNode)); - bFlag = true; + if (xmlNodeGetContent(curNode) != nullptr) { + SetKeyValue(elementsObject, m_Options.cdata, (const char*)xmlNodeGetContent(curNode)); + bFlag = true; + } } } void ConvertXml::SetNodeInfo(xmlNodePtr curNode, napi_value &elementsObject) { - if (curNode->type == xmlElementType::XML_PI_NODE) { - if (!m_Options.ignoreInstruction) { - SetKeyValue(elementsObject, m_Options.type, GetNodeType(curNode->type)); - } + if (curNode->type == xmlElementType::XML_TEXT_NODE) { + return; } else { - SetKeyValue(elementsObject, m_Options.type, GetNodeType(curNode->type)); - } - if ((curNode->type != xmlElementType::XML_COMMENT_NODE) && - (curNode->type != xmlElementType::XML_CDATA_SECTION_NODE)) { - if (!(curNode->type == xmlElementType::XML_PI_NODE && m_Options.ignoreInstruction)) { - SetKeyValue(elementsObject, m_Options.name, (char*)curNode->name); + if (curNode->type == xmlElementType::XML_PI_NODE) { + if (!m_Options.ignoreInstruction) { + SetKeyValue(elementsObject, m_Options.type, GetNodeType(curNode->type)); + } + } else { + SetKeyValue(elementsObject, m_Options.type, GetNodeType(curNode->type)); + } + if ((curNode->type != xmlElementType::XML_COMMENT_NODE) && + (curNode->type != xmlElementType::XML_CDATA_SECTION_NODE)) { + if (!(curNode->type == xmlElementType::XML_PI_NODE && m_Options.ignoreInstruction)) { + SetKeyValue(elementsObject, m_Options.name, (char*)curNode->name); + } } } } -void ConvertXml::SetEndInfo(xmlNodePtr curNode, napi_value &elementsObject, bool &bFlag, bool &bText, int32_t index) +void ConvertXml::SetEndInfo(xmlNodePtr curNode, napi_value &elementsObject, bool &bFlag) { SetKeyValue(elementsObject, m_Options.type, GetNodeType(curNode->type)); if (curNode->type == xmlElementType::XML_ELEMENT_NODE) { @@ -182,16 +196,17 @@ void ConvertXml::SetEndInfo(xmlNodePtr curNode, napi_value &elementsObject, bool bFlag = true; } else if (curNode->type == xmlElementType::XML_TEXT_NODE) { if (m_Options.trim) { - SetKeyValue(elementsObject, m_Options.text, Trim((const char*)xmlNodeGetContent(curNode))); + if (xmlNodeGetContent(curNode) != nullptr) { + SetKeyValue(elementsObject, m_Options.text, Trim((const char*)xmlNodeGetContent(curNode))); + } } else { - SetKeyValue(elementsObject, m_Options.text, (const char*)xmlNodeGetContent(curNode)); + if (xmlNodeGetContent(curNode) != nullptr) { + SetKeyValue(elementsObject, m_Options.text, (const char*)xmlNodeGetContent(curNode)); + } } if (!m_Options.ignoreText) { bFlag = true; } - if (index != 0) { - bText = false; - } } } @@ -208,21 +223,17 @@ void ConvertXml::GetXMLInfo(xmlNodePtr curNode, napi_value &object, int flag) { napi_value elements = nullptr; napi_create_array(env_, &elements); - napi_value recvElement; + napi_value recvElement = nullptr; napi_create_array(env_, &recvElement); xmlNodePtr pNode = curNode; int32_t index = 0; int32_t index1 = 0; bool bFlag = false; - bool bText = true; while (pNode != nullptr) { bFlag = false; - bText = true; napi_value elementsObject = nullptr; napi_create_object(env_, &elementsObject); - if (flag == 0 || (index % 2 != 0)) { // 2:pNode - SetNodeInfo(pNode, elementsObject); - } + SetNodeInfo(pNode, elementsObject); SetAttributes(pNode, elementsObject); napi_value tempElement = nullptr; napi_create_array(env_, &tempElement); @@ -233,16 +244,15 @@ void ConvertXml::GetXMLInfo(xmlNodePtr curNode, napi_value &object, int flag) curNode = pNode->children; GetXMLInfo(curNode, elementsObject, 1); bFlag = true; - } else if (index % 2 != 0) { // 2:pNode + } else { SetXmlElementType(pNode, elementsObject, bFlag); - } else if (pNode->next == nullptr) { - SetEndInfo(pNode, elementsObject, bFlag, bText, index); + SetEndInfo(pNode, elementsObject, bFlag); } } SetPrevInfo(recvElement, flag, index1); - if (elementsObject != nullptr && bFlag && bText) { - napi_set_element(env_, recvElement, index1++, elementsObject); - elementsObject = nullptr; + if (elementsObject != nullptr && bFlag) { + napi_set_element(env_, recvElement, index1++, elementsObject); + elementsObject = nullptr; } index++; pNode = pNode->next; @@ -252,37 +262,8 @@ void ConvertXml::GetXMLInfo(xmlNodePtr curNode, napi_value &object, int flag) } } -napi_value ConvertXml::convert(std::string strXml) +void ConvertXml::SetSpacesInfo(napi_value &object) { - xmlDocPtr doc = NULL; - xmlNodePtr curNode = NULL; - napi_status status = napi_ok; - size_t len = strXml.size(); - doc = xmlParseMemory(strXml.c_str(), len); - if (!doc) { - xmlFreeDoc(doc); - } - napi_value object = nullptr; - status = napi_create_object(env_, &object); - if (status != napi_ok) { - return NULL; - } - napi_value subObject = nullptr; - napi_value subSubObject = nullptr; - napi_value napiKey = nullptr; - napi_create_object(env_, &subSubObject); - napi_create_object(env_, &subObject); - napi_create_string_utf8(env_, (const char*)doc->version, NAPI_AUTO_LENGTH, &napiKey); - napi_set_named_property(env_, subSubObject, "version", napiKey); - napi_create_string_utf8(env_, (const char*)doc->encoding, NAPI_AUTO_LENGTH, &napiKey); - napi_set_named_property(env_, subSubObject, "encoding", napiKey); - if (!m_Options.ignoreDeclaration) { - napi_set_named_property(env_, subObject, m_Options.attributes.c_str(), subSubObject); - napi_set_named_property(env_, object, m_Options.declaration.c_str(), subObject); - } - curNode = xmlDocGetRootElement(doc); - GetPrevNodeList(curNode); - GetXMLInfo(curNode, object, 0); napi_value iTemp = nullptr; switch (m_SpaceType) { case (SpaceType::T_INT32): @@ -297,7 +278,50 @@ napi_value ConvertXml::convert(std::string strXml) break; default: break; + } +} + +napi_value ConvertXml::convert(std::string strXml) +{ + xmlDocPtr doc = nullptr; + xmlNodePtr curNode = nullptr; + napi_status status = napi_ok; + napi_value object = nullptr; + status = napi_create_object(env_, &object); + if (status != napi_ok) { + return nullptr; } + Replace(strXml, "\\r", "\r"); + Replace(strXml, "\\n", "\n"); + Replace(strXml, "\\v", "\v"); + Replace(strXml, "]]> version != nullptr) { + SetKeyValue(subSubObject, "version", (const char*)doc->version); + } + if (doc != nullptr && doc->encoding != nullptr) { + SetKeyValue(subSubObject, "encoding", (const char*)doc->encoding); + } + if (!m_Options.ignoreDeclaration && strXml.find("xml") != std::string::npos) { + napi_set_named_property(env_, subObject, m_Options.attributes.c_str(), subSubObject); + napi_set_named_property(env_, object, m_Options.declaration.c_str(), subObject); + } + if (doc != nullptr) { + curNode = xmlDocGetRootElement(doc); + GetPrevNodeList(curNode); + GetXMLInfo(curNode, object, 0); + } + SetSpacesInfo(object); return object; } @@ -310,9 +334,10 @@ napi_status ConvertXml::DealNapiStrValue(napi_value napi_StrValue, std::string & if (status != napi_ok) { return status; } - buffer = new char[bufferSize + 1]; - napi_get_value_string_utf8(env_, napi_StrValue, buffer, bufferSize + 1, &bufferSize); - + if (bufferSize > 0) { + buffer = new char[bufferSize + 1]; + napi_get_value_string_utf8(env_, napi_StrValue, buffer, bufferSize + 1, &bufferSize); + } if (buffer != nullptr) { result = buffer; delete []buffer; @@ -341,8 +366,9 @@ void ConvertXml::DealSpaces(napi_value napi_obj) void ConvertXml::DealIgnore(napi_value napi_obj) { - std::vectorvctIgnore = { "compact", "trim", "ignoreDeclaration", "ignoreInstruction", - "ignoreAttributes", "ignoreComment", "ignoreCdata", "ignoreDoctype", "ignoreText" }; + std::vector vctIgnore = {"compact", "trim", "ignoreDeclaration", "ignoreInstruction", + "ignoreAttributes", "ignoreComment", "ignoreCdata", + "ignoreDoctype", "ignoreText"}; for (size_t i = 0; i < vctIgnore.size(); ++i) { napi_value recvTemp = nullptr; bool bRecv = false; @@ -426,8 +452,9 @@ void ConvertXml::SetDefaultKey(size_t i, std::string strRecv) void ConvertXml::DealOptions(napi_value napi_obj) { - std::vectorvctOptions = { "declarationKey", "instructionKey", "attributesKey", "textKey", - "cdataKey", "doctypeKey", "commentKey", "parentKey", "typeKey", "nameKey", "elementsKey" }; + std::vector vctOptions = {"declarationKey", "instructionKey", "attributesKey", "textKey", + "cdataKey", "doctypeKey", "commentKey", "parentKey", "typeKey", + "nameKey", "elementsKey"}; for (size_t i = 0; i < vctOptions.size(); ++i) { napi_value recvTemp = nullptr; std::string strRecv = ""; @@ -439,3 +466,117 @@ void ConvertXml::DealOptions(napi_value napi_obj) DealIgnore(napi_obj); DealSpaces(napi_obj); } + +void ConvertXml::DealSingleLine(std::string &strXml, napi_value &object) +{ + size_t iXml = 0; + if ((iXml = strXml.find("xml")) != std::string::npos) { + m_XmlInfo.bXml = true; + napi_value declObj = nullptr; + napi_create_object(env_, &declObj); + napi_value attrObj = nullptr; + bool bFlag = false; + napi_create_object(env_, &attrObj); + if (strXml.find("version=") != std::string::npos) { + m_XmlInfo.bVersion = true; + SetKeyValue(attrObj, "version", "1.0"); + bFlag = true; + } + if (strXml.find("encoding=") != std::string::npos) { + m_XmlInfo.bEncoding = false; + SetKeyValue(attrObj, "encoding", "utf-8"); + bFlag = true; + } + if (bFlag) { + napi_set_named_property(env_, declObj, m_Options.attributes.c_str(), attrObj); + napi_set_named_property(env_, object, m_Options.declaration.c_str(), declObj); + } else { + napi_set_named_property(env_, object, m_Options.declaration.c_str(), declObj); + } + if (strXml.find(">", iXml) == strXml.size() - 1) { + strXml = ""; + } else { + strXml = strXml.substr(0, strXml.rfind("<", iXml)) + strXml.substr(strXml.find(">", iXml) + 1); + } + } + size_t iCount = 0; + size_t iLen = strXml.size(); + for (; iCount < iLen; ++iCount) { + if (strXml[iCount] != ' ' && strXml[iCount] != '\v' && + strXml[iCount] != '\t' && strXml[iCount] != '\n') { + break; + } + } + if (iCount < iLen) { + DealComplex(strXml, object); + } +} + +void ConvertXml::DealComplex(std::string &strXml, napi_value &object) +{ + if (strXml.find(""; + } else { + strXml = "" + strXml + ""; + } + xmlDocPtr doc = nullptr; + xmlNodePtr curNode = nullptr; + size_t len = strXml.size(); + doc = xmlParseMemory(strXml.c_str(), len); + if (!doc) { + xmlFreeDoc(doc); + } + if (doc) { + curNode = xmlDocGetRootElement(doc); + curNode = curNode->children; + napi_value elements = nullptr; + napi_create_array(env_, &elements); + bool bHasEle = false; + int index = 0; + bool bCData = false; + if (strXml.find("type == xmlElementType::XML_CDATA_SECTION_NODE && + curNode->next && curNode->next->type == xmlElementType::XML_TEXT_NODE && + curNode->next->next && curNode->next->next->type == xmlElementType::XML_CDATA_SECTION_NODE) { + if (xmlNodeGetContent(curNode->next) != nullptr) { + std::string strTemp = (char*)xmlNodeGetContent(curNode->next); + Replace(strTemp, " ", ""); + Replace(strTemp, "\v", ""); + Replace(strTemp, "\t", ""); + Replace(strTemp, "\n", ""); + if (strTemp == "") { + curNode = curNode->next->next; + } + } + } else { + curNode = curNode->next; + } +} \ No newline at end of file diff --git a/convertxml/js_convertxml.h b/convertxml/js_convertxml.h index bbe2381f45ee7f6bed5299e47fec8a62e98ed162..380fab061d5f01912e2b37e8dc2449bfecf5fb2e 100755 --- a/convertxml/js_convertxml.h +++ b/convertxml/js_convertxml.h @@ -30,33 +30,41 @@ enum class SpaceType { }; struct Options { - std::string declaration = "_declaration"; - std::string instruction = "_instruction"; - std::string attributes = "_attributes"; - std::string text = "_text"; - std::string cdata = "_cdata"; - std::string doctype = "_doctype"; - std::string comment = "_comment"; - std::string parent = "_parent"; - std::string type = "_type"; - std::string name = "_name"; - std::string elements = "_elements"; - bool compact = false; - bool trim = false; - bool nativetype = false; - bool nativetypeattributes = false; - bool addparent = false; - bool alwaysArray = false; - bool alwaysChildren = false; - bool instructionHasAttributes = false; - bool ignoreDeclaration = false; - bool ignoreInstruction = false; - bool ignoreAttributes = false; - bool ignoreComment = false; - bool ignoreCdata = false; - bool ignoreDoctype = false; - bool ignoreText = false; - bool spaces = false; + std::string declaration = "_declaration"; + std::string instruction = "_instruction"; + std::string attributes = "_attributes"; + std::string text = "_text"; + std::string cdata = "_cdata"; + std::string doctype = "_doctype"; + std::string comment = "_comment"; + std::string parent = "_parent"; + std::string type = "_type"; + std::string name = "_name"; + std::string elements = "_elements"; + bool compact = false; + bool trim = false; + bool nativetype = false; + bool nativetypeattributes = false; + bool addparent = false; + bool alwaysArray = false; + bool alwaysChildren = false; + bool instructionHasAttributes = false; + bool ignoreDeclaration = false; + bool ignoreInstruction = false; + bool ignoreAttributes = false; + bool ignoreComment = false; + bool ignoreCdata = false; + bool ignoreDoctype = false; + bool ignoreText = false; + bool spaces = false; +}; + +struct XmlInfo { + bool bXml = false; + bool bVersion = false; + std::string strVersion = ""; + bool bEncoding = false; + std::string strEncoding = ""; }; class ConvertXml { @@ -66,7 +74,7 @@ public: void SetAttributes(xmlNodePtr curNode, napi_value &elementsObject); void SetXmlElementType(xmlNodePtr curNode, napi_value &elementsObject, bool &bFlag); void SetNodeInfo(xmlNodePtr curNode, napi_value &elementsObject); - void SetEndInfo(xmlNodePtr curNode, napi_value &elementsObject, bool &bFlag, bool &bText, int32_t index); + void SetEndInfo(xmlNodePtr curNode, napi_value &elementsObject, bool &bFlag); void GetXMLInfo(xmlNodePtr curNode, napi_value &object, int flag = 0); napi_value convert(std::string strXml); std::string GetNodeType(xmlElementType enumType); @@ -79,6 +87,11 @@ public: void DealIgnore(napi_value napi_obj); void SetPrevInfo(napi_value &recvElement, int flag, int32_t &index1); void SetDefaultKey(size_t i, std::string strRecv); + void SetSpacesInfo(napi_value &object); + void DealSingleLine(std::string &strXml, napi_value &object); + void DealComplex(std::string &strXml, napi_value &object); + void Replace(std::string &str, const std::string src, const std::string dst); + void DealCDataInfo(bool bCData, xmlNodePtr &curNode); private: napi_env env_; SpaceType m_SpaceType; @@ -86,5 +99,6 @@ private: std::string m_strSpace; Options m_Options; std::vector m_prevObj; + XmlInfo m_XmlInfo; }; #endif \ No newline at end of file diff --git a/convertxml/js_convertxml.js b/convertxml/js_convertxml.js old mode 100755 new mode 100644 index a0305b036471c70e26b7e2e989878f63a6464e36..e045ea7af880775d6a90ebbe6fda58f36bca7b02 --- a/convertxml/js_convertxml.js +++ b/convertxml/js_convertxml.js @@ -21,14 +21,106 @@ class ConvertXml { this.convertxmlclass = new convertXml.ConvertXml(); } convert(strXml, options) { + strXml = DealXml(strXml); let converted = this.convertxmlclass.convert(strXml, options); let space = 0; if (converted.hasOwnProperty("spaces")) { space = converted.spaces; delete converted.spaces; } - return JSON.stringify(converted, null, space); + var strEnd = JSON.stringify(converted, null, space); + var idx = 0; + while ((idx = strEnd.indexOf('\\t')) != -1) { + strEnd = strEnd.substring(0, idx) + '\t' + strEnd.substring(idx + 2); + } + while ((idx = strEnd.indexOf('\\n')) != -1) { + strEnd = strEnd.substring(0, idx) + '\n' + strEnd.substring(idx + 2); + } + while ((idx = strEnd.indexOf('\\')) != -1) { + strEnd = strEnd.substring(0, idx) + '' + strEnd.substring(idx + 1); + } + return strEnd; + } +} + +function DealXml(strXml) +{ + var idx = 0; + var idxSec = 0; + var idxThir = 0; + var idxCData = 0; + var idxCDataSec = 0; + while ((idx = strXml.indexOf(']]>', idxSec)) != -1) { + idxThir = strXml.indexOf('<', idx); + strXml = DealReplace(strXml, idx, idxThir); + if (strXml.indexOf('<', idx) != -1) { + idxCData = strXml.indexOf('', idxCData); + var i = idx + 1; + for (; i < idxThir ; i++) { + var cXml = strXml.charAt(i) + switch (cXml) { + case '\n': + strXml = strXml.substring(0, i) + '\\n' + strXml.substring(i + 1); + break; + case '\v': + strXml = strXml.substring(0, i) + '\\v' + strXml.substring(i + 1); + break; + case '\t': + strXml = strXml.substring(0, i) + '\\t' + strXml.substring(i + 1); + break; + default: + break; + } + } + idxCDataSec = idxSec; + } + } + else { + break; + } + } + return strXml; +} + +function DealReplace(strXml, idx, idxThir) +{ + var i = idx + 1; + for (; i < idxThir ; i++) { + var cXml = strXml.charAt(i); + if (cXml != '\n' && cXml != '\v' && cXml != '\t' && cXml != ' ') + { + break; + } + } + var j = idx + 1; + for (; j < strXml.indexOf('<', idx) ; j++) { + var cXml = strXml.charAt(j); + if (i != idxThir) { + switch (cXml) { + case '\n': + strXml = strXml.substring(0, j) + '\\n' + strXml.substring(j + 1); + break; + case '\v': + strXml = strXml.substring(0, j) + '\\v' + strXml.substring(j + 1); + break; + case '\t': + strXml = strXml.substring(0, j) + '\\t' + strXml.substring(j + 1); + break; + default: + break; + } + } else { + strXml = strXml.substring(0, j) + strXml.substring(j + 1); + --j; + } } + return strXml; } export default { diff --git a/convertxml/native_module_convertxml.cpp b/convertxml/native_module_convertxml.cpp index 25223d8adad4cf2b0b437238bfab6b4d63aaa71f..05ca39431e8171359fbb404df137cedd841f282d 100755 --- a/convertxml/native_module_convertxml.cpp +++ b/convertxml/native_module_convertxml.cpp @@ -19,6 +19,8 @@ extern const char _binary_js_convertxml_js_start[]; extern const char _binary_js_convertxml_js_end[]; +extern const char _binary_convertxml_abc_start[]; +extern const char _binary_convertxml_abc_end[]; static napi_value ConvertXmlConstructor(napi_env env, napi_callback_info info) { @@ -95,6 +97,16 @@ __attribute__((visibility("default"))) void NAPI_convertxml_GetJSCode(const char *bufLen = _binary_js_convertxml_js_end - _binary_js_convertxml_js_start; } } +extern "C" +__attribute__((visibility("default"))) void NAPI_convertxml_GetABCCode(const char** buf, int* buflen) +{ + if (buf != nullptr) { + *buf = _binary_convertxml_abc_start; + } + if (buflen != nullptr) { + *buflen = _binary_convertxml_abc_end - _binary_convertxml_abc_start; + } +} static napi_module ConvertXmlModule = { .nm_version = 1, @@ -106,7 +118,8 @@ static napi_module ConvertXmlModule = { .reserved = { 0 }, }; -extern "C" __attribute__ ((constructor)) void RegisterModule() { +extern "C" __attribute__ ((constructor)) void RegisterModule() +{ napi_module_register(&ConvertXmlModule); } diff --git a/ohos.build b/ohos.build index 78ce498f8f20a1076122ddc37358f15cdf140e13..f29595a7277028ecf3994117f37bb8831836a356 100755 --- a/ohos.build +++ b/ohos.build @@ -1,21 +1,21 @@ -{ - "subsystem": "ccruntime", - "parts": { - "jsapi_api": { - "variants": [ - "wearable", - "phone" - ], - "module_list": [ - "//base/compileruntime/js_api_module/uri:uri_packages", - "//base/compileruntime/js_api_module/url:url_packages", - "//base/compileruntime/js_api_module/convertxml:convertxml_packages" - ], - "inner_kits": [ - ], - "test_list": [ - "//base/compileruntime/js_api_module/test_uri/unittest:unittest" - ] - } - } -} +{ + "subsystem": "ccruntime", + "parts": { + "jsapi_api": { + "variants": [ + "wearable", + "phone" + ], + "module_list": [ + "//base/compileruntime/js_api_module/uri:uri_packages", + "//base/compileruntime/js_api_module/url:url_packages", + "//base/compileruntime/js_api_module/convertxml:convertxml_packages" + ], + "inner_kits": [ + ], + "test_list": [ + "//base/compileruntime/js_api_module/test_uri/unittest:unittest" + ] + } + } +} diff --git a/test_uri/unittest/BUILD.gn b/test_uri/unittest/BUILD.gn index 51f6637cfe0b442bd422055f9dd98ae67971c1a7..fcac9024c4cb1a04e4d4fb9f84c32214f8b99141 100755 --- a/test_uri/unittest/BUILD.gn +++ b/test_uri/unittest/BUILD.gn @@ -1,63 +1,63 @@ -# Copyright (c) 2021 Huawei Device Co., Ltd. -# 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. - -import("//build/test.gni") - -if (is_standard_system) { - module_output_path = "jsapi_api/napi" -} - -ohos_unittest("test_uri_unittest") { - module_out_path = module_output_path - - include_dirs = [ - "//base/compileruntime/js_api_module/uri", - "//foundation/ace/napi", - "//foundation/ace/napi/interfaces/kits", - "//foundation/ace/napi/native_engine", - "//foundation/ace/napi/native_engine/impl/quickjs", - "//third_party/icu/icu4c/source/common", - "//third_party/googletest/include", - "//third_party/node/src", - "//utils/native/base/include", - ] - - cflags = [ "-g3" ] - - sources = [ - "test_napi.cpp", - "test_quickjs.cpp", - ] - - deps = [ - "//base/compileruntime/js_api_module/uri:uri_packages", - "//foundation/ace/napi/:ace_napi", - "//foundation/ace/napi/:ace_napi_quickjs", - "//third_party/googletest:gtest", - "//third_party/googletest:gtest_main", - "//third_party/icu/icu4c:static_icuuc", - "//third_party/libuv:uv_static", - "//third_party/quickjs:qjs", - "//utils/native/base:utils", - "//utils/native/base:utilsecurec", - ] - - if (is_standard_system) { - external_deps = [ "hiviewdfx_hilog_native:libhilog" ] - } -} - -group("unittest") { - testonly = true - deps = [ ":test_uri_unittest" ] -} +# Copyright (c) 2021 Huawei Device Co., Ltd. +# 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. + +import("//build/test.gni") + +if (is_standard_system) { + module_output_path = "jsapi_api/napi" +} + +ohos_unittest("test_uri_unittest") { + module_out_path = module_output_path + + include_dirs = [ + "//base/compileruntime/js_api_module/uri", + "//foundation/ace/napi", + "//foundation/ace/napi/interfaces/kits", + "//foundation/ace/napi/native_engine", + "//foundation/ace/napi/native_engine/impl/quickjs", + "//third_party/icu/icu4c/source/common", + "//third_party/googletest/include", + "//third_party/node/src", + "//utils/native/base/include", + ] + + cflags = [ "-g3" ] + + sources = [ + "test_napi.cpp", + "test_quickjs.cpp", + ] + + deps = [ + "//base/compileruntime/js_api_module/uri:uri_packages", + "//foundation/ace/napi/:ace_napi", + "//foundation/ace/napi/:ace_napi_quickjs", + "//third_party/googletest:gtest", + "//third_party/googletest:gtest_main", + "//third_party/icu/icu4c:static_icuuc", + "//third_party/libuv:uv_static", + "//third_party/quickjs:qjs", + "//utils/native/base:utils", + "//utils/native/base:utilsecurec", + ] + + if (is_standard_system) { + external_deps = [ "hiviewdfx_hilog_native:libhilog" ] + } +} + +group("unittest") { + testonly = true + deps = [ ":test_uri_unittest" ] +} diff --git a/test_uri/unittest/test.h b/test_uri/unittest/test.h index 753199cf332de264e2097396495923991dfa140a..f826c4e1f337d1064fd20b37aae398cd550d8f9c 100755 --- a/test_uri/unittest/test.h +++ b/test_uri/unittest/test.h @@ -1,33 +1,33 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * 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. - */ - -#ifndef FOUNDATION_ACE_NAPI_TEST_UNITTEST_TEST_H -#define FOUNDATION_ACE_NAPI_TEST_UNITTEST_TEST_H - -#include "native_engine.h" - -#include "gtest/gtest.h" - -class NativeEngineTest : public testing::Test { -public: - NativeEngineTest(); - virtual ~NativeEngineTest(); - void SetUp() override {} - void TearDown() override {} -protected: - NativeEngine *engine_; -}; - +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * 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. + */ + +#ifndef FOUNDATION_ACE_NAPI_TEST_UNITTEST_TEST_H +#define FOUNDATION_ACE_NAPI_TEST_UNITTEST_TEST_H + +#include "native_engine.h" + +#include "gtest/gtest.h" + +class NativeEngineTest : public testing::Test { +public: + NativeEngineTest(); + virtual ~NativeEngineTest(); + void SetUp() override {} + void TearDown() override {} +protected: + NativeEngine *engine_; +}; + #endif /* FOUNDATION_ACE_NAPI_TEST_UNITTEST_TEST_H */ \ No newline at end of file diff --git a/test_uri/unittest/test_napi.cpp b/test_uri/unittest/test_napi.cpp index 95a077bcef1bd2436bca803cb55ae458e7ee2f4f..8c4dc9c0f6fc849d40903fae57927b29f712bbcd 100755 --- a/test_uri/unittest/test_napi.cpp +++ b/test_uri/unittest/test_napi.cpp @@ -1,414 +1,414 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * 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. - */ - -#include "test.h" -#include "napi/native_api.h" -#include "napi/native_node_api.h" -#include "utils/log.h" -#include "js_uri.h" - -#define ASSERT_CHECK_CALL(call) \ - { \ - ASSERT_EQ(call, napi_ok); \ - } - -#define ASSERT_CHECK_VALUE_TYPE(env, value, type) \ - { \ - napi_valuetype valueType = napi_undefined; \ - ASSERT_TRUE(value != nullptr); \ - ASSERT_CHECK_CALL(napi_typeof(env, value, &valueType)); \ - ASSERT_EQ(valueType, type); \ - } - -HWTEST_F(NativeEngineTest, ConstructorTest001, testing::ext::TestSize.Level0) -{ - napi_env env = (napi_env)engine_; - OHOS::Uri::Uri uri(env, "http://username:password@www.baidu.com:99/path/path?query#fagment"); - ASSERT_STREQ(uri.GetScheme().c_str(), "http"); - ASSERT_STREQ(uri.GetAuthority().c_str(), "username:password@www.baidu.com:99"); - ASSERT_STREQ(uri.GetSsp().c_str(), "//username:password@www.baidu.com:99/path/path?query"); - ASSERT_STREQ(uri.GetUserinfo().c_str(), "username:password"); - ASSERT_STREQ(uri.GetHost().c_str(), "www.baidu.com"); - ASSERT_STREQ(uri.GetPort().c_str(), "99"); - ASSERT_STREQ(uri.GetPath().c_str(), "/path/path"); - ASSERT_STREQ(uri.GetQuery().c_str(), "query"); - ASSERT_STREQ(uri.GetFragment().c_str(), "fagment"); -} - -HWTEST_F(NativeEngineTest, ConstructorTest002, testing::ext::TestSize.Level0) -{ - napi_env env = (napi_env)engine_; - OHOS::Uri::Uri uri(env, "http://username:password@[1080::8:800:200C:417A]:99/path/66path1?query#fagment"); - ASSERT_STREQ(uri.GetScheme().c_str(), "http"); - ASSERT_STREQ(uri.GetAuthority().c_str(), "username:password@[1080::8:800:200C:417A]:99"); - ASSERT_STREQ(uri.GetSsp().c_str(), "//username:password@[1080::8:800:200C:417A]:99/path/66path1?query"); - ASSERT_STREQ(uri.GetUserinfo().c_str(), "username:password"); - ASSERT_STREQ(uri.GetHost().c_str(), "[1080::8:800:200C:417A]"); - ASSERT_STREQ(uri.GetPort().c_str(), "99"); - ASSERT_STREQ(uri.GetPath().c_str(), "/path/66path1"); - ASSERT_STREQ(uri.GetQuery().c_str(), "query"); - ASSERT_STREQ(uri.GetFragment().c_str(), "fagment"); -} - -HWTEST_F(NativeEngineTest, ConstructorTest003, testing::ext::TestSize.Level0) -{ - napi_env env = (napi_env)engine_; - OHOS::Uri::Uri uri(env, "http://username:password@[::]:88/path/path66?foooo#gaogao"); - ASSERT_STREQ(uri.GetScheme().c_str(), "http"); - ASSERT_STREQ(uri.GetAuthority().c_str(), "username:password@[::]:88"); - ASSERT_STREQ(uri.GetSsp().c_str(), "//username:password@[::]:88/path/path66?foooo"); - ASSERT_STREQ(uri.GetUserinfo().c_str(), "username:password"); - ASSERT_STREQ(uri.GetHost().c_str(), "[::]"); - ASSERT_STREQ(uri.GetPort().c_str(), "88"); - ASSERT_STREQ(uri.GetPath().c_str(), "/path/path66"); - ASSERT_STREQ(uri.GetQuery().c_str(), "foooo"); - ASSERT_STREQ(uri.GetFragment().c_str(), "gaogao"); -} - -HWTEST_F(NativeEngineTest, ConstructorTest004, testing::ext::TestSize.Level0) -{ - napi_env env = (napi_env)engine_; - OHOS::Uri::Uri uri(env, "http://username:password@[1:0:0:1:2:1:2:1]:99/path/66path1?query#fagment"); - ASSERT_STREQ(uri.GetScheme().c_str(), "http"); - ASSERT_STREQ(uri.GetAuthority().c_str(), "username:password@[1:0:0:1:2:1:2:1]:99"); - ASSERT_STREQ(uri.GetSsp().c_str(), "//username:password@[1:0:0:1:2:1:2:1]:99/path/66path1?query"); - ASSERT_STREQ(uri.GetUserinfo().c_str(), "username:password"); - ASSERT_STREQ(uri.GetHost().c_str(), "[1:0:0:1:2:1:2:1]"); - ASSERT_STREQ(uri.GetPort().c_str(), "99"); - ASSERT_STREQ(uri.GetPath().c_str(), "/path/66path1"); - ASSERT_STREQ(uri.GetQuery().c_str(), "query"); - ASSERT_STREQ(uri.GetFragment().c_str(), "fagment"); -} - -HWTEST_F(NativeEngineTest, ConstructorTest005, testing::ext::TestSize.Level0) -{ - napi_env env = (napi_env)engine_; - OHOS::Uri::Uri uri(env, "http://username:password@[::FFFF:129.144.52.38]:99/path/path?query#fagment"); - ASSERT_STREQ(uri.GetScheme().c_str(), "http"); - ASSERT_STREQ(uri.GetAuthority().c_str(), "username:password@[::FFFF:129.144.52.38]:99"); - ASSERT_STREQ(uri.GetSsp().c_str(), "//username:password@[::FFFF:129.144.52.38]:99/path/path?query"); - ASSERT_STREQ(uri.GetUserinfo().c_str(), "username:password"); - ASSERT_STREQ(uri.GetHost().c_str(), "[::FFFF:129.144.52.38]"); - ASSERT_STREQ(uri.GetPort().c_str(), "99"); - ASSERT_STREQ(uri.GetPath().c_str(), "/path/path"); - ASSERT_STREQ(uri.GetQuery().c_str(), "query"); - ASSERT_STREQ(uri.GetFragment().c_str(), "fagment"); -} - -HWTEST_F(NativeEngineTest, ConstructorTest006, testing::ext::TestSize.Level0) -{ - napi_env env = (napi_env)engine_; - OHOS::Uri::Uri uri(env, "http://username:password@[::192.9.5.5]:99/path/path?query#fagment"); - ASSERT_STREQ(uri.GetScheme().c_str(), "http"); - ASSERT_STREQ(uri.GetAuthority().c_str(), "username:password@[::192.9.5.5]:99"); - ASSERT_STREQ(uri.GetSsp().c_str(), "//username:password@[::192.9.5.5]:99/path/path?query"); - ASSERT_STREQ(uri.GetUserinfo().c_str(), "username:password"); - ASSERT_STREQ(uri.GetHost().c_str(), "[::192.9.5.5]"); - ASSERT_STREQ(uri.GetPort().c_str(), "99"); - ASSERT_STREQ(uri.GetPath().c_str(), "/path/path"); - ASSERT_STREQ(uri.GetQuery().c_str(), "query"); - ASSERT_STREQ(uri.GetFragment().c_str(), "fagment"); -} - -HWTEST_F(NativeEngineTest, ConstructorTest007, testing::ext::TestSize.Level0) -{ - napi_env env = (napi_env)engine_; - OHOS::Uri::Uri uri(env, "http://username:password@[22::22:2:2%ss]:99/path/path?query#fagment"); - ASSERT_STREQ(uri.GetScheme().c_str(), "http"); - ASSERT_STREQ(uri.GetAuthority().c_str(), "username:password@[22::22:2:2%ss]:99"); - ASSERT_STREQ(uri.GetSsp().c_str(), "//username:password@[22::22:2:2%ss]:99/path/path?query"); - ASSERT_STREQ(uri.GetUserinfo().c_str(), "username:password"); - ASSERT_STREQ(uri.GetHost().c_str(), "[22::22:2:2%ss]"); - ASSERT_STREQ(uri.GetPort().c_str(), "99"); - ASSERT_STREQ(uri.GetPath().c_str(), "/path/path"); - ASSERT_STREQ(uri.GetQuery().c_str(), "query"); - ASSERT_STREQ(uri.GetFragment().c_str(), "fagment"); -} - -HWTEST_F(NativeEngineTest, ConstructorTest008, testing::ext::TestSize.Level0) -{ - napi_env env = (napi_env)engine_; - OHOS::Uri::Uri uri(env, "http://username:password@[fe80:0000:0001:0000:0440:44ff:1233:5678]" - ":99/path/path?query#fagment"); - ASSERT_STREQ(uri.GetScheme().c_str(), "http"); - ASSERT_STREQ(uri.GetAuthority().c_str(), "username:password@[fe80:0000:0001:0000:0440:44ff:1233:5678]:99"); - ASSERT_STREQ(uri.GetSsp().c_str(), "//username:password@[fe80:0000:0001:0000:0440:44ff:1233:5678]" - ":99/path/path?query"); - ASSERT_STREQ(uri.GetUserinfo().c_str(), "username:password"); - ASSERT_STREQ(uri.GetHost().c_str(), "[fe80:0000:0001:0000:0440:44ff:1233:5678]"); - ASSERT_STREQ(uri.GetPort().c_str(), "99"); - ASSERT_STREQ(uri.GetPath().c_str(), "/path/path"); - ASSERT_STREQ(uri.GetQuery().c_str(), "query"); - ASSERT_STREQ(uri.GetFragment().c_str(), "fagment"); -} - -HWTEST_F(NativeEngineTest, ConstructorTest009, testing::ext::TestSize.Level0) -{ - napi_env env = (napi_env)engine_; - OHOS::Uri::Uri uri(env, "http://username:password@[fe80::0001:0000]:99/path/path?query#fagment"); - ASSERT_STREQ(uri.GetScheme().c_str(), "http"); - ASSERT_STREQ(uri.GetAuthority().c_str(), "username:password@[fe80::0001:0000]:99"); - ASSERT_STREQ(uri.GetSsp().c_str(), "//username:password@[fe80::0001:0000]:99/path/path?query"); - ASSERT_STREQ(uri.GetUserinfo().c_str(), "username:password"); - ASSERT_STREQ(uri.GetHost().c_str(), "[fe80::0001:0000]"); - ASSERT_STREQ(uri.GetPort().c_str(), "99"); - ASSERT_STREQ(uri.GetPath().c_str(), "/path/path"); - ASSERT_STREQ(uri.GetQuery().c_str(), "query"); - ASSERT_STREQ(uri.GetFragment().c_str(), "fagment"); -} - -HWTEST_F(NativeEngineTest, ConstructorTest010, testing::ext::TestSize.Level0) -{ - napi_env env = (napi_env)engine_; - OHOS::Uri::Uri uri(env, "http://username:password@www.baidu.com:99/path/path?query#fagment"); - ASSERT_STREQ(uri.GetScheme().c_str(), "http"); - ASSERT_STREQ(uri.GetAuthority().c_str(), "username:password@www.baidu.com:99"); - ASSERT_STREQ(uri.GetSsp().c_str(), "//username:password@www.baidu.com:99/path/path?query"); - ASSERT_STREQ(uri.GetUserinfo().c_str(), "username:password"); - ASSERT_STREQ(uri.GetHost().c_str(), "www.baidu.com"); - ASSERT_STREQ(uri.GetPort().c_str(), "99"); - ASSERT_STREQ(uri.GetPath().c_str(), "/path/path"); - ASSERT_STREQ(uri.GetQuery().c_str(), "query"); - ASSERT_STREQ(uri.GetFragment().c_str(), "fagment"); -} - -HWTEST_F(NativeEngineTest, ConstructorTest011, testing::ext::TestSize.Level0) -{ - napi_env env = (napi_env)engine_; - OHOS::Uri::Uri uri(env, "http://username:password@199.98.55.44:99/path/path?query#fagment"); - ASSERT_STREQ(uri.GetScheme().c_str(), "http"); - ASSERT_STREQ(uri.GetAuthority().c_str(), "username:password@199.98.55.44:99"); - ASSERT_STREQ(uri.GetSsp().c_str(), "//username:password@199.98.55.44:99/path/path?query"); - ASSERT_STREQ(uri.GetUserinfo().c_str(), "username:password"); - ASSERT_STREQ(uri.GetHost().c_str(), "199.98.55.44"); - ASSERT_STREQ(uri.GetPort().c_str(), "99"); - ASSERT_STREQ(uri.GetPath().c_str(), "/path/path"); - ASSERT_STREQ(uri.GetQuery().c_str(), "query"); - ASSERT_STREQ(uri.GetFragment().c_str(), "fagment"); -} - -HWTEST_F(NativeEngineTest, ConstructorTest012, testing::ext::TestSize.Level0) -{ - napi_env env = (napi_env)engine_; - OHOS::Uri::Uri uri(env, "http://16.9.5.4:99/path/path?query#fagment"); - ASSERT_STREQ(uri.GetScheme().c_str(), "http"); - ASSERT_STREQ(uri.GetAuthority().c_str(), "16.9.5.4:99"); - ASSERT_STREQ(uri.GetSsp().c_str(), "//16.9.5.4:99/path/path?query"); - ASSERT_STREQ(uri.GetUserinfo().c_str(), "null"); - ASSERT_STREQ(uri.GetHost().c_str(), "16.9.5.4"); - ASSERT_STREQ(uri.GetPort().c_str(), "99"); - ASSERT_STREQ(uri.GetPath().c_str(), "/path/path"); - ASSERT_STREQ(uri.GetQuery().c_str(), "query"); - ASSERT_STREQ(uri.GetFragment().c_str(), "fagment"); -} - -HWTEST_F(NativeEngineTest, ConstructorTest013, testing::ext::TestSize.Level0) -{ - napi_env env = (napi_env)engine_; - OHOS::Uri::Uri uri(env, "http://[::168:169:333]:99/path/path?query#fagment"); - ASSERT_STREQ(uri.GetScheme().c_str(), "http"); - ASSERT_STREQ(uri.GetAuthority().c_str(), "[::168:169:333]:99"); - ASSERT_STREQ(uri.GetSsp().c_str(), "//[::168:169:333]:99/path/path?query"); - ASSERT_STREQ(uri.GetUserinfo().c_str(), "null"); - ASSERT_STREQ(uri.GetHost().c_str(), "[::168:169:333]"); - ASSERT_STREQ(uri.GetPort().c_str(), "99"); - ASSERT_STREQ(uri.GetPath().c_str(), "/path/path"); - ASSERT_STREQ(uri.GetQuery().c_str(), "query"); - ASSERT_STREQ(uri.GetFragment().c_str(), "fagment"); -} - -HWTEST_F(NativeEngineTest, ConstructorTest014, testing::ext::TestSize.Level0) -{ - napi_env env = (napi_env)engine_; - OHOS::Uri::Uri uri(env, "http://user@49.10hh8.54.12:80/path/path?query#qwer"); - ASSERT_STREQ(uri.GetScheme().c_str(), "http"); - ASSERT_STREQ(uri.GetAuthority().c_str(), "user@49.10hh8.54.12:80"); - ASSERT_STREQ(uri.GetSsp().c_str(), "//user@49.10hh8.54.12:80/path/path?query"); - ASSERT_STREQ(uri.GetUserinfo().c_str(), "null"); - ASSERT_STREQ(uri.GetHost().c_str(), "null"); - ASSERT_STREQ(uri.GetPort().c_str(), "-1"); - ASSERT_STREQ(uri.GetPath().c_str(), "/path/path"); - ASSERT_STREQ(uri.GetQuery().c_str(), "query"); - ASSERT_STREQ(uri.GetFragment().c_str(), "qwer"); -} - -HWTEST_F(NativeEngineTest, ConstructorTest015, testing::ext::TestSize.Level0) -{ - napi_env env = (napi_env)engine_; - OHOS::Uri::Uri uri(env, "http://user@www.baidu.com/path/path?query#qwer"); - ASSERT_STREQ(uri.GetScheme().c_str(), "http"); - ASSERT_STREQ(uri.GetAuthority().c_str(), "user@www.baidu.com"); - ASSERT_STREQ(uri.GetSsp().c_str(), "//user@www.baidu.com/path/path?query"); - ASSERT_STREQ(uri.GetUserinfo().c_str(), "user"); - ASSERT_STREQ(uri.GetHost().c_str(), "www.baidu.com"); - ASSERT_STREQ(uri.GetPort().c_str(), "-1"); - ASSERT_STREQ(uri.GetPath().c_str(), "/path/path"); - ASSERT_STREQ(uri.GetQuery().c_str(), "query"); - ASSERT_STREQ(uri.GetFragment().c_str(), "qwer"); -} - -HWTEST_F(NativeEngineTest, ConstructorTest016, testing::ext::TestSize.Level0) -{ - napi_env env = (napi_env)engine_; - OHOS::Uri::Uri uri(env, "ftp://user@www.1hw.1com:77/path/path?query#qwer"); - ASSERT_STREQ(uri.GetScheme().c_str(), "ftp"); - ASSERT_STREQ(uri.GetAuthority().c_str(), "user@www.1hw.1com:77"); - ASSERT_STREQ(uri.GetSsp().c_str(), "//user@www.1hw.1com:77/path/path?query"); - ASSERT_STREQ(uri.GetUserinfo().c_str(), "null"); - ASSERT_STREQ(uri.GetHost().c_str(), "null"); - ASSERT_STREQ(uri.GetPort().c_str(), "-1"); - ASSERT_STREQ(uri.GetPath().c_str(), "/path/path"); - ASSERT_STREQ(uri.GetQuery().c_str(), "query"); - ASSERT_STREQ(uri.GetFragment().c_str(), "qwer"); -} - -HWTEST_F(NativeEngineTest, ConstructorTest017, testing::ext::TestSize.Level0) -{ - napi_env env = (napi_env)engine_; - OHOS::Uri::Uri uri(env, "http://user@hosthost/path/path?query#qwer"); - ASSERT_STREQ(uri.GetScheme().c_str(), "http"); - ASSERT_STREQ(uri.GetAuthority().c_str(), "user@hosthost"); - ASSERT_STREQ(uri.GetSsp().c_str(), "//user@hosthost/path/path?query"); - ASSERT_STREQ(uri.GetUserinfo().c_str(), "user"); - ASSERT_STREQ(uri.GetHost().c_str(), "hosthost"); - ASSERT_STREQ(uri.GetPort().c_str(), "-1"); - ASSERT_STREQ(uri.GetPath().c_str(), "/path/path"); - ASSERT_STREQ(uri.GetQuery().c_str(), "query"); - ASSERT_STREQ(uri.GetFragment().c_str(), "qwer"); -} - -HWTEST_F(NativeEngineTest, ConstructorTest018, testing::ext::TestSize.Level0) -{ - napi_env env = (napi_env)engine_; - OHOS::Uri::Uri uri(env, "http://user@[::]/path/path?query#qwer"); - ASSERT_STREQ(uri.GetScheme().c_str(), "http"); - ASSERT_STREQ(uri.GetAuthority().c_str(), "user@[::]"); - ASSERT_STREQ(uri.GetSsp().c_str(), "//user@[::]/path/path?query"); - ASSERT_STREQ(uri.GetUserinfo().c_str(), "user"); - ASSERT_STREQ(uri.GetHost().c_str(), "[::]"); - ASSERT_STREQ(uri.GetPort().c_str(), "-1"); - ASSERT_STREQ(uri.GetPath().c_str(), "/path/path"); - ASSERT_STREQ(uri.GetQuery().c_str(), "query"); - ASSERT_STREQ(uri.GetFragment().c_str(), "qwer"); -} - -HWTEST_F(NativeEngineTest, ConstructorTest019, testing::ext::TestSize.Level0) -{ - napi_env env = (napi_env)engine_; - OHOS::Uri::Uri uri(env, "http://[::192:0:5]/path/path?query#qwer"); - ASSERT_STREQ(uri.GetScheme().c_str(), "http"); - ASSERT_STREQ(uri.GetAuthority().c_str(), "[::192:0:5]"); - ASSERT_STREQ(uri.GetSsp().c_str(), "//[::192:0:5]/path/path?query"); - ASSERT_STREQ(uri.GetUserinfo().c_str(), "null"); - ASSERT_STREQ(uri.GetHost().c_str(), "[::192:0:5]"); - ASSERT_STREQ(uri.GetPort().c_str(), "-1"); - ASSERT_STREQ(uri.GetPath().c_str(), "/path/path"); - ASSERT_STREQ(uri.GetQuery().c_str(), "query"); - ASSERT_STREQ(uri.GetFragment().c_str(), "qwer"); -} - -HWTEST_F(NativeEngineTest, EqualsTest001, testing::ext::TestSize.Level0) -{ - napi_env env = (napi_env)engine_; - OHOS::Uri::Uri uri(env, "http://gg:gaogao@[1:0:0:1:2:1:2:1]:99/path1?query#fagment"); - OHOS::Uri::Uri uri1 = uri; - ASSERT_TRUE(uri.Equals(uri1)); -} - -HWTEST_F(NativeEngineTest, EqualsTest002, testing::ext::TestSize.Level0) -{ - napi_env env = (napi_env)engine_; - OHOS::Uri::Uri uri(env, "http://gg:gaogao@[1:0:0:1:2:1:2:1]:99/path1?query#fagment"); - OHOS::Uri::Uri uri1(env, "http://gg:gaogao@[1:0:0:1:2:1:2:1]:99/path1?query#fagment"); - ASSERT_TRUE(uri.Equals(uri1)); -} - -HWTEST_F(NativeEngineTest, EqualsTest003, testing::ext::TestSize.Level0) -{ - napi_env env = (napi_env)engine_; - OHOS::Uri::Uri uri(env, "http://gg:gaogao@[1:0:0:1:2:1:2:1]:99/path1?query#fagment"); - OHOS::Uri::Uri uri1(env, "http://gg:gaogao@[1:0:0:1:2:1:2:1]:99/path1?query#fagment123"); - ASSERT_FALSE(uri.Equals(uri1)); -} - -HWTEST_F(NativeEngineTest, NormalizeTest001, testing::ext::TestSize.Level0) -{ - napi_env env = (napi_env)engine_; - OHOS::Uri::Uri uri(env, "http://user@[1:0:0:1:2:1:2:1]:99/path/66./../././mm/.././path1?query#fagment"); - std::string normalize = uri.Normalize(); - ASSERT_STREQ(normalize.c_str(), "http://user@[1:0:0:1:2:1:2:1]:99/path/path1?query#fagment"); -} - -HWTEST_F(NativeEngineTest, NormalizeTest002, testing::ext::TestSize.Level0) -{ - napi_env env = (napi_env)engine_; - OHOS::Uri::Uri uri(env, "http://gg:gaogao@[1:0:0:1:2:1:2:1]:99/../../path?query#fagment"); - std::string normalize = uri.Normalize(); - ASSERT_STREQ(normalize.c_str(), "http://gg:gaogao@[1:0:0:1:2:1:2:1]:99/../../path?query#fagment"); -} - -HWTEST_F(NativeEngineTest, NormalizeTest003, testing::ext::TestSize.Level0) -{ - napi_env env = (napi_env)engine_; - OHOS::Uri::Uri uri(env, "http://gg:gaogao@[1:0:0:1:2:1:2:1]:99/../../path/.././../aa/bb/cc?query#fagment"); - std::string normalize = uri.Normalize(); - ASSERT_STREQ(normalize.c_str(), "http://gg:gaogao@[1:0:0:1:2:1:2:1]:99/../../../aa/bb/cc?query#fagment"); -} - -HWTEST_F(NativeEngineTest, ToStringTest001, testing::ext::TestSize.Level0) -{ - napi_env env = (napi_env)engine_; - OHOS::Uri::Uri uri(env, "http://gg:gaogao@[1:0:0:1:2:1:2:1]:99/aa/bb/cc?query#fagment"); - ASSERT_STREQ(uri.ToString().c_str(), "http://gg:gaogao@[1:0:0:1:2:1:2:1]:99/aa/bb/cc?query#fagment"); -} - -HWTEST_F(NativeEngineTest, ToStringTest002, testing::ext::TestSize.Level0) -{ - napi_env env = (napi_env)engine_; - OHOS::Uri::Uri uri(env, "htt1p://gg:gaogao@[::192.9.5.5]:99/path/66path1?query#fagment"); - ASSERT_STREQ(uri.ToString().c_str(), "htt1p://gg:gaogao@[::192.9.5.5]:99/path/66path1?query#fagment"); -} - -HWTEST_F(NativeEngineTest, ToStringTest003, testing::ext::TestSize.Level0) -{ - napi_env env = (napi_env)engine_; - OHOS::Uri::Uri uri(env, "ftp://username:www.baidu.com/path?query#fagment"); - ASSERT_STREQ(uri.ToString().c_str(), "ftp://username:www.baidu.com/path?query#fagment"); -} - -HWTEST_F(NativeEngineTest, IsAbsoluteTest001, testing::ext::TestSize.Level0) -{ - napi_env env = (napi_env)engine_; - OHOS::Uri::Uri uri(env, "f/tp://username:password@www.baidu.com:88/path?query#fagment"); - bool res = uri.IsAbsolute(); - ASSERT_FALSE(res); -} - -HWTEST_F(NativeEngineTest, IsAbsoluteTest002, testing::ext::TestSize.Level0) -{ - napi_env env = (napi_env)engine_; - OHOS::Uri::Uri uri(env, "ftp://username:password@www.baidu.com:88/path?query#fagment"); - bool res = uri.IsAbsolute(); - ASSERT_TRUE(res); -} - -HWTEST_F(NativeEngineTest, IsAbsoluteTest003, testing::ext::TestSize.Level0) -{ - napi_env env = (napi_env)engine_; - OHOS::Uri::Uri uri(env, "htt/p://username:password@www.baidu.com:88/path?query#fagment"); - bool res = uri.IsAbsolute(); - ASSERT_FALSE(res); -} - +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * 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. + */ + +#include "test.h" +#include "napi/native_api.h" +#include "napi/native_node_api.h" +#include "utils/log.h" +#include "js_uri.h" + +#define ASSERT_CHECK_CALL(call) \ + { \ + ASSERT_EQ(call, napi_ok); \ + } + +#define ASSERT_CHECK_VALUE_TYPE(env, value, type) \ + { \ + napi_valuetype valueType = napi_undefined; \ + ASSERT_TRUE(value != nullptr); \ + ASSERT_CHECK_CALL(napi_typeof(env, value, &valueType)); \ + ASSERT_EQ(valueType, type); \ + } + +HWTEST_F(NativeEngineTest, ConstructorTest001, testing::ext::TestSize.Level0) +{ + napi_env env = (napi_env)engine_; + OHOS::Uri::Uri uri(env, "http://username:password@www.baidu.com:99/path/path?query#fagment"); + ASSERT_STREQ(uri.GetScheme().c_str(), "http"); + ASSERT_STREQ(uri.GetAuthority().c_str(), "username:password@www.baidu.com:99"); + ASSERT_STREQ(uri.GetSsp().c_str(), "//username:password@www.baidu.com:99/path/path?query"); + ASSERT_STREQ(uri.GetUserinfo().c_str(), "username:password"); + ASSERT_STREQ(uri.GetHost().c_str(), "www.baidu.com"); + ASSERT_STREQ(uri.GetPort().c_str(), "99"); + ASSERT_STREQ(uri.GetPath().c_str(), "/path/path"); + ASSERT_STREQ(uri.GetQuery().c_str(), "query"); + ASSERT_STREQ(uri.GetFragment().c_str(), "fagment"); +} + +HWTEST_F(NativeEngineTest, ConstructorTest002, testing::ext::TestSize.Level0) +{ + napi_env env = (napi_env)engine_; + OHOS::Uri::Uri uri(env, "http://username:password@[1080::8:800:200C:417A]:99/path/66path1?query#fagment"); + ASSERT_STREQ(uri.GetScheme().c_str(), "http"); + ASSERT_STREQ(uri.GetAuthority().c_str(), "username:password@[1080::8:800:200C:417A]:99"); + ASSERT_STREQ(uri.GetSsp().c_str(), "//username:password@[1080::8:800:200C:417A]:99/path/66path1?query"); + ASSERT_STREQ(uri.GetUserinfo().c_str(), "username:password"); + ASSERT_STREQ(uri.GetHost().c_str(), "[1080::8:800:200C:417A]"); + ASSERT_STREQ(uri.GetPort().c_str(), "99"); + ASSERT_STREQ(uri.GetPath().c_str(), "/path/66path1"); + ASSERT_STREQ(uri.GetQuery().c_str(), "query"); + ASSERT_STREQ(uri.GetFragment().c_str(), "fagment"); +} + +HWTEST_F(NativeEngineTest, ConstructorTest003, testing::ext::TestSize.Level0) +{ + napi_env env = (napi_env)engine_; + OHOS::Uri::Uri uri(env, "http://username:password@[::]:88/path/path66?foooo#gaogao"); + ASSERT_STREQ(uri.GetScheme().c_str(), "http"); + ASSERT_STREQ(uri.GetAuthority().c_str(), "username:password@[::]:88"); + ASSERT_STREQ(uri.GetSsp().c_str(), "//username:password@[::]:88/path/path66?foooo"); + ASSERT_STREQ(uri.GetUserinfo().c_str(), "username:password"); + ASSERT_STREQ(uri.GetHost().c_str(), "[::]"); + ASSERT_STREQ(uri.GetPort().c_str(), "88"); + ASSERT_STREQ(uri.GetPath().c_str(), "/path/path66"); + ASSERT_STREQ(uri.GetQuery().c_str(), "foooo"); + ASSERT_STREQ(uri.GetFragment().c_str(), "gaogao"); +} + +HWTEST_F(NativeEngineTest, ConstructorTest004, testing::ext::TestSize.Level0) +{ + napi_env env = (napi_env)engine_; + OHOS::Uri::Uri uri(env, "http://username:password@[1:0:0:1:2:1:2:1]:99/path/66path1?query#fagment"); + ASSERT_STREQ(uri.GetScheme().c_str(), "http"); + ASSERT_STREQ(uri.GetAuthority().c_str(), "username:password@[1:0:0:1:2:1:2:1]:99"); + ASSERT_STREQ(uri.GetSsp().c_str(), "//username:password@[1:0:0:1:2:1:2:1]:99/path/66path1?query"); + ASSERT_STREQ(uri.GetUserinfo().c_str(), "username:password"); + ASSERT_STREQ(uri.GetHost().c_str(), "[1:0:0:1:2:1:2:1]"); + ASSERT_STREQ(uri.GetPort().c_str(), "99"); + ASSERT_STREQ(uri.GetPath().c_str(), "/path/66path1"); + ASSERT_STREQ(uri.GetQuery().c_str(), "query"); + ASSERT_STREQ(uri.GetFragment().c_str(), "fagment"); +} + +HWTEST_F(NativeEngineTest, ConstructorTest005, testing::ext::TestSize.Level0) +{ + napi_env env = (napi_env)engine_; + OHOS::Uri::Uri uri(env, "http://username:password@[::FFFF:129.144.52.38]:99/path/path?query#fagment"); + ASSERT_STREQ(uri.GetScheme().c_str(), "http"); + ASSERT_STREQ(uri.GetAuthority().c_str(), "username:password@[::FFFF:129.144.52.38]:99"); + ASSERT_STREQ(uri.GetSsp().c_str(), "//username:password@[::FFFF:129.144.52.38]:99/path/path?query"); + ASSERT_STREQ(uri.GetUserinfo().c_str(), "username:password"); + ASSERT_STREQ(uri.GetHost().c_str(), "[::FFFF:129.144.52.38]"); + ASSERT_STREQ(uri.GetPort().c_str(), "99"); + ASSERT_STREQ(uri.GetPath().c_str(), "/path/path"); + ASSERT_STREQ(uri.GetQuery().c_str(), "query"); + ASSERT_STREQ(uri.GetFragment().c_str(), "fagment"); +} + +HWTEST_F(NativeEngineTest, ConstructorTest006, testing::ext::TestSize.Level0) +{ + napi_env env = (napi_env)engine_; + OHOS::Uri::Uri uri(env, "http://username:password@[::192.9.5.5]:99/path/path?query#fagment"); + ASSERT_STREQ(uri.GetScheme().c_str(), "http"); + ASSERT_STREQ(uri.GetAuthority().c_str(), "username:password@[::192.9.5.5]:99"); + ASSERT_STREQ(uri.GetSsp().c_str(), "//username:password@[::192.9.5.5]:99/path/path?query"); + ASSERT_STREQ(uri.GetUserinfo().c_str(), "username:password"); + ASSERT_STREQ(uri.GetHost().c_str(), "[::192.9.5.5]"); + ASSERT_STREQ(uri.GetPort().c_str(), "99"); + ASSERT_STREQ(uri.GetPath().c_str(), "/path/path"); + ASSERT_STREQ(uri.GetQuery().c_str(), "query"); + ASSERT_STREQ(uri.GetFragment().c_str(), "fagment"); +} + +HWTEST_F(NativeEngineTest, ConstructorTest007, testing::ext::TestSize.Level0) +{ + napi_env env = (napi_env)engine_; + OHOS::Uri::Uri uri(env, "http://username:password@[22::22:2:2%ss]:99/path/path?query#fagment"); + ASSERT_STREQ(uri.GetScheme().c_str(), "http"); + ASSERT_STREQ(uri.GetAuthority().c_str(), "username:password@[22::22:2:2%ss]:99"); + ASSERT_STREQ(uri.GetSsp().c_str(), "//username:password@[22::22:2:2%ss]:99/path/path?query"); + ASSERT_STREQ(uri.GetUserinfo().c_str(), "username:password"); + ASSERT_STREQ(uri.GetHost().c_str(), "[22::22:2:2%ss]"); + ASSERT_STREQ(uri.GetPort().c_str(), "99"); + ASSERT_STREQ(uri.GetPath().c_str(), "/path/path"); + ASSERT_STREQ(uri.GetQuery().c_str(), "query"); + ASSERT_STREQ(uri.GetFragment().c_str(), "fagment"); +} + +HWTEST_F(NativeEngineTest, ConstructorTest008, testing::ext::TestSize.Level0) +{ + napi_env env = (napi_env)engine_; + OHOS::Uri::Uri uri(env, "http://username:password@[fe80:0000:0001:0000:0440:44ff:1233:5678]" + ":99/path/path?query#fagment"); + ASSERT_STREQ(uri.GetScheme().c_str(), "http"); + ASSERT_STREQ(uri.GetAuthority().c_str(), "username:password@[fe80:0000:0001:0000:0440:44ff:1233:5678]:99"); + ASSERT_STREQ(uri.GetSsp().c_str(), "//username:password@[fe80:0000:0001:0000:0440:44ff:1233:5678]" + ":99/path/path?query"); + ASSERT_STREQ(uri.GetUserinfo().c_str(), "username:password"); + ASSERT_STREQ(uri.GetHost().c_str(), "[fe80:0000:0001:0000:0440:44ff:1233:5678]"); + ASSERT_STREQ(uri.GetPort().c_str(), "99"); + ASSERT_STREQ(uri.GetPath().c_str(), "/path/path"); + ASSERT_STREQ(uri.GetQuery().c_str(), "query"); + ASSERT_STREQ(uri.GetFragment().c_str(), "fagment"); +} + +HWTEST_F(NativeEngineTest, ConstructorTest009, testing::ext::TestSize.Level0) +{ + napi_env env = (napi_env)engine_; + OHOS::Uri::Uri uri(env, "http://username:password@[fe80::0001:0000]:99/path/path?query#fagment"); + ASSERT_STREQ(uri.GetScheme().c_str(), "http"); + ASSERT_STREQ(uri.GetAuthority().c_str(), "username:password@[fe80::0001:0000]:99"); + ASSERT_STREQ(uri.GetSsp().c_str(), "//username:password@[fe80::0001:0000]:99/path/path?query"); + ASSERT_STREQ(uri.GetUserinfo().c_str(), "username:password"); + ASSERT_STREQ(uri.GetHost().c_str(), "[fe80::0001:0000]"); + ASSERT_STREQ(uri.GetPort().c_str(), "99"); + ASSERT_STREQ(uri.GetPath().c_str(), "/path/path"); + ASSERT_STREQ(uri.GetQuery().c_str(), "query"); + ASSERT_STREQ(uri.GetFragment().c_str(), "fagment"); +} + +HWTEST_F(NativeEngineTest, ConstructorTest010, testing::ext::TestSize.Level0) +{ + napi_env env = (napi_env)engine_; + OHOS::Uri::Uri uri(env, "http://username:password@www.baidu.com:99/path/path?query#fagment"); + ASSERT_STREQ(uri.GetScheme().c_str(), "http"); + ASSERT_STREQ(uri.GetAuthority().c_str(), "username:password@www.baidu.com:99"); + ASSERT_STREQ(uri.GetSsp().c_str(), "//username:password@www.baidu.com:99/path/path?query"); + ASSERT_STREQ(uri.GetUserinfo().c_str(), "username:password"); + ASSERT_STREQ(uri.GetHost().c_str(), "www.baidu.com"); + ASSERT_STREQ(uri.GetPort().c_str(), "99"); + ASSERT_STREQ(uri.GetPath().c_str(), "/path/path"); + ASSERT_STREQ(uri.GetQuery().c_str(), "query"); + ASSERT_STREQ(uri.GetFragment().c_str(), "fagment"); +} + +HWTEST_F(NativeEngineTest, ConstructorTest011, testing::ext::TestSize.Level0) +{ + napi_env env = (napi_env)engine_; + OHOS::Uri::Uri uri(env, "http://username:password@199.98.55.44:99/path/path?query#fagment"); + ASSERT_STREQ(uri.GetScheme().c_str(), "http"); + ASSERT_STREQ(uri.GetAuthority().c_str(), "username:password@199.98.55.44:99"); + ASSERT_STREQ(uri.GetSsp().c_str(), "//username:password@199.98.55.44:99/path/path?query"); + ASSERT_STREQ(uri.GetUserinfo().c_str(), "username:password"); + ASSERT_STREQ(uri.GetHost().c_str(), "199.98.55.44"); + ASSERT_STREQ(uri.GetPort().c_str(), "99"); + ASSERT_STREQ(uri.GetPath().c_str(), "/path/path"); + ASSERT_STREQ(uri.GetQuery().c_str(), "query"); + ASSERT_STREQ(uri.GetFragment().c_str(), "fagment"); +} + +HWTEST_F(NativeEngineTest, ConstructorTest012, testing::ext::TestSize.Level0) +{ + napi_env env = (napi_env)engine_; + OHOS::Uri::Uri uri(env, "http://16.9.5.4:99/path/path?query#fagment"); + ASSERT_STREQ(uri.GetScheme().c_str(), "http"); + ASSERT_STREQ(uri.GetAuthority().c_str(), "16.9.5.4:99"); + ASSERT_STREQ(uri.GetSsp().c_str(), "//16.9.5.4:99/path/path?query"); + ASSERT_STREQ(uri.GetUserinfo().c_str(), "null"); + ASSERT_STREQ(uri.GetHost().c_str(), "16.9.5.4"); + ASSERT_STREQ(uri.GetPort().c_str(), "99"); + ASSERT_STREQ(uri.GetPath().c_str(), "/path/path"); + ASSERT_STREQ(uri.GetQuery().c_str(), "query"); + ASSERT_STREQ(uri.GetFragment().c_str(), "fagment"); +} + +HWTEST_F(NativeEngineTest, ConstructorTest013, testing::ext::TestSize.Level0) +{ + napi_env env = (napi_env)engine_; + OHOS::Uri::Uri uri(env, "http://[::168:169:333]:99/path/path?query#fagment"); + ASSERT_STREQ(uri.GetScheme().c_str(), "http"); + ASSERT_STREQ(uri.GetAuthority().c_str(), "[::168:169:333]:99"); + ASSERT_STREQ(uri.GetSsp().c_str(), "//[::168:169:333]:99/path/path?query"); + ASSERT_STREQ(uri.GetUserinfo().c_str(), "null"); + ASSERT_STREQ(uri.GetHost().c_str(), "[::168:169:333]"); + ASSERT_STREQ(uri.GetPort().c_str(), "99"); + ASSERT_STREQ(uri.GetPath().c_str(), "/path/path"); + ASSERT_STREQ(uri.GetQuery().c_str(), "query"); + ASSERT_STREQ(uri.GetFragment().c_str(), "fagment"); +} + +HWTEST_F(NativeEngineTest, ConstructorTest014, testing::ext::TestSize.Level0) +{ + napi_env env = (napi_env)engine_; + OHOS::Uri::Uri uri(env, "http://user@49.10hh8.54.12:80/path/path?query#qwer"); + ASSERT_STREQ(uri.GetScheme().c_str(), "http"); + ASSERT_STREQ(uri.GetAuthority().c_str(), "user@49.10hh8.54.12:80"); + ASSERT_STREQ(uri.GetSsp().c_str(), "//user@49.10hh8.54.12:80/path/path?query"); + ASSERT_STREQ(uri.GetUserinfo().c_str(), "null"); + ASSERT_STREQ(uri.GetHost().c_str(), "null"); + ASSERT_STREQ(uri.GetPort().c_str(), "-1"); + ASSERT_STREQ(uri.GetPath().c_str(), "/path/path"); + ASSERT_STREQ(uri.GetQuery().c_str(), "query"); + ASSERT_STREQ(uri.GetFragment().c_str(), "qwer"); +} + +HWTEST_F(NativeEngineTest, ConstructorTest015, testing::ext::TestSize.Level0) +{ + napi_env env = (napi_env)engine_; + OHOS::Uri::Uri uri(env, "http://user@www.baidu.com/path/path?query#qwer"); + ASSERT_STREQ(uri.GetScheme().c_str(), "http"); + ASSERT_STREQ(uri.GetAuthority().c_str(), "user@www.baidu.com"); + ASSERT_STREQ(uri.GetSsp().c_str(), "//user@www.baidu.com/path/path?query"); + ASSERT_STREQ(uri.GetUserinfo().c_str(), "user"); + ASSERT_STREQ(uri.GetHost().c_str(), "www.baidu.com"); + ASSERT_STREQ(uri.GetPort().c_str(), "-1"); + ASSERT_STREQ(uri.GetPath().c_str(), "/path/path"); + ASSERT_STREQ(uri.GetQuery().c_str(), "query"); + ASSERT_STREQ(uri.GetFragment().c_str(), "qwer"); +} + +HWTEST_F(NativeEngineTest, ConstructorTest016, testing::ext::TestSize.Level0) +{ + napi_env env = (napi_env)engine_; + OHOS::Uri::Uri uri(env, "ftp://user@www.1hw.1com:77/path/path?query#qwer"); + ASSERT_STREQ(uri.GetScheme().c_str(), "ftp"); + ASSERT_STREQ(uri.GetAuthority().c_str(), "user@www.1hw.1com:77"); + ASSERT_STREQ(uri.GetSsp().c_str(), "//user@www.1hw.1com:77/path/path?query"); + ASSERT_STREQ(uri.GetUserinfo().c_str(), "null"); + ASSERT_STREQ(uri.GetHost().c_str(), "null"); + ASSERT_STREQ(uri.GetPort().c_str(), "-1"); + ASSERT_STREQ(uri.GetPath().c_str(), "/path/path"); + ASSERT_STREQ(uri.GetQuery().c_str(), "query"); + ASSERT_STREQ(uri.GetFragment().c_str(), "qwer"); +} + +HWTEST_F(NativeEngineTest, ConstructorTest017, testing::ext::TestSize.Level0) +{ + napi_env env = (napi_env)engine_; + OHOS::Uri::Uri uri(env, "http://user@hosthost/path/path?query#qwer"); + ASSERT_STREQ(uri.GetScheme().c_str(), "http"); + ASSERT_STREQ(uri.GetAuthority().c_str(), "user@hosthost"); + ASSERT_STREQ(uri.GetSsp().c_str(), "//user@hosthost/path/path?query"); + ASSERT_STREQ(uri.GetUserinfo().c_str(), "user"); + ASSERT_STREQ(uri.GetHost().c_str(), "hosthost"); + ASSERT_STREQ(uri.GetPort().c_str(), "-1"); + ASSERT_STREQ(uri.GetPath().c_str(), "/path/path"); + ASSERT_STREQ(uri.GetQuery().c_str(), "query"); + ASSERT_STREQ(uri.GetFragment().c_str(), "qwer"); +} + +HWTEST_F(NativeEngineTest, ConstructorTest018, testing::ext::TestSize.Level0) +{ + napi_env env = (napi_env)engine_; + OHOS::Uri::Uri uri(env, "http://user@[::]/path/path?query#qwer"); + ASSERT_STREQ(uri.GetScheme().c_str(), "http"); + ASSERT_STREQ(uri.GetAuthority().c_str(), "user@[::]"); + ASSERT_STREQ(uri.GetSsp().c_str(), "//user@[::]/path/path?query"); + ASSERT_STREQ(uri.GetUserinfo().c_str(), "user"); + ASSERT_STREQ(uri.GetHost().c_str(), "[::]"); + ASSERT_STREQ(uri.GetPort().c_str(), "-1"); + ASSERT_STREQ(uri.GetPath().c_str(), "/path/path"); + ASSERT_STREQ(uri.GetQuery().c_str(), "query"); + ASSERT_STREQ(uri.GetFragment().c_str(), "qwer"); +} + +HWTEST_F(NativeEngineTest, ConstructorTest019, testing::ext::TestSize.Level0) +{ + napi_env env = (napi_env)engine_; + OHOS::Uri::Uri uri(env, "http://[::192:0:5]/path/path?query#qwer"); + ASSERT_STREQ(uri.GetScheme().c_str(), "http"); + ASSERT_STREQ(uri.GetAuthority().c_str(), "[::192:0:5]"); + ASSERT_STREQ(uri.GetSsp().c_str(), "//[::192:0:5]/path/path?query"); + ASSERT_STREQ(uri.GetUserinfo().c_str(), "null"); + ASSERT_STREQ(uri.GetHost().c_str(), "[::192:0:5]"); + ASSERT_STREQ(uri.GetPort().c_str(), "-1"); + ASSERT_STREQ(uri.GetPath().c_str(), "/path/path"); + ASSERT_STREQ(uri.GetQuery().c_str(), "query"); + ASSERT_STREQ(uri.GetFragment().c_str(), "qwer"); +} + +HWTEST_F(NativeEngineTest, EqualsTest001, testing::ext::TestSize.Level0) +{ + napi_env env = (napi_env)engine_; + OHOS::Uri::Uri uri(env, "http://gg:gaogao@[1:0:0:1:2:1:2:1]:99/path1?query#fagment"); + OHOS::Uri::Uri uri1 = uri; + ASSERT_TRUE(uri.Equals(uri1)); +} + +HWTEST_F(NativeEngineTest, EqualsTest002, testing::ext::TestSize.Level0) +{ + napi_env env = (napi_env)engine_; + OHOS::Uri::Uri uri(env, "http://gg:gaogao@[1:0:0:1:2:1:2:1]:99/path1?query#fagment"); + OHOS::Uri::Uri uri1(env, "http://gg:gaogao@[1:0:0:1:2:1:2:1]:99/path1?query#fagment"); + ASSERT_TRUE(uri.Equals(uri1)); +} + +HWTEST_F(NativeEngineTest, EqualsTest003, testing::ext::TestSize.Level0) +{ + napi_env env = (napi_env)engine_; + OHOS::Uri::Uri uri(env, "http://gg:gaogao@[1:0:0:1:2:1:2:1]:99/path1?query#fagment"); + OHOS::Uri::Uri uri1(env, "http://gg:gaogao@[1:0:0:1:2:1:2:1]:99/path1?query#fagment123"); + ASSERT_FALSE(uri.Equals(uri1)); +} + +HWTEST_F(NativeEngineTest, NormalizeTest001, testing::ext::TestSize.Level0) +{ + napi_env env = (napi_env)engine_; + OHOS::Uri::Uri uri(env, "http://user@[1:0:0:1:2:1:2:1]:99/path/66./../././mm/.././path1?query#fagment"); + std::string normalize = uri.Normalize(); + ASSERT_STREQ(normalize.c_str(), "http://user@[1:0:0:1:2:1:2:1]:99/path/path1?query#fagment"); +} + +HWTEST_F(NativeEngineTest, NormalizeTest002, testing::ext::TestSize.Level0) +{ + napi_env env = (napi_env)engine_; + OHOS::Uri::Uri uri(env, "http://gg:gaogao@[1:0:0:1:2:1:2:1]:99/../../path?query#fagment"); + std::string normalize = uri.Normalize(); + ASSERT_STREQ(normalize.c_str(), "http://gg:gaogao@[1:0:0:1:2:1:2:1]:99/../../path?query#fagment"); +} + +HWTEST_F(NativeEngineTest, NormalizeTest003, testing::ext::TestSize.Level0) +{ + napi_env env = (napi_env)engine_; + OHOS::Uri::Uri uri(env, "http://gg:gaogao@[1:0:0:1:2:1:2:1]:99/../../path/.././../aa/bb/cc?query#fagment"); + std::string normalize = uri.Normalize(); + ASSERT_STREQ(normalize.c_str(), "http://gg:gaogao@[1:0:0:1:2:1:2:1]:99/../../../aa/bb/cc?query#fagment"); +} + +HWTEST_F(NativeEngineTest, ToStringTest001, testing::ext::TestSize.Level0) +{ + napi_env env = (napi_env)engine_; + OHOS::Uri::Uri uri(env, "http://gg:gaogao@[1:0:0:1:2:1:2:1]:99/aa/bb/cc?query#fagment"); + ASSERT_STREQ(uri.ToString().c_str(), "http://gg:gaogao@[1:0:0:1:2:1:2:1]:99/aa/bb/cc?query#fagment"); +} + +HWTEST_F(NativeEngineTest, ToStringTest002, testing::ext::TestSize.Level0) +{ + napi_env env = (napi_env)engine_; + OHOS::Uri::Uri uri(env, "htt1p://gg:gaogao@[::192.9.5.5]:99/path/66path1?query#fagment"); + ASSERT_STREQ(uri.ToString().c_str(), "htt1p://gg:gaogao@[::192.9.5.5]:99/path/66path1?query#fagment"); +} + +HWTEST_F(NativeEngineTest, ToStringTest003, testing::ext::TestSize.Level0) +{ + napi_env env = (napi_env)engine_; + OHOS::Uri::Uri uri(env, "ftp://username:www.baidu.com/path?query#fagment"); + ASSERT_STREQ(uri.ToString().c_str(), "ftp://username:www.baidu.com/path?query#fagment"); +} + +HWTEST_F(NativeEngineTest, IsAbsoluteTest001, testing::ext::TestSize.Level0) +{ + napi_env env = (napi_env)engine_; + OHOS::Uri::Uri uri(env, "f/tp://username:password@www.baidu.com:88/path?query#fagment"); + bool res = uri.IsAbsolute(); + ASSERT_FALSE(res); +} + +HWTEST_F(NativeEngineTest, IsAbsoluteTest002, testing::ext::TestSize.Level0) +{ + napi_env env = (napi_env)engine_; + OHOS::Uri::Uri uri(env, "ftp://username:password@www.baidu.com:88/path?query#fagment"); + bool res = uri.IsAbsolute(); + ASSERT_TRUE(res); +} + +HWTEST_F(NativeEngineTest, IsAbsoluteTest003, testing::ext::TestSize.Level0) +{ + napi_env env = (napi_env)engine_; + OHOS::Uri::Uri uri(env, "htt/p://username:password@www.baidu.com:88/path?query#fagment"); + bool res = uri.IsAbsolute(); + ASSERT_FALSE(res); +} + diff --git a/test_uri/unittest/test_quickjs.cpp b/test_uri/unittest/test_quickjs.cpp index b14aa3ce8b55412914a522a0b0ee2b81dc8fd28d..3501fabf9c7e6cb9cb9ba85ba72d9971dccf9474 100755 --- a/test_uri/unittest/test_quickjs.cpp +++ b/test_uri/unittest/test_quickjs.cpp @@ -1,60 +1,60 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * 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. - */ - -#include "test.h" - -#include "quickjs_native_engine.h" - -static NativeEngine *g_nativeEngine = nullptr; - -NativeEngineTest::NativeEngineTest() -{ - engine_ = g_nativeEngine; -} - -NativeEngineTest::~NativeEngineTest() {} - -int main(int argc, char **argv) -{ - testing::GTEST_FLAG(output) = "xml:./"; - testing::InitGoogleTest(&argc, argv); - - JSRuntime *rt = JS_NewRuntime(); - if (rt == nullptr) { - return 0; - } - - JSContext *ctx = JS_NewContext(rt); - if (ctx == nullptr) { - return 0; - } - - js_std_add_helpers(ctx, 0, nullptr); - - g_nativeEngine = new QuickJSNativeEngine(rt, ctx, 0); // default instance id 0 - - int ret = RUN_ALL_TESTS(); - - g_nativeEngine->Loop(LOOP_DEFAULT); - - delete g_nativeEngine; - g_nativeEngine = nullptr; - - js_std_free_handlers(rt); - JS_FreeContext(ctx); - JS_FreeRuntime(rt); - - return ret; -} +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * 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. + */ + +#include "test.h" + +#include "quickjs_native_engine.h" + +static NativeEngine *g_nativeEngine = nullptr; + +NativeEngineTest::NativeEngineTest() +{ + engine_ = g_nativeEngine; +} + +NativeEngineTest::~NativeEngineTest() {} + +int main(int argc, char **argv) +{ + testing::GTEST_FLAG(output) = "xml:./"; + testing::InitGoogleTest(&argc, argv); + + JSRuntime *rt = JS_NewRuntime(); + if (rt == nullptr) { + return 0; + } + + JSContext *ctx = JS_NewContext(rt); + if (ctx == nullptr) { + return 0; + } + + js_std_add_helpers(ctx, 0, nullptr); + + g_nativeEngine = new QuickJSNativeEngine(rt, ctx, 0); // default instance id 0 + + int ret = RUN_ALL_TESTS(); + + g_nativeEngine->Loop(LOOP_DEFAULT); + + delete g_nativeEngine; + g_nativeEngine = nullptr; + + js_std_free_handlers(rt); + JS_FreeContext(ctx); + JS_FreeRuntime(rt); + + return ret; +} diff --git a/uri/BUILD.gn b/uri/BUILD.gn index 0249e7a398c05f7ad3fabe6685670b171ce9837a..8d84a14e7fa48ab53ed47fa3a33cf155cc54d9c5 100755 --- a/uri/BUILD.gn +++ b/uri/BUILD.gn @@ -10,9 +10,41 @@ # 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. - +import("//ark/ts2abc/ts2panda/ts2abc_config.gni") import("//build/ohos.gni") import("//build/ohos/ace/ace.gni") +import("//foundation/ace/ace_engine/ace_config.gni") + +# compile .js to .abc. +action("gen_uri_abc") { + visibility = [ ":*" ] + script = "//ark/ts2abc/ts2panda/scripts/generate_js_bytecode.py" + + args = [ + "--src-js", + rebase_path("//base/compileruntime/js_api_module/uri/js_uri.js"), + "--dst-file", + rebase_path(target_out_dir + "/uri.abc"), + "--node", + rebase_path("${node_path}"), + "--frontend-tool-path", + rebase_path("${ts2abc_build_path}"), + "--node-modules", + rebase_path("${node_modules}"), + ] + deps = [ "//ark/ts2abc/ts2panda:ark_ts2abc_build" ] + + inputs = [ "//base/compileruntime/js_api_module/uri/js_uri.js" ] + outputs = [ target_out_dir + "/uri.abc" ] +} + +abc_output_path = get_label_info(":uri_abc", "target_out_dir") +uri_abc_obj_path = abc_output_path + "/uri_abc.o" +gen_js_obj("uri_abc") { + input = "$target_out_dir/uri.abc" + output = uri_abc_obj_path + dep = ":gen_uri_abc" +} base_output_path = get_label_info(":js_uri", "target_out_dir") js_uri_obj_path = base_output_path + "/uri.o" @@ -36,6 +68,7 @@ ohos_shared_library("uri") { deps = [ ":js_uri", + ":uri_abc", "//base/compileruntime/js_api_module/uri/:js_uri", "//foundation/ace/napi/:ace_napi", "//foundation/ace/napi/:ace_napi_quickjs", @@ -57,4 +90,3 @@ ohos_shared_library("uri") { group("uri_packages") { deps = [ ":uri" ] } - diff --git a/uri/js_uri.cpp b/uri/js_uri.cpp index 3af8ab0c9e651343528f5e1b2bca77c21d5525ec..34452121891811f25686dfb49a533cf1a2d2b1fe 100755 --- a/uri/js_uri.cpp +++ b/uri/js_uri.cpp @@ -15,14 +15,14 @@ #include "js_uri.h" #include "utils/log.h" namespace OHOS::Uri { - std::bitset g_ruleAlpha; - std::bitset g_ruleScheme; - std::bitset g_ruleUrlc; - std::bitset g_rulePath; - std::bitset g_ruleUserInfo; - std::bitset g_ruleScope; - std::bitset g_ruleDigit; - std::bitset g_rulePort; + std::bitset g_ruleAlpha; + std::bitset g_ruleScheme; + std::bitset g_ruleUrlc; + std::bitset g_rulePath; + std::bitset g_ruleUserInfo; + std::bitset g_ruleScope; + std::bitset g_ruleDigit; + std::bitset g_rulePort; void Uri::PreliminaryWork() const { std::string digitAggregate = "0123456789"; diff --git a/uri/native_module_uri.cpp b/uri/native_module_uri.cpp index cb013be86fad1ddea9a9f16941cf4596062376e5..96107d99f1c64928d4460a6460ca8e2200707256 100755 --- a/uri/native_module_uri.cpp +++ b/uri/native_module_uri.cpp @@ -21,6 +21,9 @@ extern const char _binary_js_uri_js_start[]; extern const char _binary_js_uri_js_end[]; +extern const char _binary_uri_abc_start[]; +extern const char _binary_uri_abc_end[]; + namespace OHOS::Uri { static napi_value UriConstructor(napi_env env, napi_callback_info info) { @@ -264,7 +267,7 @@ namespace OHOS::Uri { DECLARE_NAPI_GETTER("isFailed", IsFailed), }; NAPI_CALL(env, napi_define_class(env, uriClassName, strlen(uriClassName), UriConstructor, - nullptr, sizeof(uriDesc) / sizeof(uriDesc[0]), uriDesc, &uriClass)); + nullptr, sizeof(uriDesc) / sizeof(uriDesc[0]), uriDesc, &uriClass)); static napi_property_descriptor desc[] = { DECLARE_NAPI_PROPERTY("Uri", uriClass) }; @@ -283,7 +286,16 @@ namespace OHOS::Uri { *bufLen = _binary_js_uri_js_end - _binary_js_uri_js_start; } } - + extern "C" + __attribute__((visibility("default"))) void NAPI_uri_GetABCCode(const char** buf, int* buflen) + { + if (buf != nullptr) { + *buf = _binary_uri_abc_start; + } + if (buflen != nullptr) { + *buflen = _binary_uri_abc_end - _binary_uri_abc_start; + } + } static napi_module UriModule = { .nm_version = 1, .nm_flags = 0, diff --git a/url/BUILD.gn b/url/BUILD.gn index 5e8d16faf82d5734f13bca03768b8c4aef43c0e1..11b32a4d4327f9f90afdf7f6eb3f5ac7d00f1ee6 100755 --- a/url/BUILD.gn +++ b/url/BUILD.gn @@ -10,9 +10,41 @@ # 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. - +import("//ark/ts2abc/ts2panda/ts2abc_config.gni") import("//build/ohos.gni") import("//build/ohos/ace/ace.gni") +import("//foundation/ace/ace_engine/ace_config.gni") + +# compile .js to .abc. +action("gen_url_abc") { + visibility = [ ":*" ] + script = "//ark/ts2abc/ts2panda/scripts/generate_js_bytecode.py" + + args = [ + "--src-js", + rebase_path("//base/compileruntime/js_api_module/url/js_url.js"), + "--dst-file", + rebase_path(target_out_dir + "/url.abc"), + "--node", + rebase_path("${node_path}"), + "--frontend-tool-path", + rebase_path("${ts2abc_build_path}"), + "--node-modules", + rebase_path("${node_modules}"), + ] + deps = [ "//ark/ts2abc/ts2panda:ark_ts2abc_build" ] + + inputs = [ "//base/compileruntime/js_api_module/url/js_url.js" ] + outputs = [ target_out_dir + "/url.abc" ] +} + +abc_output_path = get_label_info(":url_abc", "target_out_dir") +url_abc_obj_path = abc_output_path + "/url_abc.o" +gen_js_obj("url_abc") { + input = "$target_out_dir/url.abc" + output = url_abc_obj_path + dep = ":gen_url_abc" +} base_output_path = get_label_info(":js_url", "target_out_dir") js_url_obj_path = base_output_path + "/url.o" @@ -36,6 +68,7 @@ ohos_shared_library("url") { deps = [ ":js_url", + ":url_abc", "//base/compileruntime/js_api_module/url/:js_url", "//foundation/ace/napi/:ace_napi", "//foundation/ace/napi/:ace_napi_quickjs", diff --git a/url/js_url.cpp b/url/js_url.cpp index ba9f1b93303998245c5fce2510b399e6e78a845f..1b53b245079c25590b9fe717a8776b117ad7a624 100755 --- a/url/js_url.cpp +++ b/url/js_url.cpp @@ -1705,7 +1705,7 @@ namespace OHOS::Url { (charaEncode & 0x0000003F)]; // Acquisition method of the second byte output += output1 + output2; } else if ((charaEncode >= 0x0000E000) || - (charaEncode <= 0x0000D7FF)) { // Convert the Unicode code into three bytes + (charaEncode <= 0x0000D7FF)) { // Convert the Unicode code into three bytes std::string output1 = reviseChar[0x000000E0 | (charaEncode / 4096)]; // 4096:Acquisition method of the first byte std::string output2 = reviseChar[numOfAscii | @@ -1935,7 +1935,7 @@ namespace OHOS::Url { sname = ToUSVString(name); } delete[] name; - for (std::vector::iterator iter = searchParams.begin(); iter != searchParams.end();) { + for (auto iter = searchParams.begin(); iter != searchParams.end();) { if (*iter == sname) { iter = searchParams.erase(iter, iter + 2); // 2:Searching for the number and number of keys and values } else { @@ -2032,7 +2032,7 @@ namespace OHOS::Url { delete[] buffer1; } bool flag = false; - for (std::vector::iterator it = searchParams.begin(); it < searchParams.end() - 1;) { + for (auto it = searchParams.begin(); it < (searchParams.end() - 1);) { if (*it == cppName) { if (!flag) { *(it + 1) = cppValue; diff --git a/url/native_module_url.cpp b/url/native_module_url.cpp index 279f4316738e6d8449c3ebcb9578845a00c8589c..57fc077dffa10be2db1deee22ed75e14188a8595 100755 --- a/url/native_module_url.cpp +++ b/url/native_module_url.cpp @@ -20,6 +20,8 @@ extern const char _binary_js_url_js_start[]; extern const char _binary_js_url_js_end[]; +extern const char _binary_url_abc_start[]; +extern const char _binary_url_abc_end[]; namespace OHOS::Url { static void UrlStructor(napi_env &env, napi_callback_info &info, URL *&object) { @@ -884,7 +886,7 @@ namespace OHOS::Url { DECLARE_NAPI_GETTER("GetIsIpv6", GetIsIpv6), }; NAPI_CALL(env, napi_define_class(env, urlClassName, strlen(urlClassName), UrlConstructor, - nullptr, sizeof(UrlDesc) / sizeof(UrlDesc[0]), UrlDesc, &urlClass)); + nullptr, sizeof(UrlDesc) / sizeof(UrlDesc[0]), UrlDesc, &urlClass)); static napi_property_descriptor desc[] = { DECLARE_NAPI_PROPERTY("Url", urlClass) }; @@ -914,7 +916,16 @@ namespace OHOS::Url { *bufLen = _binary_js_url_js_end - _binary_js_url_js_start; } } - + extern "C" + __attribute__((visibility("default"))) void NAPI_url_GetABCCode(const char** buf, int* buflen) + { + if (buf != nullptr) { + *buf = _binary_url_abc_start; + } + if (buflen != nullptr) { + *buflen = _binary_url_abc_end - _binary_url_abc_start; + } + } static napi_module UrlModule = { .nm_version = 1, .nm_flags = 0,