idlize

Форк
0
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
 */
15
import { pointer, nullptr } from "@koalaui/interop"
16
import { SerializerBase } from "@arkoala/arkui/SerializerBase"
17
import { DeserializerBase } from "@arkoala/arkui/DeserializerBase"
18
import { Serializer } from "@arkoala/arkui/Serializer"
19
import { Deserializer } from "@arkoala/arkui/Deserializer"
20
import { wrapCallback, callCallback } from "./callback_registry"
21
import { ArkButtonPeer } from "@arkoala/arkui/ArkButtonPeer"
22
import { ArkCommonPeer } from "@arkoala/arkui/ArkCommonPeer"
23
import { ArkCalendarPickerPeer } from "@arkoala/arkui/ArkCalendarPickerPeer"
24
import { ArkFormComponentPeer } from "@arkoala/arkui/ArkFormComponentPeer"
25
import { ArkNavigationPeer } from "@arkoala/arkui/ArkNavigationPeer"
26
import { ArkSideBarContainerPeer } from "@arkoala/arkui/ArkSidebarPeer"
27
import { ArkSideBarContainerComponent } from "@arkoala/arkui/ArkSidebar"
28
import { ArkTabContentPeer } from "@arkoala/arkui/ArkTabContentPeer"
29
import { SubTabBarStyle } from "@arkoala/arkui/ArkSubTabBarStyleBuilder"
30
import { CanvasRenderingContext2D } from "@arkoala/arkui/ArkCanvasRenderingContext2DMaterialized"
31
import { ArkUINodeType } from "@arkoala/arkui/ArkUINodeType"
32
import { startPerformanceTest } from "@arkoala/arkui/test_performance"
33
import { testLength_10_lpx } from "@arkoala/arkui/test_data"
34
import { deserializePeerEvent, PeerEventKind,
35
    CommonMethod_onChildTouchTest_event,
36
    List_onScrollVisibleContentChange_event,
37
    TextPicker_onAccept_event
38
} from "./peer_events"
39
// imports required interfaces (now generation is disabled)
40
// import { Resource, BackgroundBlurStyleOptions, TouchTestInfo } from "@arkoala/arkui"
41

42
import {
43
    getNativeLog,
44
    reportTestFailures,
45
    checkResult,
46
    checkTestFailures,
47
    startNativeLog,
48
    CALL_GROUP_LOG,
49
    stopNativeLog,
50
    assertEquals,
51
    assertTrue,
52
    assertThrows,
53
} from "./test_utils"
54
import { nativeModule } from "@koalaui/arkoala"
55
import { mkdirSync, writeFileSync } from "fs"
56

57

58
if (!reportTestFailures) {
59
    console.log("WARNING: ignore test result")
60
}
61

62
const recordCallLog = false
63

64
function checkSerdeResult(name: string, value: any, expected: any) {
65
    if (value !== expected) {
66
        console.log(`TEST ${name} FAILURE: ${value} != ${expected}`)
67
    } else {
68
        console.log(`TEST ${name} PASS`)
69
    }
70
}
71

72
function checkSerdeBaseLength() {
73
    const ser = new SerializerBase()
74
    ser.writeLength("10px")
75
    ser.writeLength("11vp")
76
    ser.writeLength("12%")
77
    ser.writeLength("13lpx")
78
    ser.writeLength(14)
79
    const des = new DeserializerBase(ser.asArray().buffer, ser.length())
80
    checkSerdeResult("DeserializerBase.readLength, unit px", des.readLength(), "10px")
81
    checkSerdeResult("DeserializerBase.readLength, unit vp", des.readLength(), "11vp")
82
    checkSerdeResult("DeserializerBase.readLength, unit %", des.readLength(), "12%")
83
    checkSerdeResult("DeserializerBase.readLength, unit lpx", des.readLength(), "13lpx")
84
    checkSerdeResult("DeserializerBase.readLength, number", des.readLength(), 14)
85
}
86

87
function checkSerdeBaseText() {
88
    const ser = new SerializerBase()
89
    const text = "test text serialization/deserialization"
90
    ser.writeString(text)
91
    const des = new DeserializerBase(ser.asArray().buffer, ser.length())
92
    checkSerdeResult("DeserializerBase.readString", des.readString(), text)
93
}
94

