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'; 20import { ErrorCode } from '../../CommonErrorCode'; 21 22const TAG = LOG_TAG + 'createPixelMapSync'; 23 24async function createPixelMapSyncPromiseTest(done: Function, testName: string, color: ArrayBuffer, 25 opts: image.InitializationOptions) { 26 try { 27 let pixelMap = sendableImage.createPixelMapSync(color, opts); 28 if (pixelMap !== undefined) { 29 expect(pixelMap.isEditable === opts.editable).assertTrue(); 30 done(); 31 } else { 32 console.info(TAG, `failed; error: pixelMap is undefined`, JSON.stringify(pixelMap), testName); 33 expect().assertFail(); 34 done(); 35 } 36 } catch (error) { 37 console.info(TAG, `failed; error: ${error},${error.code}`, testName); 38 expect().assertFail(); 39 done(); 40 } 41} 42 43async function createPixelMapSyncAbnormalPromiseTest(done: Function, testName: string, color: ArrayBuffer, 44 opts: image.InitializationOptions) { 45 try { 46 let pixelMap = sendableImage.createPixelMapSync(color, opts); 47 if (pixelMap !== undefined) { 48 expect(pixelMap.isEditable === opts.editable).assertTrue(); 49 done(); 50 } else { 51 console.info(TAG, `failed; error: pixelMap is undefined`, JSON.stringify(pixelMap), testName); 52 expect().assertFail(); 53 done(); 54 } 55 } catch (error) { 56 console.info(TAG, `failed; error: ${error},${error.code}`, testName); 57 if (error & error.code) { 58 expect(error.code == ErrorCode.Operation_Failed).assertTrue(); 59 done(); 60 } else { 61 expect(error == ErrorCode.Operation_Failed).assertTrue(); 62 done(); 63 } 64 } 65} 66 67 68export default function sendableCreatePixelMapSyncTest() { 69 describe('sendableCreatePixelMapSyncTest', () => { 70 71 beforeAll(async () => { 72 console.info(TAG, 'beforeAll case.'); 73 }); 74 75 beforeEach(() => { 76 console.info(TAG, 'beforeEach case.'); 77 }); 78 79 afterEach(() => { 80 console.info(TAG, 'afterEach case.'); 81 }); 82 83 afterAll(() => { 84 console.info(TAG, 'afterAll case.'); 85 }); 86 87 /** 88 * @tc.number :SENDABLE_IMAGE_CREATE_PIXEL_MAP_SYNC_001 89 * @tc.name : sendableImage_createPixelMapSync_sendable_promise_001 90 * @tc.desc : sendableImage_createPixelMapSync 91 * @tc.size : MEDIUM 92 * @tc.type : Function 93 * @tc.level : Level 0 94 */ 95 it('sendableImage_createPixelMapSync_sendable_promise_001', Level.LEVEL0, async (done: Function) => { 96 const testName = 'sendableImage_createPixelMapSync_sendable_promise_001'; 97 const color: ArrayBuffer = new ArrayBuffer(96); 98 const opts: image.InitializationOptions = 99 { editable: true, pixelFormat: image.PixelMapFormat.UNKNOWN, size: { height: 4, width: 6 } }; 100 await createPixelMapSyncPromiseTest(done, testName, color, opts); 101 }) 102 103 /** 104 * @tc.number :SENDABLE_IMAGE_CREATE_PIXEL_MAP_SYNC_002 105 * @tc.name : sendableImage_createPixelMapSync_sendable_promise_002 106 * @tc.desc : sendableImage_createPixelMapSync 107 * @tc.size : MEDIUM 108 * @tc.type : Function 109 * @tc.level : Level 0 110 */ 111 it('sendableImage_createPixelMapSync_sendable_promise_002', Level.LEVEL0, async (done: Function) => { 112 const testName = 'sendableImage_createPixelMapSync_sendable_promise_002'; 113 const color: ArrayBuffer = new ArrayBuffer(96); 114 const opts: image.InitializationOptions = 115 { editable: true, pixelFormat: image.PixelMapFormat.ARGB_8888, size: { height: 6, width: 4 } }; 116 await createPixelMapSyncPromiseTest(done, testName, color, opts); 117 }) 118 119 /** 120 * @tc.number :SENDABLE_IMAGE_CREATE_PIXEL_MAP_SYNC_003 121 * @tc.name : sendableImage_createPixelMapSync_sendable_promise_003 122 * @tc.desc : sendableImage_createPixelMapSync 123 * @tc.size : MEDIUM 124 * @tc.type : Function 125 * @tc.level : Level 0 126 */ 127 it('sendableImage_createPixelMapSync_sendable_promise_003', Level.LEVEL0, async (done: Function) => { 128 const testName = 'sendableImage_createPixelMapSync_sendable_promise_003'; 129 const color: ArrayBuffer = new ArrayBuffer(96); 130 const opts: image.InitializationOptions = 131 { editable: false, pixelFormat: image.PixelMapFormat.RGB_565, size: { height: 6, width: 4 } }; 132 await createPixelMapSyncPromiseTest(done, testName, color, opts); 133 }) 134 135 /** 136 * @tc.number :SENDABLE_IMAGE_CREATE_PIXEL_MAP_SYNC_004 137 * @tc.name : sendableImage_createPixelMapSync_sendable_promise_004 138 * @tc.desc : sendableImage_createPixelMapSync 139 * @tc.size : MEDIUM 140 * @tc.type : Function 141 * @tc.level : Level 0 142 */ 143 it('sendableImage_createPixelMapSync_sendable_promise_004', Level.LEVEL0, async (done: Function) => { 144 const testName = 'sendableImage_createPixelMapSync_sendable_promise_004'; 145 const color: ArrayBuffer = new ArrayBuffer(96); 146 const opts: image.InitializationOptions = 147 { editable: false, pixelFormat: image.PixelMapFormat.RGBA_8888, size: { height: 6, width: 4 } }; 148 await createPixelMapSyncPromiseTest(done, testName, color, opts); 149 }) 150 151 /** 152 * @tc.number :SENDABLE_IMAGE_CREATE_PIXEL_MAP_SYNC_005 153 * @tc.name : sendableImage_createPixelMapSync_sendable_promise_005 154 * @tc.desc : sendableImage_createPixelMapSync 155 * @tc.size : MEDIUM 156 * @tc.type : Function 157 * @tc.level : Level 0 158 */ 159 it('sendableImage_createPixelMapSync_sendable_promise_005', Level.LEVEL0, async (done: Function) => { 160 const testName = 'sendableImage_createPixelMapSync_sendable_promise_005'; 161 const color: ArrayBuffer = new ArrayBuffer(96); 162 const opts: image.InitializationOptions = 163 { editable: false, pixelFormat: image.PixelMapFormat.BGRA_8888, size: { height: 6, width: 4 } }; 164 await createPixelMapSyncPromiseTest(done, testName, color, opts); 165 }) 166 167 /** 168 * @tc.number :SENDABLE_IMAGE_CREATE_PIXEL_MAP_SYNC_006 169 * @tc.name : sendableImage_createPixelMapSync_sendable_promise_006 170 * @tc.desc : sendableImage_createPixelMapSync 171 * @tc.size : MEDIUM 172 * @tc.type : Function 173 * @tc.level : Level 0 174 */ 175 it('sendableImage_createPixelMapSync_sendable_promise_006', Level.LEVEL0, async (done: Function) => { 176 const testName = 'sendableImage_createPixelMapSync_sendable_promise_006'; 177 const color: ArrayBuffer = new ArrayBuffer(96); 178 const opts: image.InitializationOptions = 179 { editable: false, pixelFormat: image.PixelMapFormat.RGB_888, size: { height: 6, width: 4 } }; 180 await createPixelMapSyncPromiseTest(done, testName, color, opts); 181 }) 182 183 /** 184 * @tc.number :SENDABLE_IMAGE_CREATE_PIXEL_MAP_SYNC_007 185 * @tc.name : sendableImage_createPixelMapSync_sendable_promise_007 186 * @tc.desc : sendableImage_createPixelMapSync 187 * @tc.size : MEDIUM 188 * @tc.type : Function 189 * @tc.level : Level 0 190 */ 191 it('sendableImage_createPixelMapSync_sendable_promise_007', Level.LEVEL0, async (done: Function) => { 192 const testName = 'sendableImage_createPixelMapSync_sendable_promise_007'; 193 const color: ArrayBuffer = new ArrayBuffer(96); 194 const opts: image.InitializationOptions = 195 { editable: false, pixelFormat: image.PixelMapFormat.ALPHA_8, size: { height: 6, width: 4 } }; 196 await createPixelMapSyncPromiseTest(done, testName, color, opts); 197 }) 198 199 /** 200 * @tc.number :SENDABLE_IMAGE_CREATE_PIXEL_MAP_SYNC_008 201 * @tc.name : sendableImage_createPixelMapSync_sendable_promise_008 202 * @tc.desc : sendableImage_createPixelMapSync 203 * @tc.size : MEDIUM 204 * @tc.type : Function 205 * @tc.level : Level 0 206 */ 207 it('sendableImage_createPixelMapSync_sendable_promise_008', Level.LEVEL0, async (done: Function) => { 208 const testName = 'sendableImage_createPixelMapSync_sendable_promise_008'; 209 const color: ArrayBuffer = new ArrayBuffer(96); 210 const opts: image.InitializationOptions = 211 { editable: false, pixelFormat: image.PixelMapFormat.ALPHA_8, size: { height: 6, width: 4 } }; 212 await createPixelMapSyncPromiseTest(done, testName, color, opts); 213 }) 214 215 /** 216 * @tc.number :SENDABLE_IMAGE_CREATE_PIXEL_MAP_SYNC_009 217 * @tc.name : sendableImage_createPixelMapSync_sendable_promise_009 218 * @tc.desc : sendableImage_createPixelMapSync 219 * @tc.size : MEDIUM 220 * @tc.type : Function 221 * @tc.level : Level 0 222 */ 223 it('sendableImage_createPixelMapSync_sendable_promise_009', Level.LEVEL0, async (done: Function) => { 224 const testName = 'sendableImage_createPixelMapSync_sendable_promise_009'; 225 const color: ArrayBuffer = new ArrayBuffer(96); 226 const opts: image.InitializationOptions = 227 { editable: false, pixelFormat: image.PixelMapFormat.RGBA_F16, size: { height: 6, width: 4 } }; 228 await createPixelMapSyncPromiseTest(done, testName, color, opts); 229 }) 230 231 /** 232 * @tc.number :SENDABLE_IMAGE_CREATE_PIXEL_MAP_SYNC_010 233 * @tc.name : sendableImage_createPixelMapSync_sendable_promise_010 234 * @tc.desc : sendableImage_createPixelMapSync 235 * @tc.size : MEDIUM 236 * @tc.type : Function 237 * @tc.level : Level 0 238 */ 239 it('sendableImage_createPixelMapSync_sendable_promise_010', Level.LEVEL0, async (done: Function) => { 240 const testName = 'sendableImage_createPixelMapSync_sendable_promise_010'; 241 const color: ArrayBuffer = new ArrayBuffer(96); 242 const opts: image.InitializationOptions = 243 { editable: false, pixelFormat: image.PixelMapFormat.NV21, size: { height: 6, width: 4 } }; 244 await createPixelMapSyncPromiseTest(done, testName, color, opts); 245 }) 246 247 /** 248 * @tc.number :SENDABLE_IMAGE_CREATE_PIXEL_MAP_SYNC_011 249 * @tc.name : sendableImage_createPixelMapSync_sendable_promise_011 250 * @tc.desc : sendableImage_createPixelMapSync 251 * @tc.size : MEDIUM 252 * @tc.type : Function 253 * @tc.level : Level 0 254 */ 255 it('sendableImage_createPixelMapSync_sendable_promise_011', Level.LEVEL0, async (done: Function) => { 256 const testName = 'sendableImage_createPixelMapSync_sendable_promise_011'; 257 const color: ArrayBuffer = new ArrayBuffer(96); 258 const opts: image.InitializationOptions = 259 { editable: false, pixelFormat: image.PixelMapFormat.NV12, size: { height: 6, width: 4 } }; 260 await createPixelMapSyncPromiseTest(done, testName, color, opts); 261 }) 262 263 /** 264 * @tc.number :SENDABLE_IMAGE_CREATE_PIXEL_MAP_SYNC_012 265 * @tc.name : sendableImage_createPixelMapSync_sendable_promise_012 266 * @tc.desc : sendableImage_createPixelMapSync 267 * @tc.size : MEDIUM 268 * @tc.type : Function 269 * @tc.level : Level 0 270 */ 271 /*it('sendableImage_createPixelMapSync_sendable_promise_012', Level.LEVEL0, async (done: Function) => { 272 const testName = 'sendableImage_createPixelMapSync_sendable_promise_012'; 273 const color: ArrayBuffer = new ArrayBuffer(96); 274 const opts: image.InitializationOptions = 275 { editable: false, pixelFormat: image.PixelMapFormat.RGBA_1010102, size: { height: 6, width: 4 } }; 276 await createPixelMapSyncPromiseTest(done, testName, color, opts); 277 })*/ 278 279 /** 280 * @tc.number :SENDABLE_IMAGE_CREATE_PIXEL_MAP_SYNC_013 281 * @tc.name : sendableImage_createPixelMapSync_sendable_promise_013 282 * @tc.desc : sendableImage_createPixelMapSync 283 * @tc.size : MEDIUM 284 * @tc.type : Function 285 * @tc.level : Level 0 286 */ 287 /*it('sendableImage_createPixelMapSync_sendable_promise_013', Level.LEVEL0, async (done: Function) => { 288 const testName = 'sendableImage_createPixelMapSync_sendable_promise_013'; 289 const color: ArrayBuffer = new ArrayBuffer(96); 290 const opts: image.InitializationOptions = 291 { editable: false, pixelFormat: image.PixelMapFormat.YCBCR_P010, size: { height: 6, width: 4 } }; 292 await createPixelMapSyncPromiseTest(done, testName, color, opts); 293 })*/ 294 295 /** 296 * @tc.number :SENDABLE_IMAGE_CREATE_PIXEL_MAP_SYNC_014 297 * @tc.name : sendableImage_createPixelMapSync_sendable_promise_014 298 * @tc.desc : sendableImage_createPixelMapSync 299 * @tc.size : MEDIUM 300 * @tc.type : Function 301 * @tc.level : Level 0 302 */ 303 /*it('sendableImage_createPixelMapSync_sendable_promise_014', Level.LEVEL0, async (done: Function) => { 304 const testName = 'sendableImage_createPixelMapSync_sendable_promise_014'; 305 const color: ArrayBuffer = new ArrayBuffer(96); 306 const opts: image.InitializationOptions = 307 { editable: false, pixelFormat: image.PixelMapFormat.YCRCB_P010, size: { height: 6, width: 4 } }; 308 await createPixelMapSyncPromiseTest(done, testName, color, opts); 309 })*/ 310 311 /** 312 * @tc.number :SENDABLE_IMAGE_CREATE_PIXEL_MAP_SYNC_015 313 * @tc.name : sendableImage_createPixelMapSync_sendable_promise_015 314 * @tc.desc : sendableImage_createPixelMapSync 315 * @tc.size : MEDIUM 316 * @tc.type : Function 317 * @tc.level : Level 0 318 */ 319 it('sendableImage_createPixelMapSync_sendable_promise_015', Level.LEVEL0, async (done: Function) => { 320 const testName = 'sendableImage_createPixelMapSync_sendable_promise_015'; 321 const color: ArrayBuffer = new ArrayBuffer(96); 322 const opts: image.InitializationOptions = 323 { editable: false, pixelFormat: image.PixelMapFormat.ASTC_4x4, size: { height: 6, width: 4 } }; 324 await createPixelMapSyncPromiseTest(done, testName, color, opts); 325 }) 326 327 /** 328 * @tc.number :SENDABLE_IMAGE_CREATE_PIXEL_MAP_SYNC_016 329 * @tc.name : sendableImage_createPixelMapSync_abnormal_sendable_promise_004 330 * @tc.desc : sendableImage_createPixelMapSync 331 * @tc.size : MEDIUM 332 * @tc.type : Function 333 * @tc.level : Level 0 334 */ 335 /*it('sendableImage_createPixelMapSync_abnormal_sendable_promise_004', Level.LEVEL0, async (done: Function) => { 336 const testName = 'sendableImage_createPixelMapSync_abnormal_sendable_promise_001'; 337 const color: ArrayBuffer = new ArrayBuffer(96); 338 const opts: image.InitializationOptions = 339 { editable: false, pixelFormat: image.PixelMapFormat.RGBA_8888, size: { height: 1000, width: 1000 } }; 340 await createPixelMapSyncAbnormalPromiseTest(done, testName, color, opts); 341 })*/ 342 343 /** 344 * @tc.number :SENDABLE_IMAGE_CREATE_PIXEL_MAP_SYNC_017 345 * @tc.name : sendableImage_createPixelMapSync_abnormal_sendable_promise_005 346 * @tc.desc : sendableImage_createPixelMapSync 347 * @tc.size : MEDIUM 348 * @tc.type : Function 349 * @tc.level : Level 0 350 */ 351 /*it('sendableImage_createPixelMapSync_abnormal_sendable_promise_005', Level.LEVEL0, async (done: Function) => { 352 const testName = 'sendableImage_createPixelMapSync_abnormal_sendable_promise_002'; 353 const color: ArrayBuffer = new ArrayBuffer(0); 354 const opts: image.InitializationOptions = 355 { editable: false, pixelFormat: image.PixelMapFormat.RGBA_8888, size: { height: 0, width: 0 } }; 356 await createPixelMapSyncAbnormalPromiseTest(done, testName, color, opts); 357 })*/ 358 }) 359}