• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (C) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15import I18n from '@ohos.i18n'
16import deviceInfo from '@ohos.deviceInfo'
17import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium'
18
19export default function I18nUtilInI18nTest() {
20describe('I18nUtilInI18nTest', function () {
21    console.log('*************start I18nUtilInI18nTest*************');
22
23    let hour = I18n.System.is24HourClock();
24    console.log('init 24 hour clock value ' + hour);
25
26    /* *
27    * execute this step before all testcases
28    */
29    beforeAll(function(){
30        console.log('step before all cases in I18n.'
31        + ' 24hour: ' + I18n.System.is24HourClock()
32        + ' prelang: ' + I18n.System.getPreferredLanguageList()
33        + ' syslocale: ' + I18n.System.getSystemLocale());
34    })
35
36    /* *
37    * execute this step before every testcase
38    */
39    beforeEach(function(){
40        console.log('step before every case in I18n.');
41    })
42
43    /* *
44    * execute this step after every testcase
45    */
46    afterEach(function(){
47        console.log('step after every case in I18n.');
48    })
49
50    /* *
51    * execute this step after all testcases
52    */
53    afterAll(function(){
54        console.log('step after all cases in I18n.'
55        + ' 24hour: ' + I18n.System.is24HourClock()
56        + ' prelang: ' + I18n.System.getPreferredLanguageList()
57        + ' syslocale: ' + I18n.System.getSystemLocale());
58    })
59
60    /**
61    * @tc.number  SUB_GLOBAL_I18N_I18NUTIL_JS_0100
62    * @tc.name    test unitConvert interface from cup to liter unit with long style
63    * @tc.desc    get the unitConvert value
64    */
65     it('i18n_i18nutil_test_0100', 0, function () {
66        console.log('i18n_i18nutil_test_0100 ' + 'start');
67        let value = I18n.I18NUtil.unitConvert({unit: 'cup', measureSystem: 'US'},
68                                        {unit: 'liter', measureSystem: 'SI'},
69                                        1000,
70                                        'en-US',
71                                        'long');
72        console.log('i18n_i18nutil_test_0100 ' + value);
73        expect(value).assertEqual('236.588 liters');
74    })
75
76    /**
77    * @tc.number  SUB_GLOBAL_I18N_I18NUTIL_JS_0200
78    * @tc.name    test unitConvert interface from cup to liter unit with undefined style
79    * @tc.desc    get the unitConvert value
80    */
81     it('i18n_i18nutil_test_0200', 0, function () {
82        console.log('i18n_i18nutil_test_0200 ' + 'start');
83        let value = I18n.I18NUtil.unitConvert({unit: 'cup', measureSystem: 'US'},
84                                        {unit: 'liter', measureSystem: 'SI'},
85                                        1000,
86                                        'en-US',
87                                        undefined);
88        console.log('i18n_i18nutil_test_0200 ' + value);
89        let devType = deviceInfo.devicType;
90        if (devType == '2in1'){
91            expect(value).assertEqual('236.588 liters');
92        }else if (devType == 'phone'){
93            expect(value).assertEqual('236.588 L');
94        }
95    })
96
97    /**
98    * @tc.number  SUB_GLOBAL_I18N_I18NUTIL_JS_0300
99    * @tc.name    test unitConvert interface from cup to liter unit with null style
100    * @tc.desc    get the unitConvert value
101    */
102     it('i18n_i18nutil_test_0300', 0, function () {
103        console.log('i18n_i18nutil_test_0300 ' + 'start');
104        let value = I18n.I18NUtil.unitConvert({unit: 'cup', measureSystem: 'US'},
105                                        {unit: 'liter', measureSystem: 'SI'},
106                                        1000,
107                                        'en-US',
108                                        null);
109        console.log('i18n_i18nutil_test_0300 ' + value);
110        let devType = deviceInfo.devicType;
111        if (devType == '2in1'){
112            expect(value).assertEqual('236.588 liters');
113        }else if (devType == 'phone'){
114            expect(value).assertEqual('236.588 L');
115        }
116    })
117
118    /**
119    * @tc.number  SUB_GLOBAL_I18N_I18NUTIL_JS_0400
120    * @tc.name    test unitConvert interface from cup to liter unit with medium style
121    * @tc.desc    get the unitConvert value
122    */
123    it('i18n_i18nutil_test_0400', 0, function () {
124        console.log('i18n_i18nutil_test_0400 ' + 'start');
125        let value = I18n.I18NUtil.unitConvert({unit: 'cup', measureSystem: 'US'},
126                                        {unit: 'liter', measureSystem: 'SI'},
127                                        1000,
128                                        'en-US',
129                                        'medium');
130        console.log('i18n_i18nutil_test_0400 ' + value);
131        let devType = deviceInfo.devicType;
132        if (devType == '2in1'){
133            expect(value).assertEqual('236.588 liters');
134        }else if (devType == 'phone'){
135            expect(value).assertEqual('236.588 L');
136        }
137    })
138
139    /**
140    * @tc.number  SUB_GLOBAL_I18N_I18NUTIL_JS_0500
141    * @tc.name    test unitConvert interface from cup to liter unit with narrow style
142    * @tc.desc    get the unitConvert value
143    */
144     it('i18n_i18nutil_test_0500', 0, function () {
145        console.log('i18n_i18nutil_test_0500 ' + 'start');
146        let value = I18n.I18NUtil.unitConvert({unit: 'cup', measureSystem: 'US'},
147            {unit: 'liter', measureSystem: 'SI'},
148            1000,
149            'en-US',
150            'narrow');
151        console.log('i18n_i18nutil_test_0500 ' + value);
152        expect(value).assertEqual('236.588L');
153    })
154
155    /**
156    * @tc.number  SUB_GLOBAL_I18N_I18NUTIL_JS_0600
157    * @tc.name    test unitConvert interface from cup to liter unit with short style
158    * @tc.desc    get the unitConvert value
159    */
160    it('i18n_i18nutil_test_0600', 0, function () {
161        console.log('i18n_i18nutil_test_0600 ' + 'start');
162        let value = I18n.I18NUtil.unitConvert({unit: 'cup', measureSystem: 'US'},
163                                        {unit: 'liter', measureSystem: 'SI'},
164                                        1000,
165                                        'en-US',
166                                        'short');
167        console.log('i18n_i18nutil_test_0600 ' + value);
168        expect(value).assertEqual('236.588 L');
169    })
170
171    /**
172    * @tc.number  SUB_GLOBAL_I18N_I18NUTIL_JS_0700
173    * @tc.name    test unitConvert interface from meter to mile unit
174    * @tc.desc    get the unitConvert value
175    */
176    it('i18n_i18nutil_test_0700', 0, function () {
177        console.log('i18n_i18nutil_test_0700 ' + 'start');
178        let value = I18n.I18NUtil.unitConvert({unit: 'meter', measureSystem: 'SI'},
179                                        {unit: 'mile', measureSystem: 'SI'},
180                                        1000,
181                                        'zh-CN',
182                                        'long');
183        console.log('i18n_i18nutil_test_0700 ' + value);
184        expect(value).assertEqual('0.621英里');
185    })
186
187    /**
188    * @tc.number  SUB_GLOBAL_I18N_I18NUTIL_JS_0800
189    * @tc.name    test unitConvert interface from hour to second unit
190    * @tc.desc    get the unitConvert value
191    */
192    it('i18n_i18nutil_test_0800', 0, function () {
193        console.log('i18n_i18nutil_test_0800 ' + 'start');
194        let value = I18n.I18NUtil.unitConvert({unit: 'hour', measureSystem: 'SI'},
195                                        {unit: 'second', measureSystem: 'SI'},
196                                        10,
197                                        'zh-CN',
198                                        'medium');
199        console.log('i18n_i18nutil_test_0800 ' + value);
200        let devType = deviceInfo.devicType;
201        if (devType == '2in1'){
202            expect(value).assertEqual('36,000秒钟');
203        }else if (devType == 'phone'){
204            expect(value).assertEqual('36,000秒');
205        }
206    })
207
208    /**
209    * @tc.number  SUB_GLOBAL_I18N_I18NUTIL_JS_0900
210    * @tc.name    test unitConvert interface from celsius to fahrenheit unit
211    * @tc.desc    get the unitConvert value
212    */
213    it('i18n_i18nutil_test_0900', 0, function () {
214        console.log('i18n_i18nutil_test_0900 ' + 'start');
215        let value = I18n.I18NUtil.unitConvert({unit: 'celsius', measureSystem: 'SI'},
216                                        {unit: 'fahrenheit', measureSystem: 'SI'},
217                                        1000,
218                                        'zh-CN',
219                                        'short');
220        console.log('i18n_i18nutil_test_0900 ' + value);
221        expect(value).assertEqual('1,832°F');
222    })
223
224    /**
225    * @tc.number  SUB_GLOBAL_I18N_I18NUTIL_JS_1000
226    * @tc.name    test unitConvert interface from acre to hectare unit
227    * @tc.desc    get the unitConvert value
228    */
229    it('i18n_i18nutil_test_1000', 0, function () {
230        console.log('i18n_i18nutil_test_1000 ' + 'start');
231        let value = I18n.I18NUtil.unitConvert({unit: 'acre', measureSystem: 'SI'},
232                                        {unit: 'hectare', measureSystem: 'SI'},
233                                        1000,
234                                        'zh-CN',
235                                        'long');
236        console.log('i18n_i18nutil_test_1000 ' + value);
237        expect(value).assertEqual('404.686公顷');
238    })
239
240    /**
241    * @tc.number  SUB_GLOBAL_I18N_I18NUTIL_JS_1100
242    * @tc.name    test unitConvert interface from acre to square-meter unit
243    * @tc.desc    get the unitConvert value
244    */
245    it('i18n_i18nutil_test_1100', 0, function () {
246        console.log('i18n_i18nutil_test_1100 ' + 'start');
247        let value = I18n.I18NUtil.unitConvert({unit: 'acre', measureSystem: 'SI'},
248                                        {unit: 'square-meter', measureSystem: 'SI'},
249                                        1000,
250                                        'zh-CN',
251                                        'long');
252        console.log('i18n_i18nutil_test_1100 ' + value);
253        expect(value).assertEqual('4,046,856.422平方米');
254    })
255
256    /**
257    * @tc.number  SUB_GLOBAL_I18N_I18NUTIL_JS_1200
258    * @tc.name    test unitConvert interface from kilometer-per-hour to knot unit
259    * @tc.desc    get the unitConvert value
260    */
261    it('i18n_i18nutil_test_1200', 0, function () {
262        console.log('i18n_i18nutil_test_1200 ' + 'start');
263        let value = I18n.I18NUtil.unitConvert({unit: 'kilometer-per-hour', measureSystem: 'SI'},
264                                        {unit: 'knot', measureSystem: 'SI'},
265                                        1000,
266                                        'zh-CN',
267                                        'long');
268        console.log('i18n_i18nutil_test_1200 ' + value);
269        expect(value).assertEqual('539.957节');
270    })
271
272    /**
273    * @tc.number  SUB_GLOBAL_I18N_I18NUTIL_JS_1300
274    * @tc.name    test unitConvert interface from kilometer-per-hour to meter-per-second unit
275    * @tc.desc    get the unitConvert value
276    */
277    it('i18n_i18nutil_test_1300', 0, function () {
278        console.log('i18n_i18nutil_test_1300 ' + 'start');
279        let value = I18n.I18NUtil.unitConvert({unit: 'kilometer-per-hour', measureSystem: 'SI'},
280                                        {unit: 'meter-per-second', measureSystem: 'SI'},
281                                        1000,
282                                        'zh-CN',
283                                        'long');
284        console.log('i18n_i18nutil_test_1300 ' + value);
285        expect(value).assertEqual('每秒277.778米');
286    })
287
288    /**
289    * @tc.number  SUB_GLOBAL_I18N_I18NUTIL_JS_1400
290    * @tc.name    test unitConvert interface from meter to kilometer unit
291    * @tc.desc    get the unitConvert value
292    */
293    it('i18n_i18nutil_test_1400', 0, function () {
294        console.log('i18n_i18nutil_test_1400 ' + 'start');
295        let value = I18n.I18NUtil.unitConvert({unit: 'meter', measureSystem: 'SI'},
296                                        {unit: 'kilometer', measureSystem: 'SI'},
297                                        1000,
298                                        'zh-CN',
299                                        'long');
300        console.log('i18n_i18nutil_test_1400 ' + value);
301        expect(value).assertEqual('1公里');
302    })
303
304    /**
305    * @tc.number  SUB_GLOBAL_I18N_I18NUTIL_JS_1500
306    * @tc.name    test unitConvert interface from meter to meter-per-second unit
307    * @tc.desc    get the unitConvert value
308    */
309    it('i18n_i18nutil_test_1500', 0, function () {
310        console.log('i18n_i18nutil_test_1500 ' + 'start');
311        let value = I18n.I18NUtil.unitConvert({unit: 'meter', measureSystem: 'SI'},
312                                        {unit: 'meter-per-second', measureSystem: 'SI'},
313                                        1000,
314                                        'zh-CN',
315                                        'long');
316        console.log('i18n_i18nutil_test_1500 ' + value);
317        expect(value).assertEqual('1,000米');
318    })
319
320    /* *
321    * @tc.number  SUB_GLOBAL_I18N_I18NUTIL_JS_1600
322    * @tc.name    test getDateOrder method with zh param
323    * @tc.desc    get the DateOrder value
324    */
325    it('i18n_i18nutil_test_1600', 0, function () {
326        console.log('i18n_i18nutil_test_1600 ' + 'start');
327        let value = I18n.I18NUtil.getDateOrder('zh');
328        console.log('i18n_i18nutil_test_1600 ' + value);
329        expect(value).assertEqual('y-L-d');
330    })
331
332    /* *
333    * @tc.number  SUB_GLOBAL_I18N_I18NUTIL_JS_1700
334    * @tc.name    test getDateOrder method with en param
335    * @tc.desc    get the DateOrder value
336    */
337    it('i18n_i18nutil_test_1700', 0, function () {
338        console.log('i18n_i18nutil_test_1700 ' + 'start');
339        let value = I18n.I18NUtil.getDateOrder('en');
340        console.log('i18n_i18nutil_test_1700 ' + value);
341        expect(value).assertEqual('LLL-d-y');
342    })
343
344    /* *
345    * @tc.number  SUB_GLOBAL_I18N_I18NUTIL_JS_1800
346    * @tc.name    test getDateOrder method with th param
347    * @tc.desc    get the DateOrder value
348    */
349    it('i18n_i18nutil_test_1800', 0, function () {
350        console.log('i18n_i18nutil_test_1800 ' + 'start');
351        let value = I18n.I18NUtil.getDateOrder('th');
352        console.log('i18n_i18nutil_test_1800 ' + value);
353        expect(value).assertEqual('d-LLL-y');
354    })
355
356    /* *
357    * @tc.number  SUB_GLOBAL_I18N_I18NUTIL_JS_1900
358    * @tc.name    test getDateOrder method with jp param
359    * @tc.desc    get the DateOrder value
360    */
361    it('i18n_i18nutil_test_1900', 0, function () {
362        console.log('i18n_i18nutil_test_1900 ' + 'start');
363        let value = I18n.I18NUtil.getDateOrder('ja');
364        console.log('i18n_i18nutil_test_1900 ' + value);
365        expect(value).assertEqual('y-LL-dd');
366    })
367
368    console.log('*************end I18nUtilInI18nTest*************');
369})}
370