idlize
566 строк · 25.9 Кб
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 { pointer, nullptr } from "@koalaui/interop"16import { SerializerBase } from "@arkoala/arkui/SerializerBase"17import { DeserializerBase } from "@arkoala/arkui/DeserializerBase"18import { Serializer } from "@arkoala/arkui/Serializer"19import { Deserializer } from "@arkoala/arkui/Deserializer"20import { wrapCallback, callCallback } from "./callback_registry"21import { ArkButtonPeer } from "@arkoala/arkui/ArkButtonPeer"22import { ArkCommonPeer } from "@arkoala/arkui/ArkCommonPeer"23import { ArkCalendarPickerPeer } from "@arkoala/arkui/ArkCalendarPickerPeer"24import { ArkFormComponentPeer } from "@arkoala/arkui/ArkFormComponentPeer"25import { ArkNavigationPeer } from "@arkoala/arkui/ArkNavigationPeer"26import { ArkSideBarContainerPeer } from "@arkoala/arkui/ArkSidebarPeer"27import { ArkSideBarContainerComponent } from "@arkoala/arkui/ArkSidebar"28import { ArkTabContentPeer } from "@arkoala/arkui/ArkTabContentPeer"29import { SubTabBarStyle } from "@arkoala/arkui/ArkSubTabBarStyleBuilder"30import { CanvasRenderingContext2D } from "@arkoala/arkui/ArkCanvasRenderingContext2DMaterialized"31import { ArkUINodeType } from "@arkoala/arkui/ArkUINodeType"32import { startPerformanceTest } from "@arkoala/arkui/test_performance"33import { testLength_10_lpx } from "@arkoala/arkui/test_data"34import { deserializePeerEvent, PeerEventKind,35CommonMethod_onChildTouchTest_event,36List_onScrollVisibleContentChange_event,37TextPicker_onAccept_event
38} from "./peer_events"39// imports required interfaces (now generation is disabled)
40// import { Resource, BackgroundBlurStyleOptions, TouchTestInfo } from "@arkoala/arkui"
41
42import {43getNativeLog,44reportTestFailures,45checkResult,46checkTestFailures,47startNativeLog,48CALL_GROUP_LOG,49stopNativeLog,50assertEquals,51assertTrue,52assertThrows,53} from "./test_utils"54import { nativeModule } from "@koalaui/arkoala"55import { mkdirSync, writeFileSync } from "fs"56
57
58if (!reportTestFailures) {59console.log("WARNING: ignore test result")60}
61
62const recordCallLog = false63
64function checkSerdeResult(name: string, value: any, expected: any) {65if (value !== expected) {66console.log(`TEST ${name} FAILURE: ${value} != ${expected}`)67} else {68console.log(`TEST ${name} PASS`)69}70}
71
72function checkSerdeBaseLength() {73const ser = new SerializerBase()74ser.writeLength("10px")75ser.writeLength("11vp")76ser.writeLength("12%")77ser.writeLength("13lpx")78ser.writeLength(14)79const des = new DeserializerBase(ser.asArray().buffer, ser.length())80checkSerdeResult("DeserializerBase.readLength, unit px", des.readLength(), "10px")81checkSerdeResult("DeserializerBase.readLength, unit vp", des.readLength(), "11vp")82checkSerdeResult("DeserializerBase.readLength, unit %", des.readLength(), "12%")83checkSerdeResult("DeserializerBase.readLength, unit lpx", des.readLength(), "13lpx")84checkSerdeResult("DeserializerBase.readLength, number", des.readLength(), 14)85}
86
87function checkSerdeBaseText() {88const ser = new SerializerBase()89const text = "test text serialization/deserialization"90ser.writeString(text)91const des = new DeserializerBase(ser.asArray().buffer, ser.length())92checkSerdeResult("DeserializerBase.readString", des.readString(), text)93}
94
95function checkSerdeBasePrimitive() {96const ser = new SerializerBase()97ser.writeNumber(10)98ser.writeNumber(10.5)99ser.writeNumber(undefined)100const des = new DeserializerBase(ser.asArray().buffer, ser.length())101checkSerdeResult("DeserializerBase.readNumber, int", des.readNumber(), 10)102checkSerdeResult("DeserializerBase.readNumber, float", des.readNumber(), 10.5)103checkSerdeResult("DeserializerBase.readNumber, undefined", des.readNumber(), undefined)104}
105
106function checkSerdeBaseCustomObject() {107const ser = new SerializerBase()108const resource: Resource = {109bundleName: "bundle name",110moduleName: "module name",111id: 1,112}113ser.writeCustomObject("Resource", resource)114const des = new DeserializerBase(ser.asArray().buffer, ser.length())115checkSerdeResult("DeserializerBase.readCustomObject, Resource",116JSON.stringify(resource),117JSON.stringify(des.readCustomObject("Resource") as Resource))118}
119
120function checkNodeAPI() {121const ARKUI_TEXT = 1122const id = 12123const flags = 7124let ptr: pointer = nativeModule()._CreateNode(ARKUI_TEXT, id, flags)125
126let stackPtr: pointer = 0127checkResult("BasicNodeAPI getNodeByViewStack",128() => stackPtr = nativeModule()._GetNodeByViewStack(),129`getNodeByViewStack()`130)131assertEquals("BasicNodeAPI getNodeByViewStack result", 234, stackPtr)132
133checkResult("BasicNodeAPI disposeNode",134() => nativeModule()._DisposeNode(ptr),135`disposeNode(0x${ptr})`)136
137checkResult("BasicNodeAPI addChild",138() => nativeModule()._AddChild(ptr, stackPtr),139`addChild(0x${ptr}, 0x234)`140)141
142checkResult("BasicNodeAPI removeChild",143() => nativeModule()._RemoveChild(ptr, stackPtr),144`removeChild(0x${ptr}, 0x234)`145)146
147checkResult("BasicNodeAPI insertChildAfter",148() => nativeModule()._InsertChildAfter(ptr, stackPtr, nullptr),149`insertChildAfter(0x${ptr}, 0x234, 0x0)`150)151
152checkResult("BasicNodeAPI insertChildBefore",153() => nativeModule()._InsertChildBefore(ptr, stackPtr, nullptr),154`insertChildBefore(0x${ptr}, 0x234, 0x0)`155)156
157checkResult("BasicNodeAPI insertChildAt",158() => nativeModule()._InsertChildAt(ptr, stackPtr, 0),159`insertChildAt(0x${ptr}, 0x234, 0)`160)161
162checkResult("BasicNodeAPI applyModifierFinish",163() => nativeModule()._ApplyModifierFinish(ptr),164`applyModifierFinish(0x${ptr})`165)166
167checkResult("BasicNodeAPI markDirty",168() => nativeModule()._MarkDirty(ptr, 123456),169`markDirty(0x${ptr}, 123456)`170)171
172let isBuilderNode = 0173checkResult("BasicNodeAPI isBuilderNode",174() => isBuilderNode = nativeModule()._IsBuilderNode(ptr),175`isBuilderNode(0x${ptr})`176)177assertEquals("BasicNodeAPI isBuilderNode result", 1, isBuilderNode)178
179let length = 0.0180checkResult("BasicNodeAPI convertLengthMetricsUnit",181() => length = nativeModule()._ConvertLengthMetricsUnit(1.23, 10, 0),182`convertLengthMetricsUnit(1.230000, 10, 0)`183)184assertTrue("BasicNodeAPI convertLengthMetricsUnit result", Math.abs(12.3 - length) < 0.00001)185}
186
187function checkCallback() {188
189const id1 = wrapCallback((args, length) => 1001)190const id2 = wrapCallback((args, length) => 1002)191assertTrue("Register callback 1", id1 != -1)192assertTrue("Register callback 2", id2 != -1)193assertTrue("Callback ids are different", id1 != id2)194
195const serializer = new Serializer()196assertEquals("Call callback 1", 1001, callCallback(id1, serializer.asArray(), serializer.length()))197assertEquals("Call callback 2", 1002, callCallback(id2, serializer.asArray(), serializer.length()))198assertThrows("Call disposed callback 1", () => { callCallback(id1, serializer.asArray(), serializer.length()) })199assertThrows("Call disposed callback 2", () => { callCallback(id2, serializer.asArray(), serializer.length()) })200}
201
202function checkWriteFunction() {203const s = new Serializer()204s.writeFunction((value: number, flag: boolean) => flag ? value + 10 : value - 10)205// TBD: id is small number206const id = s.asArray()[0]207const args = new Serializer()208args.writeNumber(20)209args.writeBoolean(true)210// TBD: callCallback() result should be 30211assertEquals("Write function", 42, callCallback(id, args.asArray(), args.length()))212}
213
214function checkButton() {215let peer = new ArkButtonPeer(ArkUINodeType.Button)216
217checkResult("width", () => peer.widthAttribute("42%"),218"width({.type=1, .value=42.000000, .unit=3, .resource=0})")219checkResult("height", () => peer.heightAttribute({ id: 43, bundleName: "MyApp", moduleName: "MyApp" }),220"height({.type=2, .value=0.000000, .unit=1, .resource=43})")221checkResult("bindSheet", () =>222peer.bindSheetAttribute(false, () => {}, {223title: {224title: { id: 43, bundleName: "MyApp", moduleName: "MyApp" }225}226}),227`bindSheet(false, {.selector=0, .value0={.id=4}}, {.tag=ARK_TAG_OBJECT, .value={.backgroundColor={.tag=ARK_TAG_UNDEFINED, .value={}}, .onAppear={.tag=ARK_TAG_UNDEFINED, .value={}}, .onDisappear={.tag=ARK_TAG_UNDEFINED, .value={}}, .onWillAppear={.tag=ARK_TAG_UNDEFINED, .value={}}, .onWillDisappear={.tag=ARK_TAG_UNDEFINED, .value={}}, .height={.tag=ARK_TAG_UNDEFINED, .value={}}, .dragBar={.tag=ARK_TAG_UNDEFINED, .value={}}, .maskColor={.tag=ARK_TAG_UNDEFINED, .value={}}, .detents={.tag=ARK_TAG_UNDEFINED, .value={}}, .blurStyle={.tag=ARK_TAG_UNDEFINED, .value={}}, .showClose={.tag=ARK_TAG_UNDEFINED, .value={}}, .preferType={.tag=ARK_TAG_UNDEFINED, .value={}}, .title={.tag=ARK_TAG_OBJECT, .value={.selector=0, .value0={.title={.selector=1, .value1={.kind="NativeErrorResource", .id=0}}, .subtitle={.tag=ARK_TAG_UNDEFINED, .value={}}}}}, .shouldDismiss={.tag=ARK_TAG_UNDEFINED, .value={}}, .onWillDismiss={.tag=ARK_TAG_UNDEFINED, .value={}}, .onWillSpringBackWhenDismiss={.tag=ARK_TAG_UNDEFINED, .value={}}, .enableOutsideInteractive={.tag=ARK_TAG_UNDEFINED, .value={}}, .width={.tag=ARK_TAG_UNDEFINED, .value={}}, .borderWidth={.tag=ARK_TAG_UNDEFINED, .value={}}, .borderColor={.tag=ARK_TAG_UNDEFINED, .value={}}, .borderStyle={.tag=ARK_TAG_UNDEFINED, .value={}}, .shadow={.tag=ARK_TAG_UNDEFINED, .value={}}, .onHeightDidChange={.tag=ARK_TAG_UNDEFINED, .value={}}, .mode={.tag=ARK_TAG_UNDEFINED, .value={}}, .onDetentsDidChange={.tag=ARK_TAG_UNDEFINED, .value={}}, .onWidthDidChange={.tag=ARK_TAG_UNDEFINED, .value={}}, .onTypeDidChange={.tag=ARK_TAG_UNDEFINED, .value={}}, .uiContext={.tag=ARK_TAG_UNDEFINED, .value={}}}})`228)229checkResult("type", () => peer.typeAttribute(1), "type(1)")230checkResult("labelStyle", () => peer.labelStyleAttribute({maxLines: 3}),231"labelStyle({.overflow={.tag=ARK_TAG_UNDEFINED, .value={}}, .maxLines={.tag=ARK_TAG_OBJECT, .value={.tag=102, .i32=3}}, .minFontSize={.tag=ARK_TAG_UNDEFINED, .value={}}, .maxFontSize={.tag=ARK_TAG_UNDEFINED, .value={}}, .heightAdaptivePolicy={.tag=ARK_TAG_UNDEFINED, .value={}}, .font={.tag=ARK_TAG_UNDEFINED, .value={}}})")232checkResult("labelStyle2", () => peer.labelStyleAttribute({}),233"labelStyle({.overflow={.tag=ARK_TAG_UNDEFINED, .value={}}, .maxLines={.tag=ARK_TAG_UNDEFINED, .value={}}, .minFontSize={.tag=ARK_TAG_UNDEFINED, .value={}}, .maxFontSize={.tag=ARK_TAG_UNDEFINED, .value={}}, .heightAdaptivePolicy={.tag=ARK_TAG_UNDEFINED, .value={}}, .font={.tag=ARK_TAG_UNDEFINED, .value={}}})")234//nativeModule()._MeausureLayoutAndDraw(peer.peer.ptr)235assertTrue("ButtonPeer finalizer", peer!.peer!.finalizer != nullptr)236}
237
238function checkCalendar() {239let peer = new ArkCalendarPickerPeer(ArkUINodeType.CalendarPicker)240checkResult("edgeAlign1", () => peer.edgeAlignAttribute(2, {dx: 5, dy: 6}),241`edgeAlign(2, {.tag=ARK_TAG_OBJECT, .value={.dx={.type=1, .value=5.000000, .unit=1, .resource=0}, .dy={.type=1, .value=6.000000, .unit=1, .resource=0}}})`)242checkResult("edgeAlign2", () => peer.edgeAlignAttribute(2),243`edgeAlign(2, {.tag=ARK_TAG_UNDEFINED, .value={}})`)244}
245
246function checkFormComponent() {247let peer = new ArkFormComponentPeer(ArkUINodeType.FormComponent)248checkResult("size int", () => peer.sizeAttribute({width: 5, height: 6}),249`size({.width={.tag=102, .i32=5}, .height={.tag=102, .i32=6}})`)250checkResult("size float", () => peer.sizeAttribute({width: 5.5, height: 6.789}),251`size({.width={.tag=103, .f32=5.50}, .height={.tag=103, .f32=6.78}})`)252checkResult("size zero", () => peer.sizeAttribute({width: 0.0, height: 0.0}),253`size({.width={.tag=102, .i32=0}, .height={.tag=102, .i32=0}})`)254}
255
256function checkCommon() {257let peer = new ArkCommonPeer(ArkUINodeType.Common)258// check backgroundBlurStyle and check the heritance by the way259let backgroundBlurStyle: BackgroundBlurStyleOptions = {260colorMode: 0,261adaptiveColor: 0,262scale: 1,263blurOptions: {264grayscale: [1, 1]265}266}267checkResult("Test backgroundBlurStyle for BackgroundBlurStyleOptions",268() => peer.backgroundBlurStyleAttribute(0, backgroundBlurStyle),269`backgroundBlurStyle(0, {.tag=ARK_TAG_OBJECT, .value={.colorMode={.tag=ARK_TAG_OBJECT, .value=0}, .adaptiveColor={.tag=ARK_TAG_OBJECT, .value=0}, .scale={.tag=ARK_TAG_OBJECT, .value={.tag=102, .i32=1}}, .blurOptions={.tag=ARK_TAG_OBJECT, .value={.grayscale={.value0={.tag=102, .i32=1}, .value1={.tag=102, .i32=1}}}}}})`270)271
272checkResult("Test dragPreviewOptions numberBadge with number",273() => peer.dragPreviewOptionsAttribute({numberBadge: 10}, {isMultiSelectionEnabled: true}),274`dragPreviewOptions({.mode={.tag=ARK_TAG_UNDEFINED, .value={}}, .modifier={.tag=ARK_TAG_UNDEFINED, .value={}}, .numberBadge={.tag=ARK_TAG_OBJECT, .value={.selector=1, .value1={.tag=102, .i32=10}}}}, {.tag=ARK_TAG_OBJECT, .value={.isMultiSelectionEnabled={.tag=ARK_TAG_OBJECT, .value=true}, .defaultAnimationBeforeLifting={.tag=ARK_TAG_UNDEFINED, .value={}}}})`275)276
277checkResult("Test dragPreviewOptions numberBadge with boolean",278() => peer.dragPreviewOptionsAttribute({numberBadge: true}, {defaultAnimationBeforeLifting: false}),279`dragPreviewOptions({.mode={.tag=ARK_TAG_UNDEFINED, .value={}}, .modifier={.tag=ARK_TAG_UNDEFINED, .value={}}, .numberBadge={.tag=ARK_TAG_OBJECT, .value={.selector=0, .value0=true}}}, {.tag=ARK_TAG_OBJECT, .value={.isMultiSelectionEnabled={.tag=ARK_TAG_UNDEFINED, .value={}}, .defaultAnimationBeforeLifting={.tag=ARK_TAG_OBJECT, .value=false}}})`280)281}
282
283class ArkSideBarContainerComponentTest extends ArkSideBarContainerComponent {284constructor(peer: ArkSideBarContainerPeer) {285super()286this.peer = peer287}288
289override checkPriority(name: string) {290return true291}292}
293
294function checkOverloads() {295const peer = new ArkSideBarContainerPeer(ArkUINodeType.SideBarContainer)296const component = new ArkSideBarContainerComponentTest(peer)297checkResult("Test number implementation for SideBarContainer.minSideBarWidth",298() => component.minSideBarWidth(11),299`minSideBarWidth({.tag=102, .i32=11})`300)301checkResult("Test string implementation for SideBarContainer.minSideBarWidth",302() => component.minSideBarWidth("42%"),303`minSideBarWidth({.type=1, .value=42.000000, .unit=3, .resource=0})`304)305}
306
307function checkNavigation() {308let peer = new ArkNavigationPeer(ArkUINodeType.Navigation)309checkResult("backButtonIcon", () => peer.backButtonIconAttribute("attr"),310`backButtonIcon({.selector=0, .value0={.chars="attr", .length=4}})`)311}
312
313function checkTabContent() {314let peer = new ArkTabContentPeer(ArkUINodeType.TabContent)315
316let subTabBarStyle: SubTabBarStyle = new SubTabBarStyle("Resource").id("testID")317assertEquals("SubTabBarStyle id", "testID", subTabBarStyle._id)318
319// TBD: Check that id field is passed to native320checkResult("new SubTabBarStyle()",321() => peer.tabBar_SubTabBarStyleBottomTabBarStyleAttribute(subTabBarStyle = new SubTabBarStyle("abc")),322`tabBar({.selector=0, .value0={._indicator={.tag=ARK_TAG_UNDEFINED, .value={}}, ._selectedMode={.tag=ARK_TAG_UNDEFINED, .value={}}, ._board={.tag=ARK_TAG_UNDEFINED, .value={}}, ._labelStyle={.tag=ARK_TAG_UNDEFINED, .value={}}, ._padding={.tag=ARK_TAG_UNDEFINED, .value={}}, ._id={.tag=ARK_TAG_UNDEFINED, .value={}}}})`)323
324
325// TBD: check SubTabBarStyle is created from static method326// subTabBarStyle = SubTabBarStyle.of("Resource2")327}
328
329function checkCanvasRenderingContext2D() {330
331let canvasRenderingContext2D: CanvasRenderingContext2D | undefined = undefined332
333checkResult("new CanvasRenderingContext2D()",334() => canvasRenderingContext2D = new CanvasRenderingContext2D(),335"new CanvasPath()[return (void*) 100]getFinalizer()[return fnPtr<KNativePointer>(dummyClassFinalizer)]" +336"new CanvasRenderer()[return (void*) 100]getFinalizer()[return fnPtr<KNativePointer>(dummyClassFinalizer)]" +337"new CanvasRenderingContext2D({.tag=ARK_TAG_UNDEFINED, .value={}})[return (void*) 100]getFinalizer()[return fnPtr<KNativePointer>(dummyClassFinalizer)]")338
339checkResult("CanvasRenderingContext2D width",340() => canvasRenderingContext2D!.width,341`getWidth()`)342
343checkResult("CanvasRenderingContext2D width",344() => canvasRenderingContext2D!.height,345`getHeight()`)346
347assertEquals("CanvasRenderingContext2D width", 0, canvasRenderingContext2D!.width)348assertEquals("CanvasRenderingContext2D height", 0, canvasRenderingContext2D!.height)349
350checkResult("CanvasRenderingContext2D peer close()",351() => canvasRenderingContext2D!.peer!.close(),352`dummyClassFinalizer(0x64)`)353}
354
355function checkPerf1(count: number) {356let module = nativeModule()357let start = performance.now()358for (let i = 0; i < count; i++) {359module._TestPerfNumber(i)360}361let passed = performance.now() - start362console.log(`NUMBER: ${passed}ms for ${count} iteration, ${Math.round(passed / count * 1000000)}ms per 1M iterations`)363
364start = performance.now()365for (let i = 0; i < count; i++) {366let serializer = new SerializerBase()367serializer.writeNumber(0)368let data = serializer.asArray()369module._TestPerfNumberWithArray(data, data.length)370}371passed = performance.now() - start372console.log(`ARRAY: ${passed}ms for ${Math.round(count)} iteration, ${Math.round(passed / count * 1000000)}ms per 1M iterations`)373}
374
375function checkPerf2(count: number) {376let peer = new ArkButtonPeer(ArkUINodeType.Button)377let start = performance.now()378for (let i = 0; i < count; i++) {379peer.backdropBlurAttribute(i, i % 2 == 0 ? undefined : {grayscale: [1, 2]})380}381let passed = performance.now() - start382console.log(`backdropBlur: ${Math.round(passed)}ms for ${count} iteration, ${Math.round(passed / count * 1000000)}ms per 1M iterations`)383}
384
385function checkPerf3(count: number) {386let peer = new ArkButtonPeer(ArkUINodeType.Button)387let start = performance.now()388for (let i = 0; i < count; i++) {389peer.widthAttribute(testLength_10_lpx)390}391let passed = performance.now() - start392console.log(`widthAttributeString: ${Math.round(passed)}ms for ${count} iteration, ${Math.round(passed / count * 1000000)}ms per 1M iterations`)393}
394
395function setEventsAPI() {396nativeModule()._Test_SetEventsApi()397}
398
399function checkEvent_Primitive() {400const BufferSize = 60 * 4401const serializer = new SerializerBase()402serializer.writeInt32(1) //nodeId403serializer.writeString("testString") //arg1404serializer.writeNumber(22) //arg2405nativeModule()._Test_TextPicker_OnAccept(serializer.asArray(), serializer.length())406
407const buffer = new Uint8Array(BufferSize)408const checkResult = nativeModule()._CheckArkoalaGeneratedEvents(buffer, BufferSize)409const event = deserializePeerEvent(new Deserializer(buffer.buffer, BufferSize))410assertEquals("Event_Primitive: read event from native", 1, checkResult)411if (checkResult !== 1)412return413
414assertEquals("Event_Primitive: valid kind", PeerEventKind.TextPicker_onAccept, event.kind)415if (event.kind !== PeerEventKind.TextPicker_onAccept)416return417
418const convertedEvent = event as TextPicker_onAccept_event419assertEquals("Event_Primitive: string argument", "testString", convertedEvent.value)420assertEquals("Event_Primitive: number argument", 22, convertedEvent.index)421}
422
423function checkEvent_Interface_Optional() {424const bufferSize = 60 * 4425const serializer = new Serializer()426const eventStart = { index: 11, itemIndexInGroup: 1 }427const eventEnd = { index: 22 }428serializer.writeInt32(1) //nodeId429serializer.writeVisibleListContentInfo(eventStart);430serializer.writeVisibleListContentInfo(eventEnd);431nativeModule()._Test_List_OnScrollVisibleContentChange(serializer.asArray(), serializer.length())432
433const buffer = new Uint8Array(bufferSize)434const checkResult = nativeModule()._CheckArkoalaGeneratedEvents(buffer, bufferSize)435const event = deserializePeerEvent(new Deserializer(buffer.buffer, bufferSize))436assertEquals("Event_Interface_Optional: read event from native", 1, checkResult)437if (checkResult !== 1)438return439
440assertEquals("Event_Interface_Optional: valid kind", PeerEventKind.List_onScrollVisibleContentChange, event.kind)441if (event.kind !== PeerEventKind.List_onScrollVisibleContentChange)442return443
444const convertedEvent = event as List_onScrollVisibleContentChange_event445assertEquals("Event_Interface_Optional: start.index", eventStart.index, convertedEvent.start.index)446assertEquals("Event_Interface_Optional: start.itemIndexInGroup", eventStart.itemIndexInGroup, convertedEvent.start.itemIndexInGroup)447assertEquals("Event_Interface_Optional: end.index", eventEnd.index, convertedEvent.end.index)448assertEquals("Event_Interface_Optional: end.itemIndexInGroup", undefined, convertedEvent.end.itemIndexInGroup)449}
450
451function checkEvent_Array_Class() {452const bufferSize = 60 * 4453const serializer = new Serializer()454const eventParam: TouchTestInfo[] = [455{ windowX: 10, windowY: 11, parentX: 12, parentY: 13, x: 14, y: 15, id: "one",456rect: { x: 100, y: 101, width: 102, height: 103 } },457{ windowX: 20, windowY: 21, parentX: 22, parentY: 23, x: 24, y: 25, id: "two",458rect: { x: 200, y: 201, width: 202, height: 203 } },459{ windowX: 30, windowY: 31, parentX: 32, parentY: 33, x: 34, y: 35, id: "three",460rect: { x: 300, y: 301, width: 302, height: 303 } }]461serializer.writeInt32(1) // nodeId462serializer.writeInt8(3) // RuntimeType.OBJECT463serializer.writeInt32(eventParam.length);464for (let i = 0; i < eventParam.length; i++) {465serializer.writeTouchTestInfo(eventParam[i]);466}467nativeModule()._Test_Common_OnChildTouchTest(serializer.asArray(), serializer.length())468
469const buffer = new Uint8Array(bufferSize)470const checkResult = nativeModule()._CheckArkoalaGeneratedEvents(buffer, bufferSize)471const event = deserializePeerEvent(new Deserializer(buffer.buffer, bufferSize))472assertEquals("Event_Array_Class: read event from native", 1, checkResult)473if (checkResult !== 1)474return475
476assertEquals("Event_Array_Class: valid kind", PeerEventKind.CommonMethod_onChildTouchTest, event.kind)477if (event.kind !== PeerEventKind.CommonMethod_onChildTouchTest)478return479
480const convertedEvent = event as CommonMethod_onChildTouchTest_event481const checkTouchTestInfo = (expected: TouchTestInfo, actual: TouchTestInfo) =>482expected.x === actual.x && expected.y === actual.y &&483expected.rect.x === actual.rect.x && expected.rect.y === actual.rect.y &&484expected.rect.width === actual.rect.width && expected.rect.height === actual.rect.height &&485expected.id === actual.id486assertEquals("Event_Array_Class: array length", eventParam.length, convertedEvent.value.length)487for (let i = 0; i < eventParam.length; i++) {488assertTrue(`Event_Array_Class: element ${i}`, checkTouchTestInfo(eventParam[i], convertedEvent.value[i]))489}490}
491checkSerdeBaseLength()492checkSerdeBaseText()493checkSerdeBasePrimitive()494checkSerdeBaseCustomObject()495
496checkPerf2(5 * 1000 * 1000)497checkPerf3(5 * 1000 * 1000)498
499startPerformanceTest()500if (recordCallLog) startNativeLog(CALL_GROUP_LOG)501checkNodeAPI()502checkCallback()503checkWriteFunction()504checkButton()505checkCalendar()506//checkDTS()
507checkFormComponent()508checkCommon()509checkOverloads()510checkNavigation()511setEventsAPI()512checkEvent_Primitive()513checkEvent_Interface_Optional()514checkEvent_Array_Class()515if (recordCallLog) stopNativeLog(CALL_GROUP_LOG)516
517const callGroupLog = getNativeLog(CALL_GROUP_LOG)518const callLogCppCode = `519/*
520* Copyright (c) 2024 Huawei Device Co., Ltd.
521* Licensed under the Apache License, Version 2.0 (the "License");
522* you may not use this file except in compliance with the License.
523* You may obtain a copy of the License at
524*
525* http://www.apache.org/licenses/LICENSE-2.0
526*
527* Unless required by applicable law or agreed to in writing, software
528* distributed under the License is distributed on an "AS IS" BASIS,
529* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
530* See the License for the specific language governing permissions and
531* limitations under the License.
532*/
533#include "arkoala_api_generated.h"
534#include "arkoala-macros.h"
535
536#include <map>
537#include <string>
538
539namespace OHOS::Ace::NG::GeneratedModifier {
540EXTERN_C IDLIZE_API_EXPORT const GENERATED_ArkUIAnyAPI* GENERATED_GetArkAnyAPI(GENERATED_Ark_APIVariantKind kind, int version);
541}
542
543const GENERATED_ArkUINodeModifiers* GetNodeModifiers() {
544static const auto val = (const GENERATED_ArkUIFullNodeAPI*)(OHOS::Ace::NG::GeneratedModifier::GENERATED_GetArkAnyAPI(GENERATED_FULL,GENERATED_ARKUI_FULL_API_VERSION));
545return val->getNodeModifiers();
546}
547
548const GENERATED_ArkUIBasicNodeAPI* GetBasicNodeApi() {
549static const auto val = (const GENERATED_ArkUIBasicNodeAPI*)OHOS::Ace::NG::GeneratedModifier::GENERATED_GetArkAnyAPI(GENERATED_BASIC, GENERATED_ARKUI_BASIC_NODE_API_VERSION);
550return val;
551}
552
553int main(int argc, const char** argv) {
554${callGroupLog}555return 0;
556}`557if (callGroupLog.length > 0) {558console.log(callLogCppCode)559mkdirSync('./generated/call_log', {recursive: true})560writeFileSync('./generated/call_log/main.cpp', callLogCppCode)561}
562checkTabContent()563checkCanvasRenderingContext2D()564
565// Report in error code.
566checkTestFailures()567