display.test.js 6.7 KB
Newer Older
1
/*
2
 * Copyright (C) 2022 Huawei Device Co., Ltd.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
 * 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 app from '@system.app'
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'
import display from '@ohos.display'

describe('display_test', function () {

    beforeAll(function () {
    })
    beforeEach(function () {
    })
    afterEach(function () {
    })
    afterAll(function () {
    })

    /**
     * @tc.number		SUB_WMS_GETDEFALUTDISPLAY_JSAPI_001
     * @tc.name			Test getDefaultDisplay_Test_001
     * @tc.desc			To test the function of obtaining the default screen
     */
    it('getDefaultDisplay_Test_001', 0, async function (done) {
36
        console.log('displayTest getDefaultDisplayTest1 begin');
37
        display.getDefaultDisplay().then(dsp => {
38
            console.log('displayTest getDefaultDisplayTest1 getDefaultDisplay id :' + JSON.stringify(dsp));
39 40 41 42
            expect(dsp.id != null).assertTrue();
            expect(dsp.refreshRate != null).assertTrue();
            expect(dsp.width != null).assertTrue();
            expect(dsp.height != null).assertTrue();
H
hk_js 已提交
43 44 45 46 47 48 49 50 51
            expect(dsp.rotation != null).assertTrue();
            expect(dsp.densityDPI != null).assertTrue();
            expect(dsp.name != null).assertTrue();
            expect(dsp.alive != null).assertTrue();
            expect(dsp.state != null).assertTrue();
            expect(dsp.densityPixels != null).assertTrue();
            expect(dsp.scaledDensity != null).assertTrue();
            expect(dsp.xDPI != null).assertTrue();
            expect(dsp.yDPI != null).assertTrue();
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
            done();
        }, (err) => {
            console.log('displayTest getDefaultDisplayTest1 getDefaultDisplay failed, err :' + JSON.stringify(err));
            expect().assertFail();
            done();
        })
    })

    /**
     * @tc.number    SUB_WMS_GETDEFALUTDISPLAY_JSAPI_001
     * @tc.name      Test getDefaultDisplay_Test_002.
     * @tc.desc      To test the function if obtaining the default screen.
     */
    it('getDefaultDisplay_Test_002', 0, async function (done) {
        console.log('displayTest getDefaultDisplayTest2 begin');
        display.getDefaultDisplay((err, data) => {
            if (err.code != 0) {
                console.log('displayTest getDefaultDisplayTest2 getDefaultDisplay callback fail' + JSON.stringify(err.code));
                expect().assertFail();
                done();
            } else {
                console.log('displayTest getDefaultDisplayTest2 getDefaultDisplay id :' + JSON.stringify(data));
                expect(data.id != null).assertTrue();
                expect(data.refreshRate != null).assertTrue();
                expect(data.width != null).assertTrue();
                expect(data.height != null).assertTrue();
H
hk_js 已提交
78 79 80 81 82 83 84 85 86
                expect(data.rotation != null).assertTrue();
                expect(data.densityDPI != null).assertTrue();
                expect(data.name != null).assertTrue();
                expect(data.alive != null).assertTrue();
                expect(data.state != null).assertTrue();
                expect(data.densityPixels != null).assertTrue();
                expect(data.scaledDensity != null).assertTrue();
                expect(data.xDPI != null).assertTrue();
                expect(data.yDPI != null).assertTrue();
87 88 89 90 91 92 93 94 95 96 97
                done();
            }
        })
    })

    /**
     * @tc.number		SUB_WMS_GETALLDISPLAY_JSAPI_001
     * @tc.name			Test getAllDisplay_Test_001.
     * @tc.desc			To verify the function of obtaining all screens.
     */
    it('getAllDisplay_Test_001', 0, async function (done) {
98
        console.log('displayTest getAllDisplayTest1 begin');
99
        display.getAllDisplay().then(dsp => {
100
            console.log('displayTest getAllDisplayTest1 getAllDisplay id :' + JSON.stringify(dsp));
101 102 103 104
            expect(dsp[0].id != null).assertTrue();
            expect(dsp[0].refreshRate != null).assertTrue();
            expect(dsp[0].width != null).assertTrue();
            expect(dsp[0].height != null).assertTrue();
H
hk_js 已提交
105 106 107 108 109 110 111 112 113
            expect(dsp[0].rotation != null).assertTrue();
            expect(dsp[0].densityDPI != null).assertTrue();
            expect(dsp[0].name != null).assertTrue();
            expect(dsp[0].alive != null).assertTrue();
            expect(dsp[0].state != null).assertTrue();
            expect(dsp[0].densityPixels != null).assertTrue();
            expect(dsp[0].scaledDensity != null).assertTrue();
            expect(dsp[0].xDPI != null).assertTrue();
            expect(dsp[0].yDPI != null).assertTrue();
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
            done();
        }, (err) => {
            console.log('displayTest getAllDisplayTest1 getAllDisplay failed, err :' + JSON.stringify(err));
            expect().assertFail();
            done();
        })
    })

    /**
     * @tc.number    SUB_WMS_GETALLDISPLAY_JSAPI_002
     * @tc.name      Test getAllDisplay_Test_002
     * @tc.desc      To test the function if obtaining the default screen
     */
    it('getAllDisplay_Test_002', 0, async function (done) {
        console.log('displayTest getAllDisplayTest2 begin');
        display.getAllDisplay((err, data) => {
            if (err.code != 0) {
131
                console.log('displayTest getAllDisplayTest2 getAllDisplay callback fail' + JSON.stringify(err));
132 133 134
                expect().assertFail();
                done();
            } else {
135
                console.log('displayTest getAllDisplayTest2 getAllDisplay id :' + JSON.stringify(data));
136 137 138
                expect(data[0].refreshRate != null).assertTrue();
                expect(data[0].width != null).assertTrue();
                expect(data[0].height != null).assertTrue();
H
hk_js 已提交
139 140 141 142 143 144 145 146 147
                expect(data[0].rotation != null).assertTrue();
                expect(data[0].densityDPI != null).assertTrue();
                expect(data[0].name != null).assertTrue();
                expect(data[0].alive != null).assertTrue();
                expect(data[0].state != null).assertTrue();
                expect(data[0].densityPixels != null).assertTrue();
                expect(data[0].scaledDensity != null).assertTrue();
                expect(data[0].xDPI != null).assertTrue();
                expect(data[0].yDPI != null).assertTrue();
148 149 150 151 152 153
                done();
            }
        })
    })

})