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

!1671 modify testcases on 20220122

Merge pull request !1671 from 杨清/1228
/*
* 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 I18n from '@ohos.i18n'
import Intl from '@ohos.intl'
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'
describe('LangTest', function () {
console.log('*************start LangTest*************');
let initPreferredLang = I18n.getPreferredLanguageList();
let initLen = initPreferredLang.length;
function getCurrentPreferredLang(){
let value = I18n.getPreferredLanguageList();
return value;
}
function isContainLang(langList, lang){
let len = langList.length;
for (let i = 0; i < len; i++){
if(langList[i] == lang){
return true
}
}
return false
}
function clearLang(langList){
let len = langList.length;
while(len > 0){
console.log('i18n_test_preferredlanguage_clearLang ' + len);
let par = len - 1;
console.log('i18n_test_preferredlanguage_clearLang ' + par);
let value = I18n.removePreferredLanguage(par);
console.log('i18n_test_preferredlanguage_clearLang ' + value);
len--;
}
console.log('i18n_test_preferredlanguage_clearLang ' + I18n.getPreferredLanguageList());
}
function restoreLang(){
for(let j = 0; j < initLen; j++){
let value = I18n.addPreferredLanguage(initPreferredLang[j]);
console.log('i18n_test_preferredlanguage_restoreLang ' + value);
expect(value).assertTrue();
}
}
beforeEach(function(){
console.log('i18n_test_preferredlanguage_beforeEach ' + getCurrentPreferredLang());
})
afterEach(function(){
let currLang = getCurrentPreferredLang();
console.log('i18n_test_preferredlanguage_afterEach ' + currLang);
clearLang(currLang);
restoreLang();
})
/* *
* @tc.number SUB_GLOBAL_I18N_JS_CLOCK_0100
* @tc.name test the is24HourClock interface
* @tc.desc check the value of is24HourClock method
*/
it('i18n_test_clock_0100', 0, function () {
console.log('i18n_test_clock_0100 ' + 'start');
let value = I18n.is24HourClock();
console.log('i18n_test_clock_0100 ' + value);
expect(value).assertTrue();
})
/* *
* @tc.number SUB_GLOBAL_I18N_JS_CLOCK_0200
* @tc.name test the set24HourClock interface with false param
* @tc.desc check the value of set24HourClock method
*/
it('i18n_test_clock_0200', 0, function () {
console.log('i18n_test_clock_0200 ' + 'start');
let value = I18n.set24HourClock(false);
console.log('i18n_test_clock_0200 ' + value);
expect(value).assertTrue();
let value2 = I18n.is24HourClock();
console.log('i18n_test_clock_0200 ' + value2);
expect(value2).assertFalse();
})
/* *
* @tc.number SUB_GLOBAL_I18N_JS_CLOCK_0300
* @tc.name test the set24HourClock interface with true param
* @tc.desc check the value of set24HourClock method
*/
it('i18n_test_clock_0300', 0, function () {
console.log('i18n_test_clock_0300 ' + 'start');
let value = I18n.set24HourClock(true);
console.log('i18n_test_clock_0300 ' + value);
expect(value).assertTrue();
let value2 = I18n.is24HourClock();
console.log('i18n_test_clock_0300 ' + value2);
expect(value).assertTrue();
})
/* *
* @tc.number SUB_GLOBAL_I18N_JS_CLOCK_0400
* @tc.name test the set24HourClock and datetime interface
* @tc.desc check the value of set24HourClock method
*/
it('i18n_test_clock_0400', 0, function () {
console.log('i18n_test_clock_0400 ' + 'start');
let value = I18n.set24HourClock(true);
console.log('i18n_test_clock_0400 ' + value);
expect(value).assertTrue();
let date = new Date(2021, 11, 17, 3, 24, 0);
let datefmt = new Intl.DateTimeFormat('en');
console.log('i18n_test_clock_0400 ' + datefmt.format(date));
expect(datefmt.format(date)).assertEqual('12/17/21');
expect(datefmt.resolvedOptions().hour12).assertFalse();
})
/* *
* @tc.number SUB_GLOBAL_I18N_JS_PREFERREDLANGUAGE_0100
* @tc.name test the getPreferredLanguageList interface
* @tc.desc check the value of getPreferredLanguageList method
*/
it('i18n_test_preferredlanguage_0100', 0, function () {
console.log('i18n_test_preferredlanguage_0100 ' + 'start');
let value = I18n.getPreferredLanguageList();
console.log('i18n_test_preferredlanguage_0100 ' + value);
expect(value.length).assertLarger(0);
})
/* *
* @tc.number SUB_GLOBAL_I18N_JS_PREFERREDLANGUAGE_0200
* @tc.name test the addPreferredLanguage interface
* @tc.desc check the value of addPreferredLanguage method
*/
it('i18n_test_preferredlanguage_0200', 0, function () {
console.log('i18n_test_preferredlanguage_0200 ' + 'start');
let value = I18n.addPreferredLanguage('zh');
console.log('i18n_test_preferredlanguage_0200 ' + value);
expect(value).assertTrue();
let list = I18n.getPreferredLanguageList();
console.log('i18n_test_preferredlanguage_0200 ' + list);
expect(list.length).assertLarger(0);
})
/* *
* @tc.number SUB_GLOBAL_I18N_JS_PREFERREDLANGUAGE_0220
* @tc.name test the addPreferredLanguage interface with abc param
* @tc.desc check the value of addPreferredLanguage method
*/
it('i18n_test_preferredlanguage_0220', 0, function () {
console.log('i18n_test_preferredlanguage_0220 ' + 'start');
let value = I18n.addPreferredLanguage('abc');
console.log('i18n_test_preferredlanguage_0220 ' + value);
expect(value).assertTrue();
let list = I18n.getPreferredLanguageList();
console.log('i18n_test_preferredlanguage_0220 ' + list);
expect(list.length).assertLarger(0);
})
/* *
* @tc.number SUB_GLOBAL_I18N_JS_PREFERREDLANGUAGE_0300
* @tc.name test the addPreferredLanguage interface with en and 0 param
* @tc.desc check the value of addPreferredLanguage method
*/
it('i18n_test_preferredlanguage_0300', 0, function () {
console.log('i18n_test_preferredlanguage_0300 ' + 'start');
let value = I18n.addPreferredLanguage('en', 0);
console.log('i18n_test_preferredlanguage_0300 ' + value);
expect(value).assertTrue();
let list = I18n.getPreferredLanguageList();
console.log('i18n_test_preferredlanguage_0300 ' + list);
expect(list.length).assertLarger(0);
})
/* *
* @tc.number SUB_GLOBAL_I18N_JS_PREFERREDLANGUAGE_0320
* @tc.name test the addPreferredLanguage interface with abc and index 0 param
* @tc.desc check the value of addPreferredLanguage method
*/
it('i18n_test_preferredlanguage_0320', 0, function () {
console.log('i18n_test_preferredlanguage_0320 ' + 'start');
let value = I18n.addPreferredLanguage('abc', 0);
console.log('i18n_test_preferredlanguage_0320 ' + value);
expect(value).assertTrue();
let list = I18n.getPreferredLanguageList();
console.log('i18n_test_preferredlanguage_0320 ' + list);
expect(list.length).assertLarger(0);
})
/* *
* @tc.number SUB_GLOBAL_I18N_JS_PREFERREDLANGUAGE_0340
* @tc.name test the addPreferredLanguage interface with en and index 1.5 param
* @tc.desc check the value of addPreferredLanguage method
*/
it('i18n_test_preferredlanguage_0340', 0, function () {
console.log('i18n_test_preferredlanguage_0340 ' + 'start');
let value = I18n.addPreferredLanguage('en', 1.5);
console.log('i18n_test_preferredlanguage_0340 ' + value);
expect(value).assertTrue();
let list = I18n.getPreferredLanguageList();
console.log('i18n_test_preferredlanguage_0340 ' + list);
expect(list.length).assertLarger(0);
})
/* *
* @tc.number SUB_GLOBAL_I18N_JS_PREFERREDLANGUAGE_0400
* @tc.name test the addPreferredLanguage interface
* @tc.desc check the value of addPreferredLanguage method
*/
it('i18n_test_preferredlanguage_0400', 0, function () {
console.log('i18n_test_preferredlanguage_0400 ' + 'start');
let value = I18n.addPreferredLanguage('en', 1);
console.log('i18n_test_preferredlanguage_0400 ' + value);
expect(value).assertTrue();
let list = I18n.getPreferredLanguageList();
console.log('i18n_test_preferredlanguage_0400 ' + list);
expect(list.length).assertLarger(0);
})
/* *
* @tc.number SUB_GLOBAL_I18N_JS_PREFERREDLANGUAGE_0500
* @tc.name test the addPreferredLanguage interface
* @tc.desc check the value of addPreferredLanguage method
*/
it('i18n_test_preferredlanguage_0500', 0, function () {
console.log('i18n_test_preferredlanguage_0500 ' + 'start');
let value = I18n.addPreferredLanguage('ja', -1);
console.log('i18n_test_preferredlanguage_0500 ' + value);
expect(value).assertTrue();
let list = I18n.getPreferredLanguageList();
console.log('i18n_test_preferredlanguage_0500 ' + list);
expect(list.length).assertLarger(0);
})
/* *
* @tc.number SUB_GLOBAL_I18N_JS_PREFERREDLANGUAGE_0600
* @tc.name test the addPreferredLanguage interface
* @tc.desc check the value of addPreferredLanguage method
*/
it('i18n_test_preferredlanguage_0600', 0, function () {
console.log('i18n_test_preferredlanguage_0600 ' + 'start');
let value = I18n.addPreferredLanguage('ko', 100);
console.log('i18n_test_preferredlanguage_0600 ' + value);
expect(value).assertTrue();
let list = I18n.getPreferredLanguageList();
console.log('i18n_test_preferredlanguage_0600 ' + list);
expect(list.length).assertLarger(0);
})
/* *
* @tc.number SUB_GLOBAL_I18N_JS_PREFERREDLANGUAGE_0700
* @tc.name test the addPreferredLanguage interface
* @tc.desc check the value of addPreferredLanguage method
*/
it('i18n_test_preferredlanguage_0700', 0, function () {
console.log('i18n_test_preferredlanguage_0700 ' + 'start');
let value = I18n.removePreferredLanguage(0);
console.log('i18n_test_preferredlanguage_0700 ' + value);
expect(value).assertTrue();
let list = I18n.getPreferredLanguageList();
console.log('i18n_test_preferredlanguage_0700 ' + list);
expect(list.length).assertLarger(0);
})
/* *
* @tc.number SUB_GLOBAL_I18N_JS_PREFERREDLANGUAGE_0720
* @tc.name test the removePreferredLanguage interface with 0.5 param
* @tc.desc check the value of removePreferredLanguage method
*/
it('i18n_test_preferredlanguage_0720', 0, function () {
console.log('i18n_test_preferredlanguage_0720 ' + 'start');
let value = I18n.removePreferredLanguage(0.5);
console.log('i18n_test_preferredlanguage_0720 ' + value);
expect(value).assertFalse();
let list = I18n.getPreferredLanguageList();
console.log('i18n_test_preferredlanguage_0720 ' + list);
expect(list.length).assertLarger(0);
})
/* *
* @tc.number SUB_GLOBAL_I18N_JS_PREFERREDLANGUAGE_0800
* @tc.name test the addPreferredLanguage interface
* @tc.desc check the value of addPreferredLanguage method
*/
it('i18n_test_preferredlanguage_0800', 0, function () {
console.log('i18n_test_preferredlanguage_0800 ' + 'start');
let value = I18n.removePreferredLanguage(-1);
console.log('i18n_test_preferredlanguage_0800 ' + value);
expect(value).assertTrue();
let list = I18n.getPreferredLanguageList();
console.log('i18n_test_preferredlanguage_0800 ' + list);
expect(list.length).assertLarger(0);
})
/* *
* @tc.number SUB_GLOBAL_I18N_JS_PREFERREDLANGUAGE_0900
* @tc.name test the addPreferredLanguage interface
* @tc.desc check the value of addPreferredLanguage method
*/
it('i18n_test_preferredlanguage_0900', 0, function () {
console.log('i18n_test_preferredlanguage_0900 ' + 'start');
let list = I18n.getPreferredLanguageList();
console.log('i18n_test_preferredlanguage_0900 ' + list);
let len = list.length;
console.log('i18n_test_preferredlanguage_0900 ' + len);
expect(len).assertLarger(0);
let parm = len - 1;
let value = I18n.removePreferredLanguage(parm);
console.log('i18n_test_preferredlanguage_0900 ' + value);
expect(value).assertTrue();
})
/* *
* @tc.number SUB_GLOBAL_I18N_JS_PREFERREDLANGUAGE_0920
* @tc.name test the addPreferredLanguage interface
* @tc.desc check the value of addPreferredLanguage method
*/
it('i18n_test_preferredlanguage_0920', 0, function () {
console.log('i18n_test_preferredlanguage_0920 ' + 'start');
let list = I18n.getPreferredLanguageList();
console.log('i18n_test_preferredlanguage_0920 ' + list);
let isContain = isContainLang(list, 'it')
console.log('i18n_test_preferredlanguage_0920 ' + isContain);
let len = list.length;
console.log('i18n_test_preferredlanguage_0920 ' + len);
expect(len).assertLarger(0);
if(!isContain) {
let value = I18n.addPreferredLanguage('it');
console.log('i18n_test_preferredlanguage_0920 ' + value);
expect(value).assertTrue();
}
let list2 = I18n.getPreferredLanguageList();
console.log('i18n_test_preferredlanguage_0920 ' + list2);
})
/* *
* @tc.number SUB_GLOBAL_I18N_JS_PREFERREDLANGUAGE_0940
* @tc.name test the addPreferredLanguage interface
* @tc.desc check the value of addPreferredLanguage method
*/
it('i18n_test_preferredlanguage_0940', 0, function () {
let value = I18n.addPreferredLanguage('it');
console.log('i18n_test_preferredlanguage_0940 ' + value);
expect(value).assertTrue();
let value2 = I18n.addPreferredLanguage('ko');
console.log('i18n_test_preferredlanguage_0940 ' + value2);
expect(value2).assertTrue();
let value3 = I18n.addPreferredLanguage('en');
console.log('i18n_test_preferredlanguage_0940 ' + value3);
expect(value3).assertTrue();
let list1 = I18n.getPreferredLanguageList();
console.log('i18n_test_preferredlanguage_0940 ' + list1);
let value4 = I18n.addPreferredLanguage('it', 3);
console.log('i18n_test_preferredlanguage_0940 ' + value4);
expect(value4).assertTrue();
let value5 = I18n.addPreferredLanguage('ko', 2);
console.log('i18n_test_preferredlanguage_0940 ' + value5);
expect(value5).assertTrue();
let value6 = I18n.addPreferredLanguage('en', 1);
console.log('i18n_test_preferredlanguage_0940 ' + value6);
expect(value6).assertTrue();
let list2 = I18n.getPreferredLanguageList();
console.log('i18n_test_preferredlanguage_0940 ' + list2);
expect(list2[1]).assertEqual('en');
expect(list2[2]).assertEqual('ko');
expect(list2[3]).assertEqual('it');
let remove1 = I18n.removePreferredLanguage(1);
console.log('i18n_test_preferredlanguage_0940 ' + remove1);
expect(remove1).assertTrue();
let list3 = I18n.getPreferredLanguageList();
console.log('i18n_test_preferredlanguage_0940 ' + list3);
expect(list3[1]).assertEqual('ko');
expect(list3[2]).assertEqual('it');
let remove2 = I18n.removePreferredLanguage(1);
console.log('i18n_test_preferredlanguage_0940 ' + remove2);
expect(remove2).assertTrue();
let list4 = I18n.getPreferredLanguageList();
console.log('i18n_test_preferredlanguage_0940 ' + list4);
expect(list4[1]).assertEqual('it');
})
/* *
* @tc.number SUB_GLOBAL_I18N_JS_PREFERREDLANGUAGE_1000
* @tc.name test the addPreferredLanguage interface
* @tc.desc check the value of addPreferredLanguage method
*/
// it('i18n_test_preferredlanguage_1000', 0, function () {
// console.log('i18n_test_preferredlanguage_1000 ' + 'start');
// let value = I18n.getFirstPreferredLanguage();
// console.log('i18n_test_preferredlanguage_1000 ' + value);
// expect(value).assertEqual('en');
// let list = I18n.getPreferredLanguageList();
// console.log('i18n_test_preferredlanguage_1000 ' + list);
// expect(list.length).assertLarger(0);
// })
console.log('*************end LangTest*************');
})
\ No newline at end of file
......@@ -13,4 +13,5 @@
* limitations under the License.
*/
require('./I18n.test.js')
require('./Intl.test.js')
\ No newline at end of file
require('./Intl.test.js')
require('./Lang.test.js')
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册