• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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 #include "napi/native_api.h"
16 #include "napi_property_test.h"
17 const size_t BUF_SIZE_MAX = 128;
18 const size_t NUM_SIZE_2 = 2;
19 const size_t NUM_SIZE_3 = 3;
20 //OH_JSVM_HasProperty
21 //obj is null,key is not null  status is not JSVM_OK
TestHasPropertyTest1(JSVM_Env env,JSVM_CallbackInfo info)22 [[maybe_unused]] JSVM_Value TestHasPropertyTest1(JSVM_Env env, JSVM_CallbackInfo info)
23 {
24     size_t argc = 1;
25     JSVM_Value args[1] = {nullptr};
26     JSVM_Value thisVar = nullptr;
27     OH_JSVM_GetCbInfo(env, info, &argc, args, &thisVar, nullptr);
28 
29     bool bRst = false;
30     JSVM_Value testObj = nullptr;
31     JSVM_Status hasProStatus = OH_JSVM_HasProperty(env, testObj, args[0], &bRst);
32     if (hasProStatus == JSVM_OK) {
33         OH_JSVM_ThrowError(env, nullptr, "TestHasPropertyTest1: OH_JSVM_HasProperty Failed");
34         return nullptr;
35     }
36 
37     bool result = true;
38     JSVM_Value value = nullptr;
39     OH_JSVM_GetBoolean(env, result, &value);
40     return value;
41 }
42 //key is nullptr, obj is not null  status is not JSVM_OK
TestHasPropertyTest2(JSVM_Env env,JSVM_CallbackInfo info)43 [[maybe_unused]] JSVM_Value TestHasPropertyTest2(JSVM_Env env, JSVM_CallbackInfo info)
44 {
45     size_t argc = 1;
46     JSVM_Value args[1] = {nullptr};
47     JSVM_Value thisVar = nullptr;
48     OH_JSVM_GetCbInfo(env, info, &argc, args, &thisVar, nullptr);
49 
50     bool bRst = false;
51     JSVM_Value testKey = nullptr;
52     JSVM_Status hasProStatus = OH_JSVM_HasProperty(env, args[0], testKey, &bRst);
53     if (hasProStatus == JSVM_OK) {
54         OH_JSVM_ThrowError(env, nullptr, "TestHasPropertyTest1: OH_JSVM_HasProperty Failed");
55         return nullptr;
56     }
57 
58     bool result = true;
59     JSVM_Value value = nullptr;
60     OH_JSVM_GetBoolean(env, result, &value);
61     return value;
62 }
63 //OH_JSVM_DeleteProperty
64 //obj is null,key is not null  status is not JSVM_OK
TestDeletePropertyTest1(JSVM_Env env,JSVM_CallbackInfo info)65 [[maybe_unused]] JSVM_Value TestDeletePropertyTest1(JSVM_Env env, JSVM_CallbackInfo info)
66 {
67     size_t argc = NUM_SIZE_2;
68     JSVM_Value args[NUM_SIZE_2] = {nullptr};
69     JSVM_Value thisVar = nullptr;
70     OH_JSVM_GetCbInfo(env, info, &argc, args, &thisVar, nullptr);
71 
72     bool bRst = false;
73     JSVM_Value testObj = nullptr;
74     JSVM_Status delProStatus = OH_JSVM_DeleteProperty(env, testObj, args[1], &bRst);
75     if (delProStatus == JSVM_OK) {
76         OH_JSVM_ThrowError(env, nullptr, "TestDeletePropertyTest1: OH_JSVM_DeleteProperty Failed");
77         return nullptr;
78     }
79 
80     bool result = true;
81     JSVM_Value value = nullptr;
82     OH_JSVM_GetBoolean(env, result, &value);
83     return value;
84 }
85 //key is nullptr, obj is not null status is not JSVM_OK
TestDeletePropertyTest2(JSVM_Env env,JSVM_CallbackInfo info)86 [[maybe_unused]] JSVM_Value TestDeletePropertyTest2(JSVM_Env env, JSVM_CallbackInfo info)
87 {
88     size_t argc = NUM_SIZE_2;
89     JSVM_Value args[NUM_SIZE_2] = {nullptr};
90     JSVM_Value thisVar = nullptr;
91     OH_JSVM_GetCbInfo(env, info, &argc, args, &thisVar, nullptr);
92 
93     bool bRst = false;
94     JSVM_Value testKey = nullptr;
95     JSVM_Status delProStatus = OH_JSVM_DeleteProperty(env, args[0], testKey, &bRst);
96     if (delProStatus == JSVM_OK) {
97         OH_JSVM_ThrowError(env, nullptr, "TestDeletePropertyTest2: OH_JSVM_HasProperty Failed");
98         return nullptr;
99     }
100 
101     bool result = true;
102     JSVM_Value value = nullptr;
103     OH_JSVM_GetBoolean(env, result, &value);
104     return value;
105 }
106 //OH_JSVM_HasOwnProperty
107 //Object is nullptr,key is not null status is not JSVM_OK
TestHasOwnPropertyTest1(JSVM_Env env,JSVM_CallbackInfo info)108 [[maybe_unused]] JSVM_Value TestHasOwnPropertyTest1(JSVM_Env env, JSVM_CallbackInfo info)
109 {
110     size_t argc = NUM_SIZE_2;
111     JSVM_Value args[NUM_SIZE_2] = {nullptr};
112     JSVM_Value thisVar = nullptr;
113     OH_JSVM_GetCbInfo(env, info, &argc, args, &thisVar, nullptr);
114 
115     bool bRst = false;
116     JSVM_Value testObj = nullptr;
117     JSVM_Status hasOwnProStatus = OH_JSVM_HasOwnProperty(env, testObj, args[1], &bRst);
118     if (hasOwnProStatus == JSVM_OK) {
119         OH_JSVM_ThrowError(env, nullptr, "TestHasOwnPropertyTest1: OH_JSVM_HasProperty Failed");
120         return nullptr;
121     }
122 
123     bool result = true;
124     JSVM_Value value = nullptr;
125     OH_JSVM_GetBoolean(env, result, &value);
126     return value;
127 }
128 //key is nullptr,object is not null status is not JSVM_OK
TestHasOwnPropertyTest2(JSVM_Env env,JSVM_CallbackInfo info)129 [[maybe_unused]] JSVM_Value TestHasOwnPropertyTest2(JSVM_Env env, JSVM_CallbackInfo info)
130 {
131     size_t argc = NUM_SIZE_2;
132     JSVM_Value args[NUM_SIZE_2] = {nullptr};
133     JSVM_Value thisVar = nullptr;
134     OH_JSVM_GetCbInfo(env, info, &argc, args, &thisVar, nullptr);
135 
136     JSVM_ValueType valueType;
137     OH_JSVM_Typeof(env, args[0], &valueType);
138     if (valueType != JSVM_OBJECT) {
139         OH_JSVM_ThrowError(env, nullptr, "TestHasOwnPropertyTest2: OH_JSVM_Typeof value1 Failed");
140         return nullptr;
141     }
142     JSVM_ValueType valuetype2;
143     OH_JSVM_Typeof(env, args[1], &valuetype2);
144     if (valuetype2 != JSVM_STRING) {
145         OH_JSVM_ThrowError(env, nullptr, "TestHasOwnPropertyTest2: OH_JSVM_Typeof value2 Failed");
146         return nullptr;
147     }
148 
149     bool bRst = false;
150     JSVM_Value testKey = nullptr;
151     JSVM_Status hasOwnProStatus = OH_JSVM_HasOwnProperty(env, args[0], testKey, &bRst);
152     if (hasOwnProStatus == JSVM_OK) {
153         OH_JSVM_ThrowError(env, nullptr, "TestHasOwnPropertyTest2: OH_JSVM_HasOwnProperty Failed");
154         return nullptr;
155     }
156 
157     bool result = true;
158     JSVM_Value value = nullptr;
159     OH_JSVM_GetBoolean(env, result, &value);
160     return value;
161 }
162 //is not own property,set property
TestHasOwnPropertyTest3(JSVM_Env env,JSVM_CallbackInfo info)163 [[maybe_unused]] JSVM_Value TestHasOwnPropertyTest3(JSVM_Env env, JSVM_CallbackInfo info)
164 {
165     size_t argc = 1;
166     JSVM_Value args[1] = {nullptr};
167     JSVM_Value thisVar = nullptr;
168     OH_JSVM_GetCbInfo(env, info, &argc, args, &thisVar, nullptr);
169 
170     const char* strKeyName = "key name";
171     JSVM_Value setKeyName = nullptr;
172     OH_JSVM_CreateStringUtf8(env, strKeyName, JSVM_AUTO_LENGTH, &setKeyName);
173     const char* strKeyValue = "key value";
174     JSVM_Value setKeyValue = nullptr;
175     OH_JSVM_CreateStringUtf8(env, strKeyValue, JSVM_AUTO_LENGTH, &setKeyValue);
176     JSVM_Status setStatus = OH_JSVM_SetProperty(env, args[0], setKeyName, setKeyValue);
177     if (setStatus != JSVM_OK) {
178         OH_JSVM_ThrowError(env, nullptr, "TestHasOwnPropertyTest3: OH_JSVM_SetProperty Failed");
179         return nullptr;
180     }
181     JSVM_ValueType valueType;
182     OH_JSVM_Typeof(env, args[0], &valueType);
183     if (valueType != JSVM_OBJECT) {
184         OH_JSVM_ThrowError(env, nullptr, "TestHasOwnPropertyTest3: OH_JSVM_Typeof obj Failed");
185         return nullptr;
186     }
187     JSVM_ValueType valuetype2;
188     OH_JSVM_Typeof(env, setKeyName, &valuetype2);
189     if (valuetype2 != JSVM_STRING) {
190         OH_JSVM_ThrowError(env, nullptr, "TestHasOwnPropertyTest3: OH_JSVM_Typeof key Failed");
191         return nullptr;
192     }
193 
194     bool bRst = false;
195     JSVM_Status hasOwnProStatus = OH_JSVM_HasOwnProperty(env, args[0], setKeyName, &bRst);
196     if (hasOwnProStatus != JSVM_OK) {
197         OH_JSVM_ThrowError(env, nullptr, "TestHasOwnPropertyTest3: OH_JSVM_HasOwnProperty status Failed");
198         return nullptr;
199     }
200     if (!bRst) {
201         OH_JSVM_ThrowError(env, nullptr, "TestHasOwnPropertyTest3: OH_JSVM_HasOwnProperty result Failed");
202         return nullptr;
203     }
204 
205     bool result = true;
206     JSVM_Value value = nullptr;
207     OH_JSVM_GetBoolean(env, result, &value);
208     return value;
209 }
210 //OH_JSVM_GetNamedProperty
211 //Object is nullptr,key is not null status is not JSVM_OK
TestGetNamedPropertyTest1(JSVM_Env env,JSVM_CallbackInfo info)212 [[maybe_unused]] JSVM_Value TestGetNamedPropertyTest1(JSVM_Env env, JSVM_CallbackInfo info)
213 {
214     size_t argc = NUM_SIZE_2;
215     JSVM_Value args[NUM_SIZE_2] = {nullptr};
216     JSVM_Value thisVar = nullptr;
217     JSVM_Status status = OH_JSVM_GetCbInfo(env, info, &argc, args, &thisVar, nullptr);
218     if (status != JSVM_OK) {
219         OH_JSVM_ThrowError(env, nullptr, "TestGetNamedPropertyTest1: OH_JSVM_GetCbInfo Failed");
220         return nullptr;
221     }
222     char strKey[BUF_SIZE_MAX] = {0};
223     size_t keyLength = 0;
224     status = OH_JSVM_GetValueStringUtf8(env, args[1], strKey, BUF_SIZE_MAX, &keyLength);
225     if (status != JSVM_OK) {
226         OH_JSVM_ThrowError(env, nullptr, "TestGetNamedPropertyTest1: OH_JSVM_GetValueStringUtf8 Failed");
227         return nullptr;
228     }
229     JSVM_Value rstValue = nullptr;
230     JSVM_Value objPro = nullptr;
231     status = OH_JSVM_GetNamedProperty(env, objPro, strKey, &rstValue);
232     if (status == JSVM_OK) {
233         OH_JSVM_ThrowError(env, nullptr, "TestGetNamedPropertyTest1: OH_JSVM_GetNamedProperty Failed");
234         return nullptr;
235     }
236 
237     bool result = true;
238     JSVM_Value value = nullptr;
239     OH_JSVM_GetBoolean(env, result, &value);
240     return value;
241 }
242 //key is nullptr,object is not null  status is not JSVM_OK
TestGetNamedPropertyTest2(JSVM_Env env,JSVM_CallbackInfo info)243 [[maybe_unused]] JSVM_Value TestGetNamedPropertyTest2(JSVM_Env env, JSVM_CallbackInfo info)
244 {
245     size_t argc = NUM_SIZE_2;
246     JSVM_Value args[NUM_SIZE_2] = {nullptr};
247     JSVM_Value thisVar = nullptr;
248     OH_JSVM_GetCbInfo(env, info, &argc, args, &thisVar, nullptr);
249 
250     JSVM_Value rstValue = nullptr;
251     const char* strKey = nullptr;
252     JSVM_Status status = OH_JSVM_GetNamedProperty(env, args[0], strKey, &rstValue);
253     if (status == JSVM_OK) {
254         OH_JSVM_ThrowError(env, nullptr, "TestGetNamedPropertyTest2: OH_JSVM_GetNamedProperty Failed");
255         return nullptr;
256     }
257 
258     bool result = true;
259     JSVM_Value value = nullptr;
260     OH_JSVM_GetBoolean(env, result, &value);
261     return value;
262 }
263 //obj is not null,get is not exist key  status is not JSVM_OK---
TestGetNamedPropertyTest3(JSVM_Env env,JSVM_CallbackInfo info)264 [[maybe_unused]] JSVM_Value TestGetNamedPropertyTest3(JSVM_Env env, JSVM_CallbackInfo info)
265 {
266     size_t argc = NUM_SIZE_2;
267     JSVM_Value args[NUM_SIZE_2] = {nullptr};
268     JSVM_Value thisVar = nullptr;
269     OH_JSVM_GetCbInfo(env, info, &argc, args, &thisVar, nullptr);
270 
271     JSVM_Value rstValue = nullptr;
272     const char* strKey = "null value";
273     JSVM_Status status = OH_JSVM_GetNamedProperty(env, args[0], strKey, &rstValue);
274     if (status != JSVM_OK) {
275         OH_JSVM_ThrowError(env, nullptr, "TestGetNamedPropertyTest3: OH_JSVM_GetNamedProperty Failed");
276         return nullptr;
277     }
278     char rstBuf[BUF_SIZE_MAX] = {0};
279     size_t rstLength = 0;
280     OH_JSVM_GetValueStringUtf8(env, rstValue, rstBuf, BUF_SIZE_MAX, &rstLength);
281     if (rstLength != 0) {
282         OH_JSVM_ThrowError(env, nullptr, "TestGetNamedPropertyTest3: rstLength != 0");
283         return nullptr;
284     }
285 
286     bool result = true;
287     JSVM_Value value = nullptr;
288     OH_JSVM_GetBoolean(env, result, &value);
289     return value;
290 }
291 //OH_JSVM_HasNamedProperty
292 //obj is null,utf8name is not null  status is not JSVM_OK
TestHasNamedPropertyTest1(JSVM_Env env,JSVM_CallbackInfo info)293 [[maybe_unused]] JSVM_Value TestHasNamedPropertyTest1(JSVM_Env env, JSVM_CallbackInfo info)
294 {
295     size_t argc = NUM_SIZE_2;
296     JSVM_Value args[NUM_SIZE_2] = {nullptr};
297     JSVM_Value thisVar = nullptr;
298     JSVM_Status status = OH_JSVM_GetCbInfo(env, info, &argc, args, &thisVar, nullptr);
299     if (status != JSVM_OK) {
300         OH_JSVM_ThrowError(env, nullptr, "TestHasNamedPropertyTest1: OH_JSVM_GetCbInfo Failed");
301         return nullptr;
302     }
303     char strKey[BUF_SIZE_MAX] = {0};
304     size_t keyLength = 0;
305     status = OH_JSVM_GetValueStringUtf8(env, args[1], strKey, BUF_SIZE_MAX, &keyLength);
306     if (status != JSVM_OK) {
307         OH_JSVM_ThrowError(env, nullptr, "TestHasNamedPropertyTest1: OH_JSVM_GetValueStringUtf8 Failed");
308         return nullptr;
309     }
310 
311     bool bRstValue = false;
312     JSVM_Value objPro = nullptr;
313     status = OH_JSVM_HasNamedProperty(env, objPro, strKey, &bRstValue);
314     if (status == JSVM_OK) {
315         OH_JSVM_ThrowError(env, nullptr, "TestHasNamedPropertyTest1: OH_JSVM_GetNamedProperty Failed");
316         return nullptr;
317     }
318 
319     bool result = true;
320     JSVM_Value value = nullptr;
321     OH_JSVM_GetBoolean(env, result, &value);
322     return value;
323 }
324 //utf8name is nullptr, obj is not null  status is not JSVM_OK
TestHasNamedPropertyTest2(JSVM_Env env,JSVM_CallbackInfo info)325 [[maybe_unused]] JSVM_Value TestHasNamedPropertyTest2(JSVM_Env env, JSVM_CallbackInfo info)
326 {
327     size_t argc = NUM_SIZE_2;
328     JSVM_Value args[NUM_SIZE_2] = {nullptr};
329     JSVM_Value thisVar = nullptr;
330     JSVM_Status status = OH_JSVM_GetCbInfo(env, info, &argc, args, &thisVar, nullptr);
331     if (status != JSVM_OK) {
332         OH_JSVM_ThrowError(env, nullptr, "TestHasNamedPropertyTest2: OH_JSVM_GetCbInfo Failed");
333         return nullptr;
334     }
335     bool bRstValue = false;
336     const char* strKey = nullptr;
337     status = OH_JSVM_HasNamedProperty(env, args[0], strKey, &bRstValue);
338     if (status == JSVM_OK) {
339         OH_JSVM_ThrowError(env, nullptr, "TestHasNamedPropertyTest2: OH_JSVM_GetNamedProperty Failed");
340         return nullptr;
341     }
342 
343     bool result = true;
344     JSVM_Value value = nullptr;
345     OH_JSVM_GetBoolean(env, result, &value);
346     return value;
347 }
348 //obj is not null,utf8name is not exist ,status  is JSVM_OK  result is false
TestHasNamedPropertyTest3(JSVM_Env env,JSVM_CallbackInfo info)349 [[maybe_unused]] JSVM_Value TestHasNamedPropertyTest3(JSVM_Env env, JSVM_CallbackInfo info)
350 {
351     size_t argc = NUM_SIZE_2;
352     JSVM_Value args[NUM_SIZE_2] = {nullptr};
353     JSVM_Value thisVar = nullptr;
354     JSVM_Status status = OH_JSVM_GetCbInfo(env, info, &argc, args, &thisVar, nullptr);
355     if (status != JSVM_OK) {
356         OH_JSVM_ThrowError(env, nullptr, "TestHasNamedPropertyTest3: OH_JSVM_GetCbInfo Failed");
357         return nullptr;
358     }
359     bool bRstValue = false;
360     const char* strKey = "not exist key";
361     status = OH_JSVM_HasNamedProperty(env, args[0], strKey, &bRstValue);
362     if (status != JSVM_OK) {
363         OH_JSVM_ThrowError(env, nullptr, "TestHasNamedPropertyTest3: OH_JSVM_GetNamedProperty status Failed");
364         return nullptr;
365     }
366     if (bRstValue) {
367         OH_JSVM_ThrowError(env, nullptr, "TestHasNamedPropertyTest3: OH_JSVM_GetNamedProperty result Failed");
368         return nullptr;
369     }
370 
371     bool result = true;
372     JSVM_Value value = nullptr;
373     OH_JSVM_GetBoolean(env, result, &value);
374     return value;
375 }
376 //obj is not null,utf8name is exist, status  is JSVM_OK,,result is true
TestHasNamedPropertyTest4(JSVM_Env env,JSVM_CallbackInfo info)377 [[maybe_unused]] JSVM_Value TestHasNamedPropertyTest4(JSVM_Env env, JSVM_CallbackInfo info)
378 {
379     size_t argc = NUM_SIZE_2;
380     JSVM_Value args[NUM_SIZE_2] = {nullptr};
381     JSVM_Value thisVar = nullptr;
382     JSVM_Status status = OH_JSVM_GetCbInfo(env, info, &argc, args, &thisVar, nullptr);
383     if (status != JSVM_OK) {
384         OH_JSVM_ThrowError(env, nullptr, "TestHasNamedPropertyTest4: OH_JSVM_GetCbInfo Failed");
385         return nullptr;
386     }
387     bool bRstValue = false;
388     const char* strKey = "key";
389     status = OH_JSVM_HasNamedProperty(env, args[0], strKey, &bRstValue);
390     if (status != JSVM_OK) {
391         OH_JSVM_ThrowError(env, nullptr, "TestHasNamedPropertyTest4: OH_JSVM_GetNamedProperty status Failed");
392         return nullptr;
393     }
394     if (!bRstValue) {
395         OH_JSVM_ThrowError(env, nullptr, "TestHasNamedPropertyTest4: OH_JSVM_GetNamedProperty result Failed");
396         return nullptr;
397     }
398 
399     bool result = true;
400     JSVM_Value value = nullptr;
401     OH_JSVM_GetBoolean(env, result, &value);
402     return value;
403 }
404 //OH_JSVM_DefineProperties
405 //Object is nullptr  status is not JSVM_OK
TestDefinePropertiesTest1(JSVM_Env env,JSVM_CallbackInfo info)406 [[maybe_unused]] JSVM_Value TestDefinePropertiesTest1(JSVM_Env env, JSVM_CallbackInfo info)
407 {
408     size_t argc = 1;
409     JSVM_Value args[1] = {nullptr};
410     JSVM_Value thisVar = nullptr;
411     JSVM_Status status = OH_JSVM_GetCbInfo(env, info, &argc, args, &thisVar, nullptr);
412     if (status != JSVM_OK) {
413         OH_JSVM_ThrowError(env, nullptr, "TestDefinePropertiesTest1: OH_JSVM_GetCbInfo Failed");
414         return nullptr;
415     }
416     bool bRstValue = false;
417     size_t proCount = 1;
418     JSVM_Value stringValue = nullptr;
419     const JSVM_PropertyDescriptor arrPro[] = {{"defineStringProperties",
420         nullptr, nullptr, nullptr, nullptr, stringValue, JSVM_DEFAULT}};
421     JSVM_Value objPro = nullptr;
422     status = OH_JSVM_DefineProperties(env, objPro, proCount, arrPro);
423     if (status == JSVM_OK) {
424         OH_JSVM_ThrowError(env, nullptr, "TestDefinePropertiesTest1: OH_JSVM_DefineProperties status Failed");
425         return nullptr;
426     }
427 
428     bool result = true;
429     JSVM_Value value = nullptr;
430     OH_JSVM_GetBoolean(env, result, &value);
431     return value;
432 }
433 //size_t propertyCount is 0  status is JSVM_OK
TestDefinePropertiesTest2(JSVM_Env env,JSVM_CallbackInfo info)434 [[maybe_unused]] JSVM_Value TestDefinePropertiesTest2(JSVM_Env env, JSVM_CallbackInfo info)
435 {
436     size_t argc = 1;
437     JSVM_Value args[1] = {nullptr};
438     JSVM_Value thisVar = nullptr;
439     JSVM_Status status = OH_JSVM_GetCbInfo(env, info, &argc, args, &thisVar, nullptr);
440     if (status != JSVM_OK) {
441         OH_JSVM_ThrowError(env, nullptr, "TestDefinePropertiesTest2: OH_JSVM_GetCbInfo Failed");
442         return nullptr;
443     }
444     bool bRstValue = false;
445     size_t proCount = 0;
446     JSVM_Value stringValue = nullptr;
447     const JSVM_PropertyDescriptor arrPro[] = {{"defineStringPropertiesExample",
448         nullptr, nullptr, nullptr, nullptr, stringValue, JSVM_DEFAULT}};
449     status = OH_JSVM_DefineProperties(env, args[0], proCount, arrPro);
450     if (status != JSVM_OK) {
451         OH_JSVM_ThrowError(env, nullptr, "TestDefinePropertiesTest2: OH_JSVM_DefineProperties status Failed");
452         return nullptr;
453     }
454 
455     bool result = true;
456     JSVM_Value value = nullptr;
457     OH_JSVM_GetBoolean(env, result, &value);
458     return value;
459 }
460 // properties = null, status is not JSVM_OK
TestDefinePropertiesTest3(JSVM_Env env,JSVM_CallbackInfo info)461 [[maybe_unused]] JSVM_Value TestDefinePropertiesTest3(JSVM_Env env, JSVM_CallbackInfo info)
462 {
463     size_t argc = 1;
464     JSVM_Value args[1] = {nullptr};
465     JSVM_Value thisVar = nullptr;
466     JSVM_Status status = OH_JSVM_GetCbInfo(env, info, &argc, args, &thisVar, nullptr);
467     if (status != JSVM_OK) {
468         OH_JSVM_ThrowError(env, nullptr, "TestDefinePropertiesTest3: OH_JSVM_GetCbInfo Failed");
469         return nullptr;
470     }
471     bool bRstValue = false;
472     size_t proCount = 1;
473     JSVM_Value stringValue = nullptr;
474     const JSVM_PropertyDescriptor *arrPro = nullptr;
475     status = OH_JSVM_DefineProperties(env, args[0], proCount, arrPro);
476     if (status == JSVM_OK) {
477         OH_JSVM_ThrowError(env, nullptr, "TestDefinePropertiesTest3: OH_JSVM_DefineProperties status Failed");
478         return nullptr;
479     }
480 
481     bool result = true;
482     JSVM_Value value = nullptr;
483     OH_JSVM_GetBoolean(env, result, &value);
484     return value;
485 }
486 //  properties is descriptor  status is JSVM_OK, HasProperty
TestDefinePropertiesTest4(JSVM_Env env,JSVM_CallbackInfo info)487 [[maybe_unused]] JSVM_Value TestDefinePropertiesTest4(JSVM_Env env, JSVM_CallbackInfo info)
488 {
489     size_t argc = 1;
490     JSVM_Value args[1] = {nullptr};
491     JSVM_Value thisVar = nullptr;
492     JSVM_Status status = OH_JSVM_GetCbInfo(env, info, &argc, args, &thisVar, nullptr);
493     if (status != JSVM_OK) {
494         OH_JSVM_ThrowError(env, nullptr, "TestDefinePropertiesTest4: OH_JSVM_GetCbInfo Failed");
495         return nullptr;
496     }
497     bool bRstValue = false;
498     size_t proCount = 1;
499     JSVM_Value stringValue = nullptr;
500     status = OH_JSVM_CreateStringUtf8(env, "create string", JSVM_AUTO_LENGTH, &stringValue);
501     if (status != JSVM_OK) {
502         OH_JSVM_ThrowError(env, nullptr, "TestDefinePropertiesTest4: OH_JSVM_CreateStringUtf8 Failed");
503         return nullptr;
504     }
505     const JSVM_PropertyDescriptor arrPro[] = {{"defineStringPropertiesExample",
506         nullptr, nullptr, nullptr, nullptr, stringValue, JSVM_DEFAULT}};
507     status = OH_JSVM_DefineProperties(env, args[0], proCount, arrPro);
508     if (status != JSVM_OK) {
509         OH_JSVM_ThrowError(env, nullptr, "TestDefinePropertiesTest4: OH_JSVM_DefineProperties status Failed");
510         return nullptr;
511     }
512     bool bRstHas = false;
513     status = OH_JSVM_HasNamedProperty(env, args[0], "defineStringPropertiesExample", &bRstHas);
514     if (status != JSVM_OK) {
515         OH_JSVM_ThrowError(env, nullptr, "TestDefinePropertiesTest4: OH_JSVM_HasNamedProperty status Failed");
516         return nullptr;
517     }
518     if (!bRstHas) {
519         OH_JSVM_ThrowError(env, nullptr, "TestDefinePropertiesTest4: OH_JSVM_HasNamedProperty result Failed");
520         return nullptr;
521     }
522 
523     bool result = true;
524     JSVM_Value value = nullptr;
525     OH_JSVM_GetBoolean(env, result, &value);
526     return value;
527 }
528 // Property combination: setProperty-> setProperty-> getProperty-> getProperty
529 // hasProperty -> hasProperty -> deleteProperty ->deleteProperty
TestCombinationPropertyTest1(JSVM_Env env,JSVM_CallbackInfo info)530 [[maybe_unused]] JSVM_Value TestCombinationPropertyTest1(JSVM_Env env, JSVM_CallbackInfo info)
531 {
532     size_t argc = NUM_SIZE_3;
533     JSVM_Value args[NUM_SIZE_3] = {nullptr};
534     JSVM_Value thisVar = nullptr;
535     JSVM_Status status = OH_JSVM_GetCbInfo(env, info, &argc, args, &thisVar, nullptr);
536     if (status != JSVM_OK) {
537         OH_JSVM_ThrowError(env, nullptr, "TestCombinationPropertyTest1: OH_JSVM_GetCbInfo Failed");
538         return nullptr;
539     }
540     // call OH_JSVM_SetProperty
541     status = OH_JSVM_SetProperty(env, args[0], args[1], args[NUM_SIZE_2]);
542     if (status != JSVM_OK) {
543         OH_JSVM_ThrowError(env, nullptr, "TestCombinationPropertyTest1: OH_JSVM_SetProperty Failed");
544         return nullptr;
545     }
546     // Call OH_JSVM_SetProperty again
547     bool bRstValue = false;
548     JSVM_Value stringValue = nullptr;
549     const char* strKeyValue = "property value1";
550     status = OH_JSVM_CreateStringUtf8(env, strKeyValue, JSVM_AUTO_LENGTH, &stringValue);
551     if (status != JSVM_OK) {
552         OH_JSVM_ThrowError(env, nullptr, "TestCombinationPropertyTest1: OH_JSVM_CreateStringUtf8 Failed");
553         return nullptr;
554     }
555     status = OH_JSVM_SetProperty(env, args[0], args[1], stringValue);
556     if (status != JSVM_OK) {
557         OH_JSVM_ThrowError(env, nullptr, "TestCombinationPropertyTest1: OH_JSVM_SetProperty again Failed");
558         return nullptr;
559     }
560     // Call getProperty
561     JSVM_Value rstValue = nullptr;
562     status = OH_JSVM_GetProperty(env, args[0], args[1], &rstValue);
563     if (status != JSVM_OK) {
564         OH_JSVM_ThrowError(env, nullptr, "TestCombinationPropertyTest1: OH_JSVM_GetProperty Failed");
565         return nullptr;
566     }
567     char strGetKeyValue[BUF_SIZE_MAX] = {0};
568     size_t rstLength = 0;
569     status = OH_JSVM_GetValueStringUtf8(env, rstValue, strGetKeyValue, BUF_SIZE_MAX, &rstLength);
570     if (status != JSVM_OK) {
571         OH_JSVM_ThrowError(env, nullptr, "TestCombinationPropertyTest1: OH_JSVM_GetValueStringUtf8 Failed");
572         return nullptr;
573     }
574     if (strcmp(strKeyValue, strGetKeyValue) != 0) {
575         OH_JSVM_ThrowError(env, nullptr, "TestCombinationPropertyTest1: GetProperty keyvalue!=getkeyvalue Failed");
576         return nullptr;
577     }
578     // Call getProperty again
579     JSVM_Value rstValue1 = nullptr;
580     status = OH_JSVM_GetProperty(env, args[0], args[1], &rstValue1);
581     if (status != JSVM_OK) {
582         OH_JSVM_ThrowError(env, nullptr, "TestCombinationPropertyTest1: OH_JSVM_GetProperty Failed");
583         return nullptr;
584     }
585     char strGetKeyValue1[BUF_SIZE_MAX] = {0};
586     size_t rstLength1 = 0;
587     status = OH_JSVM_GetValueStringUtf8(env, rstValue1, strGetKeyValue1, BUF_SIZE_MAX, &rstLength1);
588     if (status != JSVM_OK) {
589         OH_JSVM_ThrowError(env, nullptr, "TestCombinationPropertyTest1: OH_JSVM_GetValueStringUtf8 Failed");
590         return nullptr;
591     }
592     if (strcmp(strKeyValue, strGetKeyValue1) != 0) {
593         OH_JSVM_ThrowError(env, nullptr, "TestCombinationPropertyTest1: GetProperty keyvalue!=getkeyvalue1 Failed");
594         return nullptr;
595     }
596     // call OH_JSVM_HasProperty
597     bool bHasRst = false;
598     status = OH_JSVM_HasProperty(env, args[0], args[1], &bHasRst);
599     if (status != JSVM_OK) {
600         OH_JSVM_ThrowError(env, nullptr, "TestCombinationPropertyTest1: OH_JSVM_HasProperty Failed");
601         return nullptr;
602     }
603     if (!bHasRst) {
604         OH_JSVM_ThrowError(env, nullptr, "TestCombinationPropertyTest1: OH_JSVM_HasProperty result is false");
605         return nullptr;
606     }
607     // call OH_JSVM_HasProperty again
608     bool bHasRst1 = false;
609     status = OH_JSVM_HasProperty(env, args[0], args[1], &bHasRst1);
610     if (status != JSVM_OK) {
611         OH_JSVM_ThrowError(env, nullptr, "TestCombinationPropertyTest1: OH_JSVM_HasProperty Failed");
612         return nullptr;
613     }
614     if (!bHasRst1) {
615         OH_JSVM_ThrowError(env, nullptr, "TestCombinationPropertyTest1: OH_JSVM_HasProperty result is false");
616         return nullptr;
617     }
618     // call OH_JSVM_DeleteProperty
619     bool bDelRst = false;
620     status = OH_JSVM_DeleteProperty(env, args[0], args[1], &bDelRst);
621     if (status != JSVM_OK) {
622         OH_JSVM_ThrowError(env, nullptr, "TestCombinationPropertyTest1: OH_JSVM_DeleteProperty Failed");
623         return nullptr;
624     }
625     if (!bDelRst) {
626         OH_JSVM_ThrowError(env, nullptr, "TestCombinationPropertyTest1: OH_JSVM_DeleteProperty result is false");
627         return nullptr;
628     }
629     // call OH_JSVM_DeleteProperty again
630     bool bDelRst1 = false;
631     status = OH_JSVM_DeleteProperty(env, args[0], args[1], &bDelRst1);
632     if (status != JSVM_OK) {
633         OH_JSVM_ThrowError(env, nullptr, "TestCombinationPropertyTest1: OH_JSVM_DeleteProperty Failed");
634         return nullptr;
635     }
636     if (!bDelRst1) {
637         OH_JSVM_ThrowError(env, nullptr, "TestCombinationPropertyTest1: OH_JSVM_DeleteProperty result is true");
638         return nullptr;
639     }
640 
641     bool result = true;
642     JSVM_Value value = nullptr;
643     OH_JSVM_GetBoolean(env, result, &value);
644     return value;
645 }
646 // Property combination: setProperty 2 property->  hasProperty 2 property -> getProperty 2 property
647 //->deleteProperty 1 property->  hasProperty other property-> getProperty other property
TestCombinationPropertyTest2(JSVM_Env env,JSVM_CallbackInfo info)648 [[maybe_unused]] JSVM_Value TestCombinationPropertyTest2(JSVM_Env env, JSVM_CallbackInfo info)
649 {
650     size_t argc = NUM_SIZE_3;
651     JSVM_Value args[NUM_SIZE_3] = {nullptr};
652     JSVM_Value thisVar = nullptr;
653     OH_JSVM_GetCbInfo(env, info, &argc, args, &thisVar, nullptr);
654     // call OH_JSVM_SetProperty
655     JSVM_Status status = OH_JSVM_SetProperty(env, args[0], args[1], args[NUM_SIZE_2]);
656     if (status != JSVM_OK) {
657         OH_JSVM_ThrowError(env, nullptr, "TestCombinationPropertyTest2: OH_JSVM_SetProperty Failed");
658         return nullptr;
659     }
660     // Call OH_JSVM_SetProperty again
661     JSVM_Value stringValue = nullptr;
662     const char* strKeyValue = "setKeyValue1";
663     OH_JSVM_CreateStringUtf8(env, strKeyValue, JSVM_AUTO_LENGTH, &stringValue);
664     JSVM_Value stringKey = nullptr;
665     const char* strKey = "setkey1";
666     OH_JSVM_CreateStringUtf8(env, strKey, JSVM_AUTO_LENGTH, &stringKey);
667     status = OH_JSVM_SetProperty(env, args[0], stringKey, stringValue);
668     if (status != JSVM_OK) {
669         OH_JSVM_ThrowError(env, nullptr, "TestCombinationPropertyTest2: OH_JSVM_SetProperty again Failed");
670         return nullptr;
671     }
672     // call OH_JSVM_HasProperty
673     bool bHasRst = false;
674     status = OH_JSVM_HasProperty(env, args[0], args[1], &bHasRst);
675     if (status != JSVM_OK) {
676         OH_JSVM_ThrowError(env, nullptr, "TestCombinationPropertyTest2: OH_JSVM_HasProperty Failed");
677         return nullptr;
678     }
679     if (!bHasRst) {
680         OH_JSVM_ThrowError(env, nullptr, "TestCombinationPropertyTest2: OH_JSVM_HasProperty result is false");
681         return nullptr;
682     }
683     // call OH_JSVM_HasProperty again
684     bool bHasRst1 = false;
685     status = OH_JSVM_HasProperty(env, args[0], stringKey, &bHasRst1);
686     if (status != JSVM_OK) {
687         OH_JSVM_ThrowError(env, nullptr, "TestCombinationPropertyTest2: OH_JSVM_HasProperty1 Failed");
688         return nullptr;
689     }
690     if (!bHasRst1) {
691         OH_JSVM_ThrowError(env, nullptr, "TestCombinationPropertyTest2: OH_JSVM_HasProperty result1 is false");
692         return nullptr;
693     }
694     // Call getProperty
695     JSVM_Value rstValue = nullptr;
696     status = OH_JSVM_GetProperty(env, args[0], args[1], &rstValue);
697     if (status != JSVM_OK) {
698         OH_JSVM_ThrowError(env, nullptr, "TestCombinationPropertyTest2: OH_JSVM_GetProperty Failed");
699         return nullptr;
700     }
701     char strGetKeyValue[BUF_SIZE_MAX] = {0};
702     size_t rstLength = 0;
703     OH_JSVM_GetValueStringUtf8(env, rstValue, strGetKeyValue, BUF_SIZE_MAX, &rstLength);
704     char strGetKeyValueFirst[BUF_SIZE_MAX] = {0};
705     size_t rstFirstLength = 0;
706     status = OH_JSVM_GetValueStringUtf8(env, args[NUM_SIZE_2], strGetKeyValueFirst, BUF_SIZE_MAX, &rstFirstLength);
707     if (status != JSVM_OK) {
708         OH_JSVM_ThrowError(env, nullptr, "TestCombinationPropertyTest2: OH_JSVM_GetValueStringUtf8 Failed");
709         return nullptr;
710     }
711     if (strcmp(strGetKeyValueFirst, strGetKeyValue) != 0) {
712         OH_JSVM_ThrowError(env, nullptr, "TestCombinationPropertyTest2: GetProperty keyvalue!=getkeyvalue Failed");
713         return nullptr;
714     }
715     // Call getProperty again
716     JSVM_Value rstValue1 = nullptr;
717     status = OH_JSVM_GetProperty(env, args[0], stringKey, &rstValue1);
718     if (status != JSVM_OK) {
719         OH_JSVM_ThrowError(env, nullptr, "TestCombinationPropertyTest2: OH_JSVM_GetProperty Failed");
720         return nullptr;
721     }
722     char strGetKeyValue1[BUF_SIZE_MAX] = {0};
723     size_t rstLength1 = 0;
724     status = OH_JSVM_GetValueStringUtf8(env, rstValue1, strGetKeyValue1, BUF_SIZE_MAX, &rstLength1);
725     if (status != JSVM_OK) {
726         OH_JSVM_ThrowError(env, nullptr, "TestCombinationPropertyTest2: OH_JSVM_GetValueStringUtf8 Failed");
727         return nullptr;
728     }
729     if (strcmp(strKeyValue, strGetKeyValue1) != 0) {
730         OH_JSVM_ThrowError(env, nullptr, "TestCombinationPropertyTest2: GetProperty keyvalue!=getkeyvalue1 Failed");
731         return nullptr;
732     }
733     // call OH_JSVM_DeleteProperty
734     bool bDelRst = false;
735     status = OH_JSVM_DeleteProperty(env, args[0], args[1], &bDelRst);
736     if (status != JSVM_OK) {
737         OH_JSVM_ThrowError(env, nullptr, "TestCombinationPropertyTest2: OH_JSVM_DeleteProperty Failed");
738         return nullptr;
739     }
740     if (!bDelRst) {
741         OH_JSVM_ThrowError(env, nullptr, "TestCombinationPropertyTest2: OH_JSVM_DeleteProperty result is false");
742         return nullptr;
743     }
744     // call OH_JSVM_HasProperty
745     bool bHasRstLast = false;
746     status = OH_JSVM_HasProperty(env, args[0], stringKey, &bHasRstLast);
747     if (status != JSVM_OK) {
748         OH_JSVM_ThrowError(env, nullptr, "TestCombinationPropertyTest2: OH_JSVM_HasProperty Failed");
749         return nullptr;
750     }
751     if (!bHasRstLast) {
752         OH_JSVM_ThrowError(env, nullptr, "TestCombinationPropertyTest2: OH_JSVM_HasProperty result is false");
753         return nullptr;
754     }
755     // Call getProperty last
756     JSVM_Value rstValueLast = nullptr;
757     status = OH_JSVM_GetProperty(env, args[0], stringKey, &rstValueLast);
758     if (status != JSVM_OK) {
759         OH_JSVM_ThrowError(env, nullptr, "TestCombinationPropertyTest2: OH_JSVM_GetProperty Failed");
760         return nullptr;
761     }
762     char strGetKeyValueLast[BUF_SIZE_MAX] = {0};
763     size_t rstLengthLast = 0;
764     status = OH_JSVM_GetValueStringUtf8(env, rstValueLast, strGetKeyValueLast, BUF_SIZE_MAX, &rstLengthLast);
765     if (status != JSVM_OK) {
766         OH_JSVM_ThrowError(env, nullptr, "TestCombinationPropertyTest2: OH_JSVM_GetValueStringUtf8 Failed");
767         return nullptr;
768     }
769     if (strcmp(strKeyValue, strGetKeyValueLast) != 0) {
770         OH_JSVM_ThrowError(env, nullptr, "TestCombinationPropertyTest2: GetProperty keyvalue!=getkeyvalue1 Failed");
771         return nullptr;
772     }
773 
774     bool result = true;
775     JSVM_Value value = nullptr;
776     OH_JSVM_GetBoolean(env, result, &value);
777     return value;
778 }
779 // Property  combination: setProperty 2 property->  hasProperty 2 property->   getProperty 2 property
780 //->   deleteProperty 1 property ->hasProperty delete property->  getProperty delete property
TestCombinationPropertyTest3(JSVM_Env env,JSVM_CallbackInfo info)781 [[maybe_unused]] JSVM_Value TestCombinationPropertyTest3(JSVM_Env env, JSVM_CallbackInfo info)
782 {
783     size_t argc = NUM_SIZE_3;
784     JSVM_Value args[NUM_SIZE_3] = {nullptr};
785     JSVM_Value thisVar = nullptr;
786     OH_JSVM_GetCbInfo(env, info, &argc, args, &thisVar, nullptr);
787     // call OH_JSVM_SetProperty
788     JSVM_Status status = OH_JSVM_SetProperty(env, args[0], args[1], args[NUM_SIZE_2]);
789     if (status != JSVM_OK) {
790         OH_JSVM_ThrowError(env, nullptr, "TestCombinationPropertyTest3: OH_JSVM_SetProperty Failed");
791         return nullptr;
792     }
793     // Call OH_JSVM_SetProperty again
794     JSVM_Value stringValue = nullptr;
795     const char* strKeyValue = "setKeyValue1";
796     OH_JSVM_CreateStringUtf8(env, strKeyValue, JSVM_AUTO_LENGTH, &stringValue);
797     JSVM_Value stringKey = nullptr;
798     const char* strKey = "setkey1";
799     OH_JSVM_CreateStringUtf8(env, strKey, JSVM_AUTO_LENGTH, &stringKey);
800     status = OH_JSVM_SetProperty(env, args[0], stringKey, stringValue);
801     if (status != JSVM_OK) {
802         OH_JSVM_ThrowError(env, nullptr, "TestCombinationPropertyTest3: OH_JSVM_SetProperty again Failed");
803         return nullptr;
804     }
805     // call OH_JSVM_HasProperty
806     bool bHasRst = false;
807     status = OH_JSVM_HasProperty(env, args[0], args[1], &bHasRst);
808     if (status != JSVM_OK) {
809         OH_JSVM_ThrowError(env, nullptr, "TestCombinationPropertyTest3: OH_JSVM_HasProperty Failed");
810         return nullptr;
811     }
812     if (!bHasRst) {
813         OH_JSVM_ThrowError(env, nullptr, "TestCombinationPropertyTest3: OH_JSVM_HasProperty result is false");
814         return nullptr;
815     }
816     // call OH_JSVM_HasProperty again
817     bool bHasRst1 = false;
818     status = OH_JSVM_HasProperty(env, args[0], stringKey, &bHasRst1);
819     if (status != JSVM_OK) {
820         OH_JSVM_ThrowError(env, nullptr, "TestCombinationPropertyTest3: OH_JSVM_HasProperty1 Failed");
821         return nullptr;
822     }
823     if (!bHasRst1) {
824         OH_JSVM_ThrowError(env, nullptr, "TestCombinationPropertyTest3: OH_JSVM_HasProperty result1 is false");
825         return nullptr;
826     }
827     // Call getProperty
828     JSVM_Value rstValue = nullptr;
829     status = OH_JSVM_GetProperty(env, args[0], args[1], &rstValue);
830     if (status != JSVM_OK) {
831         OH_JSVM_ThrowError(env, nullptr, "TestCombinationPropertyTest3: OH_JSVM_GetProperty Failed");
832         return nullptr;
833     }
834     char strGetKeyValue[BUF_SIZE_MAX] = {0};
835     size_t rstLength = 0;
836     status = OH_JSVM_GetValueStringUtf8(env, rstValue, strGetKeyValue, BUF_SIZE_MAX, &rstLength);
837     if (status != JSVM_OK) {
838         OH_JSVM_ThrowError(env, nullptr, "TestCombinationPropertyTest3: OH_JSVM_GetValueStringUtf8 Failed");
839         return nullptr;
840     }
841     char strGetKeyValueFirst[BUF_SIZE_MAX] = {0};
842     size_t rstFirstLength = 0;
843     status = OH_JSVM_GetValueStringUtf8(env, args[NUM_SIZE_2], strGetKeyValueFirst, BUF_SIZE_MAX, &rstFirstLength);
844     if (status != JSVM_OK) {
845         OH_JSVM_ThrowError(env, nullptr, "TestCombinationPropertyTest3: OH_JSVM_GetValueStringUtf8 Failed");
846         return nullptr;
847     }
848     if (strcmp(strGetKeyValueFirst, strGetKeyValue) != 0) {
849         OH_JSVM_ThrowError(env, nullptr, "TestCombinationPropertyTest3: GetProperty keyvalue!=getkeyvalue Failed");
850         return nullptr;
851     }
852     // Call getProperty again
853     JSVM_Value rstValue1 = nullptr;
854     status = OH_JSVM_GetProperty(env, args[0], stringKey, &rstValue1);
855     if (status != JSVM_OK) {
856         OH_JSVM_ThrowError(env, nullptr, "TestCombinationPropertyTest3: OH_JSVM_GetProperty Failed");
857         return nullptr;
858     }
859     char strGetKeyValue1[BUF_SIZE_MAX] = {0};
860     size_t rstLength1 = 0;
861     status = OH_JSVM_GetValueStringUtf8(env, rstValue1, strGetKeyValue1, BUF_SIZE_MAX, &rstLength1);
862     if (status != JSVM_OK) {
863         OH_JSVM_ThrowError(env, nullptr, "TestCombinationPropertyTest3: OH_JSVM_GetValueStringUtf8 Failed");
864         return nullptr;
865     }
866     if (strcmp(strKeyValue, strGetKeyValue1) != 0) {
867         OH_JSVM_ThrowError(env, nullptr, "TestCombinationPropertyTest3: GetProperty keyvalue!=getkeyvalue1 Failed");
868         return nullptr;
869     }
870     // call OH_JSVM_DeleteProperty
871     bool bDelRst = false;
872     status = OH_JSVM_DeleteProperty(env, args[0], args[1], &bDelRst);
873     if (status != JSVM_OK) {
874         OH_JSVM_ThrowError(env, nullptr, "TestCombinationPropertyTest3: OH_JSVM_DeleteProperty Failed");
875         return nullptr;
876     }
877     if (!bDelRst) {
878         OH_JSVM_ThrowError(env, nullptr, "TestCombinationPropertyTest3: OH_JSVM_DeleteProperty result is false");
879         return nullptr;
880     }
881     // call OH_JSVM_HasProperty
882     bool bHasRstLast = false;
883     status = OH_JSVM_HasProperty(env, args[0], args[1], &bHasRstLast);
884     if (status != JSVM_OK) {
885         OH_JSVM_ThrowError(env, nullptr, "TestCombinationPropertyTest3: OH_JSVM_HasProperty Failed");
886         return nullptr;
887     }
888     if (bHasRstLast) {
889         OH_JSVM_ThrowError(env, nullptr, "TestCombinationPropertyTest3: OH_JSVM_HasProperty result is false");
890         return nullptr;
891     }
892     // Call getProperty last
893     JSVM_Value rstValueLast = nullptr;
894     status = OH_JSVM_GetProperty(env, args[0], args[1], &rstValueLast);
895     if (status != JSVM_OK) {
896         OH_JSVM_ThrowError(env, nullptr, "TestCombinationPropertyTest3: OH_JSVM_GetProperty Failed");
897         return nullptr;
898     }
899     char strGetKeyValue2[BUF_SIZE_MAX] = {0};
900     size_t rstLength2 = 0;
901     bool bRst = false;
902     status = OH_JSVM_IsUndefined(env, rstValueLast, &bRst);
903     if (status != JSVM_OK) {
904         OH_JSVM_ThrowError(env, nullptr, "TestCombinationPropertyTest3: OH_JSVM_GetValueStringUtf8 Failed");
905         return nullptr;
906     }
907 
908     bool result = true;
909     JSVM_Value value = nullptr;
910     OH_JSVM_GetBoolean(env, result, &value);
911     return value;
912 }
913 // Property  combination: setPropert 2 property->  hasProperty 2 property-> getProperty 2 property
914 //-> deleteProperty 1 property-> setProperty 1 property->  hasProperty 1 property->  getProperty delete property
TestCombinationPropertyTest4(JSVM_Env env,JSVM_CallbackInfo info)915 [[maybe_unused]] JSVM_Value TestCombinationPropertyTest4(JSVM_Env env, JSVM_CallbackInfo info)
916 {
917     size_t argc = NUM_SIZE_3;
918     JSVM_Value args[NUM_SIZE_3] = {nullptr};
919     JSVM_Value thisVar = nullptr;
920     JSVM_Status status = OH_JSVM_GetCbInfo(env, info, &argc, args, &thisVar, nullptr);
921     if (status != JSVM_OK) {
922         OH_JSVM_ThrowError(env, nullptr, "TestCombinationPropertyTest4: OH_JSVM_GetCbInfo Failed");
923         return nullptr;
924     }
925     // call OH_JSVM_SetProperty
926     status = OH_JSVM_SetProperty(env, args[0], args[1], args[NUM_SIZE_2]);
927     if (status != JSVM_OK) {
928         OH_JSVM_ThrowError(env, nullptr, "TestCombinationPropertyTest4: OH_JSVM_SetProperty Failed");
929         return nullptr;
930     }
931     // Call OH_JSVM_SetProperty again
932     JSVM_Value stringValue = nullptr;
933     const char* strKeyValue = "setKeyValue1";
934     OH_JSVM_CreateStringUtf8(env, strKeyValue, JSVM_AUTO_LENGTH, &stringValue);
935     JSVM_Value stringKey = nullptr;
936     const char* strKey = "setkey1";
937     OH_JSVM_CreateStringUtf8(env, strKey, JSVM_AUTO_LENGTH, &stringKey);
938     status = OH_JSVM_SetProperty(env, args[0], stringKey, stringValue);
939     if (status != JSVM_OK) {
940         OH_JSVM_ThrowError(env, nullptr, "TestCombinationPropertyTest4: OH_JSVM_SetProperty again Failed");
941         return nullptr;
942     }
943     // call OH_JSVM_HasProperty
944     bool bHasRst = false;
945     status = OH_JSVM_HasProperty(env, args[0], args[1], &bHasRst);
946     if (status != JSVM_OK) {
947         OH_JSVM_ThrowError(env, nullptr, "TestCombinationPropertyTest4: OH_JSVM_HasProperty Failed");
948         return nullptr;
949     }
950     if (!bHasRst) {
951         OH_JSVM_ThrowError(env, nullptr, "TestCombinationPropertyTest4: OH_JSVM_HasProperty result is false");
952         return nullptr;
953     }
954     // call OH_JSVM_HasProperty again
955     bool bHasRst1 = false;
956     OH_JSVM_HasProperty(env, args[0], stringKey, &bHasRst1);
957     if (!bHasRst1) {
958         OH_JSVM_ThrowError(env, nullptr, "TestCombinationPropertyTest4: OH_JSVM_HasProperty result1 is false");
959         return nullptr;
960     }
961     // Call getProperty
962     JSVM_Value rstValue = nullptr;
963     status = OH_JSVM_GetProperty(env, args[0], args[1], &rstValue);
964     if (status != JSVM_OK) {
965         OH_JSVM_ThrowError(env, nullptr, "TestCombinationPropertyTest4: OH_JSVM_GetProperty Failed");
966         return nullptr;
967     }
968     char strGetKeyValue[BUF_SIZE_MAX] = {0};
969     size_t rstLength = 0;
970     OH_JSVM_GetValueStringUtf8(env, rstValue, strGetKeyValue, BUF_SIZE_MAX, &rstLength);
971     char strGetKeyValueFirst[BUF_SIZE_MAX] = {0};
972     size_t rstFirstLength = 0;
973     OH_JSVM_GetValueStringUtf8(env, args[NUM_SIZE_2], strGetKeyValueFirst, BUF_SIZE_MAX, &rstFirstLength);
974     if (strcmp(strGetKeyValueFirst, strGetKeyValue) != 0) {
975         OH_JSVM_ThrowError(env, nullptr, "TestCombinationPropertyTest4: GetProperty keyvalue!=getkeyvalue Failed");
976         return nullptr;
977     }
978     // Call getProperty again
979     JSVM_Value rstValue1 = nullptr;
980     status = OH_JSVM_GetProperty(env, args[0], stringKey, &rstValue1);
981     if (status != JSVM_OK) {
982         OH_JSVM_ThrowError(env, nullptr, "TestCombinationPropertyTest4: OH_JSVM_GetProperty Failed");
983         return nullptr;
984     }
985     char strGetKeyValue1[BUF_SIZE_MAX] = {0};
986     size_t rstLength1 = 0;
987     status = OH_JSVM_GetValueStringUtf8(env, rstValue1, strGetKeyValue1, BUF_SIZE_MAX, &rstLength1);
988     if (status != JSVM_OK) {
989         OH_JSVM_ThrowError(env, nullptr, "TestCombinationPropertyTest4: OH_JSVM_GetValueStringUtf8 Failed");
990         return nullptr;
991     }
992     if (strcmp(strKeyValue, strGetKeyValue1) != 0) {
993         OH_JSVM_ThrowError(env, nullptr, "TestCombinationPropertyTest4: GetProperty keyvalue!=getkeyvalue1 Failed");
994         return nullptr;
995     }
996     // call OH_JSVM_DeleteProperty
997     bool bDelRst = false;
998     status = OH_JSVM_DeleteProperty(env, args[0], args[1], &bDelRst);
999     if (status != JSVM_OK) {
1000         OH_JSVM_ThrowError(env, nullptr, "TestCombinationPropertyTest4: OH_JSVM_DeleteProperty Failed");
1001         return nullptr;
1002     }
1003     if (!bDelRst) {
1004         OH_JSVM_ThrowError(env, nullptr, "TestCombinationPropertyTest4: OH_JSVM_DeleteProperty result is false");
1005         return nullptr;
1006     }
1007     // Call OH_JSVM_SetProperty last
1008     JSVM_Value stringValueLast = nullptr;
1009     const char* strKeyValueLast = "setKeyValueLast";
1010     status = OH_JSVM_CreateStringUtf8(env, strKeyValueLast, JSVM_AUTO_LENGTH, &stringValueLast);
1011     if (status != JSVM_OK) {
1012         OH_JSVM_ThrowError(env, nullptr, "TestCombinationPropertyTest4: OH_JSVM_CreateStringUtf8 Failed");
1013         return nullptr;
1014     }
1015     JSVM_Value stringKeyLast = nullptr;
1016     const char* strKeyLast = "setkeylast";
1017     status = OH_JSVM_CreateStringUtf8(env, strKeyLast, JSVM_AUTO_LENGTH, &stringKeyLast);
1018     if (status != JSVM_OK) {
1019         OH_JSVM_ThrowError(env, nullptr, "TestCombinationPropertyTest4: OH_JSVM_CreateStringUtf8 Failed");
1020         return nullptr;
1021     }
1022     status = OH_JSVM_SetProperty(env, args[0], stringKeyLast, stringValueLast);
1023     if (status != JSVM_OK) {
1024         OH_JSVM_ThrowError(env, nullptr, "TestCombinationPropertyTest4: OH_JSVM_SetProperty again Failed");
1025         return nullptr;
1026     }
1027     // call OH_JSVM_HasProperty
1028     bool bHasRstLast = false;
1029     status = OH_JSVM_HasProperty(env, args[0], stringKeyLast, &bHasRstLast);
1030     if (status != JSVM_OK) {
1031         OH_JSVM_ThrowError(env, nullptr, "TestCombinationPropertyTest4: OH_JSVM_HasProperty Failed");
1032         return nullptr;
1033     }
1034     if (!bHasRstLast) {
1035         OH_JSVM_ThrowError(env, nullptr, "TestCombinationPropertyTest4: OH_JSVM_HasProperty result is false");
1036         return nullptr;
1037     }
1038     // Call getProperty last
1039     JSVM_Value rstValueLast = nullptr;
1040     status = OH_JSVM_GetProperty(env, args[0], stringKeyLast, &rstValueLast);
1041     if (status != JSVM_OK) {
1042         OH_JSVM_ThrowError(env, nullptr, "TestCombinationPropertyTest4: OH_JSVM_GetProperty Failed");
1043         return nullptr;
1044     }
1045 
1046     bool result = true;
1047     JSVM_Value value = nullptr;
1048     OH_JSVM_GetBoolean(env, result, &value);
1049     return value;
1050 }
1051 //namedProperty  combination: SetNamedProperty ->setProperty-> GetNamedProperty-> GetNamedProperty
1052 //-> HasNamedProperty ->HasNamedProperty
TestCombinationNamedPropertyTest1(JSVM_Env env,JSVM_CallbackInfo info)1053 [[maybe_unused]] JSVM_Value TestCombinationNamedPropertyTest1(JSVM_Env env, JSVM_CallbackInfo info)
1054 {
1055     size_t argc = NUM_SIZE_3;
1056     JSVM_Value args[NUM_SIZE_3] = {nullptr};
1057     JSVM_Value thisVar = nullptr;
1058     JSVM_Status status = OH_JSVM_GetCbInfo(env, info, &argc, args, &thisVar, nullptr);
1059     if (status != JSVM_OK) {
1060         OH_JSVM_ThrowError(env, nullptr, "TestCombinationNamedPropertyTest1: OH_JSVM_GetCbInfo Failed");
1061         return nullptr;
1062     }
1063     // call OH_JSVM_SetNamedProperty
1064     char strNamedProperty[BUF_SIZE_MAX] = {0};
1065     size_t strLengthNamedProperty = 0;
1066     status = OH_JSVM_GetValueStringUtf8(env, args[1], strNamedProperty, BUF_SIZE_MAX, &strLengthNamedProperty);
1067     if (status != JSVM_OK) {
1068         OH_JSVM_ThrowError(env, nullptr, "TestCombinationNamedPropertyTest1: OH_JSVM_GetValueStringUtf8 Failed");
1069         return nullptr;
1070     }
1071     status = OH_JSVM_SetNamedProperty(env, args[0], strNamedProperty, args[NUM_SIZE_2]);
1072     if (status != JSVM_OK) {
1073         OH_JSVM_ThrowError(env, nullptr, "TestCombinationNamedPropertyTest1: OH_JSVM_SetNamedProperty Failed");
1074         return nullptr;
1075     }
1076     // call OH_JSVM_SetNamedProperty again
1077     JSVM_Value stringValue = nullptr;
1078     const char* strKeyValue = "setKeyValue";
1079     status = OH_JSVM_CreateStringUtf8(env, strKeyValue, JSVM_AUTO_LENGTH, &stringValue);
1080     if (status != JSVM_OK) {
1081         OH_JSVM_ThrowError(env, nullptr, "TestCombinationNamedPropertyTest1: OH_JSVM_CreateStringUtf8 Failed");
1082         return nullptr;
1083     }
1084     status = OH_JSVM_SetNamedProperty(env, args[0], strNamedProperty, stringValue);
1085     if (status != JSVM_OK) {
1086         OH_JSVM_ThrowError(env, nullptr, "TestCombinationNamedPropertyTest1: OH_JSVM_SetNamedProperty Failed");
1087         return nullptr;
1088     }
1089     // OH_JSVM_GetNamedProperty
1090     JSVM_Value rstValue = nullptr;
1091     status = OH_JSVM_GetNamedProperty(env, args[0], strNamedProperty, &rstValue);
1092     if (status != JSVM_OK) {
1093         OH_JSVM_ThrowError(env, nullptr, "TestCombinationNamedPropertyTest1: OH_JSVM_SetNamedProperty Failed");
1094         return nullptr;
1095     }
1096     char strGetKeyValue[BUF_SIZE_MAX] = {0};
1097     size_t rstLength = 0;
1098     status = OH_JSVM_GetValueStringUtf8(env, rstValue, strGetKeyValue, BUF_SIZE_MAX, &rstLength);
1099     if (status != JSVM_OK) {
1100         OH_JSVM_ThrowError(env, nullptr, "TestCombinationNamedPropertyTest1: OH_JSVM_GetValueStringUtf8 Failed");
1101         return nullptr;
1102     }
1103     if (strcmp(strKeyValue, strGetKeyValue) != 0) {
1104         OH_JSVM_ThrowError(env, nullptr, "TestCombinationNamedPropertyTest1: GetProperty keyvalue!=getkeyvalue1");
1105         return nullptr;
1106     }
1107     // OH_JSVM_GetNamedProperty again
1108     JSVM_Value rstValue1 = nullptr;
1109     status = OH_JSVM_GetNamedProperty(env, args[0], strNamedProperty, &rstValue1);
1110     if (status != JSVM_OK) {
1111         OH_JSVM_ThrowError(env, nullptr, "TestCombinationNamedPropertyTest1: OH_JSVM_SetNamedProperty Failed");
1112         return nullptr;
1113     }
1114     char strGetKeyValue1[BUF_SIZE_MAX] = {0};
1115     size_t rstLength1 = 0;
1116     status = OH_JSVM_GetValueStringUtf8(env, rstValue1, strGetKeyValue1, BUF_SIZE_MAX, &rstLength1);
1117     if (status != JSVM_OK) {
1118         OH_JSVM_ThrowError(env, nullptr, "TestCombinationNamedPropertyTest1: OH_JSVM_GetValueStringUtf8 Failed");
1119         return nullptr;
1120     }
1121     if (strcmp(strKeyValue, strGetKeyValue1) != 0) {
1122         OH_JSVM_ThrowError(env, nullptr, "TestCombinationNamedPropertyTest1:GetProperty keyvalue!=getkeyvalue1");
1123         return nullptr;
1124     }
1125     // call OH_JSVM_HasNamedProperty
1126     bool bHasRst = false;
1127     status = OH_JSVM_HasNamedProperty(env, args[0], strNamedProperty, &bHasRst);
1128     if (status != JSVM_OK) {
1129         OH_JSVM_ThrowError(env, nullptr, "TestCombinationNamedPropertyTest1: OH_JSVM_HasProperty Failed");
1130         return nullptr;
1131     }
1132     if (!bHasRst) {
1133         OH_JSVM_ThrowError(env, nullptr, "TestCombinationNamedPropertyTest1: OH_JSVM_HasProperty result is false");
1134         return nullptr;
1135     }
1136     // call OH_JSVM_HasNamedProperty again
1137     bool bHasRst1 = false;
1138     status = OH_JSVM_HasNamedProperty(env, args[0], strNamedProperty, &bHasRst1);
1139     if (status != JSVM_OK) {
1140         OH_JSVM_ThrowError(env, nullptr, "TestCombinationNamedPropertyTest1: OH_JSVM_HasProperty Failed");
1141         return nullptr;
1142     }
1143     if (!bHasRst1) {
1144         OH_JSVM_ThrowError(env, nullptr, "TestCombinationNamedPropertyTest1: OH_JSVM_HasProperty result is false");
1145         return nullptr;
1146     }
1147 
1148     bool result = true;
1149     JSVM_Value value = nullptr;
1150     OH_JSVM_GetBoolean(env, result, &value);
1151     return value;
1152 }
1153 //namedProperty  combination: setNamedProperty 2 property-> hasNamedProperty 2 property-> getNamedProperty 2 property
TestCombinationNamedPropertyTest2(JSVM_Env env,JSVM_CallbackInfo info)1154 [[maybe_unused]] JSVM_Value TestCombinationNamedPropertyTest2(JSVM_Env env, JSVM_CallbackInfo info)
1155 {
1156     size_t argc = 1;
1157     JSVM_Value args[1] = {nullptr};
1158     JSVM_Value thisVar = nullptr;
1159     JSVM_Status status = OH_JSVM_GetCbInfo(env, info, &argc, args, &thisVar, nullptr);
1160     if (status != JSVM_OK) {
1161         OH_JSVM_ThrowError(env, nullptr, "TestCombinationNamedPropertyTest2: OH_JSVM_GetCbInfo Failed");
1162         return nullptr;
1163     }
1164     // first call OH_JSVM_SetNamedProperty
1165     // create new obj
1166     JSVM_Value createObj;
1167     status = OH_JSVM_CreateObject(env, &createObj);
1168     if (status != JSVM_OK) {
1169         OH_JSVM_ThrowError(env, nullptr, "TestCombinationNamedPropertyTest2: OH_JSVM_CreateObject Failed");
1170         return nullptr;
1171     }
1172     // first set property
1173     const char* strKeyName = "key name";
1174     const char* strKeyValue = "key value";
1175     JSVM_Value keyValue = nullptr;
1176     status = OH_JSVM_CreateStringUtf8(env, strKeyValue, JSVM_AUTO_LENGTH, &keyValue);
1177     if (status != JSVM_OK) {
1178         OH_JSVM_ThrowError(env, nullptr, "TestCombinationNamedPropertyTest2: OH_JSVM_CreateStringUtf8 Failed");
1179         return nullptr;
1180     }
1181     status = OH_JSVM_SetNamedProperty(env, createObj, strKeyName, keyValue);
1182     if (status != JSVM_OK) {
1183         OH_JSVM_ThrowError(env, nullptr, "TestCombinationNamedPropertyTest2: OH_JSVM_SetNamedProperty Failed");
1184         return nullptr;
1185     }
1186     //  second call OH_JSVM_SetNamedProperty
1187     const char* strKeyName1 = "key name second";
1188     const char* strKeyValue1 = "key value second";
1189     JSVM_Value keyValue1 = nullptr;
1190     status = OH_JSVM_CreateStringUtf8(env, strKeyValue1, JSVM_AUTO_LENGTH, &keyValue1);
1191     if (status != JSVM_OK) {
1192         OH_JSVM_ThrowError(env, nullptr, "TestCombinationNamedPropertyTest2: OH_JSVM_CreateStringUtf8 Failed");
1193         return nullptr;
1194     }
1195     status = OH_JSVM_SetNamedProperty(env, createObj, strKeyName1, keyValue1);
1196     if (status != JSVM_OK) {
1197         OH_JSVM_ThrowError(env, nullptr, "TestCombinationNamedPropertyTest2: OH_JSVM_SetNamedProperty Failed");
1198         return nullptr;
1199     }
1200     // first call OH_JSVM_HasNamedProperty
1201     bool bHasRst = false;
1202     status = OH_JSVM_HasNamedProperty(env, createObj, strKeyName, &bHasRst);
1203     if (status != JSVM_OK) {
1204         OH_JSVM_ThrowError(env, nullptr, "TestCombinationNamedPropertyTest2: OH_JSVM_HasProperty Failed");
1205         return nullptr;
1206     }
1207     if (!bHasRst) {
1208         OH_JSVM_ThrowError(env, nullptr, "TestCombinationNamedPropertyTest2: OH_JSVM_HasProperty result is false");
1209         return nullptr;
1210     }
1211     // second call OH_JSVM_HasNamedProperty
1212     bool bHasRst1 = false;
1213     status = OH_JSVM_HasNamedProperty(env, createObj, strKeyName1, &bHasRst1);
1214     if (status != JSVM_OK) {
1215         OH_JSVM_ThrowError(env, nullptr, "TestCombinationNamedPropertyTest2: OH_JSVM_HasProperty Failed");
1216         return nullptr;
1217     }
1218     if (!bHasRst1) {
1219         OH_JSVM_ThrowError(env, nullptr, "TestCombinationNamedPropertyTest2: OH_JSVM_HasProperty result is false");
1220         return nullptr;
1221     }
1222     // OH_JSVM_GetNamedProperty
1223     JSVM_Value rstValue = nullptr;
1224     status = OH_JSVM_GetNamedProperty(env, createObj, strKeyName, &rstValue);
1225     if (status != JSVM_OK) {
1226         OH_JSVM_ThrowError(env, nullptr, "TestCombinationNamedPropertyTest2: OH_JSVM_SetNamedProperty Failed");
1227         return nullptr;
1228     }
1229     char strGetKeyValue[BUF_SIZE_MAX] = {0};
1230     size_t rstLength = 0;
1231     status = OH_JSVM_GetValueStringUtf8(env, rstValue, strGetKeyValue, BUF_SIZE_MAX, &rstLength);
1232     if (status != JSVM_OK) {
1233         OH_JSVM_ThrowError(env, nullptr, "TestCombinationNamedPropertyTest2: OH_JSVM_GetValueStringUtf8 Failed");
1234         return nullptr;
1235     }
1236     if (strcmp(strKeyValue, strGetKeyValue) != 0) {
1237         OH_JSVM_ThrowError(env, nullptr, "TestCombinationNamedPropertyTest2: GetProperty keyvalue!=getkeyvalue1");
1238         return nullptr;
1239     }
1240     // second OH_JSVM_GetNamedProperty
1241     JSVM_Value rstValue1 = nullptr;
1242     status = OH_JSVM_GetNamedProperty(env, createObj, strKeyName1, &rstValue1);
1243     if (status != JSVM_OK) {
1244         OH_JSVM_ThrowError(env, nullptr, "TestCombinationNamedPropertyTest2: OH_JSVM_SetNamedProperty Failed");
1245         return nullptr;
1246     }
1247     char strGetKeyValue1[BUF_SIZE_MAX] = {0};
1248     size_t rstLength1 = 0;
1249     status = OH_JSVM_GetValueStringUtf8(env, rstValue1, strGetKeyValue1, BUF_SIZE_MAX, &rstLength1);
1250     if (status != JSVM_OK) {
1251         OH_JSVM_ThrowError(env, nullptr, "TestCombinationNamedPropertyTest2: OH_JSVM_GetValueStringUtf8 Failed");
1252         return nullptr;
1253     }
1254     if (strcmp(strKeyValue1, strGetKeyValue1) != 0) {
1255         OH_JSVM_ThrowError(env, nullptr, "TestCombinationNamedPropertyTest2: GetProperty keyvalue!=getkeyvalue1");
1256         return nullptr;
1257     }
1258 
1259     bool result = true;
1260     JSVM_Value value = nullptr;
1261     OH_JSVM_GetBoolean(env, result, &value);
1262     return value;
1263 }