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*/
15const { fun1, fun2, fun3 } = require("./out/build/Release/napitest")
16const { fun4, fun5, fun6 } = require("./out/build/Release/napitest")
17const test = require("./out/build/Release/napitest")
18var assert = require("assert");
19
20describe('enum', function () {
21    // 测试:function fun1(v0: string, v1: GrantStatus): GrantStatus;
22    it('test fun1', function () {
23        let ret = fun1('aaaa', test.GrantStatus.PERMISSION_DENIED);
24        assert.strictEqual(ret, test.GrantStatus.PERMISSION_DEFAULT);
25    });
26
27    // 测试:function fun2(v0: number, v1: LaunchReason): LaunchReason;
28    it('test fun2', function () {
29        let ret = fun2(18, test.LaunchReason.START_ABILITY);
30        assert.strictEqual(ret, test.LaunchReason.UNKNOWN);
31    });
32
33    // 测试:function fun3(v0: string, v1: Action): Action;
34    it('test fun3', function () {
35        let ret = fun3('ggg', test.Action.ACTION_DIAL);
36        assert.strictEqual(ret, '');
37    });
38
39    // 测试:function fun4(v0: number, v1: PlayingState): PlayingState;
40    it('test fun4', function () {
41        let ret = fun4(18, test.PlayingState.STATE_PLAYING);
42        assert.strictEqual(ret, 0);
43    });
44
45    function abc(ret) {
46        assert.deepStrictEqual(ret, test.LaunchReason.UNKNOWN);
47    }
48
49    // 测试:function fun5(V0: string, callback: Callback<LaunchReason>): void;
50    it('test fun5', function () {
51        fun5('aaa', abc);
52    });
53
54    function asynFun1(err, ret) {
55        assert.deepStrictEqual(err.code, 0)
56        assert.deepStrictEqual(ret, '')
57    }
58
59    // 测试:function fun6(v0: string, callback: AsyncCallback<GrantStatus>): void;
60    it('test fun6_callback', function () {
61        fun6('hhh', asynFun1);
62        fun6('hhh').then(def1);
63    });
64
65    function def1(ret) {
66        assert.deepStrictEqual(ret, '');
67    }
68
69    // 测试:function fun6(v0: string): Promise<GrantStatus>;
70    it('test fun6_promise', function () {
71        let promiseObj = fun6('hhh');
72        promiseObj.then(ret => { def1(ret) });
73    });
74});
75
76describe('enum second part', function () {
77    function def2(ret) {
78        assert.deepStrictEqual(ret, 0);
79    }
80
81    // 测试:function fun8(v0: string): Promise<PlayingTest>;
82    it('test fun8_promise', function () {
83        let promiseObj = test.fun8('test');
84        promiseObj.then(ret => { def2(ret) });
85    });
86
87    // 测试:function fun9(v0: PlayingTest): string;
88    it('test fun9', function () {
89        let ret = test.fun9(test.PlayingTest.STATE_TEST_START);
90        assert.strictEqual(ret, '');
91    });
92
93    // 测试:function fun10(v: TestStatus): string;
94    it('test fun10', function () {
95        let ret = test.fun10(test.PlayingTest.STATE_TEST_START);
96        assert.strictEqual(ret, '');
97    })
98
99    /* 测试
100    function fun11(v: EnumString): string;
101    export enum EnumString {
102        ENUM_HOME = 'ohos.want.enum.home',
103        ENUM_DIAL = 'ohos.want.enum.dial',
104        ENUM_SEARCH = 'ohos.want.enum.search',
105        ENUM_WIRELESS_SETTINGS = 'ohos.settings.enum.wireless',
106    }
107    */
108    it('test fun11', function () {
109        let ret = test.fun11(test.EnumString.ENUM_SEARCH);
110        assert.strictEqual(ret, '');
111    })
112
113    // 测试:function fun12(v: HttpStatus): number;
114    it('test fun12', function () {
115        let ret = test.fun12(test.HttpStatus.STATUS0);
116        assert.strictEqual(ret, 0);
117    });
118});
119
120// 测试:Input exception testing
121describe('enum third part', function () {
122    // 测试:function fun1(v0: string, v1: GrantStatus): GrantStatus;
123    it('test fun1 exception ', function () {
124        let ret2 = false;
125        try {
126            let ret = fun1('aaaa', "bbbb");
127        } catch (err) {
128            ret2 = true;
129            console.info("err: "+ err)
130        }
131        assert.strictEqual(ret2, true)
132    });
133
134    // 测试:function fun2(v0: number, v1: LaunchReason): LaunchReason;
135    it('test fun2 exception', function () {
136        let ret3 = false;
137        try {
138            let ret = fun2(18, 9);
139        } catch (err) {
140            ret3 = true;
141            console.info("err: "+ err)
142        }
143        assert.strictEqual(ret3, true)
144    });
145
146    // 测试:function fun3(v0: string, v1: Action): Action;
147    it('test fun3 exception', function () {
148        let ret2 = false;
149        try {
150            let ret = fun3('ggg', 'ccc');
151        } catch (err) {
152            ret2 = true;
153            console.info("err: "+ err)
154        }
155        assert.strictEqual(ret2, true)
156    });
157
158    // 测试:function fun4(v0: number, v1: PlayingState): PlayingState;
159    it('test fun4 exception', function () {
160        let ret3 = false;
161        try {
162            let ret = fun4(18, 8);
163        } catch (err) {
164            ret3 = true;
165            console.info("err: "+ err)
166        }
167        assert.strictEqual(ret3, true)
168    });
169
170    // 测试:function fun12(v: HttpStatus): number;
171    it('test fun12 exception', function () {
172        let ret3 = false;
173        try {
174            let ret = test.fun12(2);
175        } catch (err) {
176            ret3 = true;
177            console.info("err: "+ err)
178        }
179        assert.strictEqual(ret3, true)
180    });
181
182})
183
184