• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 
16 #include "ecmascript/containers/containers_private.h"
17 #include "ecmascript/ecma_vm.h"
18 #include "ecmascript/ecma_runtime_call_info.h"
19 #include "ecmascript/js_tagged_value.h"
20 #include "ecmascript/js_api/js_api_bitvector.h"
21 #include "ecmascript/global_env.h"
22 #include "ecmascript/object_factory.h"
23 #include "ecmascript/tests/test_helper.h"
24 #include "ecmascript/containers/containers_errors.h"
25 
26 using namespace panda;
27 using namespace panda::ecmascript;
28 
29 namespace panda::test {
30 class JSAPIBitVectorTest : public testing::Test {
31 public:
SetUpTestCase()32     static void SetUpTestCase()
33     {
34         GTEST_LOG_(INFO) << "SetUpTestCase";
35     }
36 
TearDownTestCase()37     static void TearDownTestCase()
38     {
39         GTEST_LOG_(INFO) << "TearDownCase";
40     }
41 
SetUp()42     void SetUp() override
43     {
44         TestHelper::CreateEcmaVMWithScope(instance, thread, scope);
45     }
46 
TearDown()47     void TearDown() override
48     {
49         TestHelper::DestroyEcmaVMWithScope(instance, scope);
50     }
51 
52     EcmaVM *instance {nullptr};
53     EcmaHandleScope *scope {nullptr};
54     JSThread *thread {nullptr};
55 
56     class TestClass : public base::BuiltinsBase {
57     public:
ComputeElementIdAndBitId(uint32_t index)58         static std::pair<uint32_t, uint32_t> ComputeElementIdAndBitId(uint32_t index)
59         {
60             uint32_t elementId = index >> 6;
61             uint32_t bitId = index & 0x3FULL;
62             return std::make_pair(elementId, bitId);
63         }
GetBit(std::vector<std::bitset<JSAPIBitVector::BIT_SET_LENGTH>> * elements,uint32_t index)64         static JSTaggedValue GetBit(std::vector<std::bitset<JSAPIBitVector::BIT_SET_LENGTH>> *elements, uint32_t index)
65         {
66             std::pair<uint32_t, uint32_t> pair = ComputeElementIdAndBitId(index);
67             uint32_t elementId = pair.first;
68             uint32_t bitId = pair.second;
69             int32_t bit = (*elements)[elementId].test(bitId);
70             return JSTaggedValue(bit);
71         }
72     };
73 protected:
CreateBitVector()74     JSAPIBitVector *CreateBitVector()
75     {
76         ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
77         JSHandle<GlobalEnv> env = thread->GetEcmaVM()->GetGlobalEnv();
78 
79         JSHandle<JSTaggedValue> globalObject = env->GetJSGlobalObject();
80         JSHandle<JSTaggedValue> key(factory->NewFromASCII("ArkPrivate"));
81         JSHandle<JSTaggedValue> value =
82             JSObject::GetProperty(thread, JSHandle<JSTaggedValue>(globalObject), key).GetValue();
83 
84         auto objCallInfo =
85             TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 8);
86         objCallInfo->SetFunction(JSTaggedValue::Undefined());
87         objCallInfo->SetThis(value.GetTaggedValue());
88         objCallInfo->SetCallArg(0, JSTaggedValue(static_cast<int>(containers::ContainerTag::BitVector)));
89 
90         [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo);
91         JSTaggedValue result = containers::ContainersPrivate::Load(objCallInfo);
92         TestHelper::TearDownFrame(thread, prev);
93 
94         JSHandle<JSTaggedValue> constructor(thread, result);
95         JSHandle<JSAPIBitVector> bitVector(
96             factory->NewJSObjectByConstructor(JSHandle<JSFunction>(constructor), constructor));
97         auto *newBitSetVector = new std::vector<std::bitset<JSAPIBitVector::BIT_SET_LENGTH>>();
98         auto deleter = []([[maybe_unused]] void *env, void *pointer, [[maybe_unused]] void *data) {
99             if (pointer == nullptr) {
100                 return;
101             }
102             delete reinterpret_cast<std::vector<std::bitset<JSAPIBitVector::BIT_SET_LENGTH>> *>(pointer);
103         };
104         JSHandle<JSNativePointer> pointer = factory->NewSJSNativePointer(newBitSetVector, deleter, newBitSetVector);
105         bitVector->SetNativePointer(thread, pointer);
106         return *bitVector;
107     }
108 };
109 
HWTEST_F_L0(JSAPIBitVectorTest,CreateBitVector)110 HWTEST_F_L0(JSAPIBitVectorTest, CreateBitVector)
111 {
112     JSAPIBitVector *bitVector = CreateBitVector();
113     EXPECT_TRUE(bitVector != nullptr);
114 }
115 
116 /**
117  * @tc.name: Push
118  * @tc.desc:
119  * @tc.type: FUNC
120  * @tc.require:
121  */
HWTEST_F_L0(JSAPIBitVectorTest,Push)122 HWTEST_F_L0(JSAPIBitVectorTest, Push)
123 {
124     uint32_t increasedLength = 5;
125     JSHandle<JSAPIBitVector> bitVector(thread, CreateBitVector());
126     for (uint32_t i = 0; i < increasedLength; i++) {
127         JSHandle<JSTaggedValue> value(thread, JSTaggedValue(1));
128         JSAPIBitVector::Push(thread, bitVector, value);
129     }
130     JSHandle<JSNativePointer> np(thread, bitVector->GetNativePointer());
131     auto elements =
132         reinterpret_cast<std::vector<std::bitset<JSAPIBitVector::BIT_SET_LENGTH>> *>(np->GetExternalPointer());
133     for (uint32_t i = 0; i < increasedLength; i++) {
134         EXPECT_EQ(TestClass::GetBit(elements, i), JSTaggedValue(1));
135     }
136 }
137 
138 /**
139  * @tc.name: Pop
140  * @tc.desc:
141  * @tc.type: FUNC
142  * @tc.require:
143  */
HWTEST_F_L0(JSAPIBitVectorTest,Pop)144 HWTEST_F_L0(JSAPIBitVectorTest, Pop)
145 {
146     uint32_t increasedLength = 5;
147     JSHandle<JSAPIBitVector> bitVector(thread, CreateBitVector());
148     for (uint32_t i = 0; i < increasedLength; i++) {
149         JSHandle<JSTaggedValue> value(thread, JSTaggedValue(1));
150         JSAPIBitVector::Push(thread, bitVector, value);
151     }
152     for (uint32_t i = 0; i < increasedLength; i++) {
153         JSTaggedValue res = JSAPIBitVector::Pop(thread, bitVector);
154         EXPECT_EQ(res, JSTaggedValue(1));
155     }
156 }
157 
158 /**
159  * @tc.name: Set
160  * @tc.desc:
161  * @tc.type: FUNC
162  * @tc.require:
163  */
HWTEST_F_L0(JSAPIBitVectorTest,Set)164 HWTEST_F_L0(JSAPIBitVectorTest, Set)
165 {
166     uint32_t increasedLength = 5;
167     uint32_t index = 3;
168 
169     JSHandle<JSAPIBitVector> bitVector(thread, CreateBitVector());
170     for (uint32_t i = 0; i < increasedLength; i++) {
171         JSHandle<JSTaggedValue> value(thread, JSTaggedValue(0));
172         JSAPIBitVector::Push(thread, bitVector, value);
173     }
174     JSHandle<JSNativePointer> np(thread, bitVector->GetNativePointer());
175     auto elements =
176         reinterpret_cast<std::vector<std::bitset<JSAPIBitVector::BIT_SET_LENGTH>> *>(np->GetExternalPointer());
177     JSTaggedValue res = bitVector->Set(thread, index, JSTaggedValue(1));
178     EXPECT_EQ(res, JSTaggedValue::Undefined());
179     EXPECT_EQ(TestClass::GetBit(elements, index), JSTaggedValue(1));
180 }
181 
182 /**
183  * @tc.name: Get
184  * @tc.desc:
185  * @tc.type: FUNC
186  * @tc.require:
187  */
HWTEST_F_L0(JSAPIBitVectorTest,Get)188 HWTEST_F_L0(JSAPIBitVectorTest, Get)
189 {
190     uint32_t increasedLength = 5;
191     JSHandle<JSAPIBitVector> bitVector(thread, CreateBitVector());
192     for (uint32_t i = 0; i < increasedLength; i++) {
193         JSHandle<JSTaggedValue> value(thread, JSTaggedValue(1));
194         JSAPIBitVector::Push(thread, bitVector, value);
195     }
196     for (uint32_t i = 0; i < increasedLength; i++) {
197         JSTaggedValue res = bitVector->Get(thread, i);
198         EXPECT_EQ(res, JSTaggedValue(1));
199     }
200 }
201 
202 /**
203  * @tc.name: Has
204  * @tc.desc:
205  * @tc.type: FUNC
206  * @tc.require:
207  */
HWTEST_F_L0(JSAPIBitVectorTest,Has)208 HWTEST_F_L0(JSAPIBitVectorTest, Has)
209 {
210     uint32_t increasedLength = 5;
211     JSHandle<JSAPIBitVector> bitVector(thread, CreateBitVector());
212     for (uint32_t i = 0; i < increasedLength; i++) {
213         JSHandle<JSTaggedValue> value(thread, JSTaggedValue(1));
214         JSAPIBitVector::Push(thread, bitVector, value);
215     }
216     JSHandle<JSTaggedValue> value(thread, JSTaggedValue(1));
217     JSHandle<JSTaggedValue> value1(thread, JSTaggedValue(0));
218     JSHandle<JSTaggedValue> value2(thread, JSTaggedValue(5));
219     bool res = JSAPIBitVector::Has(thread, bitVector, value, value1, value2);
220     EXPECT_TRUE(res);
221 }
222 
223 /**
224  * @tc.name: Has_instance
225  * @tc.desc:
226  * @tc.type: FUNC
227  * @tc.require:
228  */
HWTEST_F_L0(JSAPIBitVectorTest,Has_instance)229 HWTEST_F_L0(JSAPIBitVectorTest, Has_instance)
230 {
231     uint32_t increasedLength = 5;
232     JSHandle<JSAPIBitVector> bitVector(thread, CreateBitVector());
233     for (uint32_t i = 0; i < increasedLength; i++) {
234         JSHandle<JSTaggedValue> value(thread, JSTaggedValue(1));
235         JSAPIBitVector::Push(thread, bitVector, value);
236     }
237     bool res = bitVector->Has(JSTaggedValue(1));
238     EXPECT_TRUE(res);
239 }
240 
241 /**
242  * @tc.name: Has_Testboundary
243  * @tc.desc:
244  * @tc.type: FUNC
245  * @tc.require:
246  */
HWTEST_F_L0(JSAPIBitVectorTest,Has_Testboundary)247 HWTEST_F_L0(JSAPIBitVectorTest, Has_Testboundary)
248 {
249     uint32_t increasedLength = 8;
250     JSHandle<JSAPIBitVector> bitVector(thread, CreateBitVector());
251     for (uint32_t i = 0; i < increasedLength; i++) {
252         JSHandle<JSTaggedValue> value(thread, JSTaggedValue(1));
253         JSAPIBitVector::Push(thread, bitVector, value);
254     }
255     JSHandle<JSTaggedValue> value(thread, JSTaggedValue(0));
256     JSHandle<JSTaggedValue> value1(thread, JSTaggedValue(7));
257     bool res = JSAPIBitVector::Has(thread, bitVector, value, value, value1);
258     EXPECT_FALSE(res);
259     JSHandle<JSTaggedValue> value2(thread, JSTaggedValue(1));
260     JSHandle<JSTaggedValue> value3(thread, JSTaggedValue(8));
261     JSAPIBitVector::Push(thread, bitVector, value2);
262     res = JSAPIBitVector::Has(thread, bitVector, value2, value, value3);
263     EXPECT_TRUE(res);
264 }
265 
266 /**
267  * @tc.name: SetBitsByRange
268  * @tc.desc:
269  * @tc.type: FUNC
270  * @tc.require:
271  */
HWTEST_F_L0(JSAPIBitVectorTest,SetBitsByRange)272 HWTEST_F_L0(JSAPIBitVectorTest, SetBitsByRange)
273 {
274     uint32_t increasedLength = 5;
275     uint32_t startIndex = 1;
276     uint32_t endIndex = 4;
277     JSHandle<JSAPIBitVector> bitVector(thread, CreateBitVector());
278     for (uint32_t i = 0; i < increasedLength; i++) {
279         JSHandle<JSTaggedValue> value(thread, JSTaggedValue(0));
280         JSAPIBitVector::Push(thread, bitVector, value);
281     }
282     JSHandle<JSTaggedValue> value(thread, JSTaggedValue(1));
283     JSHandle<JSTaggedValue> value1(thread, JSTaggedValue(startIndex));
284     JSHandle<JSTaggedValue> value2(thread, JSTaggedValue(endIndex));
285     JSTaggedValue res = JSAPIBitVector::SetBitsByRange(thread, bitVector, value, value1, value2);
286     EXPECT_EQ(res, JSTaggedValue::Undefined());
287 
288     JSHandle<JSNativePointer> np(thread, bitVector->GetNativePointer());
289     auto elements =
290         reinterpret_cast<std::vector<std::bitset<JSAPIBitVector::BIT_SET_LENGTH>> *>(np->GetExternalPointer());
291     for (uint32_t i = startIndex; i < endIndex; i++) {
292         EXPECT_EQ(TestClass::GetBit(elements, i), JSTaggedValue(1));
293     }
294 }
295 
296 /**
297  * @tc.name: GetBitsByRange
298  * @tc.desc:
299  * @tc.type: FUNC
300  * @tc.require:
301  */
HWTEST_F_L0(JSAPIBitVectorTest,GetBitsByRange)302 HWTEST_F_L0(JSAPIBitVectorTest, GetBitsByRange)
303 {
304     uint32_t increasedLength = 5;
305     uint32_t startIndex = 1;
306     uint32_t endIndex = 4;
307     JSHandle<JSAPIBitVector> bitVector(thread, CreateBitVector());
308     for (uint32_t i = 0; i < increasedLength; i++) {
309         JSHandle<JSTaggedValue> value(thread, JSTaggedValue(1));
310         JSAPIBitVector::Push(thread, bitVector, value);
311     }
312     JSHandle<JSTaggedValue> value1(thread, JSTaggedValue(startIndex));
313     JSHandle<JSTaggedValue> value2(thread, JSTaggedValue(endIndex));
314     JSTaggedValue res = JSAPIBitVector::GetBitsByRange(thread, bitVector, value1, value2);
315     JSHandle<JSAPIBitVector> getBitVector(thread, res);
316     EXPECT_EQ(getBitVector->GetLength(), endIndex - startIndex);
317     for (uint32_t i = 0; i < endIndex - startIndex; i++) {
318         EXPECT_EQ(getBitVector->Get(thread, i), JSTaggedValue(1));
319     }
320 }
321 
322 /**
323  * @tc.name: SetAllBits
324  * @tc.desc:
325  * @tc.type: FUNC
326  * @tc.require:
327  */
HWTEST_F_L0(JSAPIBitVectorTest,SetAllBits)328 HWTEST_F_L0(JSAPIBitVectorTest, SetAllBits)
329 {
330     uint32_t increasedLength = 5;
331     JSHandle<JSAPIBitVector> bitVector(thread, CreateBitVector());
332     for (uint32_t i = 0; i < increasedLength; i++) {
333         JSHandle<JSTaggedValue> value(thread, JSTaggedValue(0));
334         JSAPIBitVector::Push(thread, bitVector, value);
335     }
336     JSHandle<JSTaggedValue> value(thread, JSTaggedValue(1));
337     JSTaggedValue res = JSAPIBitVector::SetAllBits(thread, bitVector, value);
338     EXPECT_EQ(res, JSTaggedValue::Undefined());
339     JSHandle<JSNativePointer> np(thread, bitVector->GetNativePointer());
340     auto elements =
341         reinterpret_cast<std::vector<std::bitset<JSAPIBitVector::BIT_SET_LENGTH>> *>(np->GetExternalPointer());
342     for (uint32_t i = 0; i < increasedLength; i++) {
343         EXPECT_EQ(TestClass::GetBit(elements, i), JSTaggedValue(1));
344     }
345 }
346 
347 /**
348  * @tc.name: GetBitCountByRange
349  * @tc.desc:
350  * @tc.type: FUNC
351  * @tc.require:
352  */
HWTEST_F_L0(JSAPIBitVectorTest,GetBitCountByRange)353 HWTEST_F_L0(JSAPIBitVectorTest, GetBitCountByRange)
354 {
355     uint32_t increasedLength = 5;
356     uint32_t startIndex = 1;
357     uint32_t endIndex = 4;
358     JSHandle<JSAPIBitVector> bitVector(thread, CreateBitVector());
359     for (uint32_t i = 0; i < increasedLength; i++) {
360         JSHandle<JSTaggedValue> value(thread, JSTaggedValue(1));
361         JSAPIBitVector::Push(thread, bitVector, value);
362     }
363     JSHandle<JSTaggedValue> value(thread, JSTaggedValue(1));
364     JSHandle<JSTaggedValue> value1(thread, JSTaggedValue(startIndex));
365     JSHandle<JSTaggedValue> value2(thread, JSTaggedValue(endIndex));
366     JSTaggedValue res = JSAPIBitVector::GetBitCountByRange(thread, bitVector, value, value1, value2);
367     EXPECT_EQ(res, JSTaggedValue(3));
368 }
369 
370 /**
371  * @tc.name: GetIndexOf
372  * @tc.desc:
373  * @tc.type: FUNC
374  * @tc.require:
375  */
HWTEST_F_L0(JSAPIBitVectorTest,GetIndexOf)376 HWTEST_F_L0(JSAPIBitVectorTest, GetIndexOf)
377 {
378     uint32_t increasedLength = 5;
379     uint32_t startIndex = 1;
380     uint32_t endIndex = 4;
381     JSHandle<JSAPIBitVector> bitVector(thread, CreateBitVector());
382     for (uint32_t i = 0; i < increasedLength; i++) {
383         JSHandle<JSTaggedValue> value(thread, JSTaggedValue(1));
384         JSAPIBitVector::Push(thread, bitVector, value);
385     }
386     JSHandle<JSTaggedValue> value(thread, JSTaggedValue(1));
387     JSHandle<JSTaggedValue> value1(thread, JSTaggedValue(startIndex));
388     JSHandle<JSTaggedValue> value2(thread, JSTaggedValue(endIndex));
389     int res = JSAPIBitVector::GetIndexOf(thread, bitVector, value, value1, value2);
390     EXPECT_EQ(res, startIndex);
391 }
392 
393 /**
394  * @tc.name: GetLastIndexOf
395  * @tc.desc:
396  * @tc.type: FUNC
397  * @tc.require:
398  */
HWTEST_F_L0(JSAPIBitVectorTest,GetLastIndexOf)399 HWTEST_F_L0(JSAPIBitVectorTest, GetLastIndexOf)
400 {
401     uint32_t increasedLength = 5;
402     uint32_t startIndex = 1;
403     uint32_t endIndex = 4;
404     JSHandle<JSAPIBitVector> bitVector(thread, CreateBitVector());
405     for (uint32_t i = 0; i < increasedLength; i++) {
406         JSHandle<JSTaggedValue> value(thread, JSTaggedValue(1));
407         JSAPIBitVector::Push(thread, bitVector, value);
408     }
409     JSHandle<JSTaggedValue> value(thread, JSTaggedValue(1));
410     JSHandle<JSTaggedValue> value1(thread, JSTaggedValue(startIndex));
411     JSHandle<JSTaggedValue> value2(thread, JSTaggedValue(endIndex));
412     int res = JSAPIBitVector::GetLastIndexOf(thread, bitVector, value, value1, value2);
413     EXPECT_EQ(res, endIndex - 1);
414 }
415 
416 /**
417  * @tc.name: FlipBitByIndex
418  * @tc.desc:
419  * @tc.type: FUNC
420  * @tc.require:
421  */
HWTEST_F_L0(JSAPIBitVectorTest,FlipBitByIndex)422 HWTEST_F_L0(JSAPIBitVectorTest, FlipBitByIndex)
423 {
424     uint32_t increasedLength = 5;
425     uint32_t index = 3;
426     JSHandle<JSAPIBitVector> bitVector(thread, CreateBitVector());
427     for (uint32_t i = 0; i < increasedLength; i++) {
428         JSHandle<JSTaggedValue> value(thread, JSTaggedValue(1));
429         JSAPIBitVector::Push(thread, bitVector, value);
430     }
431     JSTaggedValue res = JSAPIBitVector::FlipBitByIndex(thread, bitVector, index);
432 
433     JSHandle<JSNativePointer> np(thread, bitVector->GetNativePointer());
434     auto elements =
435         reinterpret_cast<std::vector<std::bitset<JSAPIBitVector::BIT_SET_LENGTH>> *>(np->GetExternalPointer());
436     EXPECT_EQ(res, JSTaggedValue::Undefined());
437     EXPECT_EQ(TestClass::GetBit(elements, index), JSTaggedValue(0));
438 }
439 
440 /**
441  * @tc.name: FlipBitsByRange
442  * @tc.desc:
443  * @tc.type: FUNC
444  * @tc.require:
445  */
HWTEST_F_L0(JSAPIBitVectorTest,FlipBitsByRange)446 HWTEST_F_L0(JSAPIBitVectorTest, FlipBitsByRange)
447 {
448     uint32_t increasedLength = 5;
449     uint32_t startIndex = 1;
450     uint32_t endIndex = 4;
451     JSHandle<JSAPIBitVector> bitVector(thread, CreateBitVector());
452     for (uint32_t i = 0; i < increasedLength; i++) {
453         JSHandle<JSTaggedValue> value(thread, JSTaggedValue(1));
454         JSAPIBitVector::Push(thread, bitVector, value);
455     }
456     JSHandle<JSTaggedValue> value1(thread, JSTaggedValue(startIndex));
457     JSHandle<JSTaggedValue> value2(thread, JSTaggedValue(endIndex));
458     JSTaggedValue res = JSAPIBitVector::FlipBitsByRange(thread, bitVector, value1, value2);
459     EXPECT_EQ(res, JSTaggedValue::Undefined());
460 
461     JSHandle<JSNativePointer> np(thread, bitVector->GetNativePointer());
462     auto elements =
463         reinterpret_cast<std::vector<std::bitset<JSAPIBitVector::BIT_SET_LENGTH>> *>(np->GetExternalPointer());
464     for (uint32_t i = startIndex; i < endIndex; i++) {
465         EXPECT_EQ(TestClass::GetBit(elements, i), JSTaggedValue(0));
466     }
467 }
468 
469 /**
470  * @tc.name: Resize
471  * @tc.desc:
472  * @tc.type: FUNC
473  * @tc.require:
474  */
HWTEST_F_L0(JSAPIBitVectorTest,Resize)475 HWTEST_F_L0(JSAPIBitVectorTest, Resize)
476 {
477     uint32_t increasedLength = 5;
478     int newLength = 10;
479     JSHandle<JSAPIBitVector> bitVector(thread, CreateBitVector());
480     for (uint32_t i = 0; i < increasedLength; i++) {
481         JSHandle<JSTaggedValue> value(thread, JSTaggedValue(1));
482         JSAPIBitVector::Push(thread, bitVector, value);
483     }
484 
485     JSAPIBitVector::Resize(thread, bitVector, newLength);
486     EXPECT_EQ(bitVector->GetLength(), newLength);
487 
488     JSHandle<JSNativePointer> np(thread, bitVector->GetNativePointer());
489     auto elements =
490         reinterpret_cast<std::vector<std::bitset<JSAPIBitVector::BIT_SET_LENGTH>> *>(np->GetExternalPointer());
491     for (uint32_t i = increasedLength; i < newLength; i++) {
492         EXPECT_EQ(TestClass::GetBit(elements, i), JSTaggedValue(0));
493     }
494 }
495 
496 /**
497  * @tc.name: OwnKeys
498  * @tc.desc:
499  * @tc.type: FUNC
500  * @tc.require:
501  */
HWTEST_F_L0(JSAPIBitVectorTest,OwnKeys)502 HWTEST_F_L0(JSAPIBitVectorTest, OwnKeys)
503 {
504     uint32_t increasedLength = 5;
505     JSHandle<JSAPIBitVector> bitVector(thread, CreateBitVector());
506     for (uint32_t i = 0; i < increasedLength; i++) {
507         JSHandle<JSTaggedValue> value(thread, JSTaggedValue(1));
508         JSAPIBitVector::Push(thread, bitVector, value);
509     }
510 
511     JSHandle<TaggedArray> keys = JSAPIBitVector::OwnKeys(thread, bitVector);
512     ASSERT_TRUE(EcmaStringAccessor::StringsAreEqual(*(base::NumberHelper::NumberToString(thread, JSTaggedValue(0))),
513         EcmaString::Cast(keys->Get(0).GetTaggedObject())));
514 }
515 
516 /**
517  * @tc.name: GetOwnProperty
518  * @tc.desc:
519  * @tc.type: FUNC
520  * @tc.require:
521  */
HWTEST_F_L0(JSAPIBitVectorTest,GetOwnProperty)522 HWTEST_F_L0(JSAPIBitVectorTest, GetOwnProperty)
523 {
524     uint32_t increasedLength = 5;
525     JSHandle<JSAPIBitVector> bitVector(thread, CreateBitVector());
526     for (uint32_t i = 0; i < increasedLength; i++) {
527         JSHandle<JSTaggedValue> value(thread, JSTaggedValue(1));
528         JSAPIBitVector::Push(thread, bitVector, value);
529     }
530 
531     for (uint32_t i = 0; i < increasedLength; i++) {
532         JSHandle<JSTaggedValue> key(thread, JSTaggedValue(i));
533         bool getOwnPropertyRes = JSAPIBitVector::GetOwnProperty(thread, bitVector, key);
534         EXPECT_EQ(getOwnPropertyRes, true);
535     }
536 }
537 
538 /**
539  * @tc.name: GetIteratorObj
540  * @tc.desc:
541  * @tc.type: FUNC
542  * @tc.require:
543  */
HWTEST_F_L0(JSAPIBitVectorTest,GetIteratorObj)544 HWTEST_F_L0(JSAPIBitVectorTest, GetIteratorObj)
545 {
546     JSHandle<JSAPIBitVector> bitVector(thread, CreateBitVector());
547     JSHandle<JSTaggedValue> iteratorObj(thread, JSAPIBitVector::GetIteratorObj(thread, bitVector));
548     EXPECT_TRUE(iteratorObj->IsJSAPIBitVectorIterator());
549 }
550 
551 /**
552  * @tc.name: GetProperty
553  * @tc.desc:
554  * @tc.type: FUNC
555  * @tc.require:
556  */
HWTEST_F_L0(JSAPIBitVectorTest,GetProperty)557 HWTEST_F_L0(JSAPIBitVectorTest, GetProperty)
558 {
559     uint32_t increasedLength = 5;
560     JSHandle<JSAPIBitVector> bitVector(thread, CreateBitVector());
561     for (uint32_t i = 0; i < increasedLength; i++) {
562         JSHandle<JSTaggedValue> value(thread, JSTaggedValue(1));
563         JSAPIBitVector::Push(thread, bitVector, value);
564     }
565 
566     for (uint32_t i = 0; i < increasedLength; i++) {
567         JSHandle<JSTaggedValue> key(thread, JSTaggedValue(i));
568         OperationResult getPropertyRes = JSAPIBitVector::GetProperty(thread, bitVector, key);
569         EXPECT_EQ(getPropertyRes.GetValue().GetTaggedValue(), JSTaggedValue(1));
570     }
571 }
572 
573 /**
574  * @tc.name: SetProperty
575  * @tc.desc:
576  * @tc.type: FUNC
577  * @tc.require:
578  */
HWTEST_F_L0(JSAPIBitVectorTest,SetProperty)579 HWTEST_F_L0(JSAPIBitVectorTest, SetProperty)
580 {
581     uint32_t increasedLength = 5;
582     JSHandle<JSAPIBitVector> bitVector(thread, CreateBitVector());
583     for (uint32_t i = 0; i < increasedLength; i++) {
584         JSHandle<JSTaggedValue> value(thread, JSTaggedValue(0));
585         JSAPIBitVector::Push(thread, bitVector, value);
586     }
587 
588     for (uint32_t i = 0; i < increasedLength; i++) {
589         JSHandle<JSTaggedValue> key(thread, JSTaggedValue(i));
590         JSHandle<JSTaggedValue> value(thread, JSTaggedValue(1));
591         bool setPropertyRes = JSAPIBitVector::SetProperty(thread, bitVector, key, value);
592         EXPECT_EQ(setPropertyRes, true);
593     }
594 }
595 }