1/*
2* Copyright (c) 2022 Shenzhen Kaihong Digital Industry Development 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 { AsyncCallback, Callback } from './../basic';
16
17declare namespace napitest {
18    export class Image {
19        width: number;
20        height: number;
21        toDataURL(type?: string, quality?: number): string;
22    }
23
24    export class Human {
25        name: string;
26        age: number;
27    }
28
29    // 变换括号位置
30    class Man 
31    {
32        name: string;
33        age: number;
34    }
35
36    // 有参构造函数的转换,成员变量包含数值型枚举
37    export class Woman {
38      constructor(name_: string, age_: number, isMarried_: boolean, status_: TestStatus);
39      w_name: string;
40      w_age: number;
41      w_isMarried: boolean;
42      w_status: TestStatus;
43    }
44
45    // 有参构造函数的转换,成员变量包含字符型枚举
46    export class Child {
47      constructor(name_: string, age_: number, status_: TestEnumString);
48      w_name: string;
49      w_age: number;
50      w_status: TestEnumString;
51    }
52
53    export enum LaunchReason {
54        UNKNOWN = 0,
55        START_ABILITY = 1,
56        CALL = 2,
57        CONTINUATION = 3,
58    }
59
60    export class TestClass1 {
61        ahuman: Human;
62        fun1(v: number): number;
63        fun2(numcc: Array<number>, mancc: Human): Human;
64        fun3: (v: number, v1: string, v2: boolean) => boolean;
65        fun4: (mancc: Map<string, string>,v?: string) => Array<number>;
66        fun5: (data: Array<Human>) => Human;
67        fun6: (v: string[], v1: { [key: string]: boolean }) => string[];
68        fun8: () => void;
69        fun9(manA: Man): string;
70        fun10(v: Image): string;
71        
72        //参数为enum
73        fun11(v: LaunchReason): string;
74        fun12(v: TestStatus): string;
75        fun13(v: TestEnumString): string;
76
77        // return value is enum type of defined later
78        // to support
79        // fun14(v: string): ReturnStatus; 
80        // fun15(v: string): ReturnEnumString;
81
82        /*fun7: (v: string, v1: LaunchReason) => LaunchReason;  --待支持*/
83    }
84
85    // class 定义在使用之后 begin
86    function func4(v: TestClassLater): string;
87
88    export class TestClassUse {
89        v0: string;
90        // v1: testClassLater;
91        funceUse(n0: TestClassLater): string;
92    }
93
94    export class TestClassLater {
95        v0: string;
96        v1: number;
97        funcLater(n0: number): string;
98    }
99    // class 定义在使用之后 end
100
101    // 数值型枚举
102    export enum TestStatus {
103        UNKNOWN = 0,
104        START_ABILITY = 1,
105        CALL = 2,
106        CONTINUATION = 3,
107    }
108
109    // 字符型枚举
110    export enum TestEnumString {
111        ACTION_HOME = 'ohos.want.action.home',
112        ACTION_DIAL = 'ohos.want.action.dial',
113        ACTION_SEARCH = 'ohos.want.action.search',
114        ACTION_WIRELESS_SETTINGS = 'ohos.settings.wireless',
115    }
116
117    // 数值型枚举
118    export enum ReturnStatus {
119        UNKNOWN = 0,
120        START_RETURN = 1,
121        MIDDLE_RETURN = 2,
122        END_RETURN = 3,
123    }
124
125    // 字符型枚举
126    export enum ReturnEnumString {
127        RETURN_HOME = 'ohos.want.return.home',
128        RETURN_DIAL = 'ohos.want.return.dial',
129        RETURN_SEARCH = 'ohos.want.return.search',
130        RETURN_WIRELESS_SETTINGS = 'ohos.settings.return.wireless',
131    }
132
133    export class TestClass2 {
134        // 函数多参数非嵌套场景
135        func1(name : string, fp3: {nm: string, age: number, flag: boolean}): string;
136
137        // 函数返回值场景
138        func2(input: string): { read: number; written: number; flag: boolean };
139
140        // Promise返回值逗号场景
141        func3(from: string, to: string): Promise<{result: number, errMsg: string, isT: boolean}>;
142
143        // Promise返回值分号场景
144        func4(from: string, to: string): Promise<{result: number; errMsg: string; isT: boolean}>;
145
146        // class成员方法隐式推导返回值
147        func5(v1: string, v2: number, v3: boolean);
148    }
149
150    // class 成员变量包含enum类型,且class成员方法自引用
151    export enum Type
152    {
153        typeA,
154        typeB,
155        typeC
156    }
157  
158    export class Test {
159        type: Type;
160        func(param: Type): boolean;
161    }
162  
163    export interface aa {
164        abc: string;
165        def: number;
166    }
167  
168    export class Demo {
169        equals(other: Demo): boolean;
170        handleCallback(): void;
171  
172        intPro: number;
173        strPro: string;
174        boolPro: boolean;
175        inter: aa;
176        type: Type;
177    }
178  
179    function funcTest(v: Type): boolean; // enum为参数
180    function funcTest2(v: Test): boolean;  // 包含enum成员变量的 class 为参数
181}
182
183export default napitest;
184