95
function checkSerdeBasePrimitive() {
96
    const ser = new SerializerBase()
97
    ser.writeNumber(10)
98
    ser.writeNumber(10.5)
99
    ser.writeNumber(undefined)
100
    const des = new DeserializerBase(ser.asArray().buffer, ser.length())
101
    checkSerdeResult("DeserializerBase.readNumber, int", des.readNumber(), 10)
102
    checkSerdeResult("DeserializerBase.readNumber, float", des.readNumber(), 10.5)
103
    checkSerdeResult("DeserializerBase.readNumber, undefined", des.readNumber(), undefined)
104
}
105

106
function checkSerdeBaseCustomObject() {
107
    const ser = new SerializerBase()
108
    const resource: Resource = {
109
        bundleName: "bundle name",
110
        moduleName: "module name",
111
        id: 1,
112
    }
113
    ser.writeCustomObject("Resource", resource)
114
    const des = new DeserializerBase(ser.asArray().buffer, ser.length())
115
    checkSerdeResult("DeserializerBase.readCustomObject, Resource",
116
        JSON.stringify(resource),
117
        JSON.stringify(des.readCustomObject("Resource") as Resource))
118
}
119

120
function checkNodeAPI() {
121
    const ARKUI_TEXT = 1
122
    const id = 12
123
    const flags = 7
124
    let ptr: pointer = nativeModule()._CreateNode(ARKUI_TEXT, id, flags)
125

126
    let stackPtr: pointer = 0
127
    checkResult("BasicNodeAPI getNodeByViewStack",
128
        () => stackPtr = nativeModule()._GetNodeByViewStack(),
129
        `getNodeByViewStack()`
130
    )
131
    assertEquals("BasicNodeAPI getNodeByViewStack result", 234, stackPtr)
132

133
    checkResult("BasicNodeAPI disposeNode",
134
        () => nativeModule()._DisposeNode(ptr),
135
        `disposeNode(0x${ptr})`)
136

137
    checkResult("BasicNodeAPI addChild",
138
        () => nativeModule()._AddChild(ptr, stackPtr),
139
        `addChild(0x${ptr}, 0x234)`
140
    )
141

142
    checkResult("BasicNodeAPI removeChild",
143
        () => nativeModule()._RemoveChild(ptr, stackPtr),
144
        `removeChild(0x${ptr}, 0x234)`
145
    )
146

147
    checkResult("BasicNodeAPI insertChildAfter",
148
        () => nativeModule()._InsertChildAfter(ptr, stackPtr, nullptr),
149
        `insertChildAfter(0x${ptr}, 0x234, 0x0)`
150
    )
151

152
    checkResult("BasicNodeAPI insertChildBefore",
153
        () => nativeModule()._InsertChildBefore(ptr, stackPtr, nullptr),
154
        `insertChildBefore(0x${ptr}, 0x234, 0x0)`
155
    )
156

157
    checkResult("BasicNodeAPI insertChildAt",
158
        () => nativeModule()._InsertChildAt(ptr, stackPtr, 0),
159
        `insertChildAt(0x${ptr}, 0x234, 0)`
160
    )
161

162
    checkResult("BasicNodeAPI applyModifierFinish",
163
        () => nativeModule()._ApplyModifierFinish(ptr),
164
        `applyModifierFinish(0x${ptr})`
165
    )
166

167
    checkResult("BasicNodeAPI markDirty",
168
        () => nativeModule()._MarkDirty(ptr, 123456),
169
        `markDirty(0x${ptr}, 123456)`
170
    )
171

172
    let isBuilderNode = 0
173
    checkResult("BasicNodeAPI isBuilderNode",
174
        () => isBuilderNode = nativeModule()._IsBuilderNode(ptr),
175
        `isBuilderNode(0x${ptr})`
176
    )
177
    assertEquals("BasicNodeAPI isBuilderNode result", 1, isBuilderNode)
178

179
    let length = 0.0
180
    checkResult("BasicNodeAPI convertLengthMetricsUnit",
181
        () => length = nativeModule()._ConvertLengthMetricsUnit(1.23, 10, 0),
182
        `convertLengthMetricsUnit(1.230000, 10, 0)`
183
    )
184
    assertTrue("BasicNodeAPI convertLengthMetricsUnit result", Math.abs(12.3 - length) < 0.00001)
185
}
186

