1/* 2* Copyright (c) 2023 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*/ 15 16import testNapi from 'libentry.so'; 17import hilog from '@ohos.hilog'; 18import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; 19 20export default function abilityTest() { 21 describe('ActsAbilityTest', () => { 22 // Defines a test suite. Two parameters are supported: test suite name and test suite function. 23 beforeAll(() => { 24 // Presets an action, which is performed only once before all test cases of the test suite start. 25 // This API supports only one parameter: preset action function. 26 }) 27 beforeEach(() => { 28 // Presets an action, which is performed before each unit test case starts. 29 // The number of execution times is the same as the number of test cases defined by **it**. 30 // This API supports only one parameter: preset action function. 31 }) 32 afterEach(() => { 33 // Presets a clear action, which is performed after each unit test case ends. 34 // The number of execution times is the same as the number of test cases defined by **it**. 35 // This API supports only one parameter: clear action function. 36 }) 37 afterAll(() => { 38 // Presets a clear action, which is performed after all test cases of the test suite end. 39 // This API supports only one parameter: clear action function. 40 }) 41 it('assertContain', 0, () => { 42 // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. 43 hilog.info(0x0000, 'testTag', '%{public}s', 'it begin'); 44 let a = 'abc'; 45 let b = 'b'; 46 // Defines a variety of assertion methods, which are used to declare expected boolean conditions. 47 expect(a).assertContain(b); 48 expect(a).assertEqual(a); 49 }) 50 51 it('KH418_cJSON_Parse', 0, () => { 52 // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. 53 hilog.info(0x0000, 'testTag', '%{public}s', 'it begin'); 54 let value = '"helloworld"' 55 let result: testNapi.cJSON = testNapi.KH418_cJSON_Parse(value); 56 let value2 = '1.8' 57 let result2: testNapi.cJSON = testNapi.KH418_cJSON_Parse(value2); 58 let value3 = '["a","b"]' 59 let result3: testNapi.cJSON = testNapi.KH418_cJSON_Parse(value3); 60 let value4 = '{"name":"JohnDoe","age":18}' 61 let result4: testNapi.cJSON = testNapi.KH418_cJSON_Parse(value4); 62 console.info("Test NAPI KH418_cJSON_Parse result1: ", JSON.stringify(result)) 63 console.info("Test NAPI KH418_cJSON_Parse result2: ", JSON.stringify(result2)) 64 console.info("Test NAPI KH418_cJSON_Parse result3: ", JSON.stringify(result3)) 65 console.info("Test NAPI KH418_cJSON_Parse result4: ", JSON.stringify(result4)) 66 }) 67 68 it('KH373_cJSON_GetArraySize', 0, () => { 69 // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. 70 hilog.info(0x0000, 'testTag', '%{public}s', 'it begin'); 71 let value: testNapi.cJSON = { 72 next: null, 73 prev: null, 74 child: null, 75 type: 0, 76 valuestring: '["apple","banana","cherry","pear","strawberry"]', 77 valueint: 0, 78 valuedouble: 0, 79 string: '' 80 } 81 let result: number = testNapi.KH373_cJSON_GetArraySize(value); 82 hilog.info(0x0000, "testTag", "Test NAPI KH734_CJSON_GetArraySize: ", result); 83 console.info("Test NAPI KH734_CJSON_GetArraySize result: ", JSON.stringify(result)) 84 // Defines a variety of assertion methods, which are used to declare expected boolean conditions. 85 }) 86 87 it('KH735_cJSON_Print', 0, () => { 88 // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. 89 hilog.info(0x0000, 'testTag', '%{public}s', 'it begin'); 90 let paramIn: testNapi.cJSON = { 91 next: null, 92 prev: null, 93 child: null, 94 type: 16, 95 valuestring: 'JohnDoe', 96 valueint: 0, 97 valuedouble: 0, 98 string: 'name' 99 } 100 let result: string = testNapi.KH735_cJSON_Print(paramIn) 101 hilog.info(0x0000, "testTag", "Test NAPI KH735_cJSON_Print: ", result); 102 console.info("Test NAPI KH735_cJSON_Print result: ", JSON.stringify(result)) 103 // Defines a variety of assertion methods, which are used to declare expected boolean conditions. 104 // e.g. expect(result).assertEqual(2+3) 105 }) 106 107 it('KH361_cJSON_CreateObject', 0, () => { 108 // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. 109 hilog.info(0x0000, 'testTag', '%{public}s', 'it begin'); 110 111 let result: testNapi.cJSON = testNapi.KH361_cJSON_CreateObject() 112 hilog.info(0x0000, "testTag", "Test NAPI KH735_cJSON_Print: ", result); 113 console.info("Test NAPI KH361_cJSON_CreateObject result: ", JSON.stringify(result)) 114 // Defines a variety of assertion methods, which are used to declare expected boolean conditions. 115 // e.g. expect(result).assertEqual(2+3) 116 }) 117 118 it('KH515_cJSON_CreateString', 0, () => { 119 // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. 120 hilog.info(0x0000, 'testTag', '%{public}s', 'it begin'); 121 122 let string = "gOtkqDFR0z" 123 let result: testNapi.cJSON = testNapi.KH515_cJSON_CreateString(string) 124 hilog.info(0x0000, "testTag", "Test NAPI KH515_cJSON_CreateString: ", JSON.stringify(result)); 125 console.info("Test NAPI KH515_cJSON_CreateString result: ", JSON.stringify(result)) 126 // Defines a variety of assertion methods, which are used to declare expected boolean conditions. 127 // e.g. expect(result).assertEqual(2+3) 128 }) 129 130 it('KH526_cJSON_AddStringToObject', 0, () => { 131 // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. 132 hilog.info(0x0000, 'testTag', '%{public}s', 'it begin'); 133 134 let valueObj: testNapi.cJSON = { 135 next: null, 136 prev: null, 137 child: null, 138 type: 0, 139 valuestring: '', 140 valueint: 0, 141 valuedouble: 0, 142 string: '' 143 } 144 // let name = "KReo699Gch" 145 // let string = "1RqeB65OeI" 146 let name = "name" 147 let string = "Anna" 148 let result: testNapi.cJSON = testNapi.KH526_cJSON_AddStringToObject(valueObj, name, string) 149 hilog.info(0x0000, "testTag", "Test NAPI KH526_cJSON_AddStringToObject: ", result); 150 console.info("Test NAPI KH526_cJSON_AddStringToObject result: ", JSON.stringify(result)) 151 // Defines a variety of assertion methods, which are used to declare expected boolean conditions. 152 // e.g. expect(result).assertEqual(2+3) 153 }) 154 155 it('KH206_cJSON_AddNumberToObject', 0, () => { 156 // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. 157 hilog.info(0x0000, 'testTag', '%{public}s', 'it begin'); 158 159 let valueObj: testNapi.cJSON = { 160 next: null, 161 prev: null, 162 child: null, 163 type: 0, 164 valuestring: '', 165 valueint: 0, 166 valuedouble: 0, 167 string: '' 168 } 169 // let name = "yMRdqT44d1" 170 let name = "age" 171 let numberIn = 12 172 let result: testNapi.cJSON = testNapi.KH206_cJSON_AddNumberToObject(valueObj, name, numberIn) 173 hilog.info(0x0000, "testTag", "Test NAPI KH206_cJSON_AddNumberToObject: ", result); 174 console.info("Test NAPI KH206_cJSON_AddNumberToObject result: ", JSON.stringify(result)) 175 176 // Defines a variety of assertion methods, which are used to declare expected boolean conditions. 177 // e.g. expect(result).assertEqual(2+3) 178 }) 179 180 it('KH545_cJSON_AddFalseToObject', 0, () => { 181 // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. 182 hilog.info(0x0000, 'testTag', '%{public}s', 'it begin'); 183 let valueObj: testNapi.cJSON = { 184 next: null, 185 prev: null, 186 child: null, 187 type: 0, 188 valuestring: '', 189 valueint: 0, 190 valuedouble: 0, 191 string: '' 192 } 193 // let name = "72QAqnlUXL" 194 let name = "is_student" 195 let result: testNapi.cJSON = testNapi.KH545_cJSON_AddFalseToObject(valueObj, name) 196 hilog.info(0x0000, "testTag", "Test NAPI KH545_cJSON_AddFalseToObject: ", result); 197 console.info("Test NAPI KH545_cJSON_AddFalseToObject result: ", JSON.stringify(result)) 198 199 // Defines a variety of assertion methods, which are used to declare expected boolean conditions. 200 // e.g. expect(result).assertEqual(2+3) 201 }) 202 it('cJSON_Sample_test1', 0, () => { 203 // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. 204 hilog.info(0x0000, 'testTag', '%{public}s', 'it cJSON_Sample_test1 begin'); 205 // 创建一个空对象 206 let cjsonObjNext: testNapi.cJSON = testNapi.KH361_cJSON_CreateObject(); 207 // 向对象中添加元素 208 cjsonObjNext = testNapi.KH526_cJSON_AddStringToObject(cjsonObjNext, "type", "rect"); 209 cjsonObjNext = testNapi.KH206_cJSON_AddNumberToObject(cjsonObjNext, "height", 1080); 210 cjsonObjNext = testNapi.KH206_cJSON_AddNumberToObject(cjsonObjNext, "width", 1920); 211 cjsonObjNext = testNapi.KH545_cJSON_AddFalseToObject(cjsonObjNext, "interface"); 212 cjsonObjNext = testNapi.KH206_cJSON_AddNumberToObject(cjsonObjNext, "frame rate", 24); 213 console.info("Test NAPI cJSON_Sample_test1 cjsonObjNext: " + JSON.stringify(cjsonObjNext)); 214 // 打印 215 let cjsonResStr: string = testNapi.KH735_cJSON_Print(cjsonObjNext); 216 console.info("Test NAPI cJSON_Sample_test1 cjsonResStr: " + JSON.stringify(cjsonResStr)); 217 hilog.info(0x0000, "testTag", "Test NAPI cJSON_Sample_test1 cjsonResStr: ", JSON.stringify(cjsonResStr)); 218 }) 219 220}) 221}