未验证 提交 4ac7862d 编写于 作者: O openharmony_ci 提交者: Gitee

!8646 增加 textencode 和 url模块相关可选参传undefined的用例

Merge pull request !8646 from 王犇/master
......@@ -206,6 +206,19 @@ describe('UrlFunTest', function () {
expect(err.message).assertEqual(`Parameter error.The type of 4 must be string`);
}
})
/**
* @tc.name: testNewURLParams001
* @tc.desc: The input parameter for New URLParams is undefined or null.
*/
it('testNewURLParams001', 0, function () {
let params = new Url.URLParams(undefined);
let result = params.toString();
expect(result).assertEqual('undefined=undefined');
let params1 = new Url.URLParams(null);
let result1 = params1.toString();
expect(result1).assertEqual('undefined=undefined');
})
/**
* @tc.name: testParamsEntries001
......@@ -488,6 +501,27 @@ describe('UrlFunTest', function () {
}
})
/**
* @tc.name: testParamsForEach007
* @tc.desc: The second parameter of forEach is undefined or null.
*/
it('testParamsForEach007', 0, function () {
let params = new Url.URLParams("key1=value1&key2=value2")
var arr = {};
var i = 0;
function func(value, key, SearchParams)
{
arr[i] = value + " " + key + " " + (params === SearchParams)
i++
}
params.forEach(func, undefined);
expect(arr[0]).assertEqual("value1 key1 true");
arr = {};
i = 0;
params.forEach(func, null);
expect(arr[0]).assertEqual("value1 key1 true");
})
/**
* @tc.name: testParamsGet001
* @tc.desc: Returns the first value associated to the given search parameter.
......@@ -1186,6 +1220,19 @@ describe('UrlFunTest', function () {
}
})
/**
* @tc.name: testNewURLSearchParams
* @tc.desc: The input parameter for New URLSearchParams is undefined or null.
*/
it('testNewURLSearchParams', 0, function () {
let params = new Url.URLSearchParams(undefined);
let result = params.toString()
expect(result).assertEqual('undefined=undefined')
let params1 = new Url.URLSearchParams(null);
let result2 = params1.toString()
expect(result2).assertEqual('undefined=undefined')
})
/**
* @tc.name: testUrlAppend001
* @tc.desc: Appends a specified key/value pair as a new search parameter.
......@@ -1585,6 +1632,27 @@ describe('UrlFunTest', function () {
expect(arr[0]).assertEqual("bar foo true");
})
/**
* @tc.name: testUrlForEach006
* @tc.desc: The second parameter of forEach is undefined or null.
*/
it('testUrlForEach006', 0, function () {
let params = new Url.URLSearchParams("key1=value1&key2=value2")
var arr = {};
var i = 0;
function func(value, key, SearchParams)
{
arr[i] = value + " " + key + " " + (params === SearchParams)
i++
}
params.forEach(func, undefined);
expect(arr[0]).assertEqual("value1 key1 true");
arr = {}
i = 0;
params.forEach(func, null);
expect(arr[0]).assertEqual("value1 key1 true");
})
/**
* @tc.name: testUrlGet001
* @tc.desc: Returns the first value associated to the given search parameter.
......@@ -2194,6 +2262,19 @@ describe('UrlFunTest', function () {
expect(paramsResult).assertEqual('abcde=fghki')
})
/**
* @tc.name: testNewUrl001
* @tc.desc: The second parameter of Url construction is undefined or null.
*/
it('testNewUrl001', 0, function () {
let params = new Url.URL('http://username:password@host:8080/directory/file?query#fragment', undefined)
let result = params.toString()
expect(result).assertEqual("http://username:password@host:8080/directory/file?query#fragment")
let params1 = new Url.URL('http://username:password@host:8080/directory/file?query#fragment', null)
let result2 = params1.toString()
expect(result2).assertEqual("http://username:password@host:8080/directory/file?query#fragment")
})
/**
* @tc.name: testUrlToString001
* @tc.desc: Returns the serialized URL as a string.
......@@ -3326,4 +3407,19 @@ describe('UrlFunTest', function () {
expect(err.message).assertEqual(`Syntax Error. Invalid Url string`);
}
})
/**
* @tc.name: testUrlparseURL011
* @tc.desc: The second parameter of parseURL is undefined or null.
*/
it('testUrlparseURL011', 0, function () {
let params = new Url.URL()
expect(params != null).assertTrue()
let params1 = Url.URL.parseURL('https://developer.mozilla.org', undefined)
let result = params1.href
expect(result).assertEqual('https://developer.mozilla.org/')
let params2 = Url.URL.parseURL('https://developer.mozilla.org', null)
let result1 = params2.href
expect(result1).assertEqual('https://developer.mozilla.org/')
})
})}
\ No newline at end of file
......@@ -1102,6 +1102,19 @@ describe('TextEncoderTest', function () {
expect(str).assertEqual('GB2312')
})
/**
* @tc.name: testencoding_textencoder_005
* @tc.desc: The TextEncoder construction parameter is undefined or null.
*/
it('testencoding_textencoder_005', 0, function () {
let encode1 = new util.TextEncoder(undefined)
let str1 = encode1.encoding
expect(str1).assertEqual('utf-8')
let encode2 = new util.TextEncoder(null)
let str2 = encode2.encoding
expect(str2).assertEqual('utf-8')
})
/**
* @tc.name: testEncode001
* @tc.desc: Returns the result of encoder.
......@@ -1311,6 +1324,18 @@ describe('TextEncoderTest', function () {
expect(result[119]).assertEqual(254)
})
/**
* @tc.name: testEncode016
* @tc.desc: The encode parameter is undefined or null.
*/
it('testEncode016', 0, function () {
let that = new util.TextEncoder()
let result1 = that.encode(undefined)
expect(result1).assertEqual(undefined)
let result2 = that.encode(null)
expect(result2).assertEqual(undefined)
})
/**
* @tc.name: testEncodeInto001
* @tc.desc: encode string, write the result to dest array.
......@@ -1422,6 +1447,18 @@ describe('TextEncoderTest', function () {
expect(result.read).assertEqual(0)
expect(result.written).assertEqual(0)
})
/**
* @tc.name: testEncodeInto001
* @tc.desc: The encodeInto parameter is undefined or null
*/
it('testEncodeInto009', 0, function () {
let that = new util.TextEncoder()
let result1 = that.encodeInto(undefined)
expect(result1).assertEqual(undefined)
let result2 = that.encodeInto(null)
expect(result2).assertEqual(undefined)
})
})
describe('ScopeTest', function () {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册