187
function checkCallback() {
188

189
    const id1 = wrapCallback((args, length) => 1001)
190
    const id2 = wrapCallback((args, length) => 1002)
191
    assertTrue("Register callback 1", id1 != -1)
192
    assertTrue("Register callback 2", id2 != -1)
193
    assertTrue("Callback ids are different", id1 != id2)
194

195
    const serializer = new Serializer()
196
    assertEquals("Call callback 1", 1001, callCallback(id1, serializer.asArray(), serializer.length()))
197
    assertEquals("Call callback 2", 1002, callCallback(id2, serializer.asArray(), serializer.length()))
198
    assertThrows("Call disposed callback 1", () => { callCallback(id1, serializer.asArray(), serializer.length()) })
199
    assertThrows("Call disposed callback 2", () => { callCallback(id2, serializer.asArray(), serializer.length()) })
200
}
201

202
function checkWriteFunction() {
203
    const s = new Serializer()
204
    s.writeFunction((value: number, flag: boolean) => flag ? value + 10 : value - 10)
205
    // TBD: id is small number
206
    const id = s.asArray()[0]
207
    const args = new Serializer()
208
    args.writeNumber(20)
209
    args.writeBoolean(true)
210
    // TBD: callCallback() result should be 30
211
    assertEquals("Write function", 42, callCallback(id, args.asArray(), args.length()))
212
}
213

