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 */ 15 16import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' 17import ddm from '@ohos.data.distributedKVStore'; 18 19describe('FieldNodeTest', function () { 20 /** 21 * @tc.name FieldNodeConstructorInvalidArgsTest 22 * @tc.desc Test Js Api FieldNode.AppendChild() with invalid child node 23 * @tc.type: FUNC 24 * @tc.require: issueNumber 25 */ 26 it('FieldNodeConstructorInvalidArgsTest', 0, async function (done) { 27 try { 28 let node = new ddm.FieldNode(); 29 expect(null).assertFail(); 30 } catch (e) { 31 console.info("FieldNodeConstructorInvalidArgsTest throws exception successfully :" + e); 32 expect(e.code == 401).assertTrue(); 33 } 34 done(); 35 }) 36 37 /** 38 * @tc.name FieldNodeAppendChildSucTest 39 * @tc.desc Test Js Api FieldNode.AppendChild() successfully 40 * @tc.type: FUNC 41 * @tc.require: issueNumber 42 */ 43 it('FieldNodeAppendChildSucTest', 0, async function (done) { 44 try { 45 let node = new ddm.FieldNode("root"); 46 let child = new ddm.FieldNode("child"); 47 node.appendChild(child); 48 expect(true).assertTrue(); 49 child = null; 50 node = null; 51 } catch (e) { 52 console.info("FieldNodeAppendChildSucTest " + e); 53 expect(null).assertFail(); 54 } 55 done(); 56 }) 57 58 /** 59 * @tc.name FieldNodeAppendChildInvalidChildTest 60 * @tc.desc Test Js Api FieldNode.AppendChild() with invalid child node 61 * @tc.type: FUNC 62 * @tc.require: issueNumber 63 */ 64 it('FieldNodeAppendChildInvalidChildTest', 0, async function (done) { 65 try { 66 let node = new ddm.FieldNode("root"); 67 node.appendChild(null); 68 expect(null).assertFail(); 69 } catch (e) { 70 console.info("FieldNodeAppendChildInvalidChildTest throws exception successfully :" + e); 71 expect(e.code == 401).assertTrue(); 72 } 73 done(); 74 }) 75 76 /** 77 * @tc.name FieldNodedefaultSucTest 78 * @tc.desc Test Js Api FieldNode.default successfully 79 * @tc.type: FUNC 80 * @tc.require: issueNumber 81 */ 82 it('FieldNodedefaultSucTest', 0, async function (done) { 83 try { 84 let node = new ddm.FieldNode("first"); 85 node.default = 'first name'; 86 console.info('defaultValue = ' + node.default); 87 expect(node.default === 'first name').assertTrue() 88 } catch (e) { 89 console.info("FieldNodedefaultSucTest fail on exception: " + e); 90 expect(null).assertFail(); 91 } 92 done(); 93 }) 94 95 /** 96 * @tc.name FieldNodenullableSucTest 97 * @tc.desc Test Js Api FieldNode.nullable successfully 98 * @tc.type: FUNC 99 * @tc.require: issueNumber 100 */ 101 it('FieldNodenullableSucTest', 0, async function (done) { 102 try { 103 let node = new ddm.FieldNode("first"); 104 node.nullable = false; 105 console.info('nullable = ' + node.nullable); 106 expect(node.nullable === false).assertTrue() 107 } catch (e) { 108 console.info("FieldNodenullableSucTest fail on exception: " + e); 109 expect(null).assertFail(); 110 } 111 done(); 112 }) 113 114 /** 115 * @tc.name FieldNodetypeStringTest 116 * @tc.desc Test Js Api FieldNode.type String 117 * @tc.type: FUNC 118 * @tc.require: issueNumber 119 */ 120 it('FieldNodetypeStringTest', 0, async function (done) { 121 try { 122 let node = new ddm.FieldNode("first"); 123 node.type = ddm.ValueType.STRING; 124 console.info('type = ' + node.type); 125 expect(node.type === ddm.ValueType.STRING).assertTrue() 126 } catch (e) { 127 console.info("FieldNodetypeStringTest fail on exception: " + e); 128 expect(null).assertFail(); 129 } 130 done(); 131 }) 132 133 /** 134 * @tc.name FieldNodetypeIntegerTest 135 * @tc.desc Test Js Api FieldNode.type integer 136 * @tc.type: FUNC 137 * @tc.require: issueNumber 138 */ 139 it('FieldNodetypeIntegerTest', 0, async function (done) { 140 try { 141 let node = new ddm.FieldNode("first"); 142 console.info("success 1"); 143 node.type = ddm.ValueType.INTEGER; 144 console.info('type = ' + node.type); 145 expect(node.type === ddm.ValueType.INTEGER).assertTrue() 146 } catch (e) { 147 console.info("FieldNodetypeIntegerTest fail on exception: " + e); 148 expect(null).assertFail; 149 } 150 done(); 151 }) 152 153 /** 154 * @tc.name FieldNodetypeFloatTest 155 * @tc.desc Test Js Api FieldNode.type float 156 * @tc.type: FUNC 157 * @tc.require: issueNumber 158 */ 159 it('FieldNodetypeFloatTest', 0, async function (done) { 160 try { 161 let node = new ddm.FieldNode("first"); 162 node.type = ddm.ValueType.FLOAT; 163 console.info('type = ' + node.type); 164 expect(node.type === ddm.ValueType.FLOAT).assertTrue() 165 } catch (e) { 166 console.info("FieldNodetypeFloatTest fail on exception: " + e); 167 expect(null).assertFail(); 168 } 169 done(); 170 }) 171 172 /** 173 * @tc.name FieldNodetypeByteArrayTest 174 * @tc.desc Test Js Api FieldNode.type byte array 175 * @tc.type: FUNC 176 * @tc.require: issueNumber 177 */ 178 it('FieldNodetypeByteArrayTest', 0, async function (done) { 179 try { 180 let node = new ddm.FieldNode("first"); 181 node.type = ddm.ValueType.BYTE_ARRAY; 182 console.info('type = ' + node.type); 183 expect(node.type === ddm.ValueType.BYTE_ARRAY).assertTrue() 184 } catch (e) { 185 console.info("FieldNodetypeByteArrayTest fail on exception: " + e); 186 expect(null).assertFail(); 187 } 188 done(); 189 }) 190 191 /** 192 * @tc.name FieldNodetypeBooleanTest 193 * @tc.desc Test Js Api FieldNode.type boolean 194 * @tc.type: FUNC 195 * @tc.require: issueNumber 196 */ 197 it('FieldNodetypeBooleanTest', 0, async function (done) { 198 try { 199 let node = new ddm.FieldNode("first"); 200 node.type = ddm.ValueType.BOOLEAN; 201 console.info('type = ' + node.type); 202 expect(node.type === ddm.ValueType.BOOLEAN).assertTrue() 203 } catch (e) { 204 console.info("FieldNodetypeBooleanTest fail on exception: " + e); 205 expect(null).assertFail(); 206 } 207 done(); 208 }) 209 210 /** 211 * @tc.name FieldNodetypeDoubleTest 212 * @tc.desc Test Js Api FieldNode.type double 213 * @tc.type: FUNC 214 * @tc.require: issueNumber 215 */ 216 it('FieldNodetypeDoubleTest', 0, async function (done) { 217 try { 218 let node = new ddm.FieldNode("first"); 219 node.type = ddm.ValueType.DOUBLE; 220 console.info('type = ' + node.type); 221 expect(node.type === ddm.ValueType.DOUBLE).assertTrue() 222 } catch (e) { 223 console.info("FieldNodetypeDoubleTest fail on exception: " + e); 224 expect(null).assertFail(); 225 } 226 done(); 227 }) 228}) 229