1/* 2 * Copyright (C) 2025 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 { sendableImage } from '@kit.ImageKit'; 17import { image } from '@kit.ImageKit'; 18import { describe, it, expect, Level, beforeAll, beforeEach, afterEach, afterAll } from '@ohos/hypium'; 19import { LOG_TAG } from '../../common'; 20 21const TAG = LOG_TAG + 'getPixelBytesNumber'; 22 23async function getPixelBytesNumberPromiseTest(done: Function, testName: string, opts: image.InitializationOptions) { 24 try { 25 const color: ArrayBuffer = 26 new ArrayBuffer(opts.size.height * opts.size.height * 4); 27 let sendablePixelMap: sendableImage.PixelMap = sendableImage.createPixelMapSync(color, opts); 28 29 if (sendablePixelMap != undefined) { 30 let rowCount: number = await sendablePixelMap.getPixelBytesNumber(); 31 expect(JSON.stringify(rowCount) !== undefined).assertTrue(); 32 done(); 33 } 34 } catch (error) { 35 console.info(TAG, `failed; error: ${error},${error.code}`, testName); 36 expect().assertFail(); 37 done(); 38 } 39} 40 41export default function sendableGetPixelBytesNumberTest() { 42 describe('sendableGetPixelBytesNumberTest', () => { 43 44 beforeAll(async () => { 45 console.info(TAG, 'beforeAll case.'); 46 }); 47 48 beforeEach(() => { 49 console.info(TAG, 'beforeEach case.'); 50 }); 51 52 afterEach(() => { 53 console.info(TAG, 'afterEach case.'); 54 }); 55 56 afterAll(() => { 57 console.info(TAG, 'afterAll case.'); 58 }); 59 60 /** 61 * @tc.number : PIXEL_MAP_GET_PIXEL_BYTES_NUMBER_001 62 * @tc.name : getPixelBytesNumber_sendable_promise_001 63 * @tc.desc : getPixelBytesNumber 64 * @tc.size : MEDIUM 65 * @tc.type : Function 66 * @tc.level : Level 0 67 */ 68 it('getPixelBytesNumber_sendable_promise_001', Level.LEVEL0, async (done: Function) => { 69 const testName = 'getPixelBytesNumber_sendable_promise_001'; 70 let opts: image.InitializationOptions = 71 { editable: true, pixelFormat: image.PixelMapFormat.RGBA_8888, size: { height: 4, width: 6 } }; 72 await getPixelBytesNumberPromiseTest(done, testName, opts); 73 }) 74 75 /** 76 * @tc.number : PIXEL_MAP_GET_PIXEL_BYTES_NUMBER_001 77 * @tc.name : getPixelBytesNumber_sendable_promise_002 78 * @tc.desc : getPixelBytesNumber 79 * @tc.size : MEDIUM 80 * @tc.type : Function 81 * @tc.level : Level 0 82 */ 83 it('getPixelBytesNumber_sendable_promise_002', Level.LEVEL0, async (done: Function) => { 84 const testName = 'getPixelBytesNumber_sendable_promise_002'; 85 let opts: image.InitializationOptions = 86 { editable: true, pixelFormat: image.PixelMapFormat.RGBA_8888, size: { height: 600, width: 400 } }; 87 await getPixelBytesNumberPromiseTest(done, testName, opts); 88 }) 89 }) 90}