mirror of
https://gitee.com/openharmony/commonlibrary_ets_utils
synced 2024-11-23 07:20:14 +00:00
!1500 Optimize text decoder
Merge pull request !1500 from 刘智杰/text_decoder
This commit is contained in:
commit
4d6c458b96
@ -31,15 +31,14 @@
|
||||
namespace OHOS::Util {
|
||||
using namespace Commonlibrary::Platform;
|
||||
|
||||
TextDecoder::TextDecoder(const std::string &buff, std::vector<int> optionVec)
|
||||
: label_(0), encStr_(buff), tranTool_(nullptr, nullptr)
|
||||
TextDecoder::TextDecoder(const std::string &buff, int32_t flags)
|
||||
: encStr_(buff), tranTool_(nullptr, nullptr)
|
||||
{
|
||||
label_ |= optionVec[0] ? static_cast<int32_t>(ConverterFlags::FATAL_FLG) : 0;
|
||||
label_ |= optionVec[1] ? static_cast<int32_t>(ConverterFlags::IGNORE_BOM_FLG) : 0;
|
||||
label_ |= flags;
|
||||
#if !defined(__ARKUI_CROSS__)
|
||||
SetHwIcuDirectory();
|
||||
#endif
|
||||
bool fatal = (label_ & static_cast<int32_t>(ConverterFlags::FATAL_FLG)) ==
|
||||
bool fatal = (flags & static_cast<int32_t>(ConverterFlags::FATAL_FLG)) ==
|
||||
static_cast<int32_t>(ConverterFlags::FATAL_FLG);
|
||||
UErrorCode codeflag = U_ZERO_ERROR;
|
||||
UConverter *conv = CreateConverter(encStr_, codeflag);
|
||||
@ -240,42 +239,6 @@ namespace OHOS::Util {
|
||||
return resultStr;
|
||||
}
|
||||
|
||||
napi_value TextDecoder::GetEncoding(napi_env env) const
|
||||
{
|
||||
size_t length = encStr_.length();
|
||||
napi_value result = nullptr;
|
||||
NAPI_CALL(env, napi_create_string_utf8(env, encStr_.c_str(), length, &result));
|
||||
return result;
|
||||
}
|
||||
|
||||
napi_value TextDecoder::GetFatal(napi_env env) const
|
||||
{
|
||||
int32_t temp = label_ & static_cast<int32_t>(ConverterFlags::FATAL_FLG);
|
||||
bool comRst = false;
|
||||
if (temp == static_cast<int32_t>(ConverterFlags::FATAL_FLG)) {
|
||||
comRst = true;
|
||||
} else {
|
||||
comRst = false;
|
||||
}
|
||||
napi_value result = nullptr;
|
||||
NAPI_CALL(env, napi_get_boolean(env, comRst, &result));
|
||||
return result;
|
||||
}
|
||||
|
||||
napi_value TextDecoder::GetIgnoreBOM(napi_env env) const
|
||||
{
|
||||
int32_t temp = label_ & static_cast<int32_t>(ConverterFlags::IGNORE_BOM_FLG);
|
||||
bool comRst = false;
|
||||
if (temp == static_cast<int32_t>(ConverterFlags::IGNORE_BOM_FLG)) {
|
||||
comRst = true;
|
||||
} else {
|
||||
comRst = false;
|
||||
}
|
||||
napi_value result;
|
||||
NAPI_CALL(env, napi_get_boolean(env, comRst, &result));
|
||||
return result;
|
||||
}
|
||||
|
||||
size_t TextDecoder::GetMinByteSize() const
|
||||
{
|
||||
if (tranTool_ == nullptr) {
|
||||
|
@ -54,7 +54,7 @@ namespace OHOS::Util {
|
||||
* @param buff Encoding format.
|
||||
* @param optionVec There are two attributes of code related option parameters: fatal and ignorebom.
|
||||
*/
|
||||
TextDecoder(const std::string &buff, std::vector<int> optionVec);
|
||||
TextDecoder(const std::string &buff, int32_t flags);
|
||||
|
||||
/**
|
||||
* Destructor of textencoder.
|
||||
@ -72,27 +72,6 @@ namespace OHOS::Util {
|
||||
|
||||
napi_value DecodeToString(napi_env env, napi_value src, bool iflag);
|
||||
|
||||
/**
|
||||
* Get encoding format.
|
||||
*
|
||||
* @param env NAPI environment parameters.
|
||||
*/
|
||||
napi_value GetEncoding(napi_env env) const;
|
||||
|
||||
/**
|
||||
* Gets the setting of the exception thrown.
|
||||
*
|
||||
* @param env NAPI environment parameters.
|
||||
*/
|
||||
napi_value GetFatal(napi_env env) const;
|
||||
|
||||
/**
|
||||
* Gets whether to ignore the setting of BOM flag.
|
||||
*
|
||||
* @param env NAPI environment parameters.
|
||||
*/
|
||||
napi_value GetIgnoreBOM(napi_env env) const;
|
||||
|
||||
/**
|
||||
* Gets the size of minimum byte.
|
||||
*/
|
||||
|
@ -350,50 +350,6 @@ namespace OHOS::Util {
|
||||
return result;
|
||||
}
|
||||
|
||||
static void SetVec(const napi_status fatSta, const napi_status bomSta, const bool fat, const bool bom,
|
||||
std::vector<int> ¶Vec)
|
||||
{
|
||||
if (paraVec.size() != 2) { // 2:The number of parameters is 2
|
||||
return;
|
||||
}
|
||||
if (fatSta == napi_ok) {
|
||||
if (fat) {
|
||||
paraVec[0] = 1;
|
||||
} else {
|
||||
paraVec[0] = 0;
|
||||
}
|
||||
}
|
||||
if (bomSta == napi_ok) {
|
||||
if (bom) {
|
||||
paraVec[1] = 1;
|
||||
} else {
|
||||
paraVec[1] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static napi_value GetSecPara(napi_env env, napi_value valData, std::vector<int> ¶Vec)
|
||||
{
|
||||
napi_value messageKeyFatal = nullptr;
|
||||
const char *messageKeyStrFatal = "fatal";
|
||||
napi_value messageKeyIgnorebom = nullptr;
|
||||
const char *messageKeyStrIgnorebom = "ignoreBOM";
|
||||
napi_value resultFatal = nullptr;
|
||||
napi_value resultIgnorebom = nullptr;
|
||||
bool bResultFat = false;
|
||||
bool bResultIgnbom = false;
|
||||
NAPI_CALL(env, napi_create_string_utf8(env, messageKeyStrFatal, strlen(messageKeyStrFatal),
|
||||
&messageKeyFatal));
|
||||
NAPI_CALL(env, napi_create_string_utf8(env, messageKeyStrIgnorebom, strlen(messageKeyStrIgnorebom),
|
||||
&messageKeyIgnorebom));
|
||||
NAPI_CALL(env, napi_get_property(env, valData, messageKeyFatal, &resultFatal));
|
||||
NAPI_CALL(env, napi_get_property(env, valData, messageKeyIgnorebom, &resultIgnorebom));
|
||||
napi_status naFat = napi_get_value_bool(env, resultFatal, &bResultFat);
|
||||
napi_status naBom = napi_get_value_bool(env, resultIgnorebom, &bResultIgnbom);
|
||||
SetVec(naFat, naBom, bResultFat, bResultIgnbom, paraVec);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static napi_value TextdecoderConstructor(napi_env env, napi_callback_info info)
|
||||
{
|
||||
size_t tempArgc = 0;
|
||||
@ -403,6 +359,7 @@ namespace OHOS::Util {
|
||||
void *data = nullptr;
|
||||
char *type = nullptr;
|
||||
size_t typeLen = 0;
|
||||
int32_t flags = 0;
|
||||
std::vector<int> paraVec(2, 0); // 2: Specifies the size of the container to be applied for.
|
||||
if (tempArgc == 1) {
|
||||
argc = 1;
|
||||
@ -423,12 +380,7 @@ namespace OHOS::Util {
|
||||
type = ApplyMemory(typeLen);
|
||||
}
|
||||
napi_get_value_string_utf8(env, argvArr[0], type, typeLen + 1, &typeLen);
|
||||
napi_valuetype valueType1;
|
||||
napi_typeof(env, argvArr[1], &valueType1);
|
||||
if (valueType1 != napi_undefined && valueType1 != napi_null) {
|
||||
// second para
|
||||
GetSecPara(env, argvArr[1], paraVec);
|
||||
}
|
||||
napi_get_value_int32(env, argvArr[1], &flags);
|
||||
}
|
||||
std::string enconding = "utf-8";
|
||||
if (type != nullptr) {
|
||||
@ -436,7 +388,7 @@ namespace OHOS::Util {
|
||||
}
|
||||
delete []type;
|
||||
type = nullptr;
|
||||
auto objectInfo = new (std::nothrow) TextDecoder(enconding, paraVec);
|
||||
auto objectInfo = new (std::nothrow) TextDecoder(enconding, flags);
|
||||
if (objectInfo == nullptr) {
|
||||
HILOG_ERROR("TextDecoder objectInfo is nullptr");
|
||||
return nullptr;
|
||||
@ -566,36 +518,6 @@ namespace OHOS::Util {
|
||||
return valStr;
|
||||
}
|
||||
|
||||
static napi_value TextdecoderGetEncoding(napi_env env, napi_callback_info info)
|
||||
{
|
||||
napi_value thisVar = nullptr;
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, nullptr));
|
||||
TextDecoder *textDecoder = nullptr;
|
||||
NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&textDecoder));
|
||||
napi_value retVal = textDecoder->GetEncoding(env);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
static napi_value TextdecoderGetFatal(napi_env env, napi_callback_info info)
|
||||
{
|
||||
napi_value thisVar = nullptr;
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, nullptr));
|
||||
TextDecoder *textDecoder = nullptr;
|
||||
NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&textDecoder));
|
||||
napi_value retVal = textDecoder->GetFatal(env);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
static napi_value TextdecoderGetIgnoreBOM(napi_env env, napi_callback_info info)
|
||||
{
|
||||
napi_value thisVar = nullptr;
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, nullptr));
|
||||
TextDecoder *textDecoder = nullptr;
|
||||
NAPI_CALL(env, napi_unwrap(env, thisVar, (void**)&textDecoder));
|
||||
napi_value retVal = textDecoder->GetIgnoreBOM(env);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
static bool CheckEncodingFormat(const std::string &encoding)
|
||||
{
|
||||
for (const auto& format : conventFormat) {
|
||||
@ -831,9 +753,6 @@ namespace OHOS::Util {
|
||||
DECLARE_NAPI_FUNCTION("decodeToString", DecodeToString),
|
||||
DECLARE_NAPI_FUNCTION("decode", TextdecoderDecode),
|
||||
DECLARE_NAPI_FUNCTION("decodeWithStream", TextdecoderDecode),
|
||||
DECLARE_NAPI_GETTER("encoding", TextdecoderGetEncoding),
|
||||
DECLARE_NAPI_GETTER("fatal", TextdecoderGetFatal),
|
||||
DECLARE_NAPI_GETTER("ignoreBOM", TextdecoderGetIgnoreBOM),
|
||||
};
|
||||
NAPI_CALL(env, napi_define_class(env, textDecoderClassName, strlen(textDecoderClassName),
|
||||
TextdecoderConstructor, nullptr,
|
||||
|
@ -41,6 +41,9 @@ let base64 = helpUtil.Base64;
|
||||
let types = helpUtil.Types;
|
||||
let stringdecoder = helpUtil.StringDecoder;
|
||||
|
||||
const CONVERTER_FLAGS_FLUSH = 0x1;
|
||||
const CONVERTER_FLAGS_FATAL = 0x2;
|
||||
const CONVERTER_FLAGS_IGNORE_BOM = 0x4;
|
||||
const typeErrorCode = 401;
|
||||
const syntaxErrorCode = 10200002;
|
||||
class BusinessError extends Error {
|
||||
@ -680,31 +683,43 @@ function promisify(func: Function): Function {
|
||||
}
|
||||
|
||||
interface TextDecoder {
|
||||
new(encoding?: string, options?: { fatal?: boolean; ignoreBOM?: boolean }): TextDecoder;
|
||||
new(encoding?: string, flags?: number): TextDecoder;
|
||||
}
|
||||
|
||||
class TextDecoder {
|
||||
static encodeStr: string = '';
|
||||
encodeStr: string = 'utf-8';
|
||||
flags: number = 0;
|
||||
isIgnoreBOM: boolean = false;
|
||||
isFatal: boolean = false;
|
||||
textDecoder: TextDecoder;
|
||||
constructor(encoding?: string, options?: { fatal?: boolean; ignoreBOM?: boolean }) {
|
||||
if (encoding) {
|
||||
this.encodeStr = encoding;
|
||||
}
|
||||
let flags = 0;
|
||||
if (arguments.length === 0) {
|
||||
this.textDecoder = new helpUtil.TextDecoder();
|
||||
} else if (arguments.length === 1) {
|
||||
this.textDecoder = new helpUtil.TextDecoder(encoding);
|
||||
} else {
|
||||
this.textDecoder = new helpUtil.TextDecoder(encoding, options);
|
||||
if (options) {
|
||||
flags |= options.fatal ? CONVERTER_FLAGS_FATAL : 0;
|
||||
flags |= options.ignoreBOM ? CONVERTER_FLAGS_IGNORE_BOM : 0;
|
||||
}
|
||||
this.isFatal = options?.fatal;
|
||||
this.isIgnoreBOM = options?.ignoreBOM;
|
||||
this.textDecoder = new helpUtil.TextDecoder(encoding, flags);
|
||||
}
|
||||
this.flags = flags;
|
||||
}
|
||||
|
||||
static create(encoding?: string, options?: { fatal?: boolean; ignoreBOM?: boolean }): TextDecoder {
|
||||
if (arguments.length === 0) {
|
||||
TextDecoder.encodeStr = 'utf-8';
|
||||
return new TextDecoder();
|
||||
} else if (arguments.length === 1) {
|
||||
if (typeof encoding !== 'string' && encoding !== undefined && encoding !== null) {
|
||||
throw new BusinessError(`Parameter error. The type of ${encoding} must be string`);
|
||||
}
|
||||
TextDecoder.encodeStr = encoding;
|
||||
return new TextDecoder(encoding);
|
||||
} else {
|
||||
if (typeof encoding !== 'string' && encoding !== undefined && encoding !== null) {
|
||||
@ -713,7 +728,6 @@ class TextDecoder {
|
||||
if (typeof options !== 'object' && options !== undefined && options !== null) {
|
||||
throw new BusinessError(`Parameter error. The type of ${options} must be object`);
|
||||
}
|
||||
TextDecoder.encodeStr = encoding;
|
||||
return new TextDecoder(encoding, options);
|
||||
}
|
||||
}
|
||||
@ -747,15 +761,15 @@ class TextDecoder {
|
||||
}
|
||||
|
||||
get encoding(): string {
|
||||
return this.textDecoder.encoding;
|
||||
return this.encodeStr;
|
||||
}
|
||||
|
||||
get fatal(): boolean {
|
||||
return this.textDecoder.fatal;
|
||||
return this.isFatal;
|
||||
}
|
||||
|
||||
get ignoreBOM(): boolean {
|
||||
return this.textDecoder.ignoreBOM;
|
||||
return this.isIgnoreBOM;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -879,323 +879,6 @@ HWTEST_F(NativeEngineTest, textEncodeIntoTest007, testing::ext::TestSize.Level0)
|
||||
ASSERT_EQ(resWritten, static_cast<uint32_t>(7));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetEncoding001
|
||||
* @tc.desc: Test date type.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(NativeEngineTest, GetEncoding001, testing::ext::TestSize.Level0)
|
||||
{
|
||||
HILOG_INFO("TextDecoder::getEncodingTest001 start");
|
||||
napi_env env = (napi_env)engine_;
|
||||
std::vector<int> inputVec;
|
||||
int fatal = -1;
|
||||
int ignoreBOM = -1;
|
||||
inputVec.push_back(fatal);
|
||||
inputVec.push_back(ignoreBOM);
|
||||
std::string str = "utf-8";
|
||||
OHOS::Util::TextDecoder textDecoder(str, inputVec);
|
||||
napi_value testString = textDecoder.GetEncoding(env);
|
||||
size_t bufferSize = 0;
|
||||
napi_get_value_string_utf8(env, testString, nullptr, 0, &bufferSize);
|
||||
std::string tmpTestStr = "utf-8";
|
||||
size_t strLength = 0;
|
||||
char* buffer = nullptr;
|
||||
if (bufferSize > 0) {
|
||||
buffer = new char[bufferSize + 1]();
|
||||
napi_get_value_string_utf8(env, testString, buffer, bufferSize + 1, &strLength);
|
||||
}
|
||||
const char *result = tmpTestStr.c_str();
|
||||
size_t resultLength = tmpTestStr.length();
|
||||
ASSERT_STREQ(result, buffer);
|
||||
ASSERT_EQ(resultLength, strLength);
|
||||
if (buffer != nullptr) {
|
||||
delete []buffer;
|
||||
buffer = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetEncoding002
|
||||
* @tc.desc: Test date type.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(NativeEngineTest, GetEncoding002, testing::ext::TestSize.Level0)
|
||||
{
|
||||
HILOG_INFO("TextDecoder::getEncodingTest002 start");
|
||||
napi_env env = (napi_env)engine_;
|
||||
std::vector<int> inputVec;
|
||||
int fatal = -1;
|
||||
int ignoreBOM = -1;
|
||||
inputVec.push_back(fatal);
|
||||
inputVec.push_back(ignoreBOM);
|
||||
std::string str = "GB18030";
|
||||
OHOS::Util::TextDecoder textDecoder(str, inputVec);
|
||||
napi_value testString = textDecoder.GetEncoding(env);
|
||||
size_t bufferSize = 0;
|
||||
napi_get_value_string_utf8(env, testString, nullptr, 0, &bufferSize);
|
||||
std::string tmpTestStr = "GB18030";
|
||||
size_t strLength = 0;
|
||||
char* buffer = nullptr;
|
||||
if (bufferSize > 0) {
|
||||
buffer = new char[bufferSize + 1]();
|
||||
napi_get_value_string_utf8(env, testString, buffer, bufferSize + 1, &strLength);
|
||||
}
|
||||
const char *result = tmpTestStr.c_str();
|
||||
size_t resultLength = tmpTestStr.length();
|
||||
ASSERT_STREQ(result, buffer);
|
||||
ASSERT_EQ(resultLength, strLength);
|
||||
if (buffer != nullptr) {
|
||||
delete []buffer;
|
||||
buffer = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetEncoding003
|
||||
* @tc.desc: Test date type.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(NativeEngineTest, GetEncoding003, testing::ext::TestSize.Level0)
|
||||
{
|
||||
HILOG_INFO("TextDecoder::getEncodingTest003 start");
|
||||
napi_env env = (napi_env)engine_;
|
||||
std::vector<int> inputVec;
|
||||
int fatal = -1;
|
||||
int ignoreBOM = -1;
|
||||
inputVec.push_back(fatal);
|
||||
inputVec.push_back(ignoreBOM);
|
||||
std::string str = "gb18030";
|
||||
OHOS::Util::TextDecoder textDecoder(str, inputVec);
|
||||
napi_value testString = textDecoder.GetEncoding(env);
|
||||
size_t bufferSize = 0;
|
||||
napi_get_value_string_utf8(env, testString, nullptr, 0, &bufferSize);
|
||||
std::string tmpTestStr = "gb18030";
|
||||
size_t strLength = 0;
|
||||
char* buffer = nullptr;
|
||||
if (bufferSize > 0) {
|
||||
buffer = new char[bufferSize + 1]();
|
||||
napi_get_value_string_utf8(env, testString, buffer, bufferSize + 1, &strLength);
|
||||
}
|
||||
const char *result = tmpTestStr.c_str();
|
||||
size_t resultLength = tmpTestStr.length();
|
||||
ASSERT_STREQ(result, buffer);
|
||||
ASSERT_EQ(resultLength, strLength);
|
||||
if (buffer != nullptr) {
|
||||
delete []buffer;
|
||||
buffer = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetEncoding004
|
||||
* @tc.desc: Test date type.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(NativeEngineTest, GetEncoding004, testing::ext::TestSize.Level0)
|
||||
{
|
||||
napi_env env = (napi_env)engine_;
|
||||
std::vector<int> inputVec;
|
||||
int fatal = 0;
|
||||
int ignoreBOM = -1;
|
||||
inputVec.push_back(fatal);
|
||||
inputVec.push_back(ignoreBOM);
|
||||
std::string str = "utf-8";
|
||||
OHOS::Util::TextDecoder textDecoder(str, inputVec);
|
||||
napi_value testString = textDecoder.GetEncoding(env);
|
||||
size_t bufferSize = 0;
|
||||
napi_get_value_string_utf8(env, testString, nullptr, 0, &bufferSize);
|
||||
std::string tmpTestStr = "utf-8";
|
||||
size_t strLength = 0;
|
||||
char *buffer = nullptr;
|
||||
if (bufferSize > 0) {
|
||||
buffer = new char[bufferSize + 1]();
|
||||
napi_get_value_string_utf8(env, testString, buffer, bufferSize + 1, &strLength);
|
||||
}
|
||||
const char *result = tmpTestStr.c_str();
|
||||
size_t resultLength = tmpTestStr.length();
|
||||
ASSERT_STREQ(result, buffer);
|
||||
ASSERT_EQ(resultLength, strLength);
|
||||
if (buffer != nullptr) {
|
||||
delete []buffer;
|
||||
buffer = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetFatal001
|
||||
* @tc.desc: Test date type.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(NativeEngineTest, GetFatal001, testing::ext::TestSize.Level0)
|
||||
{
|
||||
HILOG_INFO("TextDecoder::GetFatal001 start");
|
||||
napi_env env = (napi_env)engine_;
|
||||
std::vector<int> inputVec;
|
||||
int fatal = 1;
|
||||
int ignoreBOM = 0;
|
||||
inputVec.push_back(fatal);
|
||||
inputVec.push_back(ignoreBOM);
|
||||
std::string str = "utf-8";
|
||||
OHOS::Util::TextDecoder textDecoder(str, inputVec);
|
||||
napi_value naVal = textDecoder.GetFatal(env);
|
||||
bool result = false;
|
||||
napi_get_value_bool(env, naVal, &result);
|
||||
ASSERT_TRUE(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetFatal002
|
||||
* @tc.desc: Test date type.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(NativeEngineTest, GetFatal002, testing::ext::TestSize.Level0)
|
||||
{
|
||||
HILOG_INFO("TextDecoder::GetFatal002 start");
|
||||
napi_env env = (napi_env)engine_;
|
||||
std::vector<int> inputVec;
|
||||
int fatal = -1;
|
||||
int ignoreBOM = 1;
|
||||
inputVec.push_back(fatal);
|
||||
inputVec.push_back(ignoreBOM);
|
||||
std::string str = "utf-8";
|
||||
OHOS::Util::TextDecoder textDecoder(str, inputVec);
|
||||
napi_value naVal = textDecoder.GetFatal(env);
|
||||
bool result = false;
|
||||
napi_get_value_bool(env, naVal, &result);
|
||||
ASSERT_TRUE(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetFatal003
|
||||
* @tc.desc: Test date type.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(NativeEngineTest, GetFatal003, testing::ext::TestSize.Level0)
|
||||
{
|
||||
HILOG_INFO("TextDecoder::GetFatal003 start");
|
||||
napi_env env = (napi_env)engine_;
|
||||
std::vector<int> inputVec;
|
||||
int fatal = 0;
|
||||
int ignoreBOM = 1;
|
||||
inputVec.push_back(fatal);
|
||||
inputVec.push_back(ignoreBOM);
|
||||
std::string str = "utf-8";
|
||||
OHOS::Util::TextDecoder textDecoder(str, inputVec);
|
||||
napi_value naVal = textDecoder.GetFatal(env);
|
||||
bool result = false;
|
||||
napi_get_value_bool(env, naVal, &result);
|
||||
ASSERT_FALSE(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetIgnoreBOM001
|
||||
* @tc.desc: Test date type.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(NativeEngineTest, GetIgnoreBOM001, testing::ext::TestSize.Level0)
|
||||
{
|
||||
HILOG_INFO("TextDecoder::GetIgnoreBOM001 start");
|
||||
napi_env env = (napi_env)engine_;
|
||||
std::vector<int> inputVec;
|
||||
int fatal = -1;
|
||||
int ignoreBOM = 1;
|
||||
inputVec.push_back(fatal);
|
||||
inputVec.push_back(ignoreBOM);
|
||||
std::string str = "utf-8";
|
||||
OHOS::Util::TextDecoder textDecoder(str, inputVec);
|
||||
napi_value naVal = textDecoder.GetIgnoreBOM(env);
|
||||
bool result = false;
|
||||
napi_get_value_bool(env, naVal, &result);
|
||||
ASSERT_TRUE(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetIgnoreBOM002
|
||||
* @tc.desc: Test date type.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(NativeEngineTest, GetIgnoreBOM002, testing::ext::TestSize.Level0)
|
||||
{
|
||||
HILOG_INFO("TextDecoder::GetIgnoreBOM002 start");
|
||||
napi_env env = (napi_env)engine_;
|
||||
std::vector<int> inputVec;
|
||||
int fatal = 0;
|
||||
int ignoreBOM = 1;
|
||||
inputVec.push_back(fatal);
|
||||
inputVec.push_back(ignoreBOM);
|
||||
std::string str = "utf-8";
|
||||
OHOS::Util::TextDecoder textDecoder(str, inputVec);
|
||||
napi_value naVal = textDecoder.GetIgnoreBOM(env);
|
||||
bool result = false;
|
||||
napi_get_value_bool(env, naVal, &result);
|
||||
ASSERT_TRUE(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetIgnoreBOM003
|
||||
* @tc.desc: Test date type.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(NativeEngineTest, GetIgnoreBOM003, testing::ext::TestSize.Level0)
|
||||
{
|
||||
HILOG_INFO("TextDecoder::GetIgnoreBOM003 start");
|
||||
napi_env env = (napi_env)engine_;
|
||||
std::vector<int> inputVec;
|
||||
int fatal = 1;
|
||||
int ignoreBOM = 1;
|
||||
inputVec.push_back(fatal);
|
||||
inputVec.push_back(ignoreBOM);
|
||||
std::string str = "utf-8";
|
||||
OHOS::Util::TextDecoder textDecoder(str, inputVec);
|
||||
napi_value naVal = textDecoder.GetIgnoreBOM(env);
|
||||
bool result = false;
|
||||
napi_get_value_bool(env, naVal, &result);
|
||||
ASSERT_TRUE(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetIgnoreBOM004
|
||||
* @tc.desc: Test date type.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(NativeEngineTest, GetIgnoreBOM004, testing::ext::TestSize.Level0)
|
||||
{
|
||||
napi_env env = (napi_env)engine_;
|
||||
std::vector<int> inputVec;
|
||||
int fatal = 0;
|
||||
int ignoreBOM = -1;
|
||||
inputVec.push_back(fatal);
|
||||
inputVec.push_back(ignoreBOM);
|
||||
std::string str = "ssn";
|
||||
OHOS::Util::TextDecoder textDecoder(str, inputVec);
|
||||
napi_value naVal = textDecoder.GetIgnoreBOM(env);
|
||||
bool result = false;
|
||||
napi_get_value_bool(env, naVal, &result);
|
||||
ASSERT_TRUE(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetIgnoreBOM005
|
||||
* @tc.desc: Test date type.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(NativeEngineTest, GetIgnoreBOM005, testing::ext::TestSize.Level0)
|
||||
{
|
||||
napi_env env = (napi_env)engine_;
|
||||
std::vector<int> inputVec;
|
||||
int fatal = -1;
|
||||
int ignoreBOM = 0;
|
||||
inputVec.push_back(fatal);
|
||||
inputVec.push_back(ignoreBOM);
|
||||
std::string str = "ssn";
|
||||
OHOS::Util::TextDecoder textDecoder(str, inputVec);
|
||||
napi_value naVal = textDecoder.GetIgnoreBOM(env);
|
||||
bool result = false;
|
||||
napi_get_value_bool(env, naVal, &result);
|
||||
ASSERT_FALSE(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: decoderUtf8001 utf-8
|
||||
* @tc.desc: Test date type.
|
||||
@ -1205,13 +888,10 @@ HWTEST_F(NativeEngineTest, decoderUtf8001, testing::ext::TestSize.Level0)
|
||||
{
|
||||
HILOG_INFO("decoderUtf8001 start");
|
||||
napi_env env = (napi_env)engine_;
|
||||
std::vector<int> inputVec;
|
||||
int fatal = -1;
|
||||
int ignoreBOM = -1;
|
||||
inputVec.push_back(fatal);
|
||||
inputVec.push_back(ignoreBOM);
|
||||
int32_t flags = static_cast<int>(OHOS::Util::TextDecoder::ConverterFlags::FATAL_FLG) |
|
||||
static_cast<int>(OHOS::Util::TextDecoder::ConverterFlags::IGNORE_BOM_FLG);
|
||||
std::string str = "utf-8";
|
||||
OHOS::Util::TextDecoder textDecoder(str, inputVec);
|
||||
OHOS::Util::TextDecoder textDecoder(str, flags);
|
||||
bool iflag = false;
|
||||
size_t byteLength = 3;
|
||||
void* data = nullptr;
|
||||
@ -1247,13 +927,9 @@ HWTEST_F(NativeEngineTest, decoderUtf8002, testing::ext::TestSize.Level0)
|
||||
{
|
||||
HILOG_INFO("decoderUtf8002 start");
|
||||
napi_env env = (napi_env)engine_;
|
||||
std::vector<int> inputVec;
|
||||
int fatal = -1;
|
||||
int ignoreBOM = 0;
|
||||
inputVec.push_back(fatal);
|
||||
inputVec.push_back(ignoreBOM);
|
||||
int32_t flags = static_cast<int>(OHOS::Util::TextDecoder::ConverterFlags::FATAL_FLG);
|
||||
std::string str = "utf-8";
|
||||
OHOS::Util::TextDecoder textDecoder(str, inputVec);
|
||||
OHOS::Util::TextDecoder textDecoder(str, flags);
|
||||
bool iflag = true;
|
||||
size_t byteLength = 5;
|
||||
void* data = nullptr;
|
||||
@ -1288,13 +964,10 @@ HWTEST_F(NativeEngineTest, decoderUtf8002, testing::ext::TestSize.Level0)
|
||||
HWTEST_F(NativeEngineTest, decoderUtf8003, testing::ext::TestSize.Level0)
|
||||
{
|
||||
napi_env env = (napi_env)engine_;
|
||||
std::vector<int> inputVec;
|
||||
int fatal = -1;
|
||||
int ignoreBOM = -1;
|
||||
inputVec.push_back(fatal);
|
||||
inputVec.push_back(ignoreBOM);
|
||||
int32_t flags = static_cast<int>(OHOS::Util::TextDecoder::ConverterFlags::FATAL_FLG) |
|
||||
static_cast<int>(OHOS::Util::TextDecoder::ConverterFlags::IGNORE_BOM_FLG);
|
||||
std::string str = "utf-8";
|
||||
OHOS::Util::TextDecoder textDecoder(str, inputVec);
|
||||
OHOS::Util::TextDecoder textDecoder(str, flags);
|
||||
bool iflag = false;
|
||||
size_t byteLength = 0;
|
||||
void *data = nullptr;
|
||||
@ -1315,13 +988,9 @@ HWTEST_F(NativeEngineTest, decoderUtf16le001, testing::ext::TestSize.Level0)
|
||||
{
|
||||
HILOG_INFO("decoderUtf16le001 start");
|
||||
napi_env env = (napi_env)engine_;
|
||||
std::vector<int> inputVec;
|
||||
int fatal = 0;
|
||||
int ignoreBOM = 0;
|
||||
inputVec.push_back(fatal);
|
||||
inputVec.push_back(ignoreBOM);
|
||||
int32_t flags = 0;
|
||||
std::string str = "utf-16le";
|
||||
OHOS::Util::TextDecoder textDecoder(str, inputVec);
|
||||
OHOS::Util::TextDecoder textDecoder(str, flags);
|
||||
bool iflag = false;
|
||||
size_t byteLength = 6;
|
||||
void* data = nullptr;
|
||||
@ -1357,13 +1026,9 @@ HWTEST_F(NativeEngineTest, decoderUtf16le002, testing::ext::TestSize.Level0)
|
||||
{
|
||||
HILOG_INFO("decoderUtf16le002 start");
|
||||
napi_env env = (napi_env)engine_;
|
||||
std::vector<int> inputVec;
|
||||
int fatal = 0;
|
||||
int ignoreBOM = 1;
|
||||
inputVec.push_back(fatal);
|
||||
inputVec.push_back(ignoreBOM);
|
||||
int32_t flags = static_cast<int>(OHOS::Util::TextDecoder::ConverterFlags::IGNORE_BOM_FLG);
|
||||
std::string str = "utf-16le";
|
||||
OHOS::Util::TextDecoder textDecoder(str, inputVec);
|
||||
OHOS::Util::TextDecoder textDecoder(str, flags);
|
||||
bool iflag = true;
|
||||
size_t byteLength = 6;
|
||||
void* data = nullptr;
|
||||
@ -1399,13 +1064,9 @@ HWTEST_F(NativeEngineTest, decoderUtf16le003, testing::ext::TestSize.Level0)
|
||||
{
|
||||
HILOG_INFO("decoderUtf16le003 start");
|
||||
napi_env env = (napi_env)engine_;
|
||||
std::vector<int> inputVec;
|
||||
int fatal = 0;
|
||||
int ignoreBOM = 0;
|
||||
inputVec.push_back(fatal);
|
||||
inputVec.push_back(ignoreBOM);
|
||||
int32_t flags = 0;
|
||||
std::string str = "utf-16le";
|
||||
OHOS::Util::TextDecoder textDecoder(str, inputVec);
|
||||
OHOS::Util::TextDecoder textDecoder(str, flags);
|
||||
bool iflag = true;
|
||||
size_t byteLength = 8;
|
||||
void* data = nullptr;
|
||||
@ -1448,13 +1109,10 @@ HWTEST_F(NativeEngineTest, decoderUtf16le004, testing::ext::TestSize.Level0)
|
||||
{
|
||||
HILOG_INFO("decoderUtf16le004 start");
|
||||
napi_env env = (napi_env)engine_;
|
||||
std::vector<int> inputVec;
|
||||
int fatal = -1;
|
||||
int ignoreBOM = -1;
|
||||
inputVec.push_back(fatal);
|
||||
inputVec.push_back(ignoreBOM);
|
||||
int32_t flags = static_cast<int>(OHOS::Util::TextDecoder::ConverterFlags::FATAL_FLG) |
|
||||
static_cast<int>(OHOS::Util::TextDecoder::ConverterFlags::IGNORE_BOM_FLG);
|
||||
std::string str = "utf-16le";
|
||||
OHOS::Util::TextDecoder textDecoder(str, inputVec);
|
||||
OHOS::Util::TextDecoder textDecoder(str, flags);
|
||||
bool iflag = false;
|
||||
size_t byteLength = 8;
|
||||
void* data = nullptr;
|
||||
@ -1497,13 +1155,9 @@ HWTEST_F(NativeEngineTest, decoderUtf16be001, testing::ext::TestSize.Level0)
|
||||
{
|
||||
HILOG_INFO("decoderUtf16be001 start");
|
||||
napi_env env = (napi_env)engine_;
|
||||
std::vector<int> inputVec;
|
||||
int fatal = 0;
|
||||
int ignoreBOM = 0;
|
||||
inputVec.push_back(fatal);
|
||||
inputVec.push_back(ignoreBOM);
|
||||
int32_t flags = 0;
|
||||
std::string str = "utf-16be";
|
||||
OHOS::Util::TextDecoder textDecoder(str, inputVec);
|
||||
OHOS::Util::TextDecoder textDecoder(str, flags);
|
||||
bool iflag = false;
|
||||
size_t byteLength = 6;
|
||||
void* data = nullptr;
|
||||
@ -1539,13 +1193,9 @@ HWTEST_F(NativeEngineTest, decoderUtf16be002, testing::ext::TestSize.Level0)
|
||||
{
|
||||
HILOG_INFO("decoderUtf16be002 start");
|
||||
napi_env env = (napi_env)engine_;
|
||||
std::vector<int> inputVec;
|
||||
int fatal = 0;
|
||||
int ignoreBOM = 0;
|
||||
inputVec.push_back(fatal);
|
||||
inputVec.push_back(ignoreBOM);
|
||||
int32_t flags = 0;
|
||||
std::string str = "utf-16be";
|
||||
OHOS::Util::TextDecoder textDecoder(str, inputVec);
|
||||
OHOS::Util::TextDecoder textDecoder(str, flags);
|
||||
bool iflag = false;
|
||||
size_t byteLength = 8;
|
||||
void* data = nullptr;
|
||||
@ -1588,13 +1238,9 @@ HWTEST_F(NativeEngineTest, decoderUtf16be003, testing::ext::TestSize.Level0)
|
||||
{
|
||||
HILOG_INFO("decoderUtf16be003 start");
|
||||
napi_env env = (napi_env)engine_;
|
||||
std::vector<int> inputVec;
|
||||
int fatal = 0;
|
||||
int ignoreBOM = 1;
|
||||
inputVec.push_back(fatal);
|
||||
inputVec.push_back(ignoreBOM);
|
||||
int32_t flags = static_cast<int>(OHOS::Util::TextDecoder::ConverterFlags::IGNORE_BOM_FLG);
|
||||
std::string str = "utf-16be";
|
||||
OHOS::Util::TextDecoder textDecoder(str, inputVec);
|
||||
OHOS::Util::TextDecoder textDecoder(str, flags);
|
||||
bool iflag = true;
|
||||
size_t byteLength = 8;
|
||||
void* data = nullptr;
|
||||
@ -1637,13 +1283,9 @@ HWTEST_F(NativeEngineTest, decoderUtf8BOM001, testing::ext::TestSize.Level0)
|
||||
{
|
||||
HILOG_INFO("decoderUtf8BOM001 start");
|
||||
napi_env env = (napi_env)engine_;
|
||||
std::vector<int> inputVec;
|
||||
int fatal = 0;
|
||||
int ignoreBOM = 1;
|
||||
inputVec.push_back(fatal);
|
||||
inputVec.push_back(ignoreBOM);
|
||||
int32_t flags = static_cast<int>(OHOS::Util::TextDecoder::ConverterFlags::IGNORE_BOM_FLG);
|
||||
std::string encoding = "utf-8";
|
||||
OHOS::Util::TextDecoder textDecoder(encoding, inputVec);
|
||||
OHOS::Util::TextDecoder textDecoder(encoding, flags);
|
||||
bool iflag = true;
|
||||
size_t byteLength = 6;
|
||||
void* data = nullptr;
|
||||
@ -1681,13 +1323,9 @@ HWTEST_F(NativeEngineTest, decoderUtf8BOM002, testing::ext::TestSize.Level0)
|
||||
{
|
||||
HILOG_INFO("decoderUtf8BOM002 start");
|
||||
napi_env env = (napi_env)engine_;
|
||||
std::vector<int> inputVec;
|
||||
int fatal = 0;
|
||||
int ignoreBOM = 0;
|
||||
inputVec.push_back(fatal);
|
||||
inputVec.push_back(ignoreBOM);
|
||||
int32_t flags = 0;
|
||||
std::string encoding = "utf-8";
|
||||
OHOS::Util::TextDecoder textDecoder(encoding, inputVec);
|
||||
OHOS::Util::TextDecoder textDecoder(encoding, flags);
|
||||
bool iflag = true;
|
||||
size_t byteLength = 6;
|
||||
void* data = nullptr;
|
||||
@ -1725,13 +1363,10 @@ HWTEST_F(NativeEngineTest, decoderUtf8BOM003, testing::ext::TestSize.Level0)
|
||||
{
|
||||
HILOG_INFO("decoderUtf8BOM003 start");
|
||||
napi_env env = (napi_env)engine_;
|
||||
std::vector<int> inputVec;
|
||||
int fatal = -1;
|
||||
int ignoreBOM = -1;
|
||||
inputVec.push_back(fatal);
|
||||
inputVec.push_back(ignoreBOM);
|
||||
int32_t flags = static_cast<int>(OHOS::Util::TextDecoder::ConverterFlags::FATAL_FLG) |
|
||||
static_cast<int>(OHOS::Util::TextDecoder::ConverterFlags::IGNORE_BOM_FLG);
|
||||
std::string str = "utf-8";
|
||||
OHOS::Util::TextDecoder textDecoder(str, inputVec);
|
||||
OHOS::Util::TextDecoder textDecoder(str, flags);
|
||||
bool iflag = false;
|
||||
size_t byteLength = 0;
|
||||
void *data = nullptr;
|
||||
@ -1752,13 +1387,9 @@ HWTEST_F(NativeEngineTest, decoderUtf8BOM004, testing::ext::TestSize.Level0)
|
||||
{
|
||||
HILOG_INFO("decoderUtf8BOM004 start");
|
||||
napi_env env = (napi_env)engine_;
|
||||
std::vector<int> inputVec;
|
||||
int fatal = 0;
|
||||
int ignoreBOM = 1;
|
||||
inputVec.push_back(fatal);
|
||||
inputVec.push_back(ignoreBOM);
|
||||
int32_t flags = static_cast<int>(OHOS::Util::TextDecoder::ConverterFlags::IGNORE_BOM_FLG);
|
||||
std::string encoding = "utf-8";
|
||||
OHOS::Util::TextDecoder textDecoder(encoding, inputVec);
|
||||
OHOS::Util::TextDecoder textDecoder(encoding, flags);
|
||||
bool iflag = false;
|
||||
size_t byteLength = 6;
|
||||
void* data = nullptr;
|
||||
@ -1796,13 +1427,9 @@ HWTEST_F(NativeEngineTest, decoderUtf8BOM005, testing::ext::TestSize.Level0)
|
||||
{
|
||||
HILOG_INFO("decoderUtf8BOM005 start");
|
||||
napi_env env = (napi_env)engine_;
|
||||
std::vector<int> inputVec;
|
||||
int fatal = 0;
|
||||
int ignoreBOM = 0;
|
||||
inputVec.push_back(fatal);
|
||||
inputVec.push_back(ignoreBOM);
|
||||
int32_t flags = 0;
|
||||
std::string encoding = "utf-8";
|
||||
OHOS::Util::TextDecoder textDecoder(encoding, inputVec);
|
||||
OHOS::Util::TextDecoder textDecoder(encoding, flags);
|
||||
bool iflag = true;
|
||||
size_t byteLength = 11;
|
||||
void* data = nullptr;
|
||||
@ -1840,13 +1467,9 @@ HWTEST_F(NativeEngineTest, decoderUtf8BOM006, testing::ext::TestSize.Level0)
|
||||
{
|
||||
HILOG_INFO("decoderUtf8BOM006 start");
|
||||
napi_env env = (napi_env)engine_;
|
||||
std::vector<int> inputVec;
|
||||
int fatal = 0;
|
||||
int ignoreBOM = 0;
|
||||
inputVec.push_back(fatal);
|
||||
inputVec.push_back(ignoreBOM);
|
||||
int32_t flags = 0;
|
||||
std::string encoding = "utf-8";
|
||||
OHOS::Util::TextDecoder textDecoder(encoding, inputVec);
|
||||
OHOS::Util::TextDecoder textDecoder(encoding, flags);
|
||||
bool iflag = true;
|
||||
size_t byteLength = 12;
|
||||
void* data = nullptr;
|
||||
@ -1884,13 +1507,9 @@ HWTEST_F(NativeEngineTest, decoderUtf8BOM007, testing::ext::TestSize.Level0)
|
||||
{
|
||||
HILOG_INFO("decoderUtf8BOM007 start");
|
||||
napi_env env = (napi_env)engine_;
|
||||
std::vector<int> inputVec;
|
||||
int fatal = 0;
|
||||
int ignoreBOM = 0;
|
||||
inputVec.push_back(fatal);
|
||||
inputVec.push_back(ignoreBOM);
|
||||
int32_t flags = 0;
|
||||
std::string encoding = "utf-8";
|
||||
OHOS::Util::TextDecoder textDecoder(encoding, inputVec);
|
||||
OHOS::Util::TextDecoder textDecoder(encoding, flags);
|
||||
bool iflag = true;
|
||||
size_t byteLength = 13;
|
||||
void* data = nullptr;
|
||||
@ -1928,13 +1547,9 @@ HWTEST_F(NativeEngineTest, decoderUtf8BOM008, testing::ext::TestSize.Level0)
|
||||
{
|
||||
HILOG_INFO("decoderUtf8BOM008 start");
|
||||
napi_env env = (napi_env)engine_;
|
||||
std::vector<int> inputVec;
|
||||
int fatal = 0;
|
||||
int ignoreBOM = 1;
|
||||
inputVec.push_back(fatal);
|
||||
inputVec.push_back(ignoreBOM);
|
||||
int32_t flags = static_cast<int>(OHOS::Util::TextDecoder::ConverterFlags::IGNORE_BOM_FLG);
|
||||
std::string encoding = "utf-8";
|
||||
OHOS::Util::TextDecoder textDecoder(encoding, inputVec);
|
||||
OHOS::Util::TextDecoder textDecoder(encoding, flags);
|
||||
bool iflag = false;
|
||||
size_t byteLength = 200;
|
||||
void* data = nullptr;
|
||||
@ -1979,13 +1594,9 @@ HWTEST_F(NativeEngineTest, decoderUtf8BOM009, testing::ext::TestSize.Level0)
|
||||
{
|
||||
HILOG_INFO("decoderUtf8BOM009 start");
|
||||
napi_env env = (napi_env)engine_;
|
||||
std::vector<int> inputVec;
|
||||
int fatal = 0;
|
||||
int ignoreBOM = 1;
|
||||
inputVec.push_back(fatal);
|
||||
inputVec.push_back(ignoreBOM);
|
||||
int32_t flags = static_cast<int>(OHOS::Util::TextDecoder::ConverterFlags::IGNORE_BOM_FLG);
|
||||
std::string encoding = "utf-16";
|
||||
OHOS::Util::TextDecoder textDecoder(encoding, inputVec);
|
||||
OHOS::Util::TextDecoder textDecoder(encoding, flags);
|
||||
bool iflag = true;
|
||||
size_t byteLength = 6;
|
||||
void* data = nullptr;
|
||||
@ -2021,13 +1632,10 @@ HWTEST_F(NativeEngineTest, decoderUtf8BOM009, testing::ext::TestSize.Level0)
|
||||
*/
|
||||
HWTEST_F(NativeEngineTest, getMinByteSizeTest001, testing::ext::TestSize.Level0)
|
||||
{
|
||||
std::vector<int> inputVec;
|
||||
int fatal = -1;
|
||||
int ignoreBOM = -1;
|
||||
inputVec.push_back(fatal);
|
||||
inputVec.push_back(ignoreBOM);
|
||||
int32_t flags = static_cast<int>(OHOS::Util::TextDecoder::ConverterFlags::FATAL_FLG) |
|
||||
static_cast<int>(OHOS::Util::TextDecoder::ConverterFlags::IGNORE_BOM_FLG);
|
||||
std::string str = "XYZ123";
|
||||
OHOS::Util::TextDecoder textDecoder(str, inputVec);
|
||||
OHOS::Util::TextDecoder textDecoder(str, flags);
|
||||
textDecoder.Reset();
|
||||
size_t rel1 = textDecoder.GetMinByteSize();
|
||||
ASSERT_EQ(rel1, 0);
|
||||
@ -3477,21 +3085,10 @@ HWTEST_F(NativeEngineTest, DecodeToStringNoStream001, testing::ext::TestSize.Lev
|
||||
{
|
||||
HILOG_INFO("DecodeToStringNoStream start");
|
||||
napi_env env = (napi_env)engine_;
|
||||
std::vector<int> inputVec;
|
||||
int fatal = 1;
|
||||
int ignoreBOM = 1;
|
||||
inputVec.push_back(fatal);
|
||||
inputVec.push_back(ignoreBOM);
|
||||
int32_t flags = static_cast<int>(OHOS::Util::TextDecoder::ConverterFlags::FATAL_FLG) |
|
||||
static_cast<int>(OHOS::Util::TextDecoder::ConverterFlags::IGNORE_BOM_FLG);
|
||||
std::string encoding = "utf-8";
|
||||
OHOS::Util::TextDecoder textDecoder(encoding, inputVec);
|
||||
bool res = false;
|
||||
napi_value bomFlag = textDecoder.GetIgnoreBOM(env);
|
||||
napi_get_value_bool(env, bomFlag, &res);
|
||||
ASSERT_TRUE(res);
|
||||
res = false;
|
||||
napi_value fatalFlag = textDecoder.GetFatal(env);
|
||||
napi_get_value_bool(env, bomFlag, &res);
|
||||
ASSERT_TRUE(res);
|
||||
OHOS::Util::TextDecoder textDecoder(encoding, flags);
|
||||
bool iflag = false;
|
||||
size_t byteLength = 6;
|
||||
void* data = nullptr;
|
||||
@ -3503,14 +3100,6 @@ HWTEST_F(NativeEngineTest, DecodeToStringNoStream001, testing::ext::TestSize.Lev
|
||||
napi_value result = nullptr;
|
||||
napi_create_typedarray(env, napi_int8_array, byteLength, resultBuff, 0, &result);
|
||||
textDecoder.DecodeToString(env, result, iflag);
|
||||
res = false;
|
||||
bomFlag = textDecoder.GetIgnoreBOM(env);
|
||||
napi_get_value_bool(env, bomFlag, &res);
|
||||
ASSERT_TRUE(res);
|
||||
res = false;
|
||||
fatalFlag = textDecoder.GetFatal(env);
|
||||
napi_get_value_bool(env, bomFlag, &res);
|
||||
ASSERT_TRUE(res);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -3522,21 +3111,10 @@ HWTEST_F(NativeEngineTest, DecodeToStringWithStream001, testing::ext::TestSize.L
|
||||
{
|
||||
HILOG_INFO("DecodeToStringWithStream start");
|
||||
napi_env env = (napi_env)engine_;
|
||||
std::vector<int> inputVec;
|
||||
int fatal = 1;
|
||||
int ignoreBOM = 1;
|
||||
inputVec.push_back(fatal);
|
||||
inputVec.push_back(ignoreBOM);
|
||||
int32_t flags = static_cast<int>(OHOS::Util::TextDecoder::ConverterFlags::FATAL_FLG) |
|
||||
static_cast<int>(OHOS::Util::TextDecoder::ConverterFlags::IGNORE_BOM_FLG);
|
||||
std::string encoding = "utf-8";
|
||||
OHOS::Util::TextDecoder textDecoder(encoding, inputVec);
|
||||
bool res = false;
|
||||
napi_value bomFlag = textDecoder.GetIgnoreBOM(env);
|
||||
napi_get_value_bool(env, bomFlag, &res);
|
||||
ASSERT_TRUE(res);
|
||||
res = false;
|
||||
napi_value fatalFlag = textDecoder.GetFatal(env);
|
||||
napi_get_value_bool(env, bomFlag, &res);
|
||||
ASSERT_TRUE(res);
|
||||
OHOS::Util::TextDecoder textDecoder(encoding, flags);
|
||||
bool iflag = true;
|
||||
size_t byteLength = 6;
|
||||
void* data = nullptr;
|
||||
@ -3548,14 +3126,6 @@ HWTEST_F(NativeEngineTest, DecodeToStringWithStream001, testing::ext::TestSize.L
|
||||
napi_value result = nullptr;
|
||||
napi_create_typedarray(env, napi_int8_array, byteLength, resultBuff, 0, &result);
|
||||
textDecoder.DecodeToString(env, result, iflag);
|
||||
res = false;
|
||||
bomFlag = textDecoder.GetIgnoreBOM(env);
|
||||
napi_get_value_bool(env, bomFlag, &res);
|
||||
ASSERT_TRUE(res);
|
||||
res = false;
|
||||
fatalFlag = textDecoder.GetFatal(env);
|
||||
napi_get_value_bool(env, bomFlag, &res);
|
||||
ASSERT_TRUE(res);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user