• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (C) 2024 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 app from '@system.app'
16import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium'
17import window from '@ohos.window'
18import display from '@ohos.display'
19import hdrCapability from '@ohos.graphics.hdrCapability'
20
21export default function display_test() {
22describe('display_test', function () {
23
24    beforeAll(function () {
25    })
26    beforeEach(function () {
27    })
28    afterEach(function () {
29    })
30    afterAll(function () {
31    })
32
33    /**
34     * @tc.number		SUB_BASIC_WMS_SPCIAL_XTS_STANDARD_JS_API_0260
35     * @tc.name			testGetDefaultDisplay_Function_Promise
36     * @tc.desc			To test the function of obtaining the default screen
37     */
38    it('testGetDefaultDisplay_Function_Promise', 0, async function (done) {
39        console.log('displayTest testGetDefaultDisplay_Function_Promise begin');
40        display.getDefaultDisplay().then(dsp => {
41            console.log('displayTest getDefaultDisplayTest1 getDefaultDisplay id :' + JSON.stringify(dsp));
42            expect(dsp.id != null).assertTrue();
43            expect(dsp.refreshRate != null).assertTrue();
44            expect(dsp.width != null).assertTrue();
45            expect(dsp.height != null).assertTrue();
46            expect(dsp.rotation != null).assertTrue();
47            expect(dsp.densityDPI != null).assertTrue();
48            expect(dsp.name != null).assertTrue();
49            expect(dsp.alive).assertTrue();
50            expect(dsp.state != null).assertTrue();
51            expect(dsp.densityPixels != null).assertTrue();
52            expect(dsp.scaledDensity !=null).assertTrue();
53            expect(dsp.xDPI != null).assertTrue();
54            expect(dsp.yDPI != null).assertTrue();
55            expect(dsp.hdrFormats != null).assertTrue();
56            console.log('www data hdrFormats : ' + JSON.stringify(dsp.hdrFormats))
57            console.log('www data colorSpaces : ' + JSON.stringify(dsp.colorSpaces))
58            done();
59        }, (err) => {
60            console.log('displayTest getDefaultDisplayTest1 getDefaultDisplay failed, err :' + JSON.stringify(err));
61            expect().assertFail();
62            done();
63        })
64    })
65
66    /**
67     * @tc.number    SUB_BASIC_WMS_SPCIAL_XTS_STANDARD_JS_API_0250
68     * @tc.name      testGetDefaultDisplay_Function_Callback
69     * @tc.desc      To test the function if obtaining the default screen.
70     */
71    it('testGetDefaultDisplay_Function_Callback', 0, async function (done) {
72        console.log('displayTest testGetDefaultDisplay_Function_Callback begin');
73        display.getDefaultDisplay((err, data) => {
74            if (err.code != 0) {
75                console.log('displayTest getDefaultDisplayTest2 getDefaultDisplay callback fail' + JSON.stringify(err.code));
76                expect().assertFail();
77                done();
78            } else {
79                console.log('displayTest getDefaultDisplayTest2 getDefaultDisplay id :' + JSON.stringify(data));
80                expect(data.id != null).assertTrue();
81                expect(data.refreshRate != null).assertTrue();
82                expect(data.width != null).assertTrue();
83                expect(data.height != null).assertTrue();
84                expect(data.rotation != null).assertTrue();
85                expect(data.densityDPI != null).assertTrue();
86                expect(data.name != null).assertTrue();
87                expect(data.alive).assertTrue();
88                expect(data.state != null).assertTrue();
89                expect(data.densityPixels != null).assertTrue();
90                expect(data.scaledDensity !=null).assertTrue();
91                expect(data.xDPI != null).assertTrue();
92                expect(data.yDPI != null).assertTrue();
93                done();
94            }
95        })
96    })
97
98    /**
99     * @tc.number		SUB_BASIC_WMS_SPCIAL_XTS_STANDARD_JS_API_0130
100     * @tc.name			testGetAllDisplay_Promise
101     * @tc.desc			To verify the function of obtaining all screens.
102     */
103    it('testGetAllDisplay_Promise', 0, async function (done) {
104        console.log('displayTest getAllDisplayTest1 begin');
105        display.getAllDisplay().then(dsp => {
106            console.log('displayTest getAllDisplayTest1 getAllDisplay id :' + JSON.stringify(dsp));
107            expect(dsp[0].id != null).assertTrue();
108            expect(dsp[0].refreshRate != null).assertTrue();
109            expect(dsp[0].width != null).assertTrue();
110            expect(dsp[0].height != null).assertTrue();
111            expect(dsp[0].rotation != null).assertTrue();
112            expect(dsp[0].densityDPI != null).assertTrue();
113            expect(dsp[0].name != null).assertTrue();
114            expect(dsp[0].alive).assertTrue();
115            expect(dsp[0].state != null).assertTrue();
116            expect(dsp[0].densityPixels != null).assertTrue();
117            expect(dsp[0].scaledDensity !=null).assertTrue();
118            expect(dsp[0].xDPI != null).assertTrue();
119            expect(dsp[0].yDPI != null).assertTrue();
120            done();
121        }, (err) => {
122            console.log('displayTest getAllDisplayTest1 getAllDisplay failed, err :' + JSON.stringify(err));
123            expect().assertFail();
124            done();
125        })
126    })
127
128    /**
129     * @tc.number    SUB_BASIC_WMS_SPCIAL_XTS_STANDARD_JS_API_0120
130     * @tc.name      testGetAllDisplay_Callback
131     * @tc.desc      To test the function if obtaining the default screen
132     */
133    it('testGetAllDisplay_Callback', 0, async function (done) {
134        console.log('displayTest getAllDisplayTest2 begin');
135        display.getAllDisplay((err, data) => {
136            if (err.code != 0) {
137                console.log('displayTest getAllDisplayTest2 getAllDisplay callback fail' + JSON.stringify(err));
138                expect().assertFail();
139                done();
140            } else {
141                console.log('displayTest getAllDisplayTest2 getAllDisplay id :' + JSON.stringify(data));
142                expect(data[0].refreshRate != null).assertTrue();
143                expect(data[0].width != null).assertTrue();
144                expect(data[0].height != null).assertTrue();
145                expect(data[0].rotation != null).assertTrue();
146                expect(data[0].densityDPI != null).assertTrue();
147                expect(data[0].name != null).assertTrue();
148                expect(data[0].alive).assertTrue();
149                expect(data[0].state != null).assertTrue();
150                expect(data[0].densityPixels != null).assertTrue();
151                expect(data[0].scaledDensity !=null).assertTrue();
152                expect(data[0].xDPI != null).assertTrue();
153                expect(data[0].yDPI != null).assertTrue();
154                done();
155            }
156        })
157    })
158
159    /**
160     * @tc.number		SUB_BASIC_WMS_SPCIAL_XTS_STANDARD_JS_API_0240
161     * @tc.name			testGetDefaultDisplaySync_SyncFunction
162     * @tc.desc			To test the sync function of obtaining the default display
163     */
164    it('testGetDefaultDisplaySync_SyncFunction', 0, async function (done) {
165        console.info('displayTest getDefaultDisplaySyncTest1 begin');
166        try {
167            var dsp = display.getDefaultDisplaySync();
168            console.info('displayTest getDefaultDisplaySyncTest1: ' + JSON.stringify(dsp));
169            expect(dsp.id != null).assertTrue();
170            expect(dsp.refreshRate != null).assertTrue();
171            expect(dsp.width != null).assertTrue();
172            expect(dsp.height != null).assertTrue();
173            expect(dsp.rotation != null).assertTrue();
174            expect(dsp.densityDPI != null).assertTrue();
175            expect(dsp.name != null).assertTrue();
176            expect(dsp.alive).assertTrue();
177            expect(dsp.state != null).assertTrue();
178            expect(dsp.densityPixels != null).assertTrue();
179            expect(dsp.scaledDensity !=null).assertTrue();
180            expect(dsp.xDPI != null).assertTrue();
181            expect(dsp.yDPI != null).assertTrue();
182            done();
183        } catch (err) {
184            console.error('getDefaultDisplaySyncTest1 error ' + JSON.stringify(err));
185            expect.assertFail();
186            done();
187        }
188    })
189
190    /**
191     * @tc.number		SUB_BASIC_WMS_SPCIAL_XTS_STANDARD_JS_API_0240
192     * @tc.name			testGetDisplayByIdSync_SyncFunction
193     * @tc.desc			To test the sync function of obtaining the target display by id
194     */
195    it('testGetDisplayByIdSync_SyncFunction', 0, async function (done) {
196        console.info('displayTestGetDisplayByIdSyncTest1 begin');
197        try {
198            var displayId = display.getDefaultDisplaySync().id;
199            var dsp = display.getDisplayByIdSync(displayId);
200            console.info('displayTest getDisplayByIdSyncTest1: ' + JSON.stringify(dsp));
201            expect(dsp.id != null).assertTrue();
202            expect(dsp.refreshRate != null).assertTrue();
203            expect(dsp.width != null).assertTrue();
204            expect(dsp.height != null).assertTrue();
205            expect(dsp.rotation != null).assertTrue();
206            expect(dsp.densityDPI != null).assertTrue();
207            expect(dsp.name != null).assertTrue();
208            expect(dsp.alive).assertTrue();
209            expect(dsp.state != null).assertTrue();
210            expect(dsp.densityPixels != null).assertTrue();
211            expect(dsp.scaledDensity !=null).assertTrue();
212            expect(dsp.xDPI != null).assertTrue();
213            expect(dsp.yDPI != null).assertTrue();
214            done();
215        } catch (err) {
216            console.error('getDisplayByIdSyncTest1 error ' + JSON.stringify(err));
217            expect.assertFail();
218            done();
219        }
220    })
221
222    /**
223     * @tc.number	SUB_BASIC_WMS_SPCIAL_XTS_STANDARD_JS_API_0070
224     * @tc.name	    testDisplayState_Enum_Value
225     * @tc.desc		To test the enum value of WindowDisplayState.
226    */
227    it('testDisplayState_Enum_Value', 0, async function (done) {
228        console.info('test the enum value of Window DisplayState begin');
229        try {
230            expect(0).assertEqual(display.DisplayState.STATE_UNKNOWN);
231            expect(1).assertEqual(display.DisplayState.STATE_OFF);
232            expect(2).assertEqual(display.DisplayState.STATE_ON);
233            expect(3).assertEqual(display.DisplayState.STATE_DOZE);
234            expect(4).assertEqual(display.DisplayState.STATE_DOZE_SUSPEND);
235            expect(5).assertEqual(display.DisplayState.STATE_VR);
236            expect(6).assertEqual(display.DisplayState.STATE_ON_SUSPEND);
237            done();
238        } catch (err) {
239            console.error('test enum value of windowDisplayState error ' + JSON.stringify(err));
240            expect.assertFail();
241            done();
242        }
243    })
244
245    /**
246     * @tc.number	SUB_BASIC_WMS_SPCIAL_XTS_STANDARD_JS_API_1060
247     * @tc.name	    testWaterfallDisplayAreaRects_Value
248     * @tc.desc		To test value of waterfallDisplayAreaRects.
249    */
250    it('testWaterfallDisplayAreaRects_Value', 0, async function (done) {
251        console.info('test the  value of waterfallDisplayAreaRects begin');
252        try {
253            var waterfallDisplayAreaRects = {
254                left : {
255                    left:20,
256                    top:20,
257                    width:20,
258                    height:20
259                },
260                right : {
261                    left:800,
262                    top:0,
263                    width:600,
264                    height:600
265                },
266                top : {
267                    left:20,
268                    top:20,
269                    width:20,
270                    height:20
271                },
272                bottom : {
273                    left:20,
274                    top:20,
275                    width:600,
276                    height:600
277                },
278
279            }
280            expect(waterfallDisplayAreaRects.left != null).assertTrue();
281            expect(waterfallDisplayAreaRects.right != null).assertTrue();
282            expect(waterfallDisplayAreaRects.top != null).assertTrue();
283            expect(waterfallDisplayAreaRects.bottom != null).assertTrue();
284            done();
285        } catch (err) {
286            console.error('test value of waterfallDisplayAreaRects error ' + JSON.stringify(err));
287            expect.assertFail();
288            done();
289        }
290    })
291
292    /**
293    * @tc.number	SUB_BASIC_WMS_SPCIAL_XTS_STANDARD_JS_API_0060
294    * @tc.name	    testDisplayAreaRects_Value
295    * @tc.desc		To test value of RECT.
296    */
297    it('testDisplayAreaRects_Value', 0, async function (done) {
298        console.info('test the value of aRect begin');
299        try {
300            var rect = {
301                left : 20,
302                right : 40,
303                width : 100,
304                height : 200
305            }
306            expect(20).assertEqual(rect.left);
307            expect(40).assertEqual(rect.right);
308            expect(100).assertEqual(rect.width);
309            expect(200).assertEqual(rect.height);
310            done();
311        } catch (err) {
312            console.error('test value of rect error ' + JSON.stringify(err));
313            expect.assertFail();
314            done();
315        }
316    })
317
318    /**
319     * @tc.number	SUB_BASIC_WMS_SPCIAL_XTS_STANDARD_JS_API_0030
320     * @tc.name	    testCutoutInfo_WaterFailDisplayAreaRects_Value
321     * @tc.desc		To test value of CutoutInfo.
322    */
323    it('testCutoutInfo_WaterFailDisplayAreaRects_Value', 0, async function (done) {
324        console.info('test the CutoutInfo of aRect begin');
325        try {
326            var cutoutInfo = {
327                boudingRects : [{
328                                    left : 20,
329                                    right : 40,
330                                    width : 100,
331                                    height : 200
332                                }],
333                waterfallDisplayAreaRects : {
334                    left : {
335                        left:20,
336                        top:20,
337                        width:20,
338                        height:20
339                    },
340                    right : {
341                        left:800,
342                        top:0,
343                        width:600,
344                        height:600
345                    },
346                    top : {
347                        left:20,
348                        top:20,
349                        width:20,
350                        height:20
351                    },
352                    bottom : {
353                        left:20,
354                        top:20,
355                        width:600,
356                        height:600
357                    },
358                }
359            }
360            expect(1).assertEqual(cutoutInfo.boudingRects.length);
361            expect(cutoutInfo.waterfallDisplayAreaRects.left != null).assertTrue();
362            expect(cutoutInfo.waterfallDisplayAreaRects.right != null).assertTrue();
363            expect(cutoutInfo.waterfallDisplayAreaRects.top != null).assertTrue();
364            expect(cutoutInfo.waterfallDisplayAreaRects.bottom != null).assertTrue();
365            done();
366        } catch (err) {
367            console.error('test value of CutoutInfo error ' + JSON.stringify(err));
368            expect().assertFail();
369            done();
370        }
371    })
372
373    /**
374     * @tc.number		SUB_BASIC_WMS_SPCIAL_XTS_STANDARD_JS_API_0230
375     * @tc.name			testGetCutoutInfo_Function_Promise
376     * @tc.desc			To test the function of getCutoutInfo
377     */
378    it('testGetCutoutInfo_Function_Promise', 0, async function (done) {
379        console.info('getCutoutInfo begin');
380        display.getDefaultDisplay().then(dsp => {
381            console.info('displayTest getCutoutInfo getDefaultDisplay id :' + JSON.stringify(dsp));
382            expect(dsp != null).assertTrue();
383            dsp.getCutoutInfo((err, data) => {
384                console.info('Succeeded in getting cutoutInfo. data: ' + JSON.stringify(data));
385                if (err.code) {
386                    console.error('Failed to get cutoutInfo. Cause: ' + JSON.stringify(err));
387                    expect().assertFail();
388                    done();
389                } else {
390                    console.error('success to get cutoutInfo. Cause: ' + JSON.stringify(err));
391                    expect(data != null).assertTrue();
392                    done();
393                }
394            })
395        }, (err) => {
396            console.log('displayTest getgetCutoutInfo getDefaultDisplay failed, err :' + JSON.stringify(err));
397            expect().assertFail();
398            done();
399        })
400    })
401
402    /**
403     * @tc.number		SUB_BASIC_WMS_SPCIAL_XTS_STANDARD_JS_API_0220
404     * @tc.name			testGetCutoutInfo_Function_Callback
405     * @tc.desc			To test the function of getCutoutInfo
406    */
407    it('testGetCutoutInfo_Function_Callback', 0, async function (done) {
408        console.info('getCutoutInfo begin');
409        display.getDefaultDisplay().then(dsp => {
410            console.info('displayTest getCutoutInfo getDefaultDisplay id2 :' + JSON.stringify(dsp));
411            expect(dsp != null).assertTrue();
412            dsp.getCutoutInfo().then(data => {
413                console.info('Succeeded in getting cutoutInfo2. data: ' + JSON.stringify(data));
414                expect(data != null).assertTrue();
415                done();
416            } ,err => {
417                  console.log('displayTest getCutoutInfo getDefaultDisplay id2 failed, err :' + JSON.stringify(err));
418                  expect().assertFail();
419                  done();
420            })
421        }, (err) => {
422            console.log('displayTest getgetCutoutInfo getDefaultDisplay failed, err :' + JSON.stringify(err));
423            expect().assertFail();
424            done();
425        })
426    })
427
428    /**
429        * @tc.number		SUB_BASIC_WMS_SPCIAL_XTS_ORIENTATION_JS_API_0290
430        * @tc.name			testOrientation_attr
431        * @tc.desc			To test the attributes of Orientation
432    */
433    it('testOrientation_attr',0, async function (done){
434        let msg = "testOrientation_attr"
435        try {
436            expect(display.Orientation.PORTRAIT).assertEqual(0)
437            expect(display.Orientation.LANDSCAPE).assertEqual(1)
438            expect(display.Orientation.PORTRAIT_INVERTED).assertEqual(2)
439            expect(display.Orientation.LANDSCAPE_INVERTED).assertEqual(3)
440            done()
441        } catch (error) {
442            expect().assertFail()
443            done()
444        }
445    })
446
447   /**
448     * @tc.number    : SUB_BASIC_WMS_SPCIAL_XTS_STANDARD_JS_API_1190
449     * @tc.name      : testHdrFormats_attr
450     * @tc.desc      : test the enum value of hdrFormats
451     * @tc.size      : MediumTest
452     * @tc.type      : Function
453     * @tc.level     : Level4
454     */
455    it('testHdrFormats_attr',0, async function (done){
456        let msg = "testHdrFormats_attr"
457        try {
458            expect(hdrCapability.hdrFormats.NONE == 0).assertTrue();
459            expect(hdrCapability.hdrFormats.VIDEO_HLG == 1).assertTrue();
460            expect(hdrCapability.hdrFormats.VIDEO_HDR10 == 2).assertTrue();
461            expect(hdrCapability.hdrFormats.VIDEO_HDR_VIVID == 3).assertTrue();
462            expect(hdrCapability.hdrFormats.IMAGE_HDR_VIVID_DUAL == 4).assertTrue();
463            expect(hdrCapability.hdrFormats.IMAGE_HDR_VIVID_SINGLE == 5).assertTrue();
464            expect(hdrCapability.hdrFormats.IMAGE_HDR_ISO_DUAL == 6).assertTrue();
465            expect(hdrCapability.hdrFormats.IMAGE_HDR_ISO_SINGLE == 7).assertTrue();
466            done()
467        } catch (error) {
468            if (error.code) {
469                expect().assertFail()
470            } else {
471                expect(true).assertTrue()
472            }
473            done()
474        }
475    })
476
477})
478}
479