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
7
* http://www.apache.org/licenses/LICENSE-2.0
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.
15
// Shall be like this import { ArkCommonPeer } from "@arkoala/arkui/common"
17
import { ArkButtonPeer } from "@arkoala/arkui/ArkButtonPeer"
18
import { ArkCalendarPickerPeer } from "@arkoala/arkui/ArkCalendarPickerPeer"
19
import { ArkFormComponentPeer } from "@arkoala/arkui/ArkFormComponentPeer"
20
import { withStringResult } from "./Interop"
21
import { nativeModule } from "@arkoala/arkui/NativeModule"
23
const TEST_GROUP_LOG = 1
24
function clearNativeLog() {
25
nativeModule()._ClearGroupedLog(TEST_GROUP_LOG)
27
function getNativeLog(): string {
28
return withStringResult(nativeModule()._GetGroupedLog(TEST_GROUP_LOG))!
31
let failedTestsCount = 0
33
// TODO: hacky way to detect subset vs full.
35
new ArkButtonPeer().labelStyle({maxLines: 3})
36
let reportTestFailures = getNativeLog().indexOf("heightAdaptivePolicy") == -1
38
if (!reportTestFailures) {
39
console.log("WARNING: ignore test result")
42
function checkResult(test: () => void, expected: string) {
45
let out = getNativeLog()
46
if (reportTestFailures && out != expected) {
48
console.log(`TEST FAIL:\n EXPECTED "${expected}"\n ACTUAL "${out}"`)
52
function checkButton() {
53
let peer = new ArkButtonPeer()
55
checkResult(() => peer.width("42%"),
56
"width(Length {value=42.000000, unit=%, resource=0})")
57
checkResult(() => peer.height({ id: 43, bundleName: "MyApp", moduleName: "MyApp" }),
58
"height(Length {value=0.000000, unit=vp, resource=43})")
60
peer.bindSheet(false, () => {}, {
62
title: { id: 43, bundleName: "MyApp", moduleName: "MyApp" }
65
"bindSheet(0, Custom kind=NativeErrorFunction id=0, tagged {[OBJECT]SheetOptions " +
66
"{title=tagged {[OBJECT]SheetTitleOptions {title=union[1] {Custom kind=NativeErrorResource id=0}, " +
67
"subtitle=tagged {[UNDEFINED]}}}, detents=tagged {[UNDEFINED]}}})")
68
checkResult(() => peer.type(1),
70
checkResult(() => peer.labelStyle({maxLines: 3}),
71
"labelStyle(LabelStyle {maxLines=tagged {[OBJECT]3}})")
74
function checkCalendar() {
75
let peer = new ArkCalendarPickerPeer()
76
checkResult(() => peer.edgeAlign(2, {dx: 5, dy: 6}),
77
"edgeAlign(2, tagged {[OBJECT]compound: {Length {value=5.000000, unit=vp, resource=0}, " +
78
"Length {value=6.000000, unit=vp, resource=0}, }})")
79
checkResult(() => peer.edgeAlign(2, undefined),
80
"edgeAlign(2, tagged {[UNDEFINED]})")
83
function checkFormComponent() {
84
let peer = new ArkFormComponentPeer()
85
checkResult(() => peer.size({width: 5, height: 6}),
86
"size(compound: {5, 6, })")
95
// Report in error code.
96
if (reportTestFailures && failedTestsCount > 0) process.exit(1)