1/*
2 * Copyright (c) 2022 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 */
15import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index'
16import ddm from '@ohos.data.distributedData';
17
18describe('fieldNodeTest', function() {
19
20    /**
21     * @tc.name FieldNodeAppendChildTest001
22     * @tc.desc  Test Js Api FieldNode.AppendChild() testcase 001
23     * @tc.type: FUNC
24     * @tc.require: issueNumber
25     */
26    it('FieldNodeAppendChildTest001', 0, async function(done) {
27        try {
28            let node = new ddm.FieldNode("root");
29            let child1 = new ddm.FieldNode("child1");
30            let child2 = new ddm.FieldNode("child2");
31            let child3 = new ddm.FieldNode("child3");
32            node.appendChild(child1);
33            node.appendChild(child2);
34            node.appendChild(child3);
35            child1 = null;
36            child2 = null;
37            child3 = null;
38            node = null;
39        } catch (e) {
40            console.info("FieldNodeAppendChildTest001 " + e);
41            expect(null).assertFail();
42        }
43        done();
44    })
45
46    /**
47     * @tc.name FieldNodeAppendChildTest002
48     * @tc.desc  Test Js Api FieldNode.AppendChild() testcase 002
49     * @tc.type: FUNC
50     * @tc.require: issueNumber
51     */
52    it('FieldNodeAppendChildTest002', 0, async function(done) {
53        try {
54            let node = new ddm.FieldNode("root");
55            let child = new ddm.FieldNode("child");
56            node.appendChild(child);
57            child = null;
58            node = null;
59        } catch (e) {
60            console.info("FieldNodeAppendChildTest002 " + e);
61            expect(null).assertFail();
62        }
63        done();
64    })
65
66    /**
67     * @tc.name FieldNodeAppendChildTest003
68     * @tc.desc  Test Js Api FieldNode.AppendChild() testcase 003
69     * @tc.type: FUNC
70     * @tc.require: issueNumber
71     */
72    it('FieldNodeAppendChildTest003', 0, async function(done) {
73        try {
74            let node = new ddm.FieldNode("root");
75            let child = new ddm.FieldNode();
76            node.appendChild(child);
77            expect(null).assertFail();
78        } catch (e) {
79            console.info("FieldNodeAppendChildTest003 fail on exception :" + e);
80        }
81        done();
82    })
83
84    /**
85     * @tc.name FieldNodeToJsonTest001
86     * @tc.desc  Test Js Api FieldNode.ToJson() testcase 001
87     * @tc.type: FUNC
88     * @tc.require: issueNumber
89     */
90    it('FieldNodeToJsonTest001', 0, async function(done) {
91        try {
92            let node = new ddm.FieldNode("root");
93            let child = new ddm.FieldNode("child");
94            node.appendChild(child);
95        } catch (e) {
96            expect(null).assertFail();
97        }
98        done();
99    })
100
101    /**
102     * @tc.name FieldNodeToJsonTest002
103     * @tc.desc  Test Js Api FieldNode.ToJson() testcase 002
104     * @tc.type: FUNC
105     * @tc.require: issueNumber
106     */
107    it('FieldNodeToJsonTest002', 0, async function(done) {
108        try {
109            let node = new ddm.FieldNode("root");
110            let child = new ddm.FieldNode("child");
111            node.appendChild(child);
112        } catch (e) {
113            expect(null).assertFail();
114        }
115        done();
116    })
117
118    /**
119     * @tc.name FieldNodeToJsonTest003
120     * @tc.desc  Test Js Api FieldNode.ToJson() testcase 003
121     * @tc.type: FUNC
122     * @tc.require: issueNumber
123     */
124    it('FieldNodeToJsonTest003', 0, async function(done) {
125        try {
126            let node = new ddm.FieldNode();
127            let child = new ddm.FieldNode();
128            node.appendChild(child);
129            expect(null).assertFail();
130        } catch (e) {
131            console.info("FieldNodeToJsonTest003 fail on exception : " + e);
132        }
133        done();
134    })
135
136    /**
137     * @tc.name FieldNodedefaultTest001
138     * @tc.desc  Test Js Api FieldNode.default testcase 001
139     * @tc.type: FUNC
140     * @tc.require: issueNumber
141     */
142     it('FieldNodedefaultTest001', 0, async function(done) {
143        try {
144            let node = new ddm.FieldNode('first');
145            node.default = 'first name';
146            console.info('defaultValue = ' + node.default);
147            expect(node.default === 'first name').assertTrue()
148        } catch (e) {
149            console.info("FieldNodedefaultTest001 fail on exception: " + e);
150        }
151        done();
152    })
153
154    /**
155     * @tc.name FieldNodenullableTest001
156     * @tc.desc  Test Js Api FieldNode.nullable testcase 001
157     * @tc.type: FUNC
158     * @tc.require: issueNumber
159     */
160     it('FieldNodenullableTest001', 0, async function(done) {
161        try {
162            let node = new ddm.FieldNode('first');
163            node.nullable = false;
164            console.info('nullable = ' + node.nullable);
165            expect(node.nullable === false).assertTrue()
166        } catch (e) {
167            console.info("FieldNodenullableTest001 fail on exception: " + e);
168        }
169        done();
170    })
171
172    /**
173     * @tc.name FieldNodetypeTest001
174     * @tc.desc  Test Js Api FieldNode.type testcase 001
175     * @tc.type: FUNC
176     * @tc.require: issueNumber
177     */
178     it('FieldNodetypeTest001', 0, async function(done) {
179        try {
180            let node = new ddm.FieldNode('first');
181            node.type = ddm.value.type.STRING;
182            console.info('type = ' + node.type);
183            expect(node.type === ddm.type.STRING).assertTrue()
184        } catch (e) {
185            console.info("FieldNodetypeTest001 fail on exception: " + e);
186        }
187        done();
188    })
189
190    /**
191     * @tc.name FieldNodetypeTest002
192     * @tc.desc  Test Js Api FieldNode.type testcase 002
193     * @tc.type: FUNC
194     * @tc.require: issueNumber
195     */
196     it('FieldNodetypeTest002', 0, async function(done) {
197        try {
198            let node = new ddm.FieldNode('first');
199            node.type = ddm.type.INTEGER;
200            console.info('type = ' + node.type);
201            expect(node.type === ddm.type.INTEGER).assertTrue()
202        } catch (e) {
203            console.info("FieldNodetypeTest002 fail on exception: " + e);
204        }
205        done();
206    })
207
208    /**
209     * @tc.name FieldNodetypeTest003
210     * @tc.desc  Test Js Api FieldNode.type testcase 003
211     * @tc.type: FUNC
212     * @tc.require: issueNumber
213     */
214     it('FieldNodetypeTest003', 0, async function(done) {
215        try {
216            let node = new ddm.FieldNode('first');
217            node.type = ddm.type.FLOAT;
218            console.info('type = ' + node.type);
219            expect(node.type === ddm.type.FLOAT).assertTrue()
220        } catch (e) {
221            console.info("FieldNodetypeTest003 fail on exception: " + e);
222        }
223        done();
224    })
225
226    /**
227     * @tc.name FieldNodetypeTest004
228     * @tc.desc  Test Js Api FieldNode.type testcase 004
229     * @tc.type: FUNC
230     * @tc.require: issueNumber
231     */
232     it('FieldNodetypeTest004', 0, async function(done) {
233        try {
234            let node = new ddm.FieldNode('first');
235            node.type = ddm.type.BYTE_ARRAY;
236            console.info('type = ' + node.type);
237            expect(node.type === ddm.type.BYTE_ARRAY).assertTrue()
238        } catch (e) {
239            console.info("FieldNodetypeTest004 fail on exception: " + e);
240        }
241        done();
242    })
243
244    /**
245     * @tc.name FieldNodetypeTest005
246     * @tc.desc  Test Js Api FieldNode.type testcase 005
247     * @tc.type: FUNC
248     * @tc.require: issueNumber
249     */
250     it('FieldNodetypeTest005', 0, async function(done) {
251        try {
252            let node = new ddm.FieldNode('first');
253            node.type = ddm.type.BOOLEAN;
254            console.info('type = ' + node.type);
255            expect(node.type === ddm.ValueType.BOOLEAN).assertTrue()
256        } catch (e) {
257            console.info("FieldNodetypeTest005 fail on exception: " + e);
258        }
259        done();
260    })
261
262    /**
263     * @tc.name FieldNodetypeTest006
264     * @tc.desc  Test Js Api FieldNode.type testcase 006
265     * @tc.type: FUNC
266     * @tc.require: issueNumber
267     */
268     it('FieldNodetypeTest006', 0, async function(done) {
269        try {
270            let node = new ddm.FieldNode('first');
271            node.type = ddm.type.DOUBLE;
272            console.info('type = ' + node.type);
273            expect(node.type === ddm.type.DOUBLE).assertTrue()
274        } catch (e) {
275            console.info("FieldNodetypeTest006 fail on exception: " + e);
276        }
277        done();
278    })
279})
280