• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2022 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 */
15
16import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium';
17import systemDateTime from "@ohos.systemDateTime";
18
19export default function systemDateTimeJsunit() {
20  describe('systemDateTimeTest', function () {
21    console.info('====>---------------systemDateTimeTest start-----------------------');
22
23    /**
24     * @tc.number    SUB_systemDateTime_getCurrentTime_JS_API_0001
25     * @tc.name      Test systemTimeDate.getCurrentTime
26     * @tc.desc      Obtains the number of milliseconds that have elapsed since the Unix epoch.
27     * @tc.size      : MEDIUM
28     * @tc.type      : Function
29     * @tc.level     : Level 1
30     */
31    it("SUB_systemDateTime_getCurrentTime_JS_API_0001", 0, async function (done) {
32      console.info("====>----------SUB_systemDateTime_getCurrentTime_JS_API_0001 start----------------");
33      systemDateTime.getCurrentTime(true, (error, data) => {
34        try {
35          if (error) {
36            console.error('====>SUB_systemDateTime_getCurrentTime_JS_API_0001 fail: ' + JSON.stringify(error));
37            expect().assertFail();
38            done();
39          };
40          console.info('====>systemDateTime.getCurrentTime success data : ' + JSON.stringify(data));
41          expect(data != null).assertEqual(true);
42          done();
43        } catch (error) {
44          console.error('====>SUB_systemDateTime_getCurrentTime_JS_API_0001 catch error: ' + JSON.stringify(error));
45          done();
46        }
47        console.info("====>----------SUB_systemDateTime_getCurrentTime_JS_API_0001 end-----------------");
48      });
49    });
50
51    /**
52     * @tc.number    SUB_systemDateTime_getCurrentTime_JS_API_0002
53     * @tc.name      Test systemTimeDate.getCurrentTime
54     * @tc.desc      Obtains the number of milliseconds that have elapsed since the Unix epoch.
55     * @tc.size      : MEDIUM
56     * @tc.type      : Function
57     * @tc.level     : Level 1
58     */
59    it("SUB_systemDateTime_getCurrentTime_JS_API_0002", 0, async function (done) {
60      console.info("====>-----SUB_systemDateTime_getCurrentTime_JS_API_0002 start----------------");
61      await systemDateTime.getCurrentTime(false).then((data) => {
62        console.info('====>SUB_systemDateTime_getCurrentTime_JS_API_0002 success data : ' + JSON.stringify(data));
63        expect(data != null).assertEqual(true);
64        done();
65      }).catch(err => {
66        console.error('====>SUB_systemDateTime_getCurrentTime_JS_API_0002 fail: ' + JSON.stringify(err));
67        expect().assertFail();
68        done();
69      });
70      console.info("====>-----SUB_systemDateTime_getCurrentTime_JS_API_0002 end------------");
71    });
72
73    /**
74     * @tc.number    SUB_systemDateTime_getCurrentTime_JS_API_0003
75     * @tc.name      Test systemTimeDate.getCurrentTime
76     * @tc.desc      Obtains the number of milliseconds that have elapsed since the Unix epoch.
77     * @tc.size      : MEDIUM
78     * @tc.type      : Function
79     * @tc.level     : Level 1
80     */
81    it("SUB_systemDateTime_getCurrentTime_JS_API_0003", 0, async function (done) {
82      console.info("====>-----SUB_systemDateTime_getCurrentTime_JS_API_0003 start----------------");
83      await systemDateTime.getCurrentTime().then((data) => {
84        console.info('====>SUB_systemDateTime_getCurrentTime_JS_API_0003 success data : ' + JSON.stringify(data));
85        expect(data != null).assertEqual(true);
86        done();
87      }).catch(err => {
88        console.error('====>SUB_systemDateTime_getCurrentTime_JS_API_0003 fail: ' + JSON.stringify(err));
89        expect().assertFail();
90        done();
91      });
92      console.info("====>-----SUB_systemDateTime_getCurrentTime_JS_API_0003 end------------");
93    });
94
95    /**
96     * @tc.number    SUB_systemDateTime_getCurrentTime_JS_API_0004
97     * @tc.name      Test systemTimeDate.getCurrentTime
98     * @tc.desc      Obtains the number of milliseconds that have elapsed since the Unix epoch.
99     * @tc.size      : MEDIUM
100     * @tc.type      : Function
101     * @tc.level     : Level 1
102     */
103    it("SUB_systemDateTime_getCurrentTime_JS_API_0004", 0, async function (done) {
104      console.info("====>----------SUB_systemDateTime_getCurrentTime_JS_API_0004 start----------------");
105      systemDateTime.getCurrentTime((error, data) => {
106        try {
107          if (error) {
108            console.error('====>SUB_systemDateTime_getCurrentTime_JS_API_0004 fail: ' + JSON.stringify(error));
109            expect().assertFail();
110            done();
111          };
112          console.info('====>systemDateTime.getCurrentTime success data : ' + JSON.stringify(data));
113          expect(data != null).assertEqual(true);
114          done();
115        } catch (error) {
116          console.error('====>SUB_systemDateTime_getCurrentTime_JS_API_0004 catch error: ' + JSON.stringify(error));
117          done();
118        }
119        console.info("====>----------SUB_systemDateTime_getCurrentTime_JS_API_0004 end-----------------");
120      });
121    });
122
123    /**
124     * @tc.number    SUB_systemDateTime_getRealActiveTime_JS_API_0001
125     * @tc.name      Test systemTimeDate.getCurrentTime
126     * @tc.desc      Obtains the number of milliseconds elapsed since the system was booted, not including deep sleep time.
127     * @tc.size      : MEDIUM
128     * @tc.type      : Function
129     * @tc.level     : Level 1
130     */
131    it("SUB_systemDateTime_getRealActiveTime_JS_API_0001", 0, async function (done) {
132      console.info("====>----------SUB_systemDateTime_getRealActiveTime_JS_API_0001 start----------------");
133      systemDateTime.getRealActiveTime(true, (error, data) => {
134        try {
135          if (error) {
136            console.error('====>SUB_systemDateTime_getRealActiveTime_JS_API_0001 fail: ' + JSON.stringify(error));
137            expect().assertFail();
138            done();
139          };
140          console.info('====>SUB_systemDateTime_getRealActiveTime_JS_API_0001 success data : ' + JSON.stringify(data));
141          expect(data != null).assertEqual(true);
142          done();
143        } catch (error) {
144          console.error('====>SUB_systemDateTime_getRealActiveTime_JS_API_0001 catch err: ' + JSON.stringify(error));
145          done();
146        }
147        console.info("====>----------SUB_systemDateTime_getRealActiveTime_JS_API_0001 end-----------------");
148      });
149    });
150
151    /**
152     * @tc.number    SUB_systemDateTime_getRealActiveTime_JS_API_0002
153     * @tc.name      Test systemTimeDate.getCurrentTime
154     * @tc.desc      Obtains the number of milliseconds elapsed since the system was booted, not including deep sleep time.
155     * @tc.size      : MEDIUM
156     * @tc.type      : Function
157     * @tc.level     : Level 1
158     */
159    it("SUB_systemDateTime_getRealActiveTime_JS_API_0002", 0, async function (done) {
160      console.info("====>-----SUB_systemDateTime_getRealActiveTime_JS_API_0002 start----------------");
161      await systemDateTime.getRealActiveTime(false).then((data) => {
162        console.log('SUB_systemDateTime_getRealActiveTime_JS_API_0002 success data : ' + JSON.stringify(data));
163        expect(data != null).assertEqual(true);
164        done();
165      }).catch(err => {
166        console.error('====>SUB_systemDateTime_getRealActiveTime_JS_API_0002 err: ' + JSON.stringify(err));
167        expect().assertFail();
168        done();
169      });
170      console.info("====>-----SUB_systemDateTime_getRealActiveTime_JS_API_0002 end------------");
171    });
172
173    /**
174     * @tc.number    SUB_systemDateTime_getRealActiveTime_JS_API_0003
175     * @tc.name      Test systemTimeDate.getCurrentTime
176     * @tc.desc      Obtains the number of milliseconds elapsed since the system was booted, not including deep sleep time.
177     * @tc.size      : MEDIUM
178     * @tc.type      : Function
179     * @tc.level     : Level 1
180     */
181    it("SUB_systemDateTime_getRealActiveTime_JS_API_0003", 0, async function (done) {
182      console.info("====>-----SUB_systemDateTime_getRealActiveTime_JS_API_0003 start----------------");
183      await systemDateTime.getRealActiveTime().then((data) => {
184        console.log('SUB_systemDateTime_getRealActiveTime_JS_API_0003 success data : ' + JSON.stringify(data));
185        expect(data != null).assertEqual(true);
186        done();
187      }).catch(err => {
188        console.error('====>SUB_systemDateTime_getRealActiveTime_JS_API_0003 err: ' + JSON.stringify(err));
189        expect().assertFail();
190        done();
191      });
192      console.info("====>-----SUB_systemDateTime_getRealActiveTime_JS_API_0003 end------------");
193    });
194
195    /**
196     * @tc.number    SUB_systemDateTime_getRealActiveTime_JS_API_0004
197     * @tc.name      Test systemTimeDate.getCurrentTime
198     * @tc.desc      Obtains the number of milliseconds elapsed since the system was booted, not including deep sleep time.
199     * @tc.size      : MEDIUM
200     * @tc.type      : Function
201     * @tc.level     : Level 1
202     */
203    it("SUB_systemDateTime_getRealActiveTime_JS_API_0004", 0, async function (done) {
204      console.info("====>----------SUB_systemDateTime_getRealActiveTime_JS_API_0004 start----------------");
205      systemDateTime.getRealActiveTime((error, data) => {
206        try {
207          if (error) {
208            console.error('====>SUB_systemDateTime_getRealActiveTime_JS_API_0004 fail: ' + JSON.stringify(error));
209            expect().assertFail();
210            done();
211          };
212          console.info('====>SUB_systemDateTime_getRealActiveTime_JS_API_0004 success data : ' + JSON.stringify(data));
213          expect(data != null).assertEqual(true);
214          done();
215        } catch (error) {
216          console.error('====>SUB_systemDateTime_getRealActiveTime_JS_API_0004 catch err: ' + JSON.stringify(error));
217          done();
218        }
219        console.info("====>----------SUB_systemDateTime_getRealActiveTime_JS_API_0004 end-----------------");
220      });
221    });
222
223    /**
224     * @tc.number    SUB_systemDateTime_getRealTime_JS_API_0001
225     * @tc.name      Test systemTimeDate.getCurrentTime
226     * @tc.desc      Obtains the number of milliseconds elapsed since the system was booted, including deep sleep time.
227     * @tc.size      : MEDIUM
228     * @tc.type      : Function
229     * @tc.level     : Level 1
230     */
231    it("SUB_systemDateTime_getRealTime_JS_API_0001", 0, async function (done) {
232      console.info("====>----------SUB_systemDateTime_getRealTime_JS_API_0001 start----------------");
233      systemDateTime.getRealTime(true, (error, data) => {
234        try {
235          if (error) {
236            console.error('SUB_systemDateTime_getRealTime_JS_API_0001 fail: ' + JSON.stringify(error));
237            expect().assertFail();
238            done();
239          };
240          console.info('====>SUB_systemDateTime_getRealTime_JS_API_0001 success data : ' + JSON.stringify(data));
241          expect(data != null).assertEqual(true);
242          done();
243        } catch (error) {
244          console.error('====>SUB_systemDateTime_getRealTime_JS_API_0001 catch err: ' + JSON.stringify(error));
245          done();
246        }
247        console.info("====>----------SUB_systemDateTime_getRealTime_JS_API_0001 end-----------------");
248      });
249    });
250
251    /**
252     * @tc.number    SUB_systemDateTime_getRealTime_JS_API_0002
253     * @tc.name      Test systemTimeDate.getCurrentTime
254     * @tc.desc      Obtains the number of milliseconds elapsed since the system was booted, not including deep sleep time.
255     * @tc.size      : MEDIUM
256     * @tc.type      : Function
257     * @tc.level     : Level 1
258     */
259    it("SUB_systemDateTime_getRealTime_JS_API_0002", 0, async function (done) {
260      console.info("====>-----SUB_systemDateTime_getRealTime_JS_API_0002 start----------------");
261      await systemDateTime.getRealTime(false).then((data) => {
262        console.info('====>SUB_systemDateTime_getRealTime_JS_API_0002 success data : ' + JSON.stringify(data));
263        expect(data != null).assertEqual(true);
264        done();
265      }).catch(error => {
266        console.error('====>SUB_systemDateTime_getRealTime_JS_API_0002 err: ' + JSON.stringify(error));
267        expect().assertFail();
268        done();
269      });
270      console.info("====>-----SUB_systemDateTime_getRealTime_JS_API_0002 end------------");
271    });
272
273    /**
274     * @tc.number    SUB_systemDateTime_getRealTime_JS_API_0003
275     * @tc.name      Test systemTimeDate.getCurrentTime
276     * @tc.desc      Obtains the number of milliseconds elapsed since the system was booted, not including deep sleep time.
277     * @tc.size      : MEDIUM
278     * @tc.type      : Function
279     * @tc.level     : Level 1
280     */
281    it("SUB_systemDateTime_getRealTime_JS_API_0003", 0, async function (done) {
282      console.info("====>-----SUB_systemDateTime_getRealTime_JS_API_0003 start----------------");
283      await systemDateTime.getRealTime().then((data) => {
284        console.info('====>SUB_systemDateTime_getRealTime_JS_API_0003 success data : ' + JSON.stringify(data));
285        expect(data != null).assertEqual(true);
286        done();
287      }).catch(error => {
288        console.error('====>SUB_systemDateTime_getRealTime_JS_API_0003 err: ' + JSON.stringify(error));
289        expect().assertFail();
290        done();
291      });
292      console.info("====>-----SUB_systemDateTime_getRealTime_JS_API_0003 end------------");
293    });
294
295    /**
296     * @tc.number    SUB_systemDateTime_getRealTime_JS_API_0004
297     * @tc.name      Test systemTimeDate.getCurrentTime
298     * @tc.desc      Obtains the number of milliseconds elapsed since the system was booted, including deep sleep time.
299     * @tc.size      : MEDIUM
300     * @tc.type      : Function
301     * @tc.level     : Level 1
302     */
303    it("SUB_systemDateTime_getRealTime_JS_API_0004", 0, async function (done) {
304      console.info("====>----------SUB_systemDateTime_getRealTime_JS_API_0004 start----------------");
305      systemDateTime.getRealTime((error, data) => {
306        try {
307          if (error) {
308            console.error('SUB_systemDateTime_getRealTime_JS_API_0004 fail: ' + JSON.stringify(error));
309            expect().assertFail();
310            done();
311          };
312          console.info('====>SUB_systemDateTime_getRealTime_JS_API_0004 success data : ' + JSON.stringify(data));
313          expect(data != null).assertEqual(true);
314          done();
315        } catch (error) {
316          console.error('====>SUB_systemDateTime_getRealTime_JS_API_0004 catch err: ' + JSON.stringify(error));
317          done();
318        }
319        console.info("====>----------SUB_systemDateTime_getRealTime_JS_API_0004 end-----------------");
320      });
321    });
322
323    /**
324     * @tc.number    SUB_systemDateTime_getDate_JS_API_0100
325     * @tc.name      Test systemTimeDate.setDate true value
326     * @tc.desc      Test systemTimeDate_setDate API functionality.
327     * @tc.size      : MEDIUM
328     * @tc.type      : Function
329     * @tc.level     : Level 0
330     */
331    it('SUB_systemDateTime_getDate_JS_API_0100', 0, async function (done) {
332      console.info("====>SUB_systemDateTime_getDate_JS_API_0100 start");
333      await systemDateTime.getDate().then((data) => {
334        console.info("====>SUB_systemDateTime_getDate_JS_API_0100 getDate: " + data);
335        expect(data != null).assertTrue();
336        done();
337      }).catch(error => {
338        console.info("====>SUB_systemDateTime_getDate_JS_API_0100 getDate fail: " + error);
339        expect().assertFail();
340        done();
341      })
342      console.info("====>SUB_systemDateTime_getDate_JS_API_0100 end");
343
344    });
345
346    /**
347     * @tc.number    SUB_systemDateTime_getDate_JS_API_0200
348     * @tc.name      Test systemTimeDate.setDate true value
349     * @tc.desc      Test systemTimeDate_setDate API functionality.
350     * @tc.size      : MEDIUM
351     * @tc.type      : Function
352     * @tc.level     : Level 0
353     */
354    it('SUB_systemDateTime_getDate_JS_API_0200', 0, async function (done) {
355      console.info("====>SUB_systemDateTime_getDate_JS_API_0200 start");
356      systemDateTime.getDate((err, data) => {
357        try{
358          if(err){
359            console.info("====>SUB_systemDateTime_getDate_JS_API_0200 getTimezone fail: " + err);
360            expect().assertFail();
361            done();
362          }
363          console.info("====>SUB_systemDateTime_getDate_JS_API_0200 getTimezone success: " + data);
364          expect(data != null).assertTrue();
365          done();
366        }catch(error){
367          console.info("====>SUB_systemDateTime_getDate_JS_API_0200 catch error " + error);
368          done();
369        }
370      })
371      console.info("====>SUB_systemDateTime_getDate_JS_API_0200 end");
372    });
373
374
375    /**
376     * @tc.number    SUB_systemDateTime_getTimezone_JS_API_0100
377     * @tc.name      Test systemTime.SUB_systemDateTime_getTimezone_JS_API_0100 true value
378     * @tc.desc      Test systemTimeDate_setTimezone API functionality.
379     * @tc.size      : MEDIUM
380     * @tc.type      : Function
381     * @tc.level     : Level 0
382     */
383    it('SUB_systemDateTime_getTimezone_JS_API_0100', 0, async function (done) {
384      console.info("====>SUB_systemDateTime_getTimezone_JS_API_0100 start");
385      await systemDateTime.getTimezone().then( data => {
386        console.info("====>SUB_systemDateTime_getTimezone_JS_API_0100 getTimezone success: " + data);
387        expect(data != null).assertTrue();
388        done();
389      }).catch(error => {
390        console.info("====>SUB_systemDateTime_getTimezone_JS_API_0100 getTimezone fail: " + error);
391        expect().assertFail();
392        done();
393      });
394      console.info("====>SUB_systemDateTime_getTimezone_JS_API_0100 end");
395    });
396
397    /**
398     * @tc.number    SUB_systemDateTime_getTimezone_JS_API_0200
399     * @tc.name      Test systemTimeDate.setTimezone true value
400     * @tc.desc      Test systemTimeDate_setTimezone API functionality.
401     * @tc.size      : MEDIUM
402     * @tc.type      : Function
403     * @tc.level     : Level 0
404     */
405    it('SUB_systemDateTime_getTimezone_JS_API_0200', 0, async function (done) {
406      console.info("====>SUB_systemDateTime_getTimezone_JS_API_0200 start");
407      systemDateTime.getTimezone((err, data) => {
408        try{
409          if(err){
410            console.info("====>SUB_systemDateTime_getTimezone_JS_API_0200 getTimezone fail: " + err);
411            expect().assertFail();
412            done();
413          }
414          console.info("====>SUB_systemDateTime_getTimezone_JS_API_0200 getTimezone success: " + data);
415          expect(data != null).assertTrue();
416          done();
417        }catch(error){
418          console.info("====>SUB_systemDateTime_getTimezone_JS_API_0200 catch error " + error);
419          done();
420        }
421      })
422      console.info("====>SUB_systemDateTime_getTimezone_JS_API_0200 end");
423    });
424
425  });
426};
427