idlize

Форк
0
/
index.ts 
96 строк · 3.4 Кб
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
// Shall be like this import { ArkCommonPeer } from "@arkoala/arkui/common"
16

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"
22

23
const TEST_GROUP_LOG = 1
24
function clearNativeLog() {
25
    nativeModule()._ClearGroupedLog(TEST_GROUP_LOG)
26
}
27
function getNativeLog(): string {
28
    return withStringResult(nativeModule()._GetGroupedLog(TEST_GROUP_LOG))!
29
}
30

31
let failedTestsCount = 0
32

33
// TODO: hacky way to detect subset vs full.
34
clearNativeLog()
35
new ArkButtonPeer().labelStyle({maxLines: 3})
36
let reportTestFailures = getNativeLog().indexOf("heightAdaptivePolicy") == -1
37

38
if (!reportTestFailures) {
39
    console.log("WARNING: ignore test result")
40
}
41

42
function checkResult(test: () => void, expected: string) {
43
    clearNativeLog()
44
    test()
45
    let out = getNativeLog()
46
    if (reportTestFailures && out != expected) {
47
        failedTestsCount++
48
        console.log(`TEST FAIL:\n  EXPECTED "${expected}"\n  ACTUAL   "${out}"`)
49
    }
50
}
51

52
function checkButton() {
53
    let peer = new ArkButtonPeer()
54

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})")
59
    checkResult(() =>
60
        peer.bindSheet(false, () => {}, {
61
            title: {
62
                title: { id: 43, bundleName: "MyApp", moduleName: "MyApp" }
63
            }
64
        }),
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),
69
        "type(1)")
70
    checkResult(() => peer.labelStyle({maxLines: 3}),
71
        "labelStyle(LabelStyle {maxLines=tagged {[OBJECT]3}})")
72
}
73

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]})")
81
}
82

83
function checkFormComponent() {
84
    let peer = new ArkFormComponentPeer()
85
    checkResult(() => peer.size({width: 5, height: 6}),
86
        "size(compound: {5, 6, })")
87
}
88

89

90
checkButton()
91
checkCalendar()
92
//checkDTS()
93
checkFormComponent()
94

95
// Report in error code.
96
if (reportTestFailures && failedTestsCount > 0) process.exit(1)

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

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

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

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