diff --git a/theme/screenlock_ets/entry/src/main/ets/test/screenLockTest.ets b/theme/screenlock_ets/entry/src/main/ets/test/screenLockTest.ets index ec78e724d12e46ae28b3fe12b8d995267911c319..b964df1a146599c72dd46f326f78633d12acf571 100755 --- a/theme/screenlock_ets/entry/src/main/ets/test/screenLockTest.ets +++ b/theme/screenlock_ets/entry/src/main/ets/test/screenLockTest.ets @@ -1,4 +1,3 @@ -// @ts-nocheck /* * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); @@ -295,15 +294,10 @@ export default function screenLockJSUnit() { console.info("------------------start SUB_MISC_THEME_screenLock_API_0009-------------------"); let flag = null; try{ - flag = await screenLock.onSystemEvent((err, data) => { + flag = await screenLock.onSystemEvent((data) => { console.info("SUB_MISC_THEME_screenLock_API_0009 screenLock.onSystemEvent start"); - if (err){ - console.info("SUB_MISC_THEME_screenLock_API_0009 screenLock.onSystemEvent err: " + JSON.stringify(err)); - expect().assertFalse(); - done(); - }; expect( data != null ).assertTrue(); - console.info("SUB_MISC_THEME_screenLock_API_0009 screenLock.onSystemEvent end" + data) + console.info("SUB_MISC_THEME_screenLock_API_0009 screenLock.onSystemEvent end" + data); done(); }); console.info("SUB_MISC_THEME_screenLock_API_0009 data: " + flag); @@ -315,5 +309,62 @@ export default function screenLockJSUnit() { console.info("-----------------end SUB_MISC_THEME_screenLock_API_0009--------------------"); done() }); + + + /* + * @tc.number SUB_MISC_THEME_screenLock_API_0010 + * @tc.name Test isLocked() to Checks whether the screen is currently locked. + * @tc.desc Function test + * @tc.level 0 + */ + it('SUB_MISC_THEME_screenLock_API_0010', 0, async function (done) { + console.info('------------------SUB_MISC_THEME_screenLock_API_0010 start----------------------'); + let lock = null; + try{ + lock = screenLock.isLocked() + console.info('SUB_MISC_THEME_screenLock_API_0010 data : ' + JSON.stringify(lock)); + if (typeof lock == "boolean") { + expect(true).assertTrue(); + done() + }else{ + expect().assertFail(); + done() + } + }catch(err){ + console.info('SUB_MISC_THEME_screenLock_API_0010 err : ' + JSON.stringify(err)); + expect().assertFail(); + done() + } + console.info('------------------SUB_MISC_THEME_screenLock_API_0010 end----------------------'); + done() + }); + + /* + * @tc.number SUB_MISC_THEME_screenLock_API_0011 + * @tc.name Test isSecure() to Checks whether the screen lock of the current device is secure. + * @tc.desc Function test + * @tc.level 0 + */ + it('SUB_MISC_THEME_screenLock_API_0011', 0, async function (done) { + console.info('------------------SUB_MISC_THEME_screenLock_API_0011 start----------------------'); + let secured = null; + try{ + secured = screenLock.isSecure() + console.info('SUB_MISC_THEME_screenLock_API_0011 data : ' + JSON.stringify(secured)); + if (typeof secured == "boolean") { + expect(true).assertTrue(); + done() + }else{ + expect().assertFail(); + done() + } + }catch(err){ + console.info('SUB_MISC_THEME_screenLock_API_0011 err : ' + JSON.stringify(err)); + expect().assertFail(); + done() + } + console.info('------------------SUB_MISC_THEME_screenLock_API_0011 end----------------------'); + done() + }); }); } diff --git a/theme/wallpaper_ets/Test.json b/theme/wallpaper_ets/Test.json index 59199b627c2face3823043b71d3b5248a1cda554..cb13254b42de66200083ff49ce7cc2dce29b3b5f 100755 --- a/theme/wallpaper_ets/Test.json +++ b/theme/wallpaper_ets/Test.json @@ -14,6 +14,15 @@ ], "type": "AppInstallKit", "cleanup-apps": true + }, + { + "type": "PushKit", + "pre-push": [ + "mount -o rw,remount /" + ], + "push": [ + "wp.png ->/system/etc/wp.png" + ] } ] } diff --git a/theme/wallpaper_ets/entry/src/main/ets/test/wallpaperTest.ets b/theme/wallpaper_ets/entry/src/main/ets/test/wallpaperTest.ets index a7a0faa44b1c0363159128a7f7e96de5eca7623e..073e7a82b18acb44b16d0abb99e4598a4259e3ec 100755 --- a/theme/wallpaper_ets/entry/src/main/ets/test/wallpaperTest.ets +++ b/theme/wallpaper_ets/entry/src/main/ets/test/wallpaperTest.ets @@ -1,4 +1,3 @@ -// @ts-nocheck /* * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,13 +12,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import wallpaper from '@ohos.wallpaper' -import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' +import wallpaper from '@ohos.wallpaper'; +import image from '@ohos.multimedia.image'; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index'; const WALLPAPER_SYSTEM = 0; const WALLPAPER_LOCKSCREEN = 1; -let imageSourceSystem = '/data/service/el1/public/wallpaper/0/system/wallpaper'; -let imageSourceLockscreen = '/data/service/el1/public/wallpaper/0/lockscreen/wallpaper_lock'; +let imageSourceSystem = '/system/etc/wp.png'; +let imageSourceLockscreen = '/system/etc/wp.png'; export default function wallpaperJSUnit() { describe('WallpaperJsunitTest', function () { @@ -76,10 +76,10 @@ export default function wallpaperJSUnit() { await wallpaper.getColors(WALLPAPER_SYSTEM, function (err, data) { let RgbaColor = { - red:data[0][0], - green:data[0][1], - blue:data[0][2], - alpha:data[0][3] + red: data[0][0], + green: data[0][1], + blue: data[0][2], + alpha: data[0][3] } console.info('wallpaperXTS ===> testGetColorsCallbackSystem err : ' + JSON.stringify(err)); console.info('wallpaperXTS ===> testGetColorsCallbackSystem data : ' + JSON.stringify(data)); @@ -90,7 +90,7 @@ export default function wallpaperJSUnit() { if (err) { expect(null).assertFail(); } - if ((data != undefined) && (data != null) && (data != '')) { + if ((data != undefined) && (data != null)) { expect(true).assertTrue(); } }) @@ -106,7 +106,7 @@ export default function wallpaperJSUnit() { it('testGetColorsPromiseSystem101', 0, async function (done) { await wallpaper.getColors(WALLPAPER_SYSTEM).then((data) => { console.info('wallpaperXTS ===> testGetColorsPromiseSystem data : ' + JSON.stringify(data)); - if ((data != undefined) && (data != null) && (data != '')) { + if ((data != undefined) && (data != null)) { expect(true).assertTrue(); } }).catch((err) => { @@ -131,7 +131,7 @@ export default function wallpaperJSUnit() { if (err) { expect(null).assertFail(); } - if ((data != undefined) && (data != null) && (data != '')) { + if ((data != undefined) && (data != null)) { expect(true).assertTrue(); } }) @@ -147,7 +147,7 @@ export default function wallpaperJSUnit() { it('testGetColorsPromiseLock102', 0, async function (done) { await wallpaper.getColors(WALLPAPER_LOCKSCREEN).then((data) => { console.info('wallpaperXTS ===> testGetColorsCallbackLock data : ' + JSON.stringify(data)); - if ((data != undefined) && (data != null) && (data != '')) { + if ((data != undefined) && (data != null)) { expect(true).assertTrue(); } }).catch((err) => { @@ -172,7 +172,7 @@ export default function wallpaperJSUnit() { if (err) { expect(null).assertFail(); } - if ((data != undefined) && (data != null) && (data != '')) { + if ((data != undefined) && (data != null)) { expect(true).assertTrue(); } }) @@ -188,7 +188,7 @@ export default function wallpaperJSUnit() { it('testGetIdPromiseSystem101', 0, async function (done) { await wallpaper.getId(WALLPAPER_SYSTEM).then((data) => { console.info('wallpaperXTS ===> testGetIdCallbackSystem data : ' + JSON.stringify(data)); - if ((data != undefined) && (data != null) && (data != '')) { + if ((data != undefined) && (data != null)) { expect(true).assertTrue(); } }).catch((err) => { @@ -213,7 +213,7 @@ export default function wallpaperJSUnit() { if (err) { expect(null).assertFail(); } - if ((data != undefined) && (data != null) && (data != '')) { + if ((data != undefined) && (data != null)) { expect(true).assertTrue(); } }) @@ -229,7 +229,7 @@ export default function wallpaperJSUnit() { it('testGetIdPromiseLock102', 0, async function (done) { await wallpaper.getId(WALLPAPER_LOCKSCREEN).then((data) => { console.info('wallpaperXTS ===> testGetIdCallbackLock data : ' + JSON.stringify(data)); - if ((data != undefined) && (data != null) && (data != '')) { + if ((data != undefined) && (data != null)) { expect(true).assertTrue(); } }).catch((err) => { @@ -254,7 +254,7 @@ export default function wallpaperJSUnit() { if (err) { expect(null).assertFail(); } - if ((data != undefined) && (data != null) && (data != '')) { + if ((data != undefined) && (data != null)) { expect(true).assertTrue(); } }) @@ -270,7 +270,7 @@ export default function wallpaperJSUnit() { it('testGetMinHeightPromise101', 0, async function (done) { await wallpaper.getMinHeight().then((data) => { console.info('wallpaperXTS ===> testGetMinHeightPromise data : ' + JSON.stringify(data)); - if ((data != undefined) && (data != null) && (data != '')) { + if ((data != undefined) && (data != null)) { expect(true).assertTrue(); } }).catch((err) => { @@ -295,7 +295,7 @@ export default function wallpaperJSUnit() { if (err) { expect(null).assertFail(); } - if ((data != undefined) && (data != null) && (data != '')) { + if ((data != undefined) && (data != null)) { expect(true).assertTrue(); } }) @@ -311,7 +311,7 @@ export default function wallpaperJSUnit() { it('testGetMinWidthPromise101', 0, async function (done) { await wallpaper.getMinWidth().then((data) => { console.info('wallpaperXTS ===> testGetMinWidthPromise data : ' + JSON.stringify(data)); - if ((data != undefined) && (data != null) && (data != '')) { + if ((data != undefined) && (data != null)) { expect(true).assertTrue(); } }).catch((err) => { @@ -337,7 +337,7 @@ export default function wallpaperJSUnit() { if (err) { expect(null).assertFail(); } - if ((data != undefined) && (data != null) && (data != '')) { + if ((data != undefined) && (data != null)) { expect(true).assertTrue(); } }) @@ -354,7 +354,7 @@ export default function wallpaperJSUnit() { it('testIsChangePermittedPromise101', 0, async function (done) { await wallpaper.isChangePermitted().then((data) => { console.info('wallpaperXTS ===> testIsChangePermittedPromise data : ' + JSON.stringify(data)); - if ((data != undefined) && (data != null) && (data != '')) { + if ((data != undefined) && (data != null)) { expect(true).assertTrue(); } }).catch((err) => { @@ -379,7 +379,7 @@ export default function wallpaperJSUnit() { if (err) { expect(null).assertFail(); } - if ((data != undefined) && (data != null) && (data != '')) { + if ((data != undefined) && (data != null)) { expect(true).assertTrue(); } }) @@ -395,7 +395,7 @@ export default function wallpaperJSUnit() { it('testIsOperationAllowedPromise101', 0, async function (done) { await wallpaper.isOperationAllowed().then((data) => { console.info('wallpaperXTS ===> testIsOperationAllowedPromise data : ' + JSON.stringify(data)); - if ((data != undefined) && (data != null) && (data != '')) { + if ((data != undefined) && (data != null)) { expect(true).assertTrue(); } }).catch((err) => { @@ -420,7 +420,7 @@ export default function wallpaperJSUnit() { if (err) { expect(null).assertFail(); } - if ((data != undefined) && (data != null) && (data != '')) { + if ((data != undefined) && (data != null)) { expect(true).assertTrue(); } }) @@ -435,7 +435,7 @@ export default function wallpaperJSUnit() { */ it('testResetPromiseSystem101', 0, async function (done) { await wallpaper.reset(WALLPAPER_SYSTEM).then((data) => { - if ((data != undefined) && (data != null) && (data != '')) { + if ((data != undefined) && (data != null)) { expect(true).assertTrue(); } done(); @@ -458,7 +458,7 @@ export default function wallpaperJSUnit() { if (err) { expect(null).assertFail(); } - if ((data != undefined) && (data != null) && (data != '')) { + if ((data != undefined) && (data != null)) { expect(true).assertTrue(); } }) @@ -474,7 +474,7 @@ export default function wallpaperJSUnit() { it('testResetPromiseLock102', 0, async function (done) { await wallpaper.reset(WALLPAPER_LOCKSCREEN).then((data) => { console.info('wallpaperXTS ===> testResetPromiseLock data : ' + JSON.stringify(data)); - if ((data != undefined) && (data != null) && (data != '')) { + if ((data != undefined) && (data != null)) { expect(true).assertTrue(); } done(); @@ -493,19 +493,26 @@ export default function wallpaperJSUnit() { * @tc.level 0 */ it('testSetWallpaperURLPromiseLock104', 0, async function (done) { - await wallpaper.setWallpaper(imageSourceLockscreen, WALLPAPER_LOCKSCREEN).then((data) => { - console.info('wallpaperXTS ===> testSetWallpaperURLPromiseLock data : ' + JSON.stringify(data)); - if ((data != undefined) && (data != null) && (data != '')) { + console.info('--------------------testSetWallpaperURLPromiseLock104 start------------------' ); + try{ + wallpaper.setWallpaper(imageSourceLockscreen, WALLPAPER_LOCKSCREEN).then((data) => { + console.info('wallpaperXTS ===> testSetWallpaperURLPromiseLock104 data : ' + data); expect(true).assertTrue(); - } + done(); + }).catch((err) => { + console.info('wallpaperXTS ===> testSetWallpaperURLPromiseLock104 err : ' + err); + expect().assertFail(); + done(); + }); + }catch(error){ + console.info('testSetWallpaperURLPromiseLock104 catch error : ' + error); + expect().assertFail(); done(); - }).catch((err) => { - console.info('wallpaperXTS ===> testSetWallpaperURLPromiseLock err : ' + JSON.stringify(err)); - expect(true).assertTrue(); - done(); - }); + } + console.info('--------------------testSetWallpaperURLPromiseLock104 end------------------' ); + }) - + /* * @tc.number testSetWallpaperURLCallbackSystem103 * @tc.name Test setWallpaper() to sets a wallpaper of the specified type based on the uri path from a @@ -514,17 +521,24 @@ export default function wallpaperJSUnit() { * @tc.level 0 */ it('testSetWallpaperURLCallbackSystem103', 0, async function (done) { - await wallpaper.setWallpaper(imageSourceSystem, WALLPAPER_SYSTEM, function (err, data) { - console.info('wallpaperXTS ===> testSetWallpaperURLCallbackSystem err : ' + JSON.stringify(err)); - console.info('wallpaperXTS ===> testSetWallpaperURLCallbackSystem data : ' + JSON.stringify(data)); - if (err) { - expect(null).assertFail(); - } - if ((data != undefined) && (data != null) && (data != '')) { + console.info('--------------------testSetWallpaperURLCallbackSystem103 start------------------' ); + try{ + wallpaper.setWallpaper(imageSourceSystem, WALLPAPER_SYSTEM, function (err, data) { + console.info('wallpaperXTS ===> testSetWallpaperURLCallbackSystem103 data : ' + data); + if (err) { + console.info('wallpaperXTS ===> testSetWallpaperURLCallbackSystem103 err : ' + err); + expect().assertFail(); + done(); + } expect(true).assertTrue(); - } - }); - done(); + done(); + }); + }catch(error){ + console.info('testSetWallpaperURLCallbackSystem103 catch error: ' + error); + expect().assertFail(); + done(); + } + console.info('--------------------testSetWallpaperURLCallbackSystem103 end------------------' ); }) /* @@ -535,22 +549,23 @@ export default function wallpaperJSUnit() { * @tc.level 0 */ it('testSetWallpaperURLPromiseSystem103', 0, function (done) { - if(true) { - expect(true).assertTrue(); - done(); - return; - } - wallpaper.setWallpaper(imageSourceSystem, WALLPAPER_SYSTEM).then((data) => { - console.info('wallpaperXTS ===> testSetWallpaperURLPromiseSystem data : ' + JSON.stringify(data)); - if ((data != undefined) && (data != null) && (data != '')) { + console.info('--------------------testSetWallpaperURLPromiseSystem103 start------------------' ); + try{ + wallpaper.setWallpaper(imageSourceSystem, WALLPAPER_SYSTEM).then((data) => { + console.info('wallpaperXTS ===> testSetWallpaperURLPromiseSystem103 data : ' + data); expect(true).assertTrue(); - } - done(); - }).catch((err) => { - console.info('wallpaperXTS ===> testSetWallpaperURLPromiseSystem err : ' + JSON.stringify(err)); - expect(true).assertTrue(); - done(); - }); + done(); + }).catch((err) => { + console.info('wallpaperXTS ===> testSetWallpaperURLPromiseSystem103 err : ' + err); + expect().assertFail(); + done(); + }); + }catch(error){ + console.info('testSetWallpaperURLPromiseSystem103 err: ' + error); + expect().assertFail(); + } + console.info('--------------------testSetWallpaperURLPromiseSystem103 end------------------' ); + }) /* @@ -561,17 +576,24 @@ export default function wallpaperJSUnit() { * @tc.level 0 */ it('testSetWallpaperURLCallbackLock104', 0, async function (done) { - await wallpaper.setWallpaper(imageSourceLockscreen, WALLPAPER_LOCKSCREEN, function (err, data) { - console.info('wallpaperXTS ===> testSetWallpaperURLCallbackLock err : ' + JSON.stringify(err)); - console.info('wallpaperXTS ===> testSetWallpaperURLCallbackLock data : ' + JSON.stringify(data)); - if (err) { - expect(null).assertFail(); - } - if ((data != undefined) && (data != null) && (data != '')) { + console.info('--------------------testSetWallpaperURLCallbackLock104 start------------------' ); + try{ + wallpaper.setWallpaper(imageSourceSystem, WALLPAPER_LOCKSCREEN, function (err, data) { + console.info('wallpaperXTS ===> testSetWallpaperURLCallbackLock104 data : ' + data); + if (err) { + console.info('wallpaperXTS ===> testSetWallpaperURLCallbackLock104 err : ' + JSON.stringify(err)); + expect().assertFail(); + done(); + } expect(true).assertTrue(); - } - }); - done(); + done(); + }); + }catch(error){ + console.info('testSetWallpaperURLCallbackLock104 catch error : ' + error); + expect().assertFail(); + } + + console.info('--------------------testSetWallpaperURLCallbackLock104 end------------------' ); }) /* @@ -582,13 +604,13 @@ export default function wallpaperJSUnit() { * @tc.level 0 */ it('testOnCallback101', 0, async function (done) { - await wallpaper.on('colorChange', function (colors, wallpaperType) { + wallpaper.on('colorChange', function (colors, wallpaperType) { console.info('wallpaperXTS ===> testOnCallback colors : ' + JSON.stringify(colors)); console.info('wallpaperXTS ===> testOnCallback wallpaperType : ' + JSON.stringify(wallpaperType)); - if ((colors != undefined) && (colors != null) && (colors != '')) { + if ((colors != undefined) && (colors != null)) { expect(true).assertTrue(); } - if ((wallpaperType != undefined) && (wallpaperType != null) && (wallpaperType != '')) { + if ((wallpaperType != undefined) && (wallpaperType != null)) { expect(true).assertTrue(); } }) @@ -603,13 +625,13 @@ export default function wallpaperJSUnit() { * @tc.level 0 */ it('testOffCallback101', 0, async function (done) { - await wallpaper.off('colorChange', function (colors, wallpaperType) { + wallpaper.off('colorChange', function (colors, wallpaperType) { console.info('wallpaperXTS ===> testOffCallback colors : ' + JSON.stringify(colors)); console.info('wallpaperXTS ===> testOffCallback wallpaperType : ' + JSON.stringify(wallpaperType)); - if ((colors != undefined) && (colors != null) && (colors != '')) { + if ((colors != undefined) && (colors != null)) { expect(true).assertTrue(); } - if ((wallpaperType != undefined) && (wallpaperType != null) && (wallpaperType != '')) { + if ((wallpaperType != undefined) && (wallpaperType != null)) { expect(true).assertTrue(); } }) @@ -627,7 +649,7 @@ export default function wallpaperJSUnit() { if (error) { console.error("callback failed to getFile because: " + JSON.stringify(error)); expect().assertFail() - }else{ + } else { expect(typeof data == "number").assertTrue(); expect(!isNaN(data)).assertTrue(); console.info("callback success to getFile: " + JSON.stringify(data)); @@ -655,5 +677,561 @@ export default function wallpaperJSUnit() { }); done(); }) - }) -} + + /* + * @tc.number testGetColorsSync101 + * @tc.name Test getColorsSync() to obtains the wallpaper colors for the wallpaper of the specified type. + * @tc.desc Function test + * @tc.level 0 + */ + it('testGetColorsSync101', 0, async function (done) { + console.info('------------------testGetColorsSync101 start----------------------'); + let colors = null; + try{ + colors = wallpaper.getColorsSync(WALLPAPER_SYSTEM) + console.info('wallpaperXTS ===> testGetColorsSync101 data : ' + JSON.stringify(colors)); + if (colors.length >= 1) { + expect(true).assertTrue(); + done() + }else{ + expect().assertFail(); + done() + } + }catch(err){ + console.info('wallpaperXTS ===> testGetColorsSync101 err : ' + JSON.stringify(err)); + expect().assertFail(); + done() + } + console.info('------------------testGetColorsSync101 end----------------------'); + done() + }) + + /* + * @tc.number testGetColorsSync102 + * @tc.name Test getColorsSync() to obtains the wallpaper colors for the wallpaper of the specified type. + * @tc.desc Function test + * @tc.level 0 + */ + it('testGetColorsSync102', 0, async function (done) { + console.info('------------------testGetColorsSync102 start----------------------'); + let colors = null; + try{ + colors = wallpaper.getColorsSync(WALLPAPER_LOCKSCREEN) + console.info('wallpaperXTS ===> testGetColorsSync102 data : ' + JSON.stringify(colors)); + if (colors.length >= 1) { + expect(true).assertTrue(); + done() + }else{ + expect().assertFail(); + done() + } + }catch(err){ + console.info('wallpaperXTS ===> testGetColorsSync102 err : ' + JSON.stringify(err)); + expect().assertFail(); + done() + } + console.info('------------------testGetColorsSync102 end----------------------'); + done() + }) + + /* + * @tc.number testGetIdSync101 + * @tc.name Test getIdSync() to Obtains the ID of the wallpaper of the specified type. + * @tc.desc Function test + * @tc.level 0 + */ + it('testGetIdSync101', 0, async function (done) { + console.info('------------------testGetIdSync101 start----------------------'); + let number = null; + try{ + number = wallpaper.getIdSync(WALLPAPER_SYSTEM) + console.info('wallpaperXTS ===> testGetIdSync101 data : ' + JSON.stringify(number)); + if (typeof number == "number") { + expect(true).assertTrue(); + done() + }else{ + expect().assertFail(); + done() + } + }catch(err){ + console.info('wallpaperXTS ===> testGetIdSync101 err : ' + JSON.stringify(err)); + expect().assertFail(); + done() + } + console.info('------------------testGetIdSync101 end----------------------'); + done() + }) + + /* + * @tc.number testGetIdSync102 + * @tc.name Test getIdSync() to Obtains the ID of the wallpaper of the specified type. + * @tc.desc Function test + * @tc.level 0 + */ + it('testGetIdSync102', 0, async function (done) { + console.info('------------------testGetIdSync102 start----------------------'); + let number = null; + try{ + number = wallpaper.getIdSync(WALLPAPER_LOCKSCREEN) + console.info('wallpaperXTS ===> testGetIdSync102 data : ' + JSON.stringify(number)); + if (typeof number == "number") { + expect(true).assertTrue(); + done() + }else{ + expect().assertFail(); + done() + } + }catch(err){ + console.info('wallpaperXTS ===> testGetIdSync102 err : ' + JSON.stringify(err)); + expect().assertFail(); + done() + } + console.info('------------------testGetIdSync102 end----------------------'); + done() + }) + + /* + * @tc.number testGetFileSync101 + * @tc.name Test getFileSync() to Obtains a file of the wallpaper of the specified type. + * @tc.desc Function test + * @tc.level 0 + */ + it('testGetFileSync101', 0, async function (done) { + console.info('------------------testGetFileSync101 start----------------------'); + let number = null; + try{ + number = wallpaper.getFileSync(WALLPAPER_SYSTEM) + console.info('wallpaperXTS ===> testGetFileSync101 data : ' + JSON.stringify(number)); + if (typeof number == "number") { + expect(true).assertTrue(); + done() + }else{ + expect().assertFail(); + done() + } + }catch(err){ + console.info('wallpaperXTS ===> testGetFileSync101 err : ' + JSON.stringify(err)); + expect().assertFail(); + done() + } + console.info('------------------testGetFileSync101 end----------------------'); + done() + }) + + /* + * @tc.number testGetFileSync102 + * @tc.name Test getFileSync() to Obtains a file of the wallpaper of the specified type. + * @tc.desc Function test + * @tc.level 0 + */ + it('testGetFileSync102', 0, async function (done) { + console.info('------------------testGetFileSync102 start----------------------'); + let number = null; + try{ + number = wallpaper.getFileSync(WALLPAPER_LOCKSCREEN) + console.info('wallpaperXTS ===> testGetFileSync102 data : ' + JSON.stringify(number)); + if (typeof number == "number") { + expect(true).assertTrue(); + done() + }else{ + expect().assertFail(); + done() + } + }catch(err){ + console.info('wallpaperXTS ===> testGetFileSync102 err : ' + JSON.stringify(err)); + expect().assertFail(); + done() + } + console.info('------------------testGetFileSync102 end----------------------'); + done() + }) + + /* + * @tc.number testGetFileSync103 + * @tc.name Test getFileSync() to Obtains a file of the wallpaper of the specified type. + * @tc.desc Function test + * @tc.level 0 + */ + it('testGetFileSync103', 0, async function (done) { + console.info('------------------testGetFileSync103 start----------------------'); + let number = null; + try{ + number = wallpaper.getFileSync(3) + console.info('wallpaperXTS ===> testGetFileSync103 data : ' + JSON.stringify(number)); + if (typeof number == "number") { + expect(true).assertTrue(); + done() + }else{ + expect().assertFail(); + done() + } + }catch(err){ + console.info('wallpaperXTS ===> testGetFileSync103 err : ' + JSON.stringify(err)); + console.info('wallpaperXTS ===> testGetFileSync103 (err.code : ' + err.code); + expect(err.code == "401").assertTrue(); + done() + } + console.info('------------------testGetFileSync103 end----------------------'); + done() + }) + + /* + * @tc.number testGetMinHeightSync101 + * @tc.name Test getMinHeightSync() to Obtains the minimum height of the wallpaper. + * @tc.desc Function test + * @tc.level 0 + */ + it('testGetMinHeightSync101', 0, async function (done) { + console.info('------------------testGetMinHeightSync101 start----------------------'); + let number = null; + try{ + number = wallpaper.getMinHeightSync() + console.info('wallpaperXTS ===> testGetMinHeightSync101 data : ' + JSON.stringify(number)); + if (typeof number == "number") { + expect(true).assertTrue(); + done() + }else{ + expect().assertFail(); + done() + } + }catch(err){ + console.info('wallpaperXTS ===> testGetMinHeightSync101 err : ' + JSON.stringify(err)); + expect().assertFail(); + done() + } + console.info('------------------testGetMinHeightSync101 end----------------------'); + done() + }) + + /* + * @tc.number testGetMinWidthSync101 + * @tc.name Test getMinWidthSync() to Obtains the minimum width of the wallpaper. + * @tc.desc Function test + * @tc.level 0 + */ + it('testGetMinWidthSync101', 0, async function (done) { + console.info('------------------testGetMinWidthSync101 start----------------------'); + let number = null; + try{ + number = wallpaper.getMinHeightSync() + console.info('wallpaperXTS ===> testGetMinWidthSync101 data : ' + JSON.stringify(number)); + if (typeof number == "number") { + expect(true).assertTrue(); + done() + }else{ + expect().assertFail(); + done() + } + }catch(err){ + console.info('wallpaperXTS ===> testGetMinWidthSync101 err : ' + JSON.stringify(err)); + expect().assertFail(); + done() + } + console.info('------------------testGetMinWidthSync101 end----------------------'); + done() + }) + + /* + * @tc.number testIsChangeAllowed101 + * @tc.name Test isChangeAllowed() to Checks whether to allow the application to change the wallpaper for the current user. + * @tc.desc Function test + * @tc.level 0 + */ + it('testIsChangeAllowed101', 0, async function (done) { + console.info('------------------testIsChangeAllowed101 start----------------------'); + let allow = null; + try{ + allow = wallpaper.isChangeAllowed() + console.info('wallpaperXTS ===> testIsChangeAllowed101 data : ' + JSON.stringify(allow)); + if (typeof allow == "boolean") { + expect(true).assertTrue(); + done() + }else{ + expect().assertFail(); + done() + } + }catch(err){ + console.info('wallpaperXTS ===> testIsChangeAllowed101 err : ' + JSON.stringify(err)); + expect().assertFail(); + done() + } + console.info('------------------testIsChangeAllowed101 end----------------------'); + done() + }) + + /* + * @tc.number testIsChangeAllowed101 + * @tc.name Test isUserChangeAllowed() to Checks whether a user is allowed to set wallpapers. + * @tc.desc Function test + * @tc.level 0 + */ + it('testIsUserChangeAllowed101', 0, async function (done) { + console.info('------------------testIsUserChangeAllowed101 start----------------------'); + let allow = null; + try{ + allow = wallpaper.isUserChangeAllowed() + console.info('wallpaperXTS ===> testIsUserChangeAllowed101 data : ' + JSON.stringify(allow)); + if (typeof allow == "boolean") { + expect(true).assertTrue(); + done() + }else{ + expect().assertFail(); + done() + } + }catch(err){ + console.info('wallpaperXTS ===> testIsUserChangeAllowed101 err : ' + JSON.stringify(err)); + expect().assertFail(); + done() + } + console.info('------------------testIsUserChangeAllowed101 end----------------------'); + done() + }) + + /* + * @tc.number testRestoreCallback101 + * @tc.name Test restore() to removes a wallpaper of the specified type and restores the default one. + * @tc.desc Function test + * @tc.level 0 + */ + it('testRestoreCallback101', 0, async function (done) { + console.info('------------------testRestoreCallback101 start----------------------'); + try{ + wallpaper.restore(WALLPAPER_LOCKSCREEN, function (err, data) { + console.info('wallpaperXTS ===> testRestoreCallback101 data : ' + data); + if (err) { + console.info('wallpaperXTS ===> testRestoreCallback101 err : ' + JSON.stringify(err)); + expect().assertFail(); + done() + } + console.info('testRestoreCallback101 restore success'); + expect(true).assertTrue(); + done() + }) + }catch(err){ + console.info('testRestoreCallback101 catch err : ' + JSON.stringify(err)); + expect().assertFail(); + done() + } + console.info('------------------testRestoreCallback101 end----------------------'); + }) + + /* + * @tc.number testRestorePromise101 + * @tc.name Test restore() to removes a wallpaper of the specified type and restores the default one. + * @tc.desc Function test + * @tc.level 0 + */ + it('testRestorePromise101', 0, async function (done) { + console.info('------------------testRestorePromise101 start----------------------'); + try{ + wallpaper.restore(WALLPAPER_SYSTEM).then((data) => { + console.info('wallpaperXTS ===> testRestorePromise101 data : ' + JSON.stringify(data)); + console.info('testRestorePromise101 restore success'); + expect(true).assertTrue(); + done() + }).catch((err) => { + console.info('wallpaperXTS ===> testRestorePromise101 err : ' + JSON.stringify(err)); + expect().assertFail(); + done(); + }); + }catch(err){ + console.info('testRestorePromise101 catch err : ' + JSON.stringify(err)); + expect().assertFail(); + done(); + } + console.info('------------------testRestorePromise101 end----------------------'); + }) + + /* + * @tc.number testSetImageCallBack101 + * @tc.name Test setImage() to removes a wallpaper of the specified type and restores the default one. + * @tc.desc Function test + * @tc.level 0 + */ + it('testSetImageCallBack101', 0, async function (done) { + console.info('------------------testSetImageCallBack101 start----------------------'); + let wallpaperPath = "/system/etc/wp.png"; + try{ + wallpaper.setImage(wallpaperPath, wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error, data) => { + if (error) { + console.error(`testSetImageCallBack101 failed to setImage because: ` + JSON.stringify(error)); + expect().assertFail(); + done(); + } + console.log(`testSetImageCallBack101 success to setImage.`); + expect(true).assertTrue(); + done(); + }); + }catch(err){ + console.info('testSetImageCallBack101 catch err : ' + JSON.stringify(err)); + expect().assertFail(); + done(); + } + console.info('------------------testSetImageCallBack101 end----------------------'); + }) + + /* + * @tc.number testSetImageCallBack102 + * @tc.name Test setImage() to removes a wallpaper of the specified type and restores the default one. + * @tc.desc Function test + * @tc.level 0 + */ + it('testSetImageCallBack102', 0, async function (done) { + console.info('------------------testSetImageCallBack102 start----------------------'); + let wallpaperPath = "/system/etc/wp.png"; + try{ + wallpaper.setImage(wallpaperPath, wallpaper.WallpaperType.WALLPAPER_LOCKSCREEN, (error, data) => { + if (error) { + console.error(`testSetImageCallBack102 failed to setImage because: ` + JSON.stringify(error)); + expect().assertFail(); + done(); + } + console.log(`testSetImageCallBack102 success to setImage.`); + expect(true).assertTrue(); + done(); + }); + }catch(err){ + console.info('testSetImageCallBack102 catch err : ' + JSON.stringify(err)); + expect().assertFail(); + done(); + } + console.info('------------------testSetImageCallBack102 end----------------------'); + }) + + /* + * @tc.number testSetImageCallBack103 + * @tc.name Test setImage() to removes a wallpaper of the specified type and restores the default one. + * @tc.desc Function test + * @tc.level 0 + */ + it('testSetImageCallBack103', 0, async function (done) { + console.info('------------------testSetImageCallBack103 start----------------------'); + const color = new ArrayBuffer(96); + let bufferArr = new Uint8Array(color); + let opts = { + editable: true, + pixelFormat: 3, + size: { height: 4, width: 6 } + } + console.log(`testSetImageCallBack103 opts success`) + try{ + image.createPixelMap(color, opts).then((pixelMap) => { + wallpaper.setImage(pixelMap, wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error, data) => { + if (error) { + console.error(`testSetImageCallBack103 failed to setImage because: ` + JSON.stringify(error)); + expect().assertFail(); + done() + } + console.log(`testSetImageCallBack103 success to setImage.`); + expect(true).assertTrue(); + done() + }); + }).catch((error) => { + console.error(`testSetImageCallBack103 failed to createPixelMap because: ` + JSON.stringify(error)); + expect().assertFail(); + done() + }); + }catch(err){ + console.info('testSetImageCallBack103 catch err : ' + JSON.stringify(err)); + expect().assertFail(); + done(); + } + console.info('------------------testSetImageCallBack103 end----------------------'); + }) + + /* + * @tc.number testSetImagePromise101 + * @tc.name Test setImage() to removes a wallpaper of the specified type and restores the default one. + * @tc.desc Function test + * @tc.level 0 + */ + it('testSetImagePromise101', 0, async function (done) { + console.info('------------------testSetImagePromise101 start----------------------'); + let wallpaperPath = "/system/etc/wp.png"; + try{ + wallpaper.setImage(wallpaperPath, wallpaper.WallpaperType.WALLPAPER_SYSTEM).then((data) => { + console.log(`testSetImagePromise101 success to setImage.`); + expect(true).assertTrue(); + done(); + }).catch(err => { + expect().assertFail(); + console.log(`testSetImagePromise101 promise catch: ` + JSON.stringify(err)); + }); + }catch(err){ + console.info('testSetImagePromise101 catch err : ' + JSON.stringify(err)); + expect().assertFail(); + done(); + } + console.info('------------------testSetImagePromise101 end----------------------'); + + }) + + /* + * @tc.number testSetImagePromise102 + * @tc.name Test setImage() to removes a wallpaper of the specified type and restores the default one. + * @tc.desc Function test + * @tc.level 0 + */ + it('testSetImagePromise102', 0, async function (done) { + console.info('------------------testSetImagePromise102 start----------------------'); + let wallpaperPath = "/system/etc/wp.png"; + try{ + wallpaper.setImage(wallpaperPath, wallpaper.WallpaperType.WALLPAPER_LOCKSCREEN).then((data) => { + console.log(`testSetImagePromise102 success to setImage.`); + expect(true).assertTrue(); + done(); + }).catch(err => { + console.log(`testSetImagePromise102 promise catch: ` + JSON.stringify(err)); + expect().assertFail(); + done() + }); + }catch(err){ + console.info('testSetImagePromise102 catch err : ' + JSON.stringify(err)); + expect().assertFail(); + done(); + } + console.info('------------------testSetImagePromise102 end----------------------'); + }) + + /* + * @tc.number testSetImagePromise103 + * @tc.name Test setImage() to removes a wallpaper of the specified type and restores the default one. + * @tc.desc Function test + * @tc.level 0 + */ + it('testSetImagePromise103', 0, async function (done) { + console.info('------------------testSetImagePromise103 start----------------------'); + const color = new ArrayBuffer(96); + let bufferArr = new Uint8Array(color); + let opts = { + editable: true, + pixelFormat: 3, + size: { height: 4, width: 6 } + } + console.log(`testSetImagePromise103 opts success`) + try{ + image.createPixelMap(color, opts).then((pixelMap) => { + wallpaper.setImage(pixelMap, wallpaper.WallpaperType.WALLPAPER_SYSTEM).then((data) => { + console.log(`testSetImagePromise103 success to setImage.`); + expect(true).assertTrue(); + done() + }).catch(err => { + console.error(`testSetImagePromise103 failed to setImage because: ` + JSON.stringify(err)); + expect().assertFail(); + done() + }); + }).catch((error) => { + console.error(`testSetImagePromise103 failed to createPixelMap because: ` + JSON.stringify(error)); + expect().assertFail(); + done() + }); + }catch(err){ + console.info('testSetImagePromise103 catch err : ' + JSON.stringify(err)); + expect().assertFail(); + done(); + } + console.info('------------------testSetImagePromise103 end----------------------'); + }); + + }); +};