214
function checkButton() {
215
    let peer = new ArkButtonPeer(ArkUINodeType.Button)
216

217
    checkResult("width", () => peer.widthAttribute("42%"),
218
        "width({.type=1, .value=42.000000, .unit=3, .resource=0})")
219
    checkResult("height", () => peer.heightAttribute({ id: 43, bundleName: "MyApp", moduleName: "MyApp" }),
220
        "height({.type=2, .value=0.000000, .unit=1, .resource=43})")
221
    checkResult("bindSheet", () =>
222
        peer.bindSheetAttribute(false, () => {}, {
223
            title: {
224
                title: { 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
    )
229
    checkResult("type", () => peer.typeAttribute(1), "type(1)")
230
    checkResult("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={}}})")
232
    checkResult("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)
235
    assertTrue("ButtonPeer finalizer", peer!.peer!.finalizer != nullptr)
236
}
237

238
function checkCalendar() {
239
    let peer = new ArkCalendarPickerPeer(ArkUINodeType.CalendarPicker)
240
    checkResult("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}}})`)
242
    checkResult("edgeAlign2", () => peer.edgeAlignAttribute(2),
243
        `edgeAlign(2, {.tag=ARK_TAG_UNDEFINED, .value={}})`)
244
}
245

246
function checkFormComponent() {
247
    let peer = new ArkFormComponentPeer(ArkUINodeType.FormComponent)
248
    checkResult("size int", () => peer.sizeAttribute({width: 5, height: 6}),
249
        `size({.width={.tag=102, .i32=5}, .height={.tag=102, .i32=6}})`)
250
    checkResult("size float", () => peer.sizeAttribute({width: 5.5, height: 6.789}),
251
        `size({.width={.tag=103, .f32=5.50}, .height={.tag=103, .f32=6.78}})`)
252
    checkResult("size zero", () => peer.sizeAttribute({width: 0.0, height: 0.0}),
253
        `size({.width={.tag=102, .i32=0}, .height={.tag=102, .i32=0}})`)
254
}
255

256
function checkCommon() {
257
    let peer = new ArkCommonPeer(ArkUINodeType.Common)
258
    // check backgroundBlurStyle and check the heritance by the way
259
    let backgroundBlurStyle: BackgroundBlurStyleOptions = {
260
        colorMode: 0,
261
        adaptiveColor: 0,
262
        scale: 1,
263
        blurOptions: {
264
            grayscale: [1, 1]
265
        }
266
    }
267
    checkResult("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

272
    checkResult("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

277
    checkResult("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

283
class ArkSideBarContainerComponentTest extends ArkSideBarContainerComponent {
284
    constructor(peer: ArkSideBarContainerPeer) {
285
        super()
286
        this.peer = peer
287
    }
288

289
    override checkPriority(name: string) {
290
        return true
291
    }
292
}
293

294
function checkOverloads() {
295
    const peer = new ArkSideBarContainerPeer(ArkUINodeType.SideBarContainer)
296
    const component = new ArkSideBarContainerComponentTest(peer)
297
    checkResult("Test number implementation for SideBarContainer.minSideBarWidth",
298
        () => component.minSideBarWidth(11),
299
        `minSideBarWidth({.tag=102, .i32=11})`
300
    )
301
    checkResult("Test string implementation for SideBarContainer.minSideBarWidth",
302
        () => component.minSideBarWidth("42%"),
303
        `minSideBarWidth({.type=1, .value=42.000000, .unit=3, .resource=0})`
304
    )
305
}
306

307
function checkNavigation() {
308
    let peer = new ArkNavigationPeer(ArkUINodeType.Navigation)
309
    checkResult("backButtonIcon", () => peer.backButtonIconAttribute("attr"),
310
        `backButtonIcon({.selector=0, .value0={.chars="attr", .length=4}})`)
311
}
312

313
function checkTabContent() {
314
    let peer = new ArkTabContentPeer(ArkUINodeType.TabContent)
315

316
    let subTabBarStyle: SubTabBarStyle = new SubTabBarStyle("Resource").id("testID")
317
    assertEquals("SubTabBarStyle id", "testID", subTabBarStyle._id)
318

319
    // TBD: Check that id field is passed to native
320
    checkResult("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 method
326
    // subTabBarStyle = SubTabBarStyle.of("Resource2")
327
}
328

329
function checkCanvasRenderingContext2D() {
330

331
    let canvasRenderingContext2D: CanvasRenderingContext2D | undefined = undefined
332

333
    checkResult("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

339
    checkResult("CanvasRenderingContext2D width",
340
        () => canvasRenderingContext2D!.width,
341
        `getWidth()`)
342

343
    checkResult("CanvasRenderingContext2D width",
344
        () => canvasRenderingContext2D!.height,
345
        `getHeight()`)
346

347
    assertEquals("CanvasRenderingContext2D width", 0, canvasRenderingContext2D!.width)
348
    assertEquals("CanvasRenderingContext2D height", 0, canvasRenderingContext2D!.height)
349

350
    checkResult("CanvasRenderingContext2D peer close()",
351
        () => canvasRenderingContext2D!.peer!.close(),
352
        `dummyClassFinalizer(0x64)`)
353
}
354

355
function checkPerf1(count: number) {
356
    let module = nativeModule()
357
    let start = performance.now()
358
    for (let i = 0; i < count; i++) {
359
        module._TestPerfNumber(i)
360
    }
361
    let passed = performance.now() - start
362
    console.log(`NUMBER: ${passed}ms for ${count} iteration, ${Math.round(passed / count * 1000000)}ms per 1M iterations`)
363

364
    start = performance.now()
365
    for (let i = 0; i < count; i++) {
366
        let serializer = new SerializerBase()
367
        serializer.writeNumber(0)
368
        let data = serializer.asArray()
369
        module._TestPerfNumberWithArray(data, data.length)
370
    }
371
    passed = performance.now() - start
372
    console.log(`ARRAY: ${passed}ms for ${Math.round(count)} iteration, ${Math.round(passed / count * 1000000)}ms per 1M iterations`)
373
}
374

375
function checkPerf2(count: number) {
376
    let peer = new ArkButtonPeer(ArkUINodeType.Button)
377
    let start = performance.now()
378
    for (let i = 0; i < count; i++) {
379
        peer.backdropBlurAttribute(i, i % 2 == 0 ? undefined : {grayscale: [1, 2]})
380
    }
381
    let passed = performance.now() - start
382
    console.log(`backdropBlur: ${Math.round(passed)}ms for ${count} iteration, ${Math.round(passed / count * 1000000)}ms per 1M iterations`)
383
}
384

385
function checkPerf3(count: number) {
386
    let peer = new ArkButtonPeer(ArkUINodeType.Button)
387
    let start = performance.now()
388
    for (let i = 0; i < count; i++) {
389
        peer.widthAttribute(testLength_10_lpx)
390
    }
391
    let passed = performance.now() - start
392
    console.log(`widthAttributeString: ${Math.round(passed)}ms for ${count} iteration, ${Math.round(passed / count * 1000000)}ms per 1M iterations`)
393
}
394

395
function setEventsAPI() {
396
    nativeModule()._Test_SetEventsApi()
397
}
398

399
function checkEvent_Primitive() {
400
    const BufferSize = 60 * 4
401
    const serializer = new SerializerBase()
402
    serializer.writeInt32(1) //nodeId
403
    serializer.writeString("testString") //arg1
404
    serializer.writeNumber(22) //arg2
405
    nativeModule()._Test_TextPicker_OnAccept(serializer.asArray(), serializer.length())
406

407
    const buffer = new Uint8Array(BufferSize)
408
    const checkResult = nativeModule()._CheckArkoalaGeneratedEvents(buffer, BufferSize)
409
    const event = deserializePeerEvent(new Deserializer(buffer.buffer, BufferSize))
410
    assertEquals("Event_Primitive: read event from native", 1, checkResult)
411
    if (checkResult !== 1)
412
        return
413

414
    assertEquals("Event_Primitive: valid kind", PeerEventKind.TextPicker_onAccept, event.kind)
415
    if (event.kind !== PeerEventKind.TextPicker_onAccept)
416
        return
417

418
    const convertedEvent = event as TextPicker_onAccept_event
419
    assertEquals("Event_Primitive: string argument", "testString", convertedEvent.value)
420
    assertEquals("Event_Primitive: number argument", 22, convertedEvent.index)
421
}
422

423
function checkEvent_Interface_Optional() {
424
    const bufferSize = 60 * 4
425
    const serializer = new Serializer()
426
    const eventStart = { index: 11, itemIndexInGroup: 1 }
427
    const eventEnd = { index: 22 }
428
    serializer.writeInt32(1) //nodeId
429
    serializer.writeVisibleListContentInfo(eventStart);
430
    serializer.writeVisibleListContentInfo(eventEnd);
431
    nativeModule()._Test_List_OnScrollVisibleContentChange(serializer.asArray(), serializer.length())
432

433
    const buffer = new Uint8Array(bufferSize)
434
    const checkResult = nativeModule()._CheckArkoalaGeneratedEvents(buffer, bufferSize)
435
    const event = deserializePeerEvent(new Deserializer(buffer.buffer, bufferSize))
436
    assertEquals("Event_Interface_Optional: read event from native", 1, checkResult)
437
    if (checkResult !== 1)
438
        return
439

440
    assertEquals("Event_Interface_Optional: valid kind", PeerEventKind.List_onScrollVisibleContentChange, event.kind)
441
    if (event.kind !== PeerEventKind.List_onScrollVisibleContentChange)
442
        return
443

444
    const convertedEvent = event as List_onScrollVisibleContentChange_event
445
    assertEquals("Event_Interface_Optional: start.index", eventStart.index, convertedEvent.start.index)
446
    assertEquals("Event_Interface_Optional: start.itemIndexInGroup", eventStart.itemIndexInGroup, convertedEvent.start.itemIndexInGroup)
447
    assertEquals("Event_Interface_Optional: end.index", eventEnd.index, convertedEvent.end.index)
448
    assertEquals("Event_Interface_Optional: end.itemIndexInGroup", undefined, convertedEvent.end.itemIndexInGroup)
449
}
450

451
function checkEvent_Array_Class() {
452
    const bufferSize = 60 * 4
453
    const serializer = new Serializer()
454
    const eventParam: TouchTestInfo[] = [
455
        { windowX: 10, windowY: 11, parentX: 12, parentY: 13, x: 14, y: 15, id: "one",
456
            rect: { x: 100, y: 101, width: 102, height: 103 } },
457
        { windowX: 20, windowY: 21, parentX: 22, parentY: 23, x: 24, y: 25, id: "two",
458
            rect: { x: 200, y: 201, width: 202, height: 203 } },
459
        { windowX: 30, windowY: 31, parentX: 32, parentY: 33, x: 34, y: 35, id: "three",
460
            rect: { x: 300, y: 301, width: 302, height: 303 } }]
461
    serializer.writeInt32(1) // nodeId
462
    serializer.writeInt8(3)  // RuntimeType.OBJECT
463
    serializer.writeInt32(eventParam.length);
464
    for (let i = 0; i < eventParam.length; i++) {
465
      serializer.writeTouchTestInfo(eventParam[i]);
466
    }
467
    nativeModule()._Test_Common_OnChildTouchTest(serializer.asArray(), serializer.length())
468

469
    const buffer = new Uint8Array(bufferSize)
470
    const checkResult = nativeModule()._CheckArkoalaGeneratedEvents(buffer, bufferSize)
471
    const event = deserializePeerEvent(new Deserializer(buffer.buffer, bufferSize))
472
    assertEquals("Event_Array_Class: read event from native", 1, checkResult)
473
    if (checkResult !== 1)
474
        return
475

476
    assertEquals("Event_Array_Class: valid kind", PeerEventKind.CommonMethod_onChildTouchTest, event.kind)
477
    if (event.kind !== PeerEventKind.CommonMethod_onChildTouchTest)
478
        return
479

480
    const convertedEvent = event as CommonMethod_onChildTouchTest_event
481
    const checkTouchTestInfo = (expected: TouchTestInfo, actual: TouchTestInfo) =>
482
        expected.x === actual.x && expected.y === actual.y &&
483
        expected.rect.x === actual.rect.x && expected.rect.y === actual.rect.y &&
484
        expected.rect.width === actual.rect.width && expected.rect.height === actual.rect.height &&
485
        expected.id === actual.id
486
    assertEquals("Event_Array_Class: array length", eventParam.length, convertedEvent.value.length)
487
    for (let i = 0; i < eventParam.length; i++) {
488
        assertTrue(`Event_Array_Class: element ${i}`, checkTouchTestInfo(eventParam[i], convertedEvent.value[i]))
489
    }
490
}
491
checkSerdeBaseLength()
492
checkSerdeBaseText()
493
checkSerdeBasePrimitive()
494
checkSerdeBaseCustomObject()
495

496
checkPerf2(5 * 1000 * 1000)
497
checkPerf3(5 * 1000 * 1000)
498

499
startPerformanceTest()
500
if (recordCallLog) startNativeLog(CALL_GROUP_LOG)
501
checkNodeAPI()
502
checkCallback()
503
checkWriteFunction()
504
checkButton()
505
checkCalendar()
506
//checkDTS()
507
checkFormComponent()
508
checkCommon()
509
checkOverloads()
510
checkNavigation()
511
setEventsAPI()
512
checkEvent_Primitive()
513
checkEvent_Interface_Optional()
514
checkEvent_Array_Class()
515
if (recordCallLog) stopNativeLog(CALL_GROUP_LOG)
516

517
const callGroupLog = getNativeLog(CALL_GROUP_LOG)
518
const 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

539
namespace OHOS::Ace::NG::GeneratedModifier {
540
    EXTERN_C IDLIZE_API_EXPORT const GENERATED_ArkUIAnyAPI* GENERATED_GetArkAnyAPI(GENERATED_Ark_APIVariantKind kind, int version);
541
}
542

543
const GENERATED_ArkUINodeModifiers* GetNodeModifiers() {
544
    static const auto val = (const GENERATED_ArkUIFullNodeAPI*)(OHOS::Ace::NG::GeneratedModifier::GENERATED_GetArkAnyAPI(GENERATED_FULL,GENERATED_ARKUI_FULL_API_VERSION));
545
    return val->getNodeModifiers();
546
}
547

548
const GENERATED_ArkUIBasicNodeAPI* GetBasicNodeApi() {
549
    static const auto val = (const GENERATED_ArkUIBasicNodeAPI*)OHOS::Ace::NG::GeneratedModifier::GENERATED_GetArkAnyAPI(GENERATED_BASIC, GENERATED_ARKUI_BASIC_NODE_API_VERSION);
550
    return val;
551
}
552

553
int main(int argc, const char** argv) {
554
${callGroupLog}
555
  return 0;
556
}`
557
if (callGroupLog.length > 0) {
558
    console.log(callLogCppCode)
559
    mkdirSync('./generated/call_log', {recursive: true})
560
    writeFileSync('./generated/call_log/main.cpp', callLogCppCode)
561
}
562
checkTabContent()
563
checkCanvasRenderingContext2D()
564

565
// Report in error code.
566
checkTestFailures()
567

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.