From 33e7a30cceacfd0bcca5ae70d0cf645f1d0fb7dc Mon Sep 17 00:00:00 2001 From: y00314596 Date: Thu, 11 May 2023 10:43:56 +0800 Subject: [PATCH] add by yangqing3@huawei.com Signed-off-by: y00314596 --- .../main/js/test/BreakIteratorInI18n.test.js | 237 ++++++ .../src/main/js/test/CalendarInI18n.test.js | 418 +++++++++++ .../intljs/src/main/js/test/I18n.test.js | 178 ----- .../src/main/js/test/I18nUtilInI18n.test.js | 348 +++++++++ .../src/main/js/test/IndexUtilInI18n.test.js | 114 +++ .../intljs/src/main/js/test/List.test.js | 13 + .../js/test/PhoneNumberFormatInI18n.test.js | 691 ++++++++++++++++++ .../src/main/js/test/UtilInI18n.test.js | 315 ++++++++ 8 files changed, 2136 insertions(+), 178 deletions(-) create mode 100644 global/i18n_standard/intljs/src/main/js/test/BreakIteratorInI18n.test.js create mode 100644 global/i18n_standard/intljs/src/main/js/test/CalendarInI18n.test.js create mode 100644 global/i18n_standard/intljs/src/main/js/test/I18nUtilInI18n.test.js create mode 100644 global/i18n_standard/intljs/src/main/js/test/IndexUtilInI18n.test.js create mode 100644 global/i18n_standard/intljs/src/main/js/test/PhoneNumberFormatInI18n.test.js create mode 100644 global/i18n_standard/intljs/src/main/js/test/UtilInI18n.test.js diff --git a/global/i18n_standard/intljs/src/main/js/test/BreakIteratorInI18n.test.js b/global/i18n_standard/intljs/src/main/js/test/BreakIteratorInI18n.test.js new file mode 100644 index 000000000..a1ad716cc --- /dev/null +++ b/global/i18n_standard/intljs/src/main/js/test/BreakIteratorInI18n.test.js @@ -0,0 +1,237 @@ +/* + * Copyright (C) 2023 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 {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' + +export default function BreakIteratorInI18nTest() { +describe('BreakIteratorInI18nTest', function () { + console.log('*************start BreakIteratorInI18nTest*************'); + + let hour = I18n.System.is24HourClock(); + console.log('init 24 hour clock value ' + hour); + + /* * + * execute this step before all testcases + */ + beforeAll(function(){ + console.log('step before all cases in I18n.' + + ' 24hour: ' + I18n.System.is24HourClock() + + ' prelang: ' + I18n.System.getPreferredLanguageList() + + ' syslocale: ' + I18n.System.getSystemLocale()); + }) + + /* * + * execute this step before every testcase + */ + beforeEach(function(){ + console.log('step before every case in I18n.'); + }) + + /* * + * execute this step after every testcase + */ + afterEach(function(){ + console.log('step after every case in I18n.'); + }) + + /* * + * execute this step after all testcases + */ + afterAll(function(){ + console.log('step after all cases in I18n.' + + ' 24hour: ' + I18n.System.is24HourClock() + + ' prelang: ' + I18n.System.getPreferredLanguageList() + + ' syslocale: ' + I18n.System.getSystemLocale()); + }) + + /* * + * @tc.number SUB_GLOBAL_I18N_JS_BREAKITERATOR_0100 + * @tc.name test current interface + * @tc.desc check the current result + */ + it('i18n_test_iterator_0100', 0, function () { + console.log('i18n_test_iterator_0100 ' + 'start'); + let iterator =I18n.getLineInstance('en'); + iterator.setLineBreakText('My name is Tom.Welcome to the sky world.'); + let value = iterator.current(); + console.log('i18n_test_iterator_0100 ' + value); + expect(value).assertEqual(0); + }) + + /* * + * @tc.number SUB_GLOBAL_I18N_JS_BREAKITERATOR_0200 + * @tc.name test first interface + * @tc.desc check the first + */ + it('i18n_test_iterator_0200', 0, function () { + console.log('i18n_test_iterator_0200 ' + 'start'); + let iterator =I18n.getLineInstance('en'); + iterator.setLineBreakText('My name is Tom.Welcome to the sky world.'); + let value = iterator.first(); + console.log('i18n_test_iterator_0200 ' + value); + expect(value).assertEqual(0); + }) + + /* * + * @tc.number SUB_GLOBAL_I18N_JS_BREAKITERATOR_0300 + * @tc.name test last interface + * @tc.desc check the last interface + */ + it('i18n_test_iterator_0300', 0, function () { + console.log('i18n_test_iterator_0300 ' + 'start'); + let iterator =I18n.getLineInstance('en'); + iterator.setLineBreakText('My name is Tom.Welcome to the sky world.'); + let value = iterator.last(); + console.log('i18n_test_iterator_0300 ' + value); + expect(value).assertEqual(40); + }) + + /* * + * @tc.number SUB_GLOBAL_I18N_JS_BREAKITERATOR_0400 + * @tc.name test next interface + * @tc.desc check the next interface + */ + it('i18n_test_iterator_0400', 0, function () { + console.log('i18n_test_iterator_0400 ' + 'start'); + let iterator =I18n.getLineInstance('en'); + iterator.setLineBreakText('My name is Tom.Welcome to the sky world.'); + let value = iterator.next(); + console.log('i18n_test_iterator_0400 ' + value); + expect(value).assertEqual(3); + }) + + /* * + * @tc.number SUB_GLOBAL_I18N_JS_BREAKITERATOR_0500 + * @tc.name test next interface with param + * @tc.desc check the next interface with param + */ + it('i18n_test_iterator_0500', 0, function () { + console.log('i18n_test_iterator_0500 ' + 'start'); + let iterator =I18n.getLineInstance('en'); + iterator.setLineBreakText('My name is Tom.Welcome to the sky world.'); + let value = iterator.next(2); + console.log('i18n_test_iterator_0500 ' + value); + expect(value).assertEqual(8); + }) + + /* * + * @tc.number SUB_GLOBAL_I18N_JS_BREAKITERATOR_0600 + * @tc.name test previous interface + * @tc.desc check the previous interface + */ + it('i18n_test_iterator_0600', 0, function () { + console.log('i18n_test_iterator_0600 ' + 'start'); + let iterator =I18n.getLineInstance('en'); + iterator.setLineBreakText('My name is Tom.Welcome to the sky world.'); + let value = iterator.previous(); + console.log('i18n_test_iterator_0600 ' + value); + expect(value).assertEqual(-1); + }) + + /* * + * @tc.number SUB_GLOBAL_I18N_JS_BREAKITERATOR_0700 + * @tc.name test following interface + * @tc.desc check the following interface + */ + it('i18n_test_iterator_0700', 0, function () { + console.log('i18n_test_iterator_0700 ' + 'start'); + let iterator =I18n.getLineInstance('en'); + iterator.setLineBreakText('My name is Tom.Welcome to the sky world.'); + let value = iterator.following(1); + console.log('i18n_test_iterator_0700 ' + value); + expect(value).assertEqual(3); + }) + + /* * + * @tc.number SUB_GLOBAL_I18N_JS_BREAKITERATOR_0800 + * @tc.name test getLineBreakText interface + * @tc.desc check the getLineBreakText interface + */ + it('i18n_test_iterator_0800', 0, function () { + console.log('i18n_test_iterator_0800 ' + 'start'); + let iterator =I18n.getLineInstance('en'); + iterator.setLineBreakText('My name is Tom.Welcome to the sky world.'); + let value = iterator.getLineBreakText(); + console.log('i18n_test_iterator_0800 ' + value); + expect(value).assertEqual('My name is Tom.Welcome to the sky world.'); + }) + + /* * + * @tc.number SUB_GLOBAL_I18N_JS_BREAKITERATOR_0900 + * @tc.name test isBoundary interface + * @tc.desc check the isBoundary interface + */ + it('i18n_test_iterator_0900', 0, function () { + console.log('i18n_test_iterator_0900 ' + 'start'); + let iterator =I18n.getLineInstance('en'); + iterator.setLineBreakText('My name is Tom.Welcome to the sky world.'); + let value = iterator.isBoundary(10); + console.log('i18n_test_iterator_0900 ' + value); + expect(value).assertFalse(); + // current + let current = iterator.current(); + console.log('i18n_test_iterator_0900 ' + current); + expect(current).assertEqual(11); + }) + + /* * + * @tc.number SUB_GLOBAL_I18N_JS_BREAKITERATOR_1000 + * @tc.name test iterator interface + * @tc.desc check the iterator interface + */ + it('i18n_test_iterator_1000', 0, function () { + console.log('i18n_test_iterator_1000 ' + 'start'); + let iterator =I18n.getLineInstance('en'); + iterator.setLineBreakText('My name is Tom.Welcome to the sky world.'); + // current + let current = iterator.current(); + console.log('i18n_test_iterator_1000 ' + current); + expect(current).assertEqual(0); + // next + let next = iterator.next(); + console.log('i18n_test_iterator_1000 ' + next); + expect(next).assertEqual(3); + // current + let current2 = iterator.current(); + console.log('i18n_test_iterator_1000 ' + current2); + expect(current2).assertEqual(3); + // next 5 + let next2 = iterator.next(5); + console.log('i18n_test_iterator_1000 ' + next2); + expect(next2).assertEqual(30); + // previous + let previous = iterator.previous(); + console.log('i18n_test_iterator_1000 ' + previous); + expect(previous).assertEqual(26); + // following 2 + let follwoing = iterator.following(3); + console.log('i18n_test_iterator_1000 ' + follwoing); + expect(follwoing).assertEqual(8); + // current + let current3 = iterator.current(); + console.log('i18n_test_iterator_1000 ' + current3); + expect(current3).assertEqual(8); + // isBoundary + let value = iterator.isBoundary(3); + console.log('i18n_test_iterator_1000 ' + value); + expect(value).assertTrue(); + // current + let current4 = iterator.current(); + console.log('i18n_test_iterator_1000 ' + current4); + expect(current4).assertEqual(3); + }) + + console.log('*************end BreakIteratorInI18nTest*************'); +})} diff --git a/global/i18n_standard/intljs/src/main/js/test/CalendarInI18n.test.js b/global/i18n_standard/intljs/src/main/js/test/CalendarInI18n.test.js new file mode 100644 index 000000000..2f10d84c2 --- /dev/null +++ b/global/i18n_standard/intljs/src/main/js/test/CalendarInI18n.test.js @@ -0,0 +1,418 @@ +/* + * Copyright (C) 2023 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 {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' + +export default function CalendarInI18nTest() { +describe('CalendarInI18nTest', function () { + console.log('*************start CalendarInI18nTest*************'); + + let hour = I18n.System.is24HourClock(); + console.log('init 24 hour clock value ' + hour); + + /* * + * execute this step before all testcases + */ + beforeAll(function(){ + console.log('step before all cases in I18n.' + + ' 24hour: ' + I18n.System.is24HourClock() + + ' prelang: ' + I18n.System.getPreferredLanguageList() + + ' syslocale: ' + I18n.System.getSystemLocale()); + }) + + /* * + * execute this step before every testcase + */ + beforeEach(function(){ + console.log('step before every case in I18n.'); + }) + + /* * + * execute this step after every testcase + */ + afterEach(function(){ + console.log('step after every case in I18n.'); + }) + + /* * + * execute this step after all testcases + */ + afterAll(function(){ + console.log('step after all cases in I18n.' + + ' 24hour: ' + I18n.System.is24HourClock() + + ' prelang: ' + I18n.System.getPreferredLanguageList() + + ' syslocale: ' + I18n.System.getSystemLocale()); + }) + + /** + * @tc.number SUB_GLOBAL_I18N_CALENDAR_JS_0100 + * @tc.name test isWeekend interface + * @tc.desc get the isWeekend value + */ + it('i18n_calendar_test_0100', 0, function () { + console.log('i18n_calendar_test_0100 ' + 'start'); + let calendar = I18n.getCalendar('zh'); + let value = calendar.isWeekend(new Date(2021, 10, 1, 10, 0, 0, 0)); + console.log('i18n_calendar_test_0100 ' + value); + expect(value).assertFalse(); + }) + + /** + * @tc.number SUB_GLOBAL_I18N_CALENDAR_JS_0200 + * @tc.name test getCalendar interface + * @tc.desc get the getCalendar value + */ + it('i18n_calendar_test_0200', 0, function () { + console.log('i18n_calendar_test_0200 ' + 'start'); + let calendar = I18n.getCalendar('ja', 'japanese'); + let name = calendar.getDisplayName('ja'); + console.log('i18n_calendar_test_0200 ' + name); + expect(name).assertEqual('和暦'); + let timezone = calendar.getTimeZone(); + console.log('i18n_calendar_test_0200 ' + timezone); + expect(timezone.length > 0).assertTrue(); + let firstday = calendar.getFirstDayOfWeek(); + console.log('i18n_calendar_test_0200 ' + firstday); + expect(firstday).assertEqual(1); + let miniday = calendar.getMinimalDaysInFirstWeek(); + console.log('i18n_calendar_test_0200 ' + miniday); + expect(miniday).assertEqual(1); + let value = calendar.isWeekend(new Date(2022, 10, 1, 10, 0, 0, 0)); + console.log('i18n_calendar_test_0200 ' + value); + expect(value).assertFalse(); + }) + + /** + * @tc.number SUB_GLOBAL_I18N_CALENDAR_JS_0300 + * @tc.name test getCalendar interface with zh param + * @tc.desc get the getCalendar value + */ + it('i18n_calendar_test_0300', 0, function () { + console.log('i18n_calendar_test_0300 ' + 'start'); + let calendar = I18n.getCalendar('zh', 'chinese'); + let name = calendar.getDisplayName('zh'); + console.log('i18n_calendar_test_0300 ' + name); + expect(name).assertEqual('农历'); + }) + + /** + * @tc.number SUB_GLOBAL_I18N_CALENDAR_JS_0400 + * @tc.name test getCalendar interface with zh param + * @tc.desc get the getCalendar value + */ + it('i18n_calendar_test_0400', 0, function () { + console.log('i18n_calendar_test_0400 ' + 'start'); + let calendar = I18n.getCalendar('zh', 'japanese'); + let name = calendar.getDisplayName('zh'); + console.log('i18n_calendar_test_0400 ' + name); + expect(name).assertEqual('和历'); + }) + + /** + * @tc.number SUB_GLOBAL_I18N_CALENDAR_JS_0500 + * @tc.name test getDisplayName interface + * @tc.desc get the getDisplayName value + */ + it('i18n_calendar_test_0500', 0, function () { + console.log('i18n_calendar_test_0500 ' + 'start'); + let calendar = I18n.getCalendar('zh'); + let value = calendar.getDisplayName('zh'); + console.log('i18n_calendar_test_0500 ' + value); + expect(value).assertEqual('公历'); + }) + + /** + * @tc.number SUB_GLOBAL_I18N_CALENDAR_JS_0600 + * @tc.name test getDisplayName interface with en param + * @tc.desc get the getDisplayName value + */ + it('i18n_calendar_test_0600', 0, function () { + console.log('i18n_calendar_test_0600 ' + 'start'); + let calendar = I18n.getCalendar('zh'); + let value = calendar.getDisplayName('en'); + console.log('i18n_calendar_test_0600 ' + value); + expect(value).assertEqual('Gregorian Calendar'); + }) + + /** + * @tc.number SUB_GLOBAL_I18N_CALENDAR_JS_0700 + * @tc.name test get interface + * @tc.desc get the get value + */ + it('i18n_calendar_test_0700', 0, function () { + console.log('i18n_calendar_test_0700 ' + 'start'); + let calendar = I18n.getCalendar('zh'); + let value = calendar.get('year'); + console.log('i18n_calendar_test_0700 ' + value); + expect(value).assertLarger(0); + }) + + /** + * @tc.number SUB_GLOBAL_I18N_CALENDAR_JS_0800 + * @tc.name test get interface with month param + * @tc.desc get the get value + */ + it('i18n_calendar_test_0800', 0, function () { + console.log('i18n_calendar_test_0800 ' + 'start'); + let calendar = I18n.getCalendar('zh'); + let date1 = new Date(2021, 8, 8, 8, 8, 8, 8); + calendar.setTime(date1); + let value = calendar.get('month'); + console.log('i18n_calendar_test_0800 ' + value); + expect(value).assertEqual(8); + }) + + /** + * @tc.number SUB_GLOBAL_I18N_CALENDAR_JS_0900 + * @tc.name test get interface with day_of_year param + * @tc.desc get the get value + */ + it('i18n_calendar_test_0900', 0, function () { + console.log('i18n_calendar_test_0900 ' + 'start'); + let calendar = I18n.getCalendar('zh'); + let value = calendar.get('day_of_year'); + console.log('i18n_calendar_test_0900 ' + value); + expect(value).assertLarger(0); + }) + + /** + * @tc.number SUB_GLOBAL_I18N_CALENDAR_JS_1000 + * @tc.name test setMinimalDaysInFirstWeek and getMinimalDaysInFirstWeek interface + * @tc.desc get the setMinimalDaysInFirstWeek and getMinimalDaysInFirstWeek value + */ + it('i18n_calendar_test_1000', 0, function () { + console.log('i18n_calendar_test_1000 ' + 'start'); + let calendar = I18n.getCalendar('zh'); + calendar.setMinimalDaysInFirstWeek(1); + let value = calendar.getMinimalDaysInFirstWeek(); + console.log('i18n_calendar_test_1000 ' + value); + expect(value).assertEqual(1); + }) + + /** + * @tc.number SUB_GLOBAL_I18N_CALENDAR_JS_1100 + * @tc.name test setMinimalDaysInFirstWeek with 0 param and getMinimalDaysInFirstWeek interface + * @tc.desc get the setMinimalDaysInFirstWeek and getMinimalDaysInFirstWeek value + */ + it('i18n_calendar_test_1100', 0, function () { + console.log('i18n_calendar_test_1100 ' + 'start'); + let calendar = I18n.getCalendar('zh'); + calendar.setMinimalDaysInFirstWeek(0); + let value = calendar.getMinimalDaysInFirstWeek(); + console.log('i18n_calendar_test_1100 ' + value); + expect(value).assertEqual(1); + }) + + /** + * @tc.number SUB_GLOBAL_I18N_CALENDAR_JS_1200 + * @tc.name test setMinimalDaysInFirstWeek with 8 param and getMinimalDaysInFirstWeek interface + * @tc.desc get the setMinimalDaysInFirstWeek and getMinimalDaysInFirstWeek value + */ + it('i18n_calendar_test_1200', 0, function () { + console.log('i18n_calendar_test_1200 ' + 'start'); + let calendar = I18n.getCalendar('zh'); + calendar.setMinimalDaysInFirstWeek(8); + let value = calendar.getMinimalDaysInFirstWeek(); + console.log('i18n_calendar_test_1200 ' + value); + expect(value).assertEqual(7); + }) + + /** + * @tc.number SUB_GLOBAL_I18N_CALENDAR_JS_1300 + * @tc.name test setMinimalDaysInFirstWeek with 7 param and getMinimalDaysInFirstWeek interface + * @tc.desc get the setMinimalDaysInFirstWeek and getMinimalDaysInFirstWeek value + */ + it('i18n_calendar_test_1300', 0, function () { + console.log('i18n_calendar_test_1300 ' + 'start'); + let calendar = I18n.getCalendar('zh'); + calendar.setMinimalDaysInFirstWeek(7); + let value = calendar.getMinimalDaysInFirstWeek(); + console.log('i18n_calendar_test_1300 ' + value); + expect(value).assertEqual(7); + }) + + /** + * @tc.number SUB_GLOBAL_I18N_CALENDAR_JS_1400 + * @tc.name test setFirstDayOfWeek and getFirstDayOfWeek interface + * @tc.desc get the setFirstDayOfWeek and getFirstDayOfWeek value + */ + it('i18n_calendar_test_1400', 0, function () { + console.log('i18n_calendar_test_1400 ' + 'start'); + let calendar = I18n.getCalendar('zh'); + calendar.setFirstDayOfWeek(1); + let value = calendar.getFirstDayOfWeek(); + console.log('i18n_calendar_test_1400 ' + value); + expect(value).assertEqual(1); + }) + + /** + * @tc.number SUB_GLOBAL_I18N_CALENDAR_JS_1500 + * @tc.name test setFirstDayOfWeek with 0 param and getFirstDayOfWeek interface + * @tc.desc get the setFirstDayOfWeek and getFirstDayOfWeek value + */ + it('i18n_calendar_test_1500', 0, function () { + console.log('i18n_calendar_test_1500 ' + 'start'); + let calendar = I18n.getCalendar('zh'); + calendar.setFirstDayOfWeek(0); + let value = calendar.getFirstDayOfWeek(); + console.log('i18n_calendar_test_1500 ' + value); + expect(value).assertEqual(1); + }) + + /** + * @tc.number SUB_GLOBAL_I18N_CALENDAR_JS_1600 + * @tc.name test setFirstDayOfWeek with 7 param and getFirstDayOfWeek interface + * @tc.desc get the setFirstDayOfWeek and getFirstDayOfWeek value + */ + it('i18n_calendar_test_1600', 0, function () { + console.log('i18n_calendar_test_1600 ' + 'start'); + let calendar = I18n.getCalendar('zh'); + calendar.setFirstDayOfWeek(7); + let value = calendar.getFirstDayOfWeek(); + console.log('i18n_calendar_test_1600 ' + value); + expect(value).assertEqual(7); + }) + + /** + * @tc.number SUB_GLOBAL_I18N_CALENDAR_JS_1700 + * @tc.name test setFirstDayOfWeek with 8 param and getFirstDayOfWeek interface + * @tc.desc get the setFirstDayOfWeek and getFirstDayOfWeek value + */ + it('i18n_calendar_test_1700', 0, function () { + console.log('i18n_calendar_test_1700 ' + 'start'); + let calendar = I18n.getCalendar('zh'); + calendar.setFirstDayOfWeek(8); + let value = calendar.getFirstDayOfWeek(); + console.log('i18n_calendar_test_1700 ' + value); + expect(value).assertEqual(1); + }) + + /** + * @tc.number SUB_GLOBAL_I18N_CALENDAR_JS_1800 + * @tc.name test setTimeZone and getTimeZone interface + * @tc.desc get the setTimeZone and getTimeZone value + */ + it('i18n_calendar_test_1800', 0, function () { + console.log('i18n_calendar_test_1800 ' + 'start'); + let calendar = I18n.getCalendar('zh'); + calendar.setTimeZone('Asia/Shanghai'); + let value = calendar.getTimeZone(); + console.log('i18n_calendar_test_1800 ' + value); + expect(value).assertEqual('China Standard Time'); + }) + + /** + * @tc.number SUB_GLOBAL_I18N_CALENDAR_JS_1900 + * @tc.name test setTimeZone with AAA param and getTimeZone interface + * @tc.desc get the setTimeZone and getTimeZone value + */ + it('i18n_calendar_test_1900', 0, function () { + console.log('i18n_calendar_test_1900 ' + 'start'); + let calendar = I18n.getCalendar('zh'); + calendar.setTimeZone('AAA'); + let value = calendar.getTimeZone(); + console.log('i18n_calendar_test_1900 ' + value); + expect(value).assertEqual('GMT'); + }) + + /** + * @tc.number SUB_GLOBAL_I18N_CALENDAR_JS_2000 + * @tc.name test set interface + * @tc.desc get the set value + */ + it('i18n_calendar_test_2000', 0, function () { + console.log('i18n_calendar_test_2000 ' + 'start'); + let calendar = I18n.getCalendar('zh'); + calendar.set(2021, 11, 11); + let value = calendar.isWeekend(); + console.log('i18n_calendar_test_2000 ' + value); + expect(value).assertTrue(); + }) + + /** + * @tc.number SUB_GLOBAL_I18N_CALENDAR_JS_2100 + * @tc.name test set interface with hour,minute,second param + * @tc.desc get the set value + */ + it('i18n_calendar_test_2100', 0, function () { + console.log('i18n_calendar_test_2100 ' + 'start'); + let calendar = I18n.getCalendar('zh'); + calendar.set(2021, 11, 11, 10, 10, 10); + let value = calendar.isWeekend(); + console.log('i18n_calendar_test_2100 ' + value); + expect(value).assertTrue(); + }) + + /** + * @tc.number SUB_GLOBAL_I18N_CALENDAR_JS_2200 + * @tc.name test set interface with hour,minute param + * @tc.desc get the set value + */ + it('i18n_calendar_test_2200', 0, function () { + console.log('i18n_calendar_test_2200 ' + 'start'); + let calendar = I18n.getCalendar('zh'); + calendar.set(2021, 11, 11, 10, 10); + let value = calendar.isWeekend(); + console.log('i18n_calendar_test_2200 ' + value); + expect(value).assertTrue(); + }) + + /** + * @tc.number SUB_GLOBAL_I18N_CALENDAR_JS_2300 + * @tc.name test setTime interface with date param + * @tc.desc get the setTime value + */ + it('i18n_calendar_test_2300', 0, function () { + console.log('i18n_calendar_test_2300 ' + 'start'); + let calendar = I18n.getCalendar('zh'); + //actuall month is 9 + let date1 = new Date(2021, 8, 8, 8, 8, 8, 8); + calendar.setTime(date1); + let value = calendar.isWeekend(); + console.log('i18n_calendar_test_2300 ' + value); + expect(value).assertFalse(); + }) + + /** + * @tc.number SUB_GLOBAL_I18N_CALENDAR_JS_2400 + * @tc.name test setTime interface with wrong month param + * @tc.desc get the setTime value + */ + it('i18n_calendar_test_2400', 0, function () { + console.log('i18n_calendar_test_2400 ' + 'start'); + let calendar = I18n.getCalendar('zh'); + let date1 = new Date(2021, 18, 8, 8, 8, 8, 8); + calendar.setTime(date1); + let value = calendar.isWeekend(); + console.log('i18n_calendar_test_2400 ' + value); + expect(value).assertFalse(); + }) + + /** + * @tc.number SUB_GLOBAL_I18N_CALENDAR_JS_2500 + * @tc.name test setTime interface + * @tc.desc get the setTime value + */ + it('i18n_calendar_test_2500', 0, function () { + console.log('i18n_calendar_test_2500 ' + 'start'); + let calendar = I18n.getCalendar('zh'); + calendar.setTime(10540800000); + let value = calendar.isWeekend(); + console.log('i18n_calendar_test_2500 ' + value); + expect(value).assertTrue(); + }) + + console.log('*************end CalendarInI18nTest*************'); +})} diff --git a/global/i18n_standard/intljs/src/main/js/test/I18n.test.js b/global/i18n_standard/intljs/src/main/js/test/I18n.test.js index d63caafdd..3be10a592 100644 --- a/global/i18n_standard/intljs/src/main/js/test/I18n.test.js +++ b/global/i18n_standard/intljs/src/main/js/test/I18n.test.js @@ -2300,184 +2300,6 @@ describe('I18nTest', function () { expect(value).assertEqual('1,000米'); }) - /* * - * @tc.number SUB_GLOBAL_I18N_JS_BREAKITERATOR_0100 - * @tc.name test current interface - * @tc.desc check the current result - */ - it('i18n_test_iterator_0100', 0, function () { - console.log('i18n_test_iterator_0100 ' + 'start'); - let iterator =I18n.getLineInstance('en'); - iterator.setLineBreakText('My name is Tom.Welcome to the sky world.'); - let value = iterator.current(); - console.log('i18n_test_iterator_0100 ' + value); - expect(value).assertEqual(0); - }) - - /* * - * @tc.number SUB_GLOBAL_I18N_JS_BREAKITERATOR_0200 - * @tc.name test first interface - * @tc.desc check the first - */ - it('i18n_test_iterator_0200', 0, function () { - console.log('i18n_test_iterator_0200 ' + 'start'); - let iterator =I18n.getLineInstance('en'); - iterator.setLineBreakText('My name is Tom.Welcome to the sky world.'); - let value = iterator.first(); - console.log('i18n_test_iterator_0200 ' + value); - expect(value).assertEqual(0); - }) - - /* * - * @tc.number SUB_GLOBAL_I18N_JS_BREAKITERATOR_0300 - * @tc.name test last interface - * @tc.desc check the last interface - */ - it('i18n_test_iterator_0300', 0, function () { - console.log('i18n_test_iterator_0300 ' + 'start'); - let iterator =I18n.getLineInstance('en'); - iterator.setLineBreakText('My name is Tom.Welcome to the sky world.'); - let value = iterator.last(); - console.log('i18n_test_iterator_0300 ' + value); - expect(value).assertEqual(40); - }) - - /* * - * @tc.number SUB_GLOBAL_I18N_JS_BREAKITERATOR_0400 - * @tc.name test next interface - * @tc.desc check the next interface - */ - it('i18n_test_iterator_0400', 0, function () { - console.log('i18n_test_iterator_0400 ' + 'start'); - let iterator =I18n.getLineInstance('en'); - iterator.setLineBreakText('My name is Tom.Welcome to the sky world.'); - let value = iterator.next(); - console.log('i18n_test_iterator_0400 ' + value); - expect(value).assertEqual(3); - }) - - /* * - * @tc.number SUB_GLOBAL_I18N_JS_BREAKITERATOR_0500 - * @tc.name test next interface with param - * @tc.desc check the next interface with param - */ - it('i18n_test_iterator_0500', 0, function () { - console.log('i18n_test_iterator_0500 ' + 'start'); - let iterator =I18n.getLineInstance('en'); - iterator.setLineBreakText('My name is Tom.Welcome to the sky world.'); - let value = iterator.next(2); - console.log('i18n_test_iterator_0500 ' + value); - expect(value).assertEqual(8); - }) - - /* * - * @tc.number SUB_GLOBAL_I18N_JS_BREAKITERATOR_0600 - * @tc.name test previous interface - * @tc.desc check the previous interface - */ - it('i18n_test_iterator_0600', 0, function () { - console.log('i18n_test_iterator_0600 ' + 'start'); - let iterator =I18n.getLineInstance('en'); - iterator.setLineBreakText('My name is Tom.Welcome to the sky world.'); - let value = iterator.previous(); - console.log('i18n_test_iterator_0600 ' + value); - expect(value).assertEqual(-1); - }) - - /* * - * @tc.number SUB_GLOBAL_I18N_JS_BREAKITERATOR_0700 - * @tc.name test following interface - * @tc.desc check the following interface - */ - it('i18n_test_iterator_0700', 0, function () { - console.log('i18n_test_iterator_0700 ' + 'start'); - let iterator =I18n.getLineInstance('en'); - iterator.setLineBreakText('My name is Tom.Welcome to the sky world.'); - let value = iterator.following(1); - console.log('i18n_test_iterator_0700 ' + value); - expect(value).assertEqual(3); - }) - - /* * - * @tc.number SUB_GLOBAL_I18N_JS_BREAKITERATOR_0800 - * @tc.name test getLineBreakText interface - * @tc.desc check the getLineBreakText interface - */ - it('i18n_test_iterator_0800', 0, function () { - console.log('i18n_test_iterator_0800 ' + 'start'); - let iterator =I18n.getLineInstance('en'); - iterator.setLineBreakText('My name is Tom.Welcome to the sky world.'); - let value = iterator.getLineBreakText(); - console.log('i18n_test_iterator_0800 ' + value); - expect(value).assertEqual('My name is Tom.Welcome to the sky world.'); - }) - - /* * - * @tc.number SUB_GLOBAL_I18N_JS_BREAKITERATOR_0900 - * @tc.name test isBoundary interface - * @tc.desc check the isBoundary interface - */ - it('i18n_test_iterator_0900', 0, function () { - console.log('i18n_test_iterator_0900 ' + 'start'); - let iterator =I18n.getLineInstance('en'); - iterator.setLineBreakText('My name is Tom.Welcome to the sky world.'); - let value = iterator.isBoundary(10); - console.log('i18n_test_iterator_0900 ' + value); - expect(value).assertFalse(); - // current - let current = iterator.current(); - console.log('i18n_test_iterator_0900 ' + current); - expect(current).assertEqual(11); - }) - - /* * - * @tc.number SUB_GLOBAL_I18N_JS_BREAKITERATOR_1000 - * @tc.name test iterator interface - * @tc.desc check the iterator interface - */ - it('i18n_test_iterator_1000', 0, function () { - console.log('i18n_test_iterator_1000 ' + 'start'); - let iterator =I18n.getLineInstance('en'); - iterator.setLineBreakText('My name is Tom.Welcome to the sky world.'); - // current - let current = iterator.current(); - console.log('i18n_test_iterator_1000 ' + current); - expect(current).assertEqual(0); - // next - let next = iterator.next(); - console.log('i18n_test_iterator_1000 ' + next); - expect(next).assertEqual(3); - // current - let current2 = iterator.current(); - console.log('i18n_test_iterator_1000 ' + current2); - expect(current2).assertEqual(3); - // next 5 - let next2 = iterator.next(5); - console.log('i18n_test_iterator_1000 ' + next2); - expect(next2).assertEqual(30); - // previous - let previous = iterator.previous(); - console.log('i18n_test_iterator_1000 ' + previous); - expect(previous).assertEqual(26); - // following 2 - let follwoing = iterator.following(3); - console.log('i18n_test_iterator_1000 ' + follwoing); - expect(follwoing).assertEqual(8); - // current - let current3 = iterator.current(); - console.log('i18n_test_iterator_1000 ' + current3); - expect(current3).assertEqual(8); - // isBoundary - let value = iterator.isBoundary(3); - console.log('i18n_test_iterator_1000 ' + value); - expect(value).assertTrue(); - // current - let current4 = iterator.current(); - console.log('i18n_test_iterator_1000 ' + current4); - expect(current4).assertEqual(3); - - }) - /* * * @tc.number SUB_GLOBAL_I18N_JS_INDEXUTIL_0100 * @tc.name test getIndex interface diff --git a/global/i18n_standard/intljs/src/main/js/test/I18nUtilInI18n.test.js b/global/i18n_standard/intljs/src/main/js/test/I18nUtilInI18n.test.js new file mode 100644 index 000000000..0c7846d7f --- /dev/null +++ b/global/i18n_standard/intljs/src/main/js/test/I18nUtilInI18n.test.js @@ -0,0 +1,348 @@ +/* + * Copyright (C) 2023 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 {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' + +export default function I18nUtilInI18nTest() { +describe('I18nUtilInI18nTest', function () { + console.log('*************start I18nUtilInI18nTest*************'); + + let hour = I18n.System.is24HourClock(); + console.log('init 24 hour clock value ' + hour); + + /* * + * execute this step before all testcases + */ + beforeAll(function(){ + console.log('step before all cases in I18n.' + + ' 24hour: ' + I18n.System.is24HourClock() + + ' prelang: ' + I18n.System.getPreferredLanguageList() + + ' syslocale: ' + I18n.System.getSystemLocale()); + }) + + /* * + * execute this step before every testcase + */ + beforeEach(function(){ + console.log('step before every case in I18n.'); + }) + + /* * + * execute this step after every testcase + */ + afterEach(function(){ + console.log('step after every case in I18n.'); + }) + + /* * + * execute this step after all testcases + */ + afterAll(function(){ + console.log('step after all cases in I18n.' + + ' 24hour: ' + I18n.System.is24HourClock() + + ' prelang: ' + I18n.System.getPreferredLanguageList() + + ' syslocale: ' + I18n.System.getSystemLocale()); + }) + + /** + * @tc.number SUB_GLOBAL_I18N_I18NUTIL_JS_0100 + * @tc.name test unitConvert interface from cup to liter unit with long style + * @tc.desc get the unitConvert value + */ + it('i18n_i18nutil_test_0100', 0, function () { + console.log('i18n_i18nutil_test_0100 ' + 'start'); + let value = I18n.I18NUtil.unitConvert({unit: 'cup', measureSystem: 'US'}, + {unit: 'liter', measureSystem: 'SI'}, + 1000, + 'en-US', + 'long'); + console.log('i18n_i18nutil_test_0100 ' + value); + expect(value).assertEqual('236.588 liters'); + }) + + /** + * @tc.number SUB_GLOBAL_I18N_I18NUTIL_JS_0200 + * @tc.name test unitConvert interface from cup to liter unit with undefined style + * @tc.desc get the unitConvert value + */ + it('i18n_i18nutil_test_0200', 0, function () { + console.log('i18n_i18nutil_test_0200 ' + 'start'); + let value = I18n.I18NUtil.unitConvert({unit: 'cup', measureSystem: 'US'}, + {unit: 'liter', measureSystem: 'SI'}, + 1000, + 'en-US', + undefined); + console.log('i18n_i18nutil_test_0200 ' + value); + expect(value).assertEqual('236.588 L'); + }) + + /** + * @tc.number SUB_GLOBAL_I18N_I18NUTIL_JS_0300 + * @tc.name test unitConvert interface from cup to liter unit with null style + * @tc.desc get the unitConvert value + */ + it('i18n_i18nutil_test_0300', 0, function () { + console.log('i18n_i18nutil_test_0300 ' + 'start'); + let value = I18n.I18NUtil.unitConvert({unit: 'cup', measureSystem: 'US'}, + {unit: 'liter', measureSystem: 'SI'}, + 1000, + 'en-US', + null); + console.log('i18n_i18nutil_test_0300 ' + value); + expect(value).assertEqual('236.588 L'); + }) + + /** + * @tc.number SUB_GLOBAL_I18N_I18NUTIL_JS_0400 + * @tc.name test unitConvert interface from cup to liter unit with medium style + * @tc.desc get the unitConvert value + */ + it('i18n_i18nutil_test_0400', 0, function () { + console.log('i18n_i18nutil_test_0400 ' + 'start'); + let value = I18n.I18NUtil.unitConvert({unit: 'cup', measureSystem: 'US'}, + {unit: 'liter', measureSystem: 'SI'}, + 1000, + 'en-US', + 'medium'); + console.log('i18n_i18nutil_test_0400 ' + value); + expect(value).assertEqual('236.588 L'); + }) + + /** + * @tc.number SUB_GLOBAL_I18N_I18NUTIL_JS_0500 + * @tc.name test unitConvert interface from cup to liter unit with narrow style + * @tc.desc get the unitConvert value + */ + it('i18n_i18nutil_test_0500', 0, function () { + console.log('i18n_i18nutil_test_0500 ' + 'start'); + let value = I18n.I18NUtil.unitConvert({unit: 'cup', measureSystem: 'US'}, + {unit: 'liter', measureSystem: 'SI'}, + 1000, + 'en-US', + 'narrow'); + console.log('i18n_i18nutil_test_0500 ' + value); + expect(value).assertEqual('236.588L'); + }) + + /** + * @tc.number SUB_GLOBAL_I18N_I18NUTIL_JS_0600 + * @tc.name test unitConvert interface from cup to liter unit with short style + * @tc.desc get the unitConvert value + */ + it('i18n_i18nutil_test_0600', 0, function () { + console.log('i18n_i18nutil_test_0600 ' + 'start'); + let value = I18n.I18NUtil.unitConvert({unit: 'cup', measureSystem: 'US'}, + {unit: 'liter', measureSystem: 'SI'}, + 1000, + 'en-US', + 'short'); + console.log('i18n_i18nutil_test_0600 ' + value); + expect(value).assertEqual('236.588 L'); + }) + + /** + * @tc.number SUB_GLOBAL_I18N_I18NUTIL_JS_0700 + * @tc.name test unitConvert interface from meter to mile unit + * @tc.desc get the unitConvert value + */ + it('i18n_i18nutil_test_0700', 0, function () { + console.log('i18n_i18nutil_test_0700 ' + 'start'); + let value = I18n.I18NUtil.unitConvert({unit: 'meter', measureSystem: 'SI'}, + {unit: 'mile', measureSystem: 'SI'}, + 1000, + 'zh-CN', + 'long'); + console.log('i18n_i18nutil_test_0700 ' + value); + expect(value).assertEqual('0.621英里'); + }) + + /** + * @tc.number SUB_GLOBAL_I18N_I18NUTIL_JS_0800 + * @tc.name test unitConvert interface from hour to second unit + * @tc.desc get the unitConvert value + */ + it('i18n_i18nutil_test_0800', 0, function () { + console.log('i18n_i18nutil_test_0800 ' + 'start'); + let value = I18n.I18NUtil.unitConvert({unit: 'hour', measureSystem: 'SI'}, + {unit: 'second', measureSystem: 'SI'}, + 10, + 'zh-CN', + 'medium'); + console.log('i18n_i18nutil_test_0800 ' + value); + expect(value).assertEqual('36,000秒'); + }) + + /** + * @tc.number SUB_GLOBAL_I18N_I18NUTIL_JS_0900 + * @tc.name test unitConvert interface from celsius to fahrenheit unit + * @tc.desc get the unitConvert value + */ + it('i18n_i18nutil_test_0900', 0, function () { + console.log('i18n_i18nutil_test_0900 ' + 'start'); + let value = I18n.I18NUtil.unitConvert({unit: 'celsius', measureSystem: 'SI'}, + {unit: 'fahrenheit', measureSystem: 'SI'}, + 1000, + 'zh-CN', + 'short'); + console.log('i18n_i18nutil_test_0900 ' + value); + expect(value).assertEqual('1,832°F'); + }) + + /** + * @tc.number SUB_GLOBAL_I18N_I18NUTIL_JS_1000 + * @tc.name test unitConvert interface from acre to hectare unit + * @tc.desc get the unitConvert value + */ + it('i18n_i18nutil_test_1000', 0, function () { + console.log('i18n_i18nutil_test_1000 ' + 'start'); + let value = I18n.I18NUtil.unitConvert({unit: 'acre', measureSystem: 'SI'}, + {unit: 'hectare', measureSystem: 'SI'}, + 1000, + 'zh-CN', + 'long'); + console.log('i18n_i18nutil_test_1000 ' + value); + expect(value).assertEqual('404.686公顷'); + }) + + /** + * @tc.number SUB_GLOBAL_I18N_I18NUTIL_JS_1100 + * @tc.name test unitConvert interface from acre to square-meter unit + * @tc.desc get the unitConvert value + */ + it('i18n_i18nutil_test_1100', 0, function () { + console.log('i18n_i18nutil_test_1100 ' + 'start'); + let value = I18n.I18NUtil.unitConvert({unit: 'acre', measureSystem: 'SI'}, + {unit: 'square-meter', measureSystem: 'SI'}, + 1000, + 'zh-CN', + 'long'); + console.log('i18n_i18nutil_test_1100 ' + value); + expect(value).assertEqual('4,046,856.422平方米'); + }) + + /** + * @tc.number SUB_GLOBAL_I18N_I18NUTIL_JS_1200 + * @tc.name test unitConvert interface from kilometer-per-hour to knot unit + * @tc.desc get the unitConvert value + */ + it('i18n_i18nutil_test_1200', 0, function () { + console.log('i18n_i18nutil_test_1200 ' + 'start'); + let value = I18n.I18NUtil.unitConvert({unit: 'kilometer-per-hour', measureSystem: 'SI'}, + {unit: 'knot', measureSystem: 'SI'}, + 1000, + 'zh-CN', + 'long'); + console.log('i18n_i18nutil_test_1200 ' + value); + expect(value).assertEqual('539.957节'); + }) + + /** + * @tc.number SUB_GLOBAL_I18N_I18NUTIL_JS_1300 + * @tc.name test unitConvert interface from kilometer-per-hour to meter-per-second unit + * @tc.desc get the unitConvert value + */ + it('i18n_i18nutil_test_1300', 0, function () { + console.log('i18n_i18nutil_test_1300 ' + 'start'); + let value = I18n.I18NUtil.unitConvert({unit: 'kilometer-per-hour', measureSystem: 'SI'}, + {unit: 'meter-per-second', measureSystem: 'SI'}, + 1000, + 'zh-CN', + 'long'); + console.log('i18n_i18nutil_test_1300 ' + value); + expect(value).assertEqual('每秒277.778米'); + }) + + /** + * @tc.number SUB_GLOBAL_I18N_I18NUTIL_JS_1400 + * @tc.name test unitConvert interface from meter to kilometer unit + * @tc.desc get the unitConvert value + */ + it('i18n_i18nutil_test_1400', 0, function () { + console.log('i18n_i18nutil_test_1400 ' + 'start'); + let value = I18n.I18NUtil.unitConvert({unit: 'meter', measureSystem: 'SI'}, + {unit: 'kilometer', measureSystem: 'SI'}, + 1000, + 'zh-CN', + 'long'); + console.log('i18n_i18nutil_test_1400 ' + value); + expect(value).assertEqual('1公里'); + }) + + /** + * @tc.number SUB_GLOBAL_I18N_I18NUTIL_JS_1500 + * @tc.name test unitConvert interface from meter to meter-per-second unit + * @tc.desc get the unitConvert value + */ + it('i18n_i18nutil_test_1500', 0, function () { + console.log('i18n_i18nutil_test_1500 ' + 'start'); + let value = I18n.I18NUtil.unitConvert({unit: 'meter', measureSystem: 'SI'}, + {unit: 'meter-per-second', measureSystem: 'SI'}, + 1000, + 'zh-CN', + 'long'); + console.log('i18n_i18nutil_test_1500 ' + value); + expect(value).assertEqual('1,000米'); + }) + + /* * + * @tc.number SUB_GLOBAL_I18N_I18NUTIL_JS_1600 + * @tc.name test getDateOrder method with zh param + * @tc.desc get the DateOrder value + */ + it('i18n_i18nutil_test_1600', 0, function () { + console.log('i18n_i18nutil_test_1600 ' + 'start'); + let value = I18n.I18NUtil.getDateOrder('zh'); + console.log('i18n_i18nutil_test_1600 ' + value); + expect(value).assertEqual('y-L-d'); + }) + + /* * + * @tc.number SUB_GLOBAL_I18N_I18NUTIL_JS_1700 + * @tc.name test getDateOrder method with en param + * @tc.desc get the DateOrder value + */ + it('i18n_i18nutil_test_1700', 0, function () { + console.log('i18n_i18nutil_test_1700 ' + 'start'); + let value = I18n.I18NUtil.getDateOrder('en'); + console.log('i18n_i18nutil_test_1700 ' + value); + expect(value).assertEqual('LLL-d-y'); + }) + + /* * + * @tc.number SUB_GLOBAL_I18N_I18NUTIL_JS_1800 + * @tc.name test getDateOrder method with th param + * @tc.desc get the DateOrder value + */ + it('i18n_i18nutil_test_1800', 0, function () { + console.log('i18n_i18nutil_test_1800 ' + 'start'); + let value = I18n.I18NUtil.getDateOrder('th'); + console.log('i18n_i18nutil_test_1800 ' + value); + expect(value).assertEqual('d-LLL-y'); + }) + + /* * + * @tc.number SUB_GLOBAL_I18N_I18NUTIL_JS_1900 + * @tc.name test getDateOrder method with jp param + * @tc.desc get the DateOrder value + */ + it('i18n_i18nutil_test_1900', 0, function () { + console.log('i18n_i18nutil_test_1900 ' + 'start'); + let value = I18n.I18NUtil.getDateOrder('jp'); + console.log('i18n_i18nutil_test_1900 ' + value); + expect(value).assertEqual('LLL-d-y'); + }) + + console.log('*************end I18nUtilInI18nTest*************'); +})} diff --git a/global/i18n_standard/intljs/src/main/js/test/IndexUtilInI18n.test.js b/global/i18n_standard/intljs/src/main/js/test/IndexUtilInI18n.test.js new file mode 100644 index 000000000..0534843ac --- /dev/null +++ b/global/i18n_standard/intljs/src/main/js/test/IndexUtilInI18n.test.js @@ -0,0 +1,114 @@ +/* + * Copyright (C) 2023 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 {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' + +export default function IndexUtilInI18nTest() { +describe('IndexUtilInI18nTest', function () { + console.log('*************start IndexUtilInI18nTest*************'); + + let hour = I18n.System.is24HourClock(); + console.log('init 24 hour clock value ' + hour); + + /* * + * execute this step before all testcases + */ + beforeAll(function(){ + console.log('step before all cases in I18n.' + + ' 24hour: ' + I18n.System.is24HourClock() + + ' prelang: ' + I18n.System.getPreferredLanguageList() + + ' syslocale: ' + I18n.System.getSystemLocale()); + }) + + /* * + * execute this step before every testcase + */ + beforeEach(function(){ + console.log('step before every case in I18n.'); + }) + + /* * + * execute this step after every testcase + */ + afterEach(function(){ + console.log('step after every case in I18n.'); + }) + + /* * + * execute this step after all testcases + */ + afterAll(function(){ + console.log('step after all cases in I18n.' + + ' 24hour: ' + I18n.System.is24HourClock() + + ' prelang: ' + I18n.System.getPreferredLanguageList() + + ' syslocale: ' + I18n.System.getSystemLocale()); + }) + + /* * + * @tc.number SUB_GLOBAL_I18N_JS_INDEXUTIL_0100 + * @tc.name test getIndex interface + * @tc.desc check the getIndex interface + */ + it('i18n_test_indexutil_0100', 0, function () { + console.log('i18n_test_indexutil_0100 ' + 'start'); + let index = I18n.getInstance(); + let value = index.getIndex('a'); + console.log('i18n_test_indexutil_0100 ' + value); + expect(value).assertEqual('A'); + }) + + /* * + * @tc.number SUB_GLOBAL_I18N_JS_INDEXUTIL_0200 + * @tc.name test getIndexList interface + * @tc.desc check the getIndexList interface + */ + it('i18n_test_indexutil_0200', 0, function () { + console.log('i18n_test_indexutil_0200 ' + 'start'); + let index = I18n.getInstance(); + let value = index.getIndexList(); + let len = value.length; + console.log('i18n_test_indexutil_0200 ' + value); + expect(len).assertLarger(0); + }) + + /* * + * @tc.number SUB_GLOBAL_I18N_JS_INDEXUTIL_0300 + * @tc.name test addLocale interface + * @tc.desc check the addLocale interface + */ + it('i18n_test_indexutil_0300', 0, function () { + console.log('i18n_test_indexutil_0300 ' + 'start'); + let index = I18n.getInstance(); + index.addLocale('en'); + let value = index.getIndex('a'); + console.log('i18n_test_indexutil_0300 ' + value); + expect(value).assertEqual('A'); + }) + + /* * + * @tc.number SUB_GLOBAL_I18N_JS_INDEXUTIL_0400 + * @tc.name test getInstance interface with zh locale + * @tc.desc check the getInstance interface with zh locale + */ + it('i18n_test_indexutil_0400', 0, function () { + console.log('i18n_test_indexutil_0400 ' + 'start'); + let index = I18n.getInstance('zh'); + let value = index.getIndex('z'); + console.log('i18n_test_indexutil_0400 ' + value); + expect(value).assertEqual('Z'); + }) + + console.log('*************end IndexUtilInI18nTest*************'); +})} diff --git a/global/i18n_standard/intljs/src/main/js/test/List.test.js b/global/i18n_standard/intljs/src/main/js/test/List.test.js index cc0f032ae..1df16a540 100644 --- a/global/i18n_standard/intljs/src/main/js/test/List.test.js +++ b/global/i18n_standard/intljs/src/main/js/test/List.test.js @@ -12,13 +12,26 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + +import BreakIteratorInI18nTest from './BreakIteratorInI18n.test.js' +import CalendarInI18nTest from './CalendarInI18n.test.js' import I18nTest from './I18n.test.js' +import I18nUtilInI18nTest from './I18nUtilInI18n.test.js' +import IndexUtilInI18nTest from './IndexUtilInI18n.test.js' import intlTest from './Intl.test.js' +import PhoneNumberFormatInI18nTest from './PhoneNumberFormatInI18n.test.js' import LangTest from './Lang.test.js' import SystemInI18nTest from './SystemInI18n.test.js' +import UtilInI18nTest from './UtilInI18n.test.js' export default function testsuite() { +BreakIteratorInI18nTest() +CalendarInI18nTest() I18nTest() +I18nUtilInI18nTest() +IndexUtilInI18nTest() intlTest() +PhoneNumberFormatInI18nTest() LangTest() SystemInI18nTest() +UtilInI18nTest() } diff --git a/global/i18n_standard/intljs/src/main/js/test/PhoneNumberFormatInI18n.test.js b/global/i18n_standard/intljs/src/main/js/test/PhoneNumberFormatInI18n.test.js new file mode 100644 index 000000000..ccf9fc134 --- /dev/null +++ b/global/i18n_standard/intljs/src/main/js/test/PhoneNumberFormatInI18n.test.js @@ -0,0 +1,691 @@ +/* + * Copyright (C) 2023 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 {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' + +export default function PhoneNumberFormatInI18nTest() { +describe('PhoneNumberFormatInI18nTest', function () { + console.log('*************start PhoneNumberFormatInI18nTest*************'); + + let hour = I18n.System.is24HourClock(); + console.log('init 24 hour clock value ' + hour); + + /* * + * execute this step before all testcases + */ + beforeAll(function(){ + console.log('step before all cases in I18n.' + + ' 24hour: ' + I18n.System.is24HourClock() + + ' prelang: ' + I18n.System.getPreferredLanguageList() + + ' syslocale: ' + I18n.System.getSystemLocale()); + }) + + /* * + * execute this step before every testcase + */ + beforeEach(function(){ + console.log('step before every case in I18n.'); + }) + + /* * + * execute this step after every testcase + */ + afterEach(function(){ + console.log('step after every case in I18n.'); + }) + + /* * + * execute this step after all testcases + */ + afterAll(function(){ + console.log('step after all cases in I18n.' + + ' 24hour: ' + I18n.System.is24HourClock() + + ' prelang: ' + I18n.System.getPreferredLanguageList() + + ' syslocale: ' + I18n.System.getSystemLocale()); + }) + + /** + * @tc.number SUB_GLOBAL_I18N_PHONENUMBERFORMAT_JS_0100 + * @tc.name test isValidNumber interface with 13510574676 param + * @tc.desc get the isValidNumber value + */ + it('i18n_phonenumberformat_test_0100', 0, function () { + console.log('i18n_phonenumberformat_test_0100 ' + 'start'); + let phonenumber = new I18n.PhoneNumberFormat('CN'); + let ran = Math.ceil(Math.random(1) * 9); + console.log('i18n_phonenumberformat_test_0100 ' + ran); + let valid = phonenumber.isValidNumber('1351057467' + ran); + console.log('i18n_phonenumberformat_test_0100 ' + valid); + expect(valid).assertEqual(true); + }) + + /** + * @tc.number SUB_GLOBAL_I18N_PHONENUMBERFORMAT_JS_0200 + * @tc.name test isValidNumber interface with 13510574676 and undefined param + * @tc.desc get the isValidNumber value + */ + it('i18n_phonenumberformat_test_0200', 0, function () { + console.log('i18n_phonenumberformat_test_0200 ' + 'start'); + let phonenumber = new I18n.PhoneNumberFormat('CN', undefined); + let ran = Math.ceil(Math.random(1) * 9); + console.log('i18n_phonenumberformat_test_0200 ' + ran); + let valid = phonenumber.isValidNumber('1351057467' + ran); + console.log('i18n_phonenumberformat_test_0200 ' + valid); + expect(valid).assertEqual(true); + }) + + /** + * @tc.number SUB_GLOBAL_I18N_PHONENUMBERFORMAT_JS_0300 + * @tc.name test isValidNumber interface with 13510574676 and null param + * @tc.desc get the isValidNumber value + */ + it('i18n_phonenumberformat_test_0300', 0, function () { + console.log('i18n_phonenumberformat_test_0300 ' + 'start'); + let phonenumber = new I18n.PhoneNumberFormat('CN', null); + let ran = Math.ceil(Math.random(1) * 9); + console.log('i18n_phonenumberformat_test_0300 ' + ran); + let valid = phonenumber.isValidNumber('1351057467' + ran); + console.log('i18n_phonenumberformat_test_0300 ' + valid); + expect(valid).assertEqual(true); + }) + + /** + * @tc.number SUB_GLOBAL_I18N_PHONENUMBERFORMAT_JS_0400 + * @tc.name test isValidNumber interface with 0755-6100088X param + * @tc.desc get the isValidNumber value + */ + it('i18n_phonenumberformat_test_0400', 0, function () { + console.log('i18n_phonenumberformat_test_0400 ' + 'start'); + let phonenumber = new I18n.PhoneNumberFormat('CN'); + let ran = Math.ceil(Math.random(1) * 9); + console.log('i18n_phonenumberformat_test_0400 ' + ran); + let valid = phonenumber.isValidNumber('0755-6100088' + ran); + console.log('i18n_phonenumberformat_test_0400 ' + valid); + expect(valid).assertEqual(true); + }) + + /** + * @tc.number SUB_GLOBAL_I18N_PHONENUMBERFORMAT_JS_0500 + * @tc.name test isValidNumber interface with 110 param + * @tc.desc get the isValidNumber value + */ + it('i18n_phonenumberformat_test_0500', 0, function () { + console.log('i18n_phonenumberformat_test_0500 ' + 'start'); + let phonenumber = new I18n.PhoneNumberFormat('CN'); + let valid = phonenumber.isValidNumber('110'); + console.log('i18n_phonenumberformat_test_0500 ' + valid); + expect(valid).assertEqual(false); + }) + + /** + * @tc.number SUB_GLOBAL_I18N_PHONENUMBERFORMAT_JS_0600 + * @tc.name test isValidNumber interface with 135 1057 4676 param + * @tc.desc get the isValidNumber value + */ + it('i18n_phonenumberformat_test_0600', 0, function () { + console.log('i18n_phonenumberformat_test_0600 ' + 'start'); + let phonenumber = new I18n.PhoneNumberFormat('CN'); + let ran = Math.ceil(Math.random(1) * 9); + console.log('i18n_phonenumberformat_test_0600 ' + ran); + let valid = phonenumber.isValidNumber('135 1057 467' + ran); + console.log('i18n_phonenumberformat_test_0600 ' + valid); + expect(valid).assertEqual(true); + }) + + /** + * @tc.number SUB_GLOBAL_I18N_PHONENUMBERFORMAT_JS_0700 + * @tc.name test isValidNumber interface with +86 135 1057 4676 param + * @tc.desc get the isValidNumber value + */ + it('i18n_phonenumberformat_test_0700', 0, function () { + console.log('i18n_phonenumberformat_test_0700 ' + 'start'); + let phonenumber = new I18n.PhoneNumberFormat('CN'); + let ran = Math.ceil(Math.random(1) * 9); + console.log('i18n_phonenumberformat_test_0700 ' + ran); + let valid = phonenumber.isValidNumber('+86 135 1057 467' + ran); + console.log('i18n_phonenumberformat_test_0700 ' + valid); + expect(valid).assertEqual(true); + }) + + /** + * @tc.number SUB_GLOBAL_I18N_PHONENUMBERFORMAT_JS_0800 + * @tc.name test isValidNumber interface with 135-1057-4676 param + * @tc.desc get the isValidNumber value + */ + it('i18n_phonenumberformat_test_0800', 0, function () { + console.log('i18n_phonenumberformat_test_0800 ' + 'start'); + let phonenumber = new I18n.PhoneNumberFormat('CN'); + let ran = Math.ceil(Math.random(1) * 9); + console.log('i18n_phonenumberformat_test_0800 ' + ran); + let valid = phonenumber.isValidNumber('135-1057-467' + ran); + console.log('i18n_phonenumberformat_test_0800 ' + valid); + expect(valid).assertEqual(true); + }) + + /** + * @tc.number SUB_GLOBAL_I18N_PHONENUMBERFORMAT_JS_0900 + * @tc.name test isValidNumber interface with tel:+86-135-1057-4676 param + * @tc.desc get the isValidNumber value + */ + it('i18n_phonenumberformat_test_0900', 0, function () { + console.log('i18n_phonenumberformat_test_0900 ' + 'start'); + let phonenumber = new I18n.PhoneNumberFormat('CN'); + let ran = Math.ceil(Math.random(1) * 9); + console.log('i18n_phonenumberformat_test_0900 ' + ran); + let valid = phonenumber.isValidNumber('tel:+86-135-1057-467' + ran); + console.log('i18n_phonenumberformat_test_0900 ' + valid); + expect(valid).assertEqual(true); + }) + + /** + * @tc.number SUB_GLOBAL_I18N_PHONENUMBERFORMAT_JS_1000 + * @tc.name test isValidNumber interface with 86-135-1057-4676 param + * @tc.desc get the isValidNumber value + */ + it('i18n_phonenumberformat_test_1000', 0, function () { + console.log('i18n_phonenumberformat_test_1000 ' + 'start'); + let phonenumber = new I18n.PhoneNumberFormat('CN'); + let ran = Math.ceil(Math.random(1) * 9); + console.log('i18n_phonenumberformat_test_1000 ' + ran); + let valid = phonenumber.isValidNumber('86-135-1057-467' + ran); + console.log('i18n_phonenumberformat_test_1000 ' + valid); + expect(valid).assertEqual(true); + }) + + /** + * @tc.number SUB_GLOBAL_I18N_PHONENUMBERFORMAT_JS_1100 + * @tc.name test isValidNumber interface with +8613510574676 param + * @tc.desc get the isValidNumber value + */ + it('i18n_phonenumberformat_test_1100', 0, function () { + console.log('i18n_phonenumberformat_test_1100 ' + 'start'); + let phonenumber = new I18n.PhoneNumberFormat('CN'); + let ran = Math.ceil(Math.random(1) * 9); + console.log('i18n_phonenumberformat_test_1100 ' + ran); + let valid = phonenumber.isValidNumber('+861351057467' + ran); + console.log('i18n_phonenumberformat_test_1100 ' + valid); + expect(valid).assertEqual(true); + }) + + /** + * @tc.number SUB_GLOBAL_I18N_PHONENUMBERFORMAT_JS_1200 + * @tc.name test isValidNumber interface with 8613510574676 param + * @tc.desc get the isValidNumber value + */ + it('i18n_phonenumberformat_test_1200', 0, function () { + console.log('i18n_phonenumberformat_test_1200 ' + 'start'); + let phonenumber = new I18n.PhoneNumberFormat('CN'); + let ran = Math.ceil(Math.random(1) * 9); + console.log('i18n_phonenumberformat_test_1200 ' + ran); + let valid = phonenumber.isValidNumber('861351057467' + ran); + console.log('i18n_phonenumberformat_test_1200 ' + valid); + expect(valid).assertEqual(true); + }) + + /** + * @tc.number SUB_GLOBAL_I18N_PHONENUMBERFORMAT_JS_1300 + * @tc.name test isValidNumber interface with 1351057467 param + * @tc.desc get the isValidNumber value + */ + it('i18n_phonenumberformat_test_1300', 0, function () { + console.log('i18n_phonenumberformat_test_1300 ' + 'start'); + let phonenumber = new I18n.PhoneNumberFormat('CN'); + let ran = Math.ceil(Math.random(1) * 9); + console.log('i18n_phonenumberformat_test_1300 ' + ran); + let valid = phonenumber.isValidNumber('135105746' + ran); + console.log('i18n_phonenumberformat_test_1300 ' + valid); + expect(valid).assertEqual(false); + }) + + /** + * @tc.number SUB_GLOBAL_I18N_PHONENUMBERFORMAT_JS_1400 + * @tc.name test isValidNumber interface with 135105746761 param + * @tc.desc get the isValidNumber value + */ + it('i18n_phonenumberformat_test_1400', 0, function () { + console.log('i18n_phonenumberformat_test_1400 ' + 'start'); + let phonenumber = new I18n.PhoneNumberFormat('CN'); + let ran = Math.ceil(Math.random(1) * 9); + console.log('i18n_phonenumberformat_test_1400 ' + ran); + let valid = phonenumber.isValidNumber('13510574676' + ran); + console.log('i18n_phonenumberformat_test_1400 ' + valid); + expect(valid).assertEqual(false); + }) + + /** + * @tc.number SUB_GLOBAL_I18N_PHONENUMBERFORMAT_JS_1500 + * @tc.name test isValidNumber interface with 1351057467a param + * @tc.desc get the isValidNumber value + */ + it('i18n_phonenumberformat_test_1500', 0, function () { + console.log('i18n_phonenumberformat_test_1500 ' + 'start'); + let phonenumber = new I18n.PhoneNumberFormat('CN'); + let ran = Math.ceil(Math.random(1) * 9); + console.log('i18n_phonenumberformat_test_1500 ' + ran); + let valid = phonenumber.isValidNumber('135105746' + ran + 'a'); + console.log('i18n_phonenumberformat_test_1500 ' + valid); + expect(valid).assertEqual(false); + }) + + /** + * @tc.number SUB_GLOBAL_I18N_PHONENUMBERFORMAT_JS_1600 + * @tc.name test isValidNumber interface with 6262023379 param + * @tc.desc get the isValidNumber value + */ + it('i18n_phonenumberformat_test_1600', 0, function () { + console.log('i18n_phonenumberformat_test_1600 ' + 'start'); + let phonenumber = new I18n.PhoneNumberFormat('US'); + let ran = Math.ceil(Math.random(1) * 9); + console.log('i18n_phonenumberformat_test_1600 ' + ran); + let valid = phonenumber.isValidNumber('626202337' + ran); + console.log('i18n_phonenumberformat_test_1600 ' + valid); + expect(valid).assertEqual(true); + }) + + /** + * @tc.number SUB_GLOBAL_I18N_PHONENUMBERFORMAT_JS_1700 + * @tc.name test isValidNumber interface with 626202337 param + * @tc.desc get the isValidNumber value + */ + it('i18n_phonenumberformat_test_1700', 0, function () { + console.log('i18n_phonenumberformat_test_1700 ' + 'start'); + let phonenumber = new I18n.PhoneNumberFormat('US'); + let ran = Math.ceil(Math.random(1) * 9); + console.log('i18n_phonenumberformat_test_1700 ' + ran); + let valid = phonenumber.isValidNumber('62620233' + ran); + console.log('i18n_phonenumberformat_test_1700 ' + valid); + expect(valid).assertEqual(false); + }) + + /** + * @tc.number SUB_GLOBAL_I18N_PHONENUMBERFORMAT_JS_1800 + * @tc.name test isValidNumber interface with 62620233791 param + * @tc.desc get the isValidNumber value + */ + it('i18n_phonenumberformat_test_1800', 0, function () { + console.log('i18n_phonenumberformat_test_1800 ' + 'start'); + let phonenumber = new I18n.PhoneNumberFormat('US'); + let ran = Math.ceil(Math.random(1) * 9); + console.log('i18n_phonenumberformat_test_1800 ' + ran); + let valid = phonenumber.isValidNumber('6262023379' + ran); + console.log('i18n_phonenumberformat_test_1800 ' + valid); + expect(valid).assertEqual(false); + }) + + /** + * @tc.number SUB_GLOBAL_I18N_PHONENUMBERFORMAT_JS_1900 + * @tc.name test isValidNumber interface with 626202337a param + * @tc.desc get the isValidNumber value + */ + it('i18n_phonenumberformat_test_1900', 0, function () { + console.log('i18n_phonenumberformat_test_1900 ' + 'start'); + let phonenumber = new I18n.PhoneNumberFormat('US'); + let ran = Math.ceil(Math.random(1) * 9); + console.log('i18n_phonenumberformat_test_1900 ' + ran); + let valid = phonenumber.isValidNumber('62620233' + ran + 'a'); + console.log('i18n_phonenumberformat_test_1900 ' + valid); + expect(valid).assertEqual(false); + }) + + /** + * @tc.number SUB_GLOBAL_I18N_PHONENUMBERFORMAT_JS_2000 + * @tc.name test format interface with 13510574676 param + * @tc.desc get the isValidNumber value + */ + it('i18n_phonenumberformat_test_2000', 0, function () { + console.log('i18n_phonenumberformat_test_2000 ' + 'start'); + let phonenumber = new I18n.PhoneNumberFormat('CN'); + let ran = Math.ceil(Math.random(1) * 9); + console.log('i18n_phonenumberformat_test_2000 ' + ran); + let value = phonenumber.format('1351057467' + ran); + console.log('i18n_phonenumberformat_test_2000 ' + value); + expect(value).assertEqual('135 1057 467' + ran); + }) + + /** + * @tc.number SUB_GLOBAL_I18N_PHONENUMBERFORMAT_JS_2100 + * @tc.name test format interface with 6262023379 param + * @tc.desc get the isValidNumber value + */ + it('i18n_phonenumberformat_test_2100', 0, function () { + console.log('i18n_phonenumberformat_test_2100 ' + 'start'); + let phonenumber = new I18n.PhoneNumberFormat('US'); + let ran = Math.ceil(Math.random(1) * 9); + console.log('i18n_phonenumberformat_test_2100 ' + ran); + let value = phonenumber.format('626202337' + ran); + console.log('i18n_phonenumberformat_test_2100 ' + value); + expect(value).assertEqual('(626) 202-337' + ran); + }) + + /** + * @tc.number SUB_GLOBAL_I18N_PHONENUMBERFORMAT_JS_2200 + * @tc.name test format interface with 13510574676 and NATIONAL type param + * @tc.desc get the isValidNumber value + */ + it('i18n_phonenumberformat_test_2200', 0, function () { + console.log('i18n_phonenumberformat_test_2200 ' + 'start'); + let phonenumber = new I18n.PhoneNumberFormat('CN', {'type': 'NATIONAL'}); + let ran = Math.ceil(Math.random(1) * 9); + console.log('i18n_phonenumberformat_test_2200 ' + ran); + let value = phonenumber.format('1351057467' + ran); + console.log('i18n_phonenumberformat_test_2200 ' + value); + expect(value).assertEqual('135 1057 467' + ran); + }) + + /** + * @tc.number SUB_GLOBAL_I18N_PHONENUMBERFORMAT_JS_2300 + * @tc.name test format interface with 1351057467 and NATIONAL type param + * @tc.desc get the isValidNumber value + */ + it('i18n_phonenumberformat_test_2300', 0, function () { + console.log('i18n_phonenumberformat_test_2300 ' + 'start'); + let phonenumber = new I18n.PhoneNumberFormat('CN', {'type': 'NATIONAL'}); + let ran = Math.ceil(Math.random(1) * 9); + console.log('i18n_phonenumberformat_test_2300 ' + ran); + let value = phonenumber.format('135105746' + ran); + console.log('i18n_phonenumberformat_test_2300 ' + value); + expect(value).assertEqual('135105746' + ran); + }) + + /** + * @tc.number SUB_GLOBAL_I18N_PHONENUMBERFORMAT_JS_2400 + * @tc.name test format interface with 135105746761 and NATIONAL type param + * @tc.desc get the isValidNumber value + */ + it('i18n_phonenumberformat_test_2400', 0, function () { + console.log('i18n_phonenumberformat_test_2400 ' + 'start'); + let phonenumber = new I18n.PhoneNumberFormat('CN', {'type': 'NATIONAL'}); + let ran = Math.ceil(Math.random(1) * 9); + console.log('i18n_phonenumberformat_test_2400 ' + ran); + let value = phonenumber.format('13510574676' + ran); + console.log('i18n_phonenumberformat_test_2400 ' + value); + expect(value).assertEqual('013 510 574 676' + ran); + }) + + /** + * @tc.number SUB_GLOBAL_I18N_PHONENUMBERFORMAT_JS_2500 + * @tc.name test format interface with 135 1057 4676 and NATIONAL type param + * @tc.desc get the isValidNumber value + */ + it('i18n_phonenumberformat_test_2500', 0, function () { + console.log('i18n_phonenumberformat_test_2500 ' + 'start'); + let phonenumber = new I18n.PhoneNumberFormat('CN', {'type': 'NATIONAL'}); + let ran = Math.ceil(Math.random(1) * 9); + console.log('i18n_phonenumberformat_test_2500 ' + ran); + let value = phonenumber.format('135 1057 467' + ran); + console.log('i18n_phonenumberformat_test_2500 ' + value); + expect(value).assertEqual('135 1057 467' + ran); + }) + + /** + * @tc.number SUB_GLOBAL_I18N_PHONENUMBERFORMAT_JS_2600 + * @tc.name test format interface with 13510574676 and INTERNATIONAL type param + * @tc.desc get the isValidNumber value + */ + it('i18n_phonenumberformat_test_2600', 0, function () { + console.log('i18n_phonenumberformat_test_2600 ' + 'start'); + let phonenumber = new I18n.PhoneNumberFormat('CN', {'type': 'INTERNATIONAL'}); + let ran = Math.ceil(Math.random(1) * 9); + console.log('i18n_phonenumberformat_test_2600 ' + ran); + let value = phonenumber.format('1351057467' + ran); + console.log('i18n_phonenumberformat_test_2600 ' + value); + expect(value).assertEqual('+86 135 1057 467' + ran); + }) + + /** + * @tc.number SUB_GLOBAL_I18N_PHONENUMBERFORMAT_JS_2700 + * @tc.name test format interface with 13510574676 and RFC3966 type param + * @tc.desc get the isValidNumber value + */ + it('i18n_phonenumberformat_test_2700', 0, function () { + console.log('i18n_phonenumberformat_test_2700 ' + 'start'); + let phonenumber = new I18n.PhoneNumberFormat('CN', {'type': 'RFC3966'}); + let ran = Math.ceil(Math.random(1) * 9); + console.log('i18n_phonenumberformat_test_2700 ' + ran); + let value = phonenumber.format('1351057467' + ran); + console.log('i18n_phonenumberformat_test_2700 ' + value); + expect(value).assertEqual('tel:+86-135-1057-467' + ran); + }) + + /** + * @tc.number SUB_GLOBAL_I18N_PHONENUMBERFORMAT_JS_2800 + * @tc.name test format interface with 13510574676 and E164 type param + * @tc.desc get the isValidNumber value + */ + it('i18n_phonenumberformat_test_2800', 0, function () { + console.log('i18n_phonenumberformat_test_2800 ' + 'start'); + let phonenumber = new I18n.PhoneNumberFormat('CN', {'type': 'E164'}); + let ran = Math.ceil(Math.random(1) * 9); + console.log('i18n_phonenumberformat_test_2800 ' + ran); + let value = phonenumber.format('1351057467' + ran); + console.log('i18n_phonenumberformat_test_2800 ' + value); + expect(value).assertEqual('+861351057467' + ran); + }) + + /** + * @tc.number SUB_GLOBAL_I18N_PHONENUMBERFORMAT_JS_2900 + * @tc.name test format interface with 6262023379 and NATIONAL type param + * @tc.desc get the isValidNumber value + */ + it('i18n_phonenumberformat_test_2900', 0, function () { + console.log('i18n_phonenumberformat_test_2900 ' + 'start'); + let phonenumber = new I18n.PhoneNumberFormat('US', {'type': 'NATIONAL'}); + let ran = Math.ceil(Math.random(1) * 9); + console.log('i18n_phonenumberformat_test_2900 ' + ran); + let value = phonenumber.format('626202337' + ran); + console.log('i18n_phonenumberformat_test_2900 ' + value); + expect(value).assertEqual('(626) 202-337' + ran); + }) + + /** + * @tc.number SUB_GLOBAL_I18N_PHONENUMBERFORMAT_JS_3000 + * @tc.name test format interface with 6262023379 and INTERNATIONAL type param + * @tc.desc get the isValidNumber value + */ + it('i18n_phonenumberformat_test_3000', 0, function () { + console.log('i18n_phonenumberformat_test_3000 ' + 'start'); + let phonenumber = new I18n.PhoneNumberFormat('US', {'type': 'INTERNATIONAL'}); + let ran = Math.ceil(Math.random(1) * 9); + console.log('i18n_phonenumberformat_test_3000 ' + ran); + let value = phonenumber.format('626202337' + ran); + console.log('i18n_phonenumberformat_test_3000 ' + value); + expect(value).assertEqual('+1 626-202-337' + ran); + }) + + /** + * @tc.number SUB_GLOBAL_I18N_PHONENUMBERFORMAT_JS_3100 + * @tc.name test format interface with 6262023379 and RFC3966 type param + * @tc.desc get the isValidNumber value + */ + it('i18n_phonenumberformat_test_3100', 0, function () { + console.log('i18n_phonenumberformat_test_3100 ' + 'start'); + let phonenumber = new I18n.PhoneNumberFormat('US', {'type': 'RFC3966'}); + let ran = Math.ceil(Math.random(1) * 9); + console.log('i18n_phonenumberformat_test_3100 ' + ran); + let value = phonenumber.format('626202337' + ran); + console.log('i18n_phonenumberformat_test_3100 ' + value); + expect(value).assertEqual('tel:+1-626-202-337' + ran); + }) + + /** + * @tc.number SUB_GLOBAL_I18N_PHONENUMBERFORMAT_JS_3200 + * @tc.name test format interface with 6262023379 and E164 type param + * @tc.desc get the isValidNumber value + */ + it('i18n_phonenumberformat_test_3200', 0, function () { + console.log('i18n_phonenumberformat_test_3200 ' + 'start'); + let phonenumber = new I18n.PhoneNumberFormat('US', {'type': 'E164'}); + let ran = Math.ceil(Math.random(1) * 9); + console.log('i18n_phonenumberformat_test_3200 ' + ran); + let value = phonenumber.format('626202337' + ran); + console.log('i18n_phonenumberformat_test_3200 ' + value); + expect(value).assertEqual('+1626202337' + ran); + }) + + /** + * @tc.number SUB_GLOBAL_I18N_PHONENUMBERFORMAT_JS_3300 + * @tc.name test getLocationName method with 135... num in zh-CN locale + * @tc.desc get the getLocationName value + */ + it('i18n_phonenumberformat_test_3300', 0, function () { + console.log('i18n_phonenumberformat_test_3300 ' + 'start'); + let phonenumber = new I18n.PhoneNumberFormat('CN'); + let ran = Math.ceil(Math.random(1) * 9); + console.log('i18n_phonenumberformat_test_3300 ' + ran); + let value = phonenumber.getLocationName('1351057467' + ran, 'zh-CN'); + console.log('i18n_phonenumberformat_test_3300 ' + value); + expect(value == '中国' || value == '广东省深圳市').assertTrue(); + }) + + /** + * @tc.number SUB_GLOBAL_I18N_PHONENUMBERFORMAT_JS_3400 + * @tc.name test getLocationName method with 135... num in en-US locale + * @tc.desc get the getLocationName value + */ + it('i18n_phonenumberformat_test_3400', 0, function () { + console.log('i18n_phonenumberformat_test_3400 ' + 'start'); + let phonenumber = new I18n.PhoneNumberFormat('CN'); + let ran = Math.ceil(Math.random(1) * 9); + console.log('i18n_phonenumberformat_test_3400 ' + ran); + let value = phonenumber.getLocationName('+861351057467' + ran, 'en-US'); + console.log('i18n_phonenumberformat_test_3400 ' + value); + expect(value == 'China' || value == 'Shenzhen, Guangdong').assertTrue(); + let value2 = phonenumber.getLocationName('+86 1351057467' + ran, 'en-US'); + console.log('i18n_phonenumberformat_test_3400 ' + value2); + expect(value2 == 'China' || value2 == 'Shenzhen, Guangdong').assertTrue(); + }) + + /** + * @tc.number SUB_GLOBAL_I18N_PHONENUMBERFORMAT_JS_3500 + * @tc.name test getLocationName method with 158... num in en-US locale + * @tc.desc get the getLocationName value + */ + it('i18n_phonenumberformat_test_3500', 0, function () { + console.log('i18n_phonenumberformat_test_3500 ' + 'start'); + let phonenumber = new I18n.PhoneNumberFormat('CN'); + let ran = Math.ceil(Math.random(1) * 9); + console.log('i18n_phonenumberformat_test_3500 ' + ran); + let value1 = phonenumber.getLocationName('+861586661737' + ran, 'en-US'); + console.log('i18n_phonenumberformat_test_3500 ' + value1); + expect(value1 == 'China' || value1 == 'Jinan, Shandong').assertTrue(); + let value2 = phonenumber.getLocationName('+86 1586661737' + ran, 'en-US'); + console.log('i18n_phonenumberformat_test_3500 ' + value2); + expect(value2 == 'China' || value2 == 'Jinan, Shandong').assertTrue(); + }) + + /** + * @tc.number SUB_GLOBAL_I18N_PHONENUMBERFORMAT_JS_3600 + * @tc.name test getLocationName method with 027... num in zh-CN locale + * @tc.desc get the getLocationName value + */ + it('i18n_phonenumberformat_test_3600', 0, function () { + console.log('i18n_phonenumberformat_test_3600 ' + 'start'); + let phonenumber = new I18n.PhoneNumberFormat('CN'); + let ran = Math.ceil(Math.random(1) * 9); + console.log('i18n_phonenumberformat_test_3600 ' + ran); + let value = phonenumber.getLocationName('027-5937411' + ran, 'zh-CN'); + console.log('i18n_phonenumberformat_test_3600 ' + value); + expect(value == '中国' || value == '湖北省武汉市').assertTrue(); + }) + + /** + * @tc.number SUB_GLOBAL_I18N_PHONENUMBERFORMAT_JS_3700 + * @tc.name test getLocationName method with 0728... num in zh-CN locale + * @tc.desc get the getLocationName value + */ + it('i18n_phonenumberformat_test_3700', 0, function () { + console.log('i18n_phonenumberformat_test_3700 ' + 'start'); + let phonenumber = new I18n.PhoneNumberFormat('CN'); + let ran = Math.ceil(Math.random(1) * 9); + console.log('i18n_phonenumberformat_test_3700 ' + ran); + let value = phonenumber.getLocationName('0728-623797' + ran, 'zh-CN'); + console.log('i18n_phonenumberformat_test_3700 ' + value); + expect(value == '中国' || value == '湖北省仙桃市').assertTrue(); + }) + + /** + * @tc.number SUB_GLOBAL_I18N_PHONENUMBERFORMAT_JS_3800 + * @tc.name test getLocationName method with +34... num in en-US locale + * @tc.desc get the getLocationName value + */ + it('i18n_phonenumberformat_test_3800', 0, function () { + console.log('i18n_phonenumberformat_test_3800 ' + 'start'); + let phonenumber = new I18n.PhoneNumberFormat('CN'); + let ran = Math.ceil(Math.random(1) * 9); + console.log('i18n_phonenumberformat_test_3800 ' + ran); + let value1 = phonenumber.getLocationName('+3460724205' + ran, 'en-US'); + console.log('i18n_phonenumberformat_test_3800 ' + value1); + expect(value1).assertEqual('Spain'); + let value2 = phonenumber.getLocationName('+34 60724205' + ran, 'en-US'); + console.log('i18n_phonenumberformat_test_3800 ' + value2); + expect(value2).assertEqual('Spain'); + }) + + /** + * @tc.number SUB_GLOBAL_I18N_PHONENUMBERFORMAT_JS_3900 + * @tc.name test getLocationName method with +39... num in en-US locale + * @tc.desc get the getLocationName value + */ + it('i18n_phonenumberformat_test_3900', 0, function () { + console.log('i18n_phonenumberformat_test_3900 ' + 'start'); + let phonenumber = new I18n.PhoneNumberFormat('CN'); + let ran = Math.ceil(Math.random(1) * 9); + console.log('i18n_phonenumberformat_test_3900 ' + ran); + let value = phonenumber.getLocationName('+39342652441' + ran, 'en-US'); + console.log('i18n_phonenumberformat_test_3900 ' + value); + expect(value).assertEqual('Italy'); + let value2 = phonenumber.getLocationName('+39 342652441' + ran, 'en-US'); + console.log('i18n_phonenumberformat_test_3900 ' + value2); + expect(value2).assertEqual('Italy'); + }) + + /** + * @tc.number SUB_GLOBAL_I18N_PHONENUMBERFORMAT_JS_4000 + * @tc.name test getLocationName method with +39... num in zh-CN locale + * @tc.desc get the getLocationName value + */ + it('i18n_phonenumberformat_test_4000', 0, function () { + console.log('i18n_phonenumberformat_test_4000 ' + 'start'); + let phonenumber = new I18n.PhoneNumberFormat('CN'); + let ran = Math.ceil(Math.random(1) * 9); + console.log('i18n_phonenumberformat_test_4000 ' + ran); + let value = phonenumber.getLocationName('+39342652441' + ran, 'zh-CN'); + console.log('i18n_phonenumberformat_test_4000 ' + value); + expect(value).assertEqual('意大利'); + let value2 = phonenumber.getLocationName('+39 342652441' + ran, 'zh-CN'); + console.log('i18n_phonenumberformat_test_4000 ' + value2); + expect(value2).assertEqual('意大利'); + }) + + /** + * @tc.number SUB_GLOBAL_I18N_PHONENUMBERFORMAT_JS_4100 + * @tc.name test getLocationName method with +34... num in zh-CN locale + * @tc.desc get the getLocationName value + */ + it('i18n_phonenumberformat_test_4100', 0, function () { + console.log('i18n_phonenumberformat_test_4100 ' + 'start'); + let phonenumber = new I18n.PhoneNumberFormat('CN'); + let ran = Math.ceil(Math.random(1) * 9); + console.log('i18n_phonenumberformat_test_4100 ' + ran); + let value1 = phonenumber.getLocationName('+3460724205' + ran, 'zh-CN'); + console.log('i18n_phonenumberformat_test_4100 ' + value1); + expect(value1).assertEqual('西班牙'); + let value2 = phonenumber.getLocationName('+34 60724205' + ran, 'zh-CN'); + console.log('i18n_phonenumberformat_test_4100 ' + value2); + expect(value2).assertEqual('西班牙'); + }) + + console.log('*************end PhoneNumberFormatInI18nTest*************'); +})} diff --git a/global/i18n_standard/intljs/src/main/js/test/UtilInI18n.test.js b/global/i18n_standard/intljs/src/main/js/test/UtilInI18n.test.js new file mode 100644 index 000000000..d82b53ea9 --- /dev/null +++ b/global/i18n_standard/intljs/src/main/js/test/UtilInI18n.test.js @@ -0,0 +1,315 @@ +/* + * Copyright (C) 2023 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 {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' + +export default function UtilInI18nTest() { +describe('UtilInI18nTest', function () { + console.log('*************start UtilInI18nTest*************'); + + let hour = I18n.System.is24HourClock(); + console.log('init 24 hour clock value ' + hour); + + /* * + * execute this step before all testcases + */ + beforeAll(function(){ + console.log('step before all cases in I18n.' + + ' 24hour: ' + I18n.System.is24HourClock() + + ' prelang: ' + I18n.System.getPreferredLanguageList() + + ' syslocale: ' + I18n.System.getSystemLocale()); + }) + + /* * + * execute this step before every testcase + */ + beforeEach(function(){ + console.log('step before every case in I18n.'); + }) + + /* * + * execute this step after every testcase + */ + afterEach(function(){ + console.log('step after every case in I18n.'); + }) + + /* * + * execute this step after all testcases + */ + afterAll(function(){ + console.log('step after all cases in I18n.' + + ' 24hour: ' + I18n.System.is24HourClock() + + ' prelang: ' + I18n.System.getPreferredLanguageList() + + ' syslocale: ' + I18n.System.getSystemLocale()); + }) + + /** + * @tc.number SUB_GLOBAL_I18N_UTIL_JS_0100 + * @tc.name test unitConvert interface from cup to liter unit with long style + * @tc.desc get the unitConvert value + */ + it('i18n_util_test_0100', 0, function () { + console.log('i18n_util_test_0100 ' + 'start'); + let util = new I18n.Util(); + let value = util.unitConvert({unit: 'cup', measureSystem: 'US'}, + {unit: 'liter', measureSystem: 'SI'}, + 1000, + 'en-US', + 'long'); + console.log('i18n_util_test_0100 ' + value); + expect(value).assertEqual('236.588 liters'); + }) + + /** + * @tc.number SUB_GLOBAL_I18N_UTIL_JS_0200 + * @tc.name test unitConvert interface from cup to liter unit with undefined style + * @tc.desc get the unitConvert value + */ + it('i18n_util_test_0200', 0, function () { + console.log('i18n_util_test_0200 ' + 'start'); + let util = new I18n.Util(); + let value = util.unitConvert({unit: 'cup', measureSystem: 'US'}, + {unit: 'liter', measureSystem: 'SI'}, + 1000, + 'en-US', + undefined); + console.log('i18n_util_test_0200 ' + value); + expect(value).assertEqual('236.588 L'); + }) + + /** + * @tc.number SUB_GLOBAL_I18N_UTIL_JS_0300 + * @tc.name test unitConvert interface from cup to liter unit with null style + * @tc.desc get the unitConvert value + */ + it('i18n_util_test_0300', 0, function () { + console.log('i18n_util_test_0300 ' + 'start'); + let util = new I18n.Util(); + let value = util.unitConvert({unit: 'cup', measureSystem: 'US'}, + {unit: 'liter', measureSystem: 'SI'}, + 1000, + 'en-US', + null); + console.log('i18n_util_test_0300 ' + value); + expect(value).assertEqual('236.588 L'); + }) + + /** + * @tc.number SUB_GLOBAL_I18N_UTIL_JS_0400 + * @tc.name test unitConvert interface from cup to liter unit with medium style + * @tc.desc get the unitConvert value + */ + it('i18n_util_test_0400', 0, function () { + console.log('i18n_util_test_0400 ' + 'start'); + let util = new I18n.Util(); + let value = util.unitConvert({unit: 'cup', measureSystem: 'US'}, + {unit: 'liter', measureSystem: 'SI'}, + 1000, + 'en-US', + 'medium'); + console.log('i18n_util_test_0400 ' + value); + expect(value).assertEqual('236.588 L'); + }) + + /** + * @tc.number SUB_GLOBAL_I18N_UTIL_JS_0500 + * @tc.name test unitConvert interface from cup to liter unit with narrow style + * @tc.desc get the unitConvert value + */ + it('i18n_util_test_0500', 0, function () { + console.log('i18n_util_test_0500 ' + 'start'); + let util = new I18n.Util(); + let value = util.unitConvert({unit: 'cup', measureSystem: 'US'}, + {unit: 'liter', measureSystem: 'SI'}, + 1000, + 'en-US', + 'narrow'); + console.log('i18n_util_test_0500 ' + value); + expect(value).assertEqual('236.588L'); + }) + + /** + * @tc.number SUB_GLOBAL_I18N_UTIL_JS_0600 + * @tc.name test unitConvert interface from cup to liter unit with short style + * @tc.desc get the unitConvert value + */ + it('i18n_util_test_0600', 0, function () { + console.log('i18n_util_test_0600 ' + 'start'); + let util = new I18n.Util(); + let value = util.unitConvert({unit: 'cup', measureSystem: 'US'}, + {unit: 'liter', measureSystem: 'SI'}, + 1000, + 'en-US', + 'short'); + console.log('i18n_util_test_0600 ' + value); + expect(value).assertEqual('236.588 L'); + }) + + /** + * @tc.number SUB_GLOBAL_I18N_UTIL_JS_0700 + * @tc.name test unitConvert interface from meter to mile unit + * @tc.desc get the unitConvert value + */ + it('i18n_util_test_0700', 0, function () { + console.log('i18n_util_test_0700 ' + 'start'); + let util = new I18n.Util(); + let value = util.unitConvert({unit: 'meter', measureSystem: 'SI'}, + {unit: 'mile', measureSystem: 'SI'}, + 1000, + 'zh-CN', + 'long'); + console.log('i18n_util_test_0700 ' + value); + expect(value).assertEqual('0.621英里'); + }) + + /** + * @tc.number SUB_GLOBAL_I18N_UTIL_JS_0800 + * @tc.name test unitConvert interface from hour to second unit + * @tc.desc get the unitConvert value + */ + it('i18n_util_test_0800', 0, function () { + console.log('i18n_util_test_0800 ' + 'start'); + let util = new I18n.Util(); + let value = util.unitConvert({unit: 'hour', measureSystem: 'SI'}, + {unit: 'second', measureSystem: 'SI'}, + 10, + 'zh-CN', + 'medium'); + console.log('i18n_util_test_0800 ' + value); + expect(value).assertEqual('36,000秒'); + }) + + /** + * @tc.number SUB_GLOBAL_I18N_UTIL_JS_0900 + * @tc.name test unitConvert interface from celsius to fahrenheit unit + * @tc.desc get the unitConvert value + */ + it('i18n_util_test_0900', 0, function () { + console.log('i18n_util_test_0900 ' + 'start'); + let util = new I18n.Util(); + let value = util.unitConvert({unit: 'celsius', measureSystem: 'SI'}, + {unit: 'fahrenheit', measureSystem: 'SI'}, + 1000, + 'zh-CN', + 'short'); + console.log('i18n_util_test_0900 ' + value); + expect(value).assertEqual('1,832°F'); + }) + + /** + * @tc.number SUB_GLOBAL_I18N_UTIL_JS_1000 + * @tc.name test unitConvert interface from acre to hectare unit + * @tc.desc get the unitConvert value + */ + it('i18n_util_test_1000', 0, function () { + console.log('i18n_util_test_1000 ' + 'start'); + let util = new I18n.Util(); + let value = util.unitConvert({unit: 'acre', measureSystem: 'SI'}, + {unit: 'hectare', measureSystem: 'SI'}, + 1000, + 'zh-CN', + 'long'); + console.log('i18n_util_test_1000 ' + value); + expect(value).assertEqual('404.686公顷'); + }) + + /** + * @tc.number SUB_GLOBAL_I18N_UTIL_JS_1100 + * @tc.name test unitConvert interface from acre to square-meter unit + * @tc.desc get the unitConvert value + */ + it('i18n_util_test_1100', 0, function () { + console.log('i18n_util_test_1100 ' + 'start'); + let util = new I18n.Util(); + let value = util.unitConvert({unit: 'acre', measureSystem: 'SI'}, + {unit: 'square-meter', measureSystem: 'SI'}, + 1000, + 'zh-CN', + 'long'); + console.log('i18n_util_test_1100 ' + value); + expect(value).assertEqual('4,046,856.422平方米'); + }) + + /** + * @tc.number SUB_GLOBAL_I18N_UTIL_JS_1200 + * @tc.name test unitConvert interface from kilometer-per-hour to knot unit + * @tc.desc get the unitConvert value + */ + it('i18n_util_test_1200', 0, function () { + console.log('i18n_util_test_1200 ' + 'start'); + let util = new I18n.Util(); + let value = util.unitConvert({unit: 'kilometer-per-hour', measureSystem: 'SI'}, + {unit: 'knot', measureSystem: 'SI'}, + 1000, + 'zh-CN', + 'long'); + console.log('i18n_util_test_1200 ' + value); + expect(value).assertEqual('539.957节'); + }) + + /** + * @tc.number SUB_GLOBAL_I18N_UTIL_JS_1300 + * @tc.name test unitConvert interface from kilometer-per-hour to meter-per-second unit + * @tc.desc get the unitConvert value + */ + it('i18n_util_test_1300', 0, function () { + console.log('i18n_util_test_1300 ' + 'start'); + let util = new I18n.Util(); + let value = util.unitConvert({unit: 'kilometer-per-hour', measureSystem: 'SI'}, + {unit: 'meter-per-second', measureSystem: 'SI'}, + 1000, + 'zh-CN', + 'long'); + console.log('i18n_util_test_1300 ' + value); + expect(value).assertEqual('每秒277.778米'); + }) + + /** + * @tc.number SUB_GLOBAL_I18N_UTIL_JS_1400 + * @tc.name test unitConvert interface from meter to kilometer unit + * @tc.desc get the unitConvert value + */ + it('i18n_util_test_1400', 0, function () { + console.log('i18n_util_test_1400 ' + 'start'); + let util = new I18n.Util(); + let value = util.unitConvert({unit: 'meter', measureSystem: 'SI'}, + {unit: 'kilometer', measureSystem: 'SI'}, + 1000, + 'zh-CN', + 'long'); + console.log('i18n_util_test_1400 ' + value); + expect(value).assertEqual('1公里'); + }) + + /** + * @tc.number SUB_GLOBAL_I18N_UTIL_JS_1500 + * @tc.name test unitConvert interface from meter to meter-per-second unit + * @tc.desc get the unitConvert value + */ + it('i18n_util_test_1500', 0, function () { + console.log('i18n_util_test_1500 ' + 'start'); + let util = new I18n.Util(); + let value = util.unitConvert({unit: 'meter', measureSystem: 'SI'}, + {unit: 'meter-per-second', measureSystem: 'SI'}, + 1000, + 'zh-CN', + 'long'); + console.log('i18n_util_test_1500 ' + value); + expect(value).assertEqual('1,000米'); + }) + + console.log('*************end UtilInI18nTest*************'); +})} -- GitLab