• 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 "arkcompiler/ets_runtime/ecmascript/containers/containers_bitvector.h"
17 #include "arkcompiler/ets_runtime/ecmascript/js_api/js_api_bitvector.h"
18 #include "arkcompiler/ets_runtime/ecmascript/js_api/js_api_bitvector_iterator.h"
19 #include "ecmascript/containers/containers_private.h"
20 #include "ecmascript/containers/tests/containers_test_helper.h"
21 #include "ecmascript/ecma_runtime_call_info.h"
22 #include "ecmascript/global_env.h"
23 #include "ecmascript/js_handle.h"
24 #include "ecmascript/js_tagged_value-inl.h"
25 #include "ecmascript/js_thread.h"
26 #include "ecmascript/object_factory.h"
27 #include "ecmascript/tests/test_helper.h"
28 using namespace panda::ecmascript;
29 using namespace panda::ecmascript::containers;
30 namespace panda::test {
31 class ContainersBitVectorTest : public testing::Test {
32 public:
SetUpTestCase()33     static void SetUpTestCase()
34     {
35         GTEST_LOG_(INFO) << "SetUpTestCase";
36     }
TearDownTestCase()37     static void TearDownTestCase()
38     {
39         GTEST_LOG_(INFO) << "TearDownCase";
40     }
SetUp()41     void SetUp() override
42     {
43         TestHelper::CreateEcmaVMWithScope(instance, thread, scope);
44     }
TearDown()45     void TearDown() override
46     {
47         TestHelper::DestroyEcmaVMWithScope(instance, scope);
48     }
49     EcmaVM* instance { nullptr };
50     EcmaHandleScope* scope { nullptr };
51     JSThread* thread { nullptr };
52 
53 protected:
InitializeBitVectorConstructor()54     JSTaggedValue InitializeBitVectorConstructor()
55     {
56         ObjectFactory* factory = thread->GetEcmaVM()->GetFactory();
57         JSHandle<GlobalEnv> env = thread->GetEcmaVM()->GetGlobalEnv();
58         JSHandle<JSTaggedValue> globalObject = env->GetJSGlobalObject();
59         JSHandle<JSTaggedValue> key(factory->NewFromASCII("ArkPrivate"));
60         JSHandle<JSTaggedValue> value =
61             JSObject::GetProperty(thread, JSHandle<JSTaggedValue>(globalObject), key).GetValue();
62         auto objCallInfo =
63             TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6);
64         objCallInfo->SetFunction(JSTaggedValue::Undefined());
65         objCallInfo->SetThis(value.GetTaggedValue());
66         objCallInfo->SetCallArg(0, JSTaggedValue(static_cast<int>(ContainerTag::BitVector)));
67         [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo);
68         JSTaggedValue result = ContainersPrivate::Load(objCallInfo);
69         TestHelper::TearDownFrame(thread, prev);
70         return result;
71     }
CreateJSAPIBitVector()72     JSHandle<JSAPIBitVector> CreateJSAPIBitVector()
73     {
74         JSHandle<JSFunction> newTarget(thread, InitializeBitVectorConstructor());
75         auto objCallInfo =
76             TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6);
77         objCallInfo->SetFunction(newTarget.GetTaggedValue());
78         objCallInfo->SetNewTarget(newTarget.GetTaggedValue());
79         objCallInfo->SetThis(JSTaggedValue::Undefined());
80         objCallInfo->SetCallArg(0, JSTaggedValue(0));
81         [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo);
82         JSTaggedValue result = ContainersBitVector::BitVectorConstructor(objCallInfo);
83         TestHelper::TearDownFrame(thread, prev);
84         JSHandle<JSAPIBitVector> bitVector(thread, result);
85         return bitVector;
86     }
Push(JSHandle<JSAPIBitVector> bitVector)87     void Push(JSHandle<JSAPIBitVector> bitVector)
88     {
89         constexpr uint32_t NODE_NUMBERS = 64;
90         for (uint32_t i = 0; i < NODE_NUMBERS; i++) {
91             if (i >= 32) { // 32 means half bitvector length
92                 auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6);
93                 callInfo->SetFunction(JSTaggedValue::Undefined());
94                 callInfo->SetThis(bitVector.GetTaggedValue());
95                 callInfo->SetCallArg(0, JSTaggedValue(1));
96                 [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo);
97                 ContainersBitVector::Push(callInfo);
98                 TestHelper::TearDownFrame(thread, prev);
99             } else {
100                 auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6);
101                 callInfo->SetFunction(JSTaggedValue::Undefined());
102                 callInfo->SetThis(bitVector.GetTaggedValue());
103                 callInfo->SetCallArg(0, JSTaggedValue(0));
104                 [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo);
105                 ContainersBitVector::Push(callInfo);
106                 TestHelper::TearDownFrame(thread, prev);
107             }
108         }
109     }
Has(JSHandle<JSAPIBitVector> bitVector,int number,int startIndex,int endIndex)110     JSTaggedValue Has(JSHandle<JSAPIBitVector> bitVector, int number, int startIndex, int endIndex)
111     {
112         auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 10);
113         callInfo->SetFunction(JSTaggedValue::Undefined());
114         callInfo->SetThis(bitVector.GetTaggedValue());
115         callInfo->SetCallArg(0, JSTaggedValue(number));
116         callInfo->SetCallArg(1, JSTaggedValue(startIndex));
117         callInfo->SetCallArg(2, JSTaggedValue(endIndex)); // 2 means third args.
118         [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo);
119         JSTaggedValue result = ContainersBitVector::Has(callInfo);
120         TestHelper::TearDownFrame(thread, prev);
121         return result;
122     }
123 };
124 /**
125    * @tc.number: _BitVector_BitVevtorConstructor_Func_001
126    * @tc.name: test_init_bitvector
127    * @tc.desc: A constructor used to create a BitVector object.
128    * @tc.size: MediumTest
129    * @tc.type: Function
130    * @tc.level: Level 0
131    */
HWTEST_F_L0(ContainersBitVectorTest,BitVectorConstructor)132 HWTEST_F_L0(ContainersBitVectorTest, BitVectorConstructor)
133 {
134     InitializeBitVectorConstructor();
135     JSHandle<JSFunction> newTarget(thread, InitializeBitVectorConstructor());
136     auto objCallInfo =
137         TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6);
138     objCallInfo->SetFunction(newTarget.GetTaggedValue());
139     objCallInfo->SetNewTarget(newTarget.GetTaggedValue());
140     objCallInfo->SetThis(JSTaggedValue::Undefined());
141     objCallInfo->SetCallArg(0, JSTaggedValue(10));
142     [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo);
143     JSTaggedValue result = ContainersBitVector::BitVectorConstructor(objCallInfo);
144     TestHelper::TearDownFrame(thread, prev);
145     ASSERT_TRUE(result.IsJSAPIBitVector());
146     JSHandle<JSAPIBitVector> bitVector(thread, result);
147     JSTaggedValue resultProto = JSObject::GetPrototype(thread, JSHandle<JSObject>::Cast(bitVector));
148     JSTaggedValue funcProto = newTarget->GetFunctionPrototype(thread);
149     ASSERT_EQ(resultProto, funcProto);
150     int length = bitVector->GetLength();
151     ASSERT_EQ(length, 10);
152     objCallInfo->SetNewTarget(JSTaggedValue::Undefined());
153     CONTAINERS_API_EXCEPTION_TEST(ContainersBitVector, BitVectorConstructor, objCallInfo);
154 }
155 /**
156    * @tc.number: _BitVector_push_Func_001
157    * @tc.name: test_push
158    * @tc.desc: Appends the bit element to the end of this bit vector.
159    * @tc.size: MediumTest
160    * @tc.type: Function
161    * @tc.level: Level 0
162    */
HWTEST_F_L0(ContainersBitVectorTest,Push_001)163 HWTEST_F_L0(ContainersBitVectorTest, Push_001)
164 {
165     constexpr uint32_t NODE_NUMBERS = 8;
166     JSHandle<JSAPIBitVector> bitVector = CreateJSAPIBitVector();
167     for (uint32_t i = 0; i < NODE_NUMBERS; i++) {
168         auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6);
169         callInfo->SetFunction(JSTaggedValue::Undefined());
170         callInfo->SetThis(bitVector.GetTaggedValue());
171         callInfo->SetCallArg(0, JSTaggedValue(1));
172         [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo);
173         JSTaggedValue result = ContainersBitVector::Push(callInfo);
174         TestHelper::TearDownFrame(thread, prev);
175         EXPECT_EQ(result, JSTaggedValue::True());
176         EXPECT_EQ(bitVector->GetLength(), i + 1);
177     }
178 }
179 /**
180    * @tc.number: _BitVector_pop_Func_001
181    * @tc.name: test_pop
182    * @tc.desc: Retrieves and removes the bit element to the end of this bit vector.
183    * @tc.size: MediumTest
184    * @tc.type: Function
185    * @tc.level: Level 0
186    */
HWTEST_F_L0(ContainersBitVectorTest,Pop_001)187 HWTEST_F_L0(ContainersBitVectorTest, Pop_001)
188 {
189     constexpr uint32_t NODE_NUMBERS = 8;
190     JSHandle<JSAPIBitVector> bitVector = CreateJSAPIBitVector();
191     for (uint32_t i = 0; i < NODE_NUMBERS; i++) {
192         auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6);
193         callInfo->SetFunction(JSTaggedValue::Undefined());
194         callInfo->SetThis(bitVector.GetTaggedValue());
195         callInfo->SetCallArg(0, JSTaggedValue(1));
196         [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo);
197         JSTaggedValue result = ContainersBitVector::Push(callInfo);
198         TestHelper::TearDownFrame(thread, prev);
199         EXPECT_EQ(result, JSTaggedValue::True());
200         EXPECT_EQ(bitVector->GetLength(), i + 1);
201     }
202     for (uint32_t i = 0; i < NODE_NUMBERS; i++) {
203         auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 4);
204         callInfo->SetFunction(JSTaggedValue::Undefined());
205         callInfo->SetThis(bitVector.GetTaggedValue());
206         [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo);
207         JSTaggedValue result = ContainersBitVector::Pop(callInfo);
208         TestHelper::TearDownFrame(thread, prev);
209         EXPECT_EQ(result, JSTaggedValue(1));
210     }
211 }
212 /**
213    * @tc.number: _BitVector_has_Func_001
214    * @tc.name: test_has
215    * @tc.desc: Check if bit vector contains a particular bit element
216    * @tc.size: MediumTest
217    * @tc.type: Function
218    * @tc.level: Level 0
219    */
HWTEST_F_L0(ContainersBitVectorTest,Has_001)220 HWTEST_F_L0(ContainersBitVectorTest, Has_001)
221 {
222     JSHandle<JSAPIBitVector> bitVector = CreateJSAPIBitVector();
223     {
224         auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6);
225         callInfo->SetFunction(JSTaggedValue::Undefined());
226         callInfo->SetThis(bitVector.GetTaggedValue());
227         callInfo->SetCallArg(0, JSTaggedValue(1));
228         [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo);
229         JSTaggedValue result = ContainersBitVector::Push(callInfo);
230         TestHelper::TearDownFrame(thread, prev);
231         EXPECT_EQ(result, JSTaggedValue::True());
232         EXPECT_EQ(bitVector->GetLength(), 1);
233     }
234     {
235         auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 10);
236         callInfo->SetFunction(JSTaggedValue::Undefined());
237         callInfo->SetThis(bitVector.GetTaggedValue());
238         callInfo->SetCallArg(0, JSTaggedValue(1));
239         callInfo->SetCallArg(1, JSTaggedValue(0));
240         callInfo->SetCallArg(2, JSTaggedValue(1));
241         [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo);
242         JSTaggedValue result = ContainersBitVector::Has(callInfo);
243         TestHelper::TearDownFrame(thread, prev);
244         EXPECT_EQ(result, JSTaggedValue::True());
245     }
246 }
247 /**
248    * @tc.number: _BitVector_has_Func_002
249    * @tc.name: test_has
250    * @tc.desc: Check if bit vector contains a particular bit element
251    * @tc.size: MediumTest
252    * @tc.type: Function
253    * @tc.level: Level 2
254    */
HWTEST_F_L0(ContainersBitVectorTest,Has_002)255 HWTEST_F_L0(ContainersBitVectorTest, Has_002)
256 {
257     JSHandle<JSAPIBitVector> bitVector = CreateJSAPIBitVector();
258     {
259         auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6);
260         callInfo->SetFunction(JSTaggedValue::Undefined());
261         callInfo->SetThis(bitVector.GetTaggedValue());
262         callInfo->SetCallArg(0, JSTaggedValue(1));
263         [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo);
264         JSTaggedValue result = ContainersBitVector::Push(callInfo);
265         TestHelper::TearDownFrame(thread, prev);
266         EXPECT_EQ(result, JSTaggedValue::True());
267         EXPECT_EQ(bitVector->GetLength(), 1);
268     }
269     {
270         auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 10);
271         callInfo->SetFunction(JSTaggedValue::Undefined());
272         callInfo->SetThis(bitVector.GetTaggedValue());
273         callInfo->SetCallArg(0, JSTaggedValue(1));
274         callInfo->SetCallArg(1, JSTaggedValue(1.1));
275         callInfo->SetCallArg(2, JSTaggedValue(1.1));
276         [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo);
277         JSTaggedValue result = ContainersBitVector::Has(callInfo);
278         TestHelper::TearDownFrame(thread, prev);
279         EXPECT_TRUE(thread->HasPendingException());
280         EXPECT_EQ(result, JSTaggedValue::Exception());
281         thread->ClearException();
282     }
283 }
284 /**
285    * @tc.number: _BitVector_has_Func_003
286    * @tc.name: test_has
287    * @tc.desc: Check if bit vector contains a particular bit element
288    * @tc.size: MediumTest
289    * @tc.type: Function
290    * @tc.level: Level 1
291    */
HWTEST_F_L0(ContainersBitVectorTest,Has_003)292 HWTEST_F_L0(ContainersBitVectorTest, Has_003)
293 {
294     JSHandle<JSAPIBitVector> bitVector = CreateJSAPIBitVector();
295     Push(bitVector);
296     JSTaggedValue result1 = Has(bitVector, 1, 0, 31);
297     EXPECT_EQ(result1, JSTaggedValue::False());
298     JSTaggedValue result2 = Has(bitVector, 0, 0, 32);
299     EXPECT_EQ(result2, JSTaggedValue::True());
300     JSTaggedValue result3 = Has(bitVector, 1, 32, 64);
301     EXPECT_EQ(result3, JSTaggedValue::True());
302     JSTaggedValue result4 = Has(bitVector, 0, 32, 63);
303     EXPECT_EQ(result4, JSTaggedValue::False());
304 }
305 /**
306    * @tc.number: _BitVector_setBitsByRange_Func_001
307    * @tc.name: test_setBitsByRange
308    * @tc.desc: Sets a range of bits in a bit vector to a particular element.
309    * @tc.size: MediumTest
310    * @tc.type: Function
311    * @tc.level: Level 0
312    */
HWTEST_F_L0(ContainersBitVectorTest,SetBitsByRange_001)313 HWTEST_F_L0(ContainersBitVectorTest, SetBitsByRange_001)
314 {
315     JSHandle<JSAPIBitVector> bitVector = CreateJSAPIBitVector();
316     {
317         auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6);
318         callInfo->SetFunction(JSTaggedValue::Undefined());
319         callInfo->SetThis(bitVector.GetTaggedValue());
320         callInfo->SetCallArg(0, JSTaggedValue(1));
321         [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo);
322         JSTaggedValue result = ContainersBitVector::Push(callInfo);
323         TestHelper::TearDownFrame(thread, prev);
324         EXPECT_EQ(result, JSTaggedValue::True());
325         EXPECT_EQ(bitVector->GetLength(), 1);
326     }
327     {
328         auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 10);
329         callInfo->SetFunction(JSTaggedValue::Undefined());
330         callInfo->SetThis(bitVector.GetTaggedValue());
331         callInfo->SetCallArg(0, JSTaggedValue(0));
332         callInfo->SetCallArg(1, JSTaggedValue(0));
333         callInfo->SetCallArg(2, JSTaggedValue(1));
334         [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo);
335         ContainersBitVector::SetBitsByRange(callInfo);
336         TestHelper::TearDownFrame(thread, prev);
337     }
338     {
339         auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6);
340         callInfo->SetFunction(JSTaggedValue::Undefined());
341         callInfo->SetThis(bitVector.GetTaggedValue());
342         [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo);
343         JSTaggedValue result = ContainersBitVector::Pop(callInfo);
344         TestHelper::TearDownFrame(thread, prev);
345         EXPECT_EQ(result, JSTaggedValue(0));
346     }
347 }
348 /**
349    * @tc.number: _BitVector_setBitsByRange_Func_002
350    * @tc.name: test_setBitsByRange
351    * @tc.desc: Sets a range of bits in a bit vector to a particular element.
352    * @tc.size: MediumTest
353    * @tc.type: Function
354    * @tc.level: Level 2
355    */
HWTEST_F_L0(ContainersBitVectorTest,SetBitsByRange_002)356 HWTEST_F_L0(ContainersBitVectorTest, SetBitsByRange_002)
357 {
358     JSHandle<JSAPIBitVector> bitVector = CreateJSAPIBitVector();
359     {
360         auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6);
361         callInfo->SetFunction(JSTaggedValue::Undefined());
362         callInfo->SetThis(bitVector.GetTaggedValue());
363         callInfo->SetCallArg(0, JSTaggedValue(1));
364         [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo);
365         JSTaggedValue result = ContainersBitVector::Push(callInfo);
366         TestHelper::TearDownFrame(thread, prev);
367         EXPECT_EQ(result, JSTaggedValue::True());
368         EXPECT_EQ(bitVector->GetLength(), 1);
369     }
370     {
371         auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 10);
372         callInfo->SetFunction(JSTaggedValue::Undefined());
373         callInfo->SetThis(bitVector.GetTaggedValue());
374         callInfo->SetCallArg(0, JSTaggedValue(0));
375         callInfo->SetCallArg(1, JSTaggedValue(1.1));
376         callInfo->SetCallArg(2, JSTaggedValue(1));
377         [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo);
378         JSTaggedValue result = ContainersBitVector::SetBitsByRange(callInfo);
379         TestHelper::TearDownFrame(thread, prev);
380         EXPECT_TRUE(thread->HasPendingException());
381         EXPECT_EQ(result, JSTaggedValue::Exception());
382         thread->ClearException();
383     }
384 }
385 /**
386    * @tc.number: _BitVector_setBitsByRange_Func_003
387    * @tc.name: test_setBitsByRange
388    * @tc.desc: Sets a range of bits in a bit vector to a particular element.
389    * @tc.size: MediumTest
390    * @tc.type: Function
391    * @tc.level: Level 1
392    */
HWTEST_F_L0(ContainersBitVectorTest,SetBitsByRange_003)393 HWTEST_F_L0(ContainersBitVectorTest, SetBitsByRange_003)
394 {
395     JSHandle<JSAPIBitVector> bitVector = CreateJSAPIBitVector();
396     Push(bitVector);
397     {
398         auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 10);
399         callInfo->SetFunction(JSTaggedValue::Undefined());
400         callInfo->SetThis(bitVector.GetTaggedValue());
401         callInfo->SetCallArg(0, JSTaggedValue(1));
402         callInfo->SetCallArg(1, JSTaggedValue(0));
403         callInfo->SetCallArg(2, JSTaggedValue(32));
404         [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo);
405         ContainersBitVector::SetBitsByRange(callInfo);
406         TestHelper::TearDownFrame(thread, prev);
407     }
408     {
409         auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 10);
410         callInfo->SetFunction(JSTaggedValue::Undefined());
411         callInfo->SetThis(bitVector.GetTaggedValue());
412         callInfo->SetCallArg(0, JSTaggedValue(0));
413         callInfo->SetCallArg(1, JSTaggedValue(32));
414         callInfo->SetCallArg(2, JSTaggedValue(64));
415         [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo);
416         ContainersBitVector::SetBitsByRange(callInfo);
417         TestHelper::TearDownFrame(thread, prev);
418     }
419     constexpr uint32_t NODE_NUMBERS = 64;
420     for (uint32_t i = 0; i < NODE_NUMBERS; i++) {
421         if (i >= 32) { // 32 means half bitvector length
422             auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 4);
423             callInfo->SetFunction(JSTaggedValue::Undefined());
424             callInfo->SetThis(bitVector.GetTaggedValue());
425             [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo);
426             JSTaggedValue result0 = ContainersBitVector::Pop(callInfo);
427             TestHelper::TearDownFrame(thread, prev);
428             EXPECT_EQ(result0, JSTaggedValue(1));
429         } else {
430             auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 4);
431             callInfo->SetFunction(JSTaggedValue::Undefined());
432             callInfo->SetThis(bitVector.GetTaggedValue());
433             [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo);
434             JSTaggedValue result1 = ContainersBitVector::Pop(callInfo);
435             TestHelper::TearDownFrame(thread, prev);
436             EXPECT_EQ(result1, JSTaggedValue(0));
437         }
438     }
439 }
440 /**
441    * @tc.number: _BitVector_setAllBits_Func_001
442    * @tc.name: test_setAllBits
443    * @tc.desc: Sets all of bits in a bit vector to a particular element.
444    * @tc.size: MediumTest MediumTest
445    * @tc.type: Function
446    * @tc.level: Level 0
447    */
HWTEST_F_L0(ContainersBitVectorTest,SetAllBits_001)448 HWTEST_F_L0(ContainersBitVectorTest, SetAllBits_001)
449 {
450     JSHandle<JSAPIBitVector> bitVector = CreateJSAPIBitVector();
451     {
452         auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6);
453         callInfo->SetFunction(JSTaggedValue::Undefined());
454         callInfo->SetThis(bitVector.GetTaggedValue());
455         callInfo->SetCallArg(0, JSTaggedValue(0));
456         [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo);
457         JSTaggedValue result = ContainersBitVector::Push(callInfo);
458         TestHelper::TearDownFrame(thread, prev);
459         EXPECT_EQ(result, JSTaggedValue::True());
460         EXPECT_EQ(bitVector->GetLength(), 1);
461     }
462     {
463         auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6);
464         callInfo->SetFunction(JSTaggedValue::Undefined());
465         callInfo->SetThis(bitVector.GetTaggedValue());
466         callInfo->SetCallArg(0, JSTaggedValue(1));
467         [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo);
468         ContainersBitVector::SetAllBits(callInfo);
469         TestHelper::TearDownFrame(thread, prev);
470         EXPECT_EQ(bitVector->GetSize(), 1);
471     }
472     {
473         auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 4);
474         callInfo->SetFunction(JSTaggedValue::Undefined());
475         callInfo->SetThis(bitVector.GetTaggedValue());
476         [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo);
477         JSTaggedValue result = ContainersBitVector::Pop(callInfo);
478         TestHelper::TearDownFrame(thread, prev);
479         EXPECT_EQ(result, JSTaggedValue(1));
480     }
481 }
482 /**
483    * @tc.number: _BitVector_setAllBits_Func_002
484    * @tc.name: test_setAllBits
485    * @tc.desc: Sets all of bits in a bit vector to a particular element.
486    * @tc.size: MediumTest
487    * @tc.type: Function
488    * @tc.level: Level 1
489    */
HWTEST_F_L0(ContainersBitVectorTest,SetAllBits_002)490 HWTEST_F_L0(ContainersBitVectorTest, SetAllBits_002)
491 {
492     constexpr uint32_t NODE_NUMBERS = 64;
493     JSHandle<JSAPIBitVector> bitVector = CreateJSAPIBitVector();
494     for (uint32_t i = 0; i < NODE_NUMBERS; i++) {
495         auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6);
496         callInfo->SetFunction(JSTaggedValue::Undefined());
497         callInfo->SetThis(bitVector.GetTaggedValue());
498         callInfo->SetCallArg(0, JSTaggedValue(0));
499         [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo);
500         ContainersBitVector::Push(callInfo);
501         TestHelper::TearDownFrame(thread, prev);
502     }
503     EXPECT_EQ(bitVector->GetSize(), 64);
504     {
505         auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6);
506         callInfo->SetFunction(JSTaggedValue::Undefined());
507         callInfo->SetThis(bitVector.GetTaggedValue());
508         callInfo->SetCallArg(0, JSTaggedValue(1));
509         [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo);
510         ContainersBitVector::SetAllBits(callInfo);
511         TestHelper::TearDownFrame(thread, prev);
512     }
513     for (uint32_t i = 0; i < NODE_NUMBERS; i++) {
514         auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 4);
515         callInfo->SetFunction(JSTaggedValue::Undefined());
516         callInfo->SetThis(bitVector.GetTaggedValue());
517         [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo);
518         JSTaggedValue result = ContainersBitVector::Pop(callInfo);
519         TestHelper::TearDownFrame(thread, prev);
520         EXPECT_EQ(result, JSTaggedValue(1));
521     }
522 }
523 /**
524    * @tc.number: _BitVector_setAllBits_Func_003
525    * @tc.name: test_setAllBits
526    * @tc.desc: Sets all of bits in a bit vector to a particular element.
527    * @tc.size: MediumTest
528    * @tc.type: Function
529    * @tc.level: Level 1
530    */
HWTEST_F_L0(ContainersBitVectorTest,SetAllBits_003)531 HWTEST_F_L0(ContainersBitVectorTest, SetAllBits_003)
532 {
533     constexpr uint32_t NODE_NUMBERS = 64;
534     JSHandle<JSAPIBitVector> bitVector = CreateJSAPIBitVector();
535     for (uint32_t i = 0; i < NODE_NUMBERS; i++) {
536         auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6);
537         callInfo->SetFunction(JSTaggedValue::Undefined());
538         callInfo->SetThis(bitVector.GetTaggedValue());
539         callInfo->SetCallArg(0, JSTaggedValue(1));
540         [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo);
541         ContainersBitVector::Push(callInfo);
542         TestHelper::TearDownFrame(thread, prev);
543     }
544     EXPECT_EQ(bitVector->GetSize(), 64);
545     {
546         auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6);
547         callInfo->SetFunction(JSTaggedValue::Undefined());
548         callInfo->SetThis(bitVector.GetTaggedValue());
549         callInfo->SetCallArg(0, JSTaggedValue(0));
550         [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo);
551         ContainersBitVector::SetAllBits(callInfo);
552         TestHelper::TearDownFrame(thread, prev);
553     }
554     for (uint32_t i = 0; i < NODE_NUMBERS; i++) {
555         auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 4);
556         callInfo->SetFunction(JSTaggedValue::Undefined());
557         callInfo->SetThis(bitVector.GetTaggedValue());
558         [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo);
559         JSTaggedValue result = ContainersBitVector::Pop(callInfo);
560         TestHelper::TearDownFrame(thread, prev);
561         EXPECT_EQ(result, JSTaggedValue(0));
562     }
563 }
564 /**
565    * @tc.number: _BitVector_getBitsByRange_Func_001
566    * @tc.name: test_getBitsByRange
567    * @tc.desc: Returns the bit values in a range of indices in a bit vector.
568    * @tc.size: MediumTest
569    * @tc.type: Function
570    * @tc.level: Level 0
571    */
HWTEST_F_L0(ContainersBitVectorTest,GetBitsByRange_001)572 HWTEST_F_L0(ContainersBitVectorTest, GetBitsByRange_001)
573 {
574     JSHandle<JSAPIBitVector> bitVector = CreateJSAPIBitVector();
575     {
576         auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6);
577         callInfo->SetFunction(JSTaggedValue::Undefined());
578         callInfo->SetThis(bitVector.GetTaggedValue());
579         callInfo->SetCallArg(0, JSTaggedValue(1));
580         [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo);
581         JSTaggedValue result = ContainersBitVector::Push(callInfo);
582         TestHelper::TearDownFrame(thread, prev);
583         EXPECT_EQ(result, JSTaggedValue::True());
584         EXPECT_EQ(bitVector->GetLength(), 1);
585     }
586     {
587         auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 8);
588         callInfo->SetFunction(JSTaggedValue::Undefined());
589         callInfo->SetThis(bitVector.GetTaggedValue());
590         callInfo->SetCallArg(0, JSTaggedValue(0));
591         callInfo->SetCallArg(1, JSTaggedValue(1));
592         [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo);
593         JSTaggedValue result = ContainersBitVector::GetBitsByRange(callInfo);
594         TestHelper::TearDownFrame(thread, prev);
595 
596         JSHandle<JSNativePointer> np(
597             thread, JSAPIBitVector::Cast(result.GetTaggedObject())
598                         ->GetNativePointer(thread));
599         auto elements =
600             reinterpret_cast<std::vector<std::bitset<JSAPIBitVector::BIT_SET_LENGTH>> *>(np->GetExternalPointer());
601         EXPECT_EQ((*elements)[0].test(0), 1);
602     }
603 }
604 /**
605    * @tc.number: _BitVector_getBitsByRange_Func_002
606    * @tc.name: test_getBitsByRange
607    * @tc.desc: Returns the bit values in a range of indices in a bit vector.
608    * @tc.size: MediumTest
609    * @tc.type: Function
610    * @tc.level: Level 2
611    */
HWTEST_F_L0(ContainersBitVectorTest,GetBitsByRange_002)612 HWTEST_F_L0(ContainersBitVectorTest, GetBitsByRange_002)
613 {
614     JSHandle<JSAPIBitVector> bitVector = CreateJSAPIBitVector();
615     {
616         auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6);
617         callInfo->SetFunction(JSTaggedValue::Undefined());
618         callInfo->SetThis(bitVector.GetTaggedValue());
619         callInfo->SetCallArg(0, JSTaggedValue(1));
620         [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo);
621         JSTaggedValue result = ContainersBitVector::Push(callInfo);
622         TestHelper::TearDownFrame(thread, prev);
623         EXPECT_EQ(result, JSTaggedValue::True());
624         EXPECT_EQ(bitVector->GetLength(), 1);
625     }
626     {
627         auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 8);
628         callInfo->SetFunction(JSTaggedValue::Undefined());
629         callInfo->SetThis(bitVector.GetTaggedValue());
630         callInfo->SetCallArg(0, JSTaggedValue(1.1));
631         callInfo->SetCallArg(1, JSTaggedValue(1.1));
632         [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo);
633         JSTaggedValue result = ContainersBitVector::GetBitsByRange(callInfo);
634         TestHelper::TearDownFrame(thread, prev);
635         EXPECT_TRUE(thread->HasPendingException());
636         EXPECT_EQ(result, JSTaggedValue::Exception());
637         thread->ClearException();
638     }
639 }
640 /**
641    * @tc.number: _BitVector_getBitsByRange_Func_003
642    * @tc.name: test_getBitsByRange
643    * @tc.desc: Returns the bit values in a range of indices in a bit vector.
644    * @tc.size: MediumTest
645    * @tc.type: Function
646    * @tc.level: Level 1
647    */
HWTEST_F_L0(ContainersBitVectorTest,GetBitsByRange_003)648 HWTEST_F_L0(ContainersBitVectorTest, GetBitsByRange_003)
649 {
650     JSHandle<JSAPIBitVector> bitVector = CreateJSAPIBitVector();
651     Push(bitVector);
652     {
653         auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 8);
654         callInfo->SetFunction(JSTaggedValue::Undefined());
655         callInfo->SetThis(bitVector.GetTaggedValue());
656         callInfo->SetCallArg(0, JSTaggedValue(0)); //range 0 to 31
657         callInfo->SetCallArg(1, JSTaggedValue(31));
658 
659         [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo);
660         JSTaggedValue result = ContainersBitVector::GetBitsByRange(callInfo);
661         TestHelper::TearDownFrame(thread, prev);
662 
663         JSHandle<JSNativePointer> np(
664             thread, JSAPIBitVector::Cast(result.GetTaggedObject())
665                         ->GetNativePointer(thread));
666         auto elements =
667             reinterpret_cast<std::vector<std::bitset<JSAPIBitVector::BIT_SET_LENGTH>> *>(np->GetExternalPointer());
668         EXPECT_EQ((*elements)[0].test(0), 0);
669     }
670     {
671         auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 8);
672         callInfo->SetFunction(JSTaggedValue::Undefined());
673         callInfo->SetThis(bitVector.GetTaggedValue());
674         callInfo->SetCallArg(0, JSTaggedValue(32));
675         callInfo->SetCallArg(1, JSTaggedValue(64));
676         [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo);
677         JSTaggedValue result = ContainersBitVector::GetBitsByRange(callInfo);
678         TestHelper::TearDownFrame(thread, prev);
679 
680         JSHandle<JSNativePointer> np(
681             thread, JSAPIBitVector::Cast(result.GetTaggedObject())
682                         ->GetNativePointer(thread));
683         auto elements =
684             reinterpret_cast<std::vector<std::bitset<JSAPIBitVector::BIT_SET_LENGTH>> *>(np->GetExternalPointer());
685         EXPECT_EQ((*elements)[0].test(0), 1);
686     }
687 }
688 /**
689    * @tc.number: _BitVector_resize_Func_001
690    * @tc.name: test_resize
691    * @tc.desc: Resize the bitVector's length.
692    * @tc.size: MediumTest
693    * @tc.type: Function
694    * @tc.level: Level 0
695    */
HWTEST_F_L0(ContainersBitVectorTest,Resize_01)696 HWTEST_F_L0(ContainersBitVectorTest, Resize_01)
697 {
698     constexpr uint32_t NODE_NUMBERS = 8;
699     JSHandle<JSAPIBitVector> bitVector = CreateJSAPIBitVector();
700     for (uint32_t i = 0; i < NODE_NUMBERS; i++) {
701         auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6);
702         callInfo->SetFunction(JSTaggedValue::Undefined());
703         callInfo->SetThis(bitVector.GetTaggedValue());
704         callInfo->SetCallArg(0, JSTaggedValue(1));
705         [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo);
706         JSTaggedValue result = ContainersBitVector::Push(callInfo);
707         TestHelper::TearDownFrame(thread, prev);
708         EXPECT_EQ(result, JSTaggedValue::True());
709         EXPECT_EQ(bitVector->GetLength(), i + 1);
710     }
711     for (uint32_t i = 0; i < NODE_NUMBERS; i++) {
712         auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6);
713         callInfo->SetFunction(JSTaggedValue::Undefined());
714         callInfo->SetThis(bitVector.GetTaggedValue());
715         callInfo->SetCallArg(0, JSTaggedValue(5));
716         [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo);
717         ContainersBitVector::Resize(callInfo);
718         TestHelper::TearDownFrame(thread, prev);
719     }
720     EXPECT_EQ(bitVector->GetLength(), 5);
721 }
722 /**
723    * @tc.number: _BitVector_resize_Func_002
724    * @tc.name: test_resize
725    * @tc.desc: Resize the bitVector's length.
726    * @tc.size: MediumTest
727    * @tc.type: Function
728    * @tc.level: Level 0
729    */
HWTEST_F_L0(ContainersBitVectorTest,Resize_02)730 HWTEST_F_L0(ContainersBitVectorTest, Resize_02)
731 {
732     constexpr uint32_t NODE_NUMBERS = 8;
733     JSHandle<JSAPIBitVector> bitVector = CreateJSAPIBitVector();
734     for (uint32_t i = 0; i < NODE_NUMBERS; i++) {
735         auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6);
736         callInfo->SetFunction(JSTaggedValue::Undefined());
737         callInfo->SetThis(bitVector.GetTaggedValue());
738         callInfo->SetCallArg(0, JSTaggedValue(1));
739         [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo);
740         JSTaggedValue result = ContainersBitVector::Push(callInfo);
741         TestHelper::TearDownFrame(thread, prev);
742         EXPECT_EQ(result, JSTaggedValue::True());
743         EXPECT_EQ(bitVector->GetLength(), i + 1);
744     }
745     for (uint32_t i = 0; i < NODE_NUMBERS; i++) {
746         auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6);
747         callInfo->SetFunction(JSTaggedValue::Undefined());
748         callInfo->SetThis(bitVector.GetTaggedValue());
749         callInfo->SetCallArg(0, JSTaggedValue(8));
750         [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo);
751         ContainersBitVector::Resize(callInfo);
752         TestHelper::TearDownFrame(thread, prev);
753     }
754     EXPECT_EQ(bitVector->GetLength(), 8);
755 }
756 /**
757    * @tc.number: _BitVector_resize_Func_003
758    * @tc.name: test_resize
759    * @tc.desc: Resize the bitVector's length.
760    * @tc.size: MediumTest
761    * @tc.type: Function
762    * @tc.level: Level 0
763    */
HWTEST_F_L0(ContainersBitVectorTest,Resize_03)764 HWTEST_F_L0(ContainersBitVectorTest, Resize_03)
765 {
766     constexpr uint32_t NODE_NUMBERS = 8;
767     JSHandle<JSAPIBitVector> bitVector = CreateJSAPIBitVector();
768     for (uint32_t i = 0; i < NODE_NUMBERS; i++) {
769         auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6);
770         callInfo->SetFunction(JSTaggedValue::Undefined());
771         callInfo->SetThis(bitVector.GetTaggedValue());
772         callInfo->SetCallArg(0, JSTaggedValue(1));
773         [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo);
774         JSTaggedValue result = ContainersBitVector::Push(callInfo);
775         TestHelper::TearDownFrame(thread, prev);
776         EXPECT_EQ(result, JSTaggedValue::True());
777         EXPECT_EQ(bitVector->GetLength(), i + 1);
778     }
779     for (uint32_t i = 0; i < NODE_NUMBERS; i++) {
780         auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6);
781         callInfo->SetFunction(JSTaggedValue::Undefined());
782         callInfo->SetThis(bitVector.GetTaggedValue());
783         callInfo->SetCallArg(0, JSTaggedValue(10));
784         [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo);
785         ContainersBitVector::Resize(callInfo);
786         TestHelper::TearDownFrame(thread, prev);
787     }
788     EXPECT_EQ(bitVector->GetLength(), 10);
789     for (uint32_t i = 0; i < 2; i++) {
790         auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 4);
791         callInfo->SetFunction(JSTaggedValue::Undefined());
792         callInfo->SetThis(bitVector.GetTaggedValue());
793         [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo);
794         JSTaggedValue result = ContainersBitVector::Pop(callInfo);
795         TestHelper::TearDownFrame(thread, prev);
796         EXPECT_EQ(result, JSTaggedValue(0));
797     }
798 }
799 /**
800    * @tc.number: _BitVector_resize_Func_004
801    * @tc.name: test_resize
802    * @tc.desc: Resize the bitVector's length.
803    * @tc.size: MediumTest
804    * @tc.type: Function
805    * @tc.level: Level 2
806    */
HWTEST_F_L0(ContainersBitVectorTest,Resize_04)807 HWTEST_F_L0(ContainersBitVectorTest, Resize_04)
808 {
809     constexpr uint32_t NODE_NUMBERS = 8;
810     JSHandle<JSAPIBitVector> bitVector = CreateJSAPIBitVector();
811     for (uint32_t i = 0; i < NODE_NUMBERS; i++) {
812         auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6);
813         callInfo->SetFunction(JSTaggedValue::Undefined());
814         callInfo->SetThis(bitVector.GetTaggedValue());
815         callInfo->SetCallArg(0, JSTaggedValue(1));
816         [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo);
817         JSTaggedValue result = ContainersBitVector::Push(callInfo);
818         TestHelper::TearDownFrame(thread, prev);
819         EXPECT_EQ(result, JSTaggedValue::True());
820         EXPECT_EQ(bitVector->GetLength(), i + 1);
821     }
822     for (uint32_t i = 0; i < NODE_NUMBERS; i++) {
823         auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6);
824         callInfo->SetFunction(JSTaggedValue::Undefined());
825         callInfo->SetThis(bitVector.GetTaggedValue());
826         callInfo->SetCallArg(0, JSTaggedValue(1.1));
827         [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo);
828         JSTaggedValue result = ContainersBitVector::Resize(callInfo);
829         TestHelper::TearDownFrame(thread, prev);
830         EXPECT_TRUE(thread->HasPendingException());
831         EXPECT_EQ(result, JSTaggedValue::Exception());
832         thread->ClearException();
833     }
834 }
835 /**
836    * @tc.number: _BitVector_getBitCountByRange_Func_001
837    * @tc.name: test_getBitCountByRange
838    * @tc.desc: Counts the number of times a certain bit element occurs within a range of bits in a bit vector.
839    * @tc.size: MediumTest
840    * @tc.type: Function
841    * @tc.level: Level 0
842    */
HWTEST_F_L0(ContainersBitVectorTest,GetBitCountByRange_001)843 HWTEST_F_L0(ContainersBitVectorTest, GetBitCountByRange_001)
844 {
845     JSHandle<JSAPIBitVector> bitVector = CreateJSAPIBitVector();
846     {
847         auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6);
848         callInfo->SetFunction(JSTaggedValue::Undefined());
849         callInfo->SetThis(bitVector.GetTaggedValue());
850         callInfo->SetCallArg(0, JSTaggedValue(1));
851         [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo);
852         JSTaggedValue result = ContainersBitVector::Push(callInfo);
853         TestHelper::TearDownFrame(thread, prev);
854         EXPECT_EQ(result, JSTaggedValue::True());
855         EXPECT_EQ(bitVector->GetLength(), 1);
856     }
857     {
858         auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 10);
859         callInfo->SetFunction(JSTaggedValue::Undefined());
860         callInfo->SetThis(bitVector.GetTaggedValue());
861         callInfo->SetCallArg(0, JSTaggedValue(1));
862         callInfo->SetCallArg(1, JSTaggedValue(0));
863         callInfo->SetCallArg(2, JSTaggedValue(1));
864         [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo);
865         JSTaggedValue result = ContainersBitVector::GetBitCountByRange(callInfo);
866         TestHelper::TearDownFrame(thread, prev);
867         EXPECT_EQ(result, JSTaggedValue(1));
868     }
869 }
870 /**
871    * @tc.number: _BitVector_getBitCountByRange_Func_002
872    * @tc.name: test_getBitCountByRange
873    * @tc.desc: Counts the number of times a certain bit element occurs within a range of bits in a bit vector.
874    * @tc.size: MediumTest
875    * @tc.type: Function
876    * @tc.level: Level 2
877    */
HWTEST_F_L0(ContainersBitVectorTest,GetBitCountByRange_002)878 HWTEST_F_L0(ContainersBitVectorTest, GetBitCountByRange_002)
879 {
880     JSHandle<JSAPIBitVector> bitVector = CreateJSAPIBitVector();
881     {
882         auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6);
883         callInfo->SetFunction(JSTaggedValue::Undefined());
884         callInfo->SetThis(bitVector.GetTaggedValue());
885         callInfo->SetCallArg(0, JSTaggedValue(1));
886         [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo);
887         JSTaggedValue result = ContainersBitVector::Push(callInfo);
888         TestHelper::TearDownFrame(thread, prev);
889         EXPECT_EQ(result, JSTaggedValue::True());
890         EXPECT_EQ(bitVector->GetLength(), 1);
891     }
892     {
893         auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 10);
894         callInfo->SetFunction(JSTaggedValue::Undefined());
895         callInfo->SetThis(bitVector.GetTaggedValue());
896         callInfo->SetCallArg(0, JSTaggedValue(1));
897         callInfo->SetCallArg(1, JSTaggedValue(1.1));
898         callInfo->SetCallArg(2, JSTaggedValue(1));
899         [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo);
900         JSTaggedValue result = ContainersBitVector::GetBitCountByRange(callInfo);
901         TestHelper::TearDownFrame(thread, prev);
902         EXPECT_TRUE(thread->HasPendingException());
903         EXPECT_EQ(result, JSTaggedValue::Exception());
904         thread->ClearException();
905     }
906 }
907 /**
908    * @tc.number: _BitVector_getBitCountByRange_Func_003
909    * @tc.name: test_getBitCountByRange
910    * @tc.desc: Counts the number of times a certain bit element occurs within a range of bits in a bit vector.
911    * @tc.size: MediumTest
912    * @tc.type: Function
913    * @tc.level: Level 1
914    */
HWTEST_F_L0(ContainersBitVectorTest,GetBitCountByRange_003)915 HWTEST_F_L0(ContainersBitVectorTest, GetBitCountByRange_003)
916 {
917     constexpr uint32_t NODE_NUMBERS = 64;
918     JSHandle<JSAPIBitVector> bitVector = CreateJSAPIBitVector();
919     for (uint32_t i = 0; i < NODE_NUMBERS; i++) {
920         if (i >= 32) {
921             auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6);
922             callInfo->SetFunction(JSTaggedValue::Undefined());
923             callInfo->SetThis(bitVector.GetTaggedValue());
924             callInfo->SetCallArg(0, JSTaggedValue(1));
925             [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo);
926             ContainersBitVector::Push(callInfo);
927             TestHelper::TearDownFrame(thread, prev);
928         } else {
929             auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6);
930             callInfo->SetFunction(JSTaggedValue::Undefined());
931             callInfo->SetThis(bitVector.GetTaggedValue());
932             callInfo->SetCallArg(0, JSTaggedValue(0));
933             [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo);
934             ContainersBitVector::Push(callInfo);
935             TestHelper::TearDownFrame(thread, prev);
936         }
937     }
938     {
939         auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 10);
940         callInfo->SetFunction(JSTaggedValue::Undefined());
941         callInfo->SetThis(bitVector.GetTaggedValue());
942         callInfo->SetCallArg(0, JSTaggedValue(1));
943         callInfo->SetCallArg(1, JSTaggedValue(0));
944         callInfo->SetCallArg(2, JSTaggedValue(64));
945         [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo);
946         JSTaggedValue result = ContainersBitVector::GetBitCountByRange(callInfo);
947         TestHelper::TearDownFrame(thread, prev);
948         EXPECT_EQ(result, JSTaggedValue(32));
949     }
950     {
951         auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 10);
952         callInfo->SetFunction(JSTaggedValue::Undefined());
953         callInfo->SetThis(bitVector.GetTaggedValue());
954         callInfo->SetCallArg(0, JSTaggedValue(0));
955         callInfo->SetCallArg(1, JSTaggedValue(0));
956         callInfo->SetCallArg(2, JSTaggedValue(64));
957         [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo);
958         JSTaggedValue result = ContainersBitVector::GetBitCountByRange(callInfo);
959         TestHelper::TearDownFrame(thread, prev);
960         EXPECT_EQ(result, JSTaggedValue(32));
961     }
962 }
963 /**
964    * @tc.number: _BitVector_getIndexOf_Func_001
965    * @tc.name: test_getIndexOf
966    * @tc.desc: Locates the first occurrence of a certain bit value within a range of bits in a bit vector.
967    * @tc.size: MediumTest
968    * @tc.type: Function
969    * @tc.level: Level 0
970    */
HWTEST_F_L0(ContainersBitVectorTest,GetIndexOf_001)971 HWTEST_F_L0(ContainersBitVectorTest, GetIndexOf_001)
972 {
973     JSHandle<JSAPIBitVector> bitVector = CreateJSAPIBitVector();
974     {
975         auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6);
976         callInfo->SetFunction(JSTaggedValue::Undefined());
977         callInfo->SetThis(bitVector.GetTaggedValue());
978         callInfo->SetCallArg(0, JSTaggedValue(1));
979         [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo);
980         JSTaggedValue result = ContainersBitVector::Push(callInfo);
981         TestHelper::TearDownFrame(thread, prev);
982         EXPECT_EQ(result, JSTaggedValue::True());
983         EXPECT_EQ(bitVector->GetLength(), 1);
984     }
985     {
986         auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 10);
987         callInfo->SetFunction(JSTaggedValue::Undefined());
988         callInfo->SetThis(bitVector.GetTaggedValue());
989         callInfo->SetCallArg(0, JSTaggedValue(1));
990         callInfo->SetCallArg(1, JSTaggedValue(0));
991         callInfo->SetCallArg(2, JSTaggedValue(1));
992         [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo);
993         JSTaggedValue result = ContainersBitVector::GetIndexOf(callInfo);
994         TestHelper::TearDownFrame(thread, prev);
995         EXPECT_EQ(result, JSTaggedValue(0));
996     }
997 }
998 /**
999    * @tc.number: _BitVector_getIndexOf_Func_002
1000    * @tc.name: test_getIndexOf
1001    * @tc.desc: Locates the first occurrence of a certain bit value within a range of bits in a bit vector.
1002    * @tc.size: MediumTest
1003    * @tc.type: Function
1004    * @tc.level: Level 2
1005    */
HWTEST_F_L0(ContainersBitVectorTest,GetIndexOf_002)1006 HWTEST_F_L0(ContainersBitVectorTest, GetIndexOf_002)
1007 {
1008     JSHandle<JSAPIBitVector> bitVector = CreateJSAPIBitVector();
1009     {
1010         auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6);
1011         callInfo->SetFunction(JSTaggedValue::Undefined());
1012         callInfo->SetThis(bitVector.GetTaggedValue());
1013         callInfo->SetCallArg(0, JSTaggedValue(1));
1014         [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo);
1015         JSTaggedValue result = ContainersBitVector::Push(callInfo);
1016         TestHelper::TearDownFrame(thread, prev);
1017         EXPECT_EQ(result, JSTaggedValue::True());
1018         EXPECT_EQ(bitVector->GetLength(), 1);
1019     }
1020     {
1021         auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 10);
1022         callInfo->SetFunction(JSTaggedValue::Undefined());
1023         callInfo->SetThis(bitVector.GetTaggedValue());
1024         callInfo->SetCallArg(0, JSTaggedValue(1));
1025         callInfo->SetCallArg(1, JSTaggedValue(1.1));
1026         callInfo->SetCallArg(2, JSTaggedValue(1));
1027         [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo);
1028         JSTaggedValue result = ContainersBitVector::GetIndexOf(callInfo);
1029         TestHelper::TearDownFrame(thread, prev);
1030         EXPECT_TRUE(thread->HasPendingException());
1031         EXPECT_EQ(result, JSTaggedValue::Exception());
1032         thread->ClearException();
1033     }
1034 }
1035 /**
1036    * @tc.number: _BitVector_getIndexOf_Func_003
1037    * @tc.name: test_getIndexOf
1038    * @tc.desc: Locates the first occurrence of a certain bit value within a range of bits in a bit vector.
1039    * @tc.size: MediumTest
1040    * @tc.type: Function
1041    * @tc.level: Level 1
1042    */
HWTEST_F_L0(ContainersBitVectorTest,GetIndexOf_003)1043 HWTEST_F_L0(ContainersBitVectorTest, GetIndexOf_003)
1044 {
1045     constexpr uint32_t NODE_NUMBERS = 64;
1046     JSHandle<JSAPIBitVector> bitVector = CreateJSAPIBitVector();
1047     for (uint32_t i = 0; i < NODE_NUMBERS; i++) {
1048         if (i >= 32) {
1049             auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6);
1050             callInfo->SetFunction(JSTaggedValue::Undefined());
1051             callInfo->SetThis(bitVector.GetTaggedValue());
1052             callInfo->SetCallArg(0, JSTaggedValue(1));
1053             [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo);
1054             ContainersBitVector::Push(callInfo);
1055             TestHelper::TearDownFrame(thread, prev);
1056         } else {
1057             auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6);
1058             callInfo->SetFunction(JSTaggedValue::Undefined());
1059             callInfo->SetThis(bitVector.GetTaggedValue());
1060             callInfo->SetCallArg(0, JSTaggedValue(0));
1061             [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo);
1062             ContainersBitVector::Push(callInfo);
1063             TestHelper::TearDownFrame(thread, prev);
1064         }
1065     }
1066     {
1067         auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 10);
1068         callInfo->SetFunction(JSTaggedValue::Undefined());
1069         callInfo->SetThis(bitVector.GetTaggedValue());
1070         callInfo->SetCallArg(0, JSTaggedValue(1));
1071         callInfo->SetCallArg(1, JSTaggedValue(0));
1072         callInfo->SetCallArg(2, JSTaggedValue(64));
1073         [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo);
1074         JSTaggedValue result = ContainersBitVector::GetIndexOf(callInfo);
1075         TestHelper::TearDownFrame(thread, prev);
1076         EXPECT_EQ(result, JSTaggedValue(32));
1077     }
1078     {
1079         auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 10);
1080         callInfo->SetFunction(JSTaggedValue::Undefined());
1081         callInfo->SetThis(bitVector.GetTaggedValue());
1082         callInfo->SetCallArg(0, JSTaggedValue(0));
1083         callInfo->SetCallArg(1, JSTaggedValue(0));
1084         callInfo->SetCallArg(2, JSTaggedValue(64));
1085         [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo);
1086         JSTaggedValue result = ContainersBitVector::GetIndexOf(callInfo);
1087         TestHelper::TearDownFrame(thread, prev);
1088         EXPECT_EQ(result, JSTaggedValue(0));
1089     }
1090 }
1091 /**
1092    * @tc.number: _BitVector_getLastIndexOf_Func_001
1093    * @tc.name: test_getLastIndexOf
1094    * @tc.desc: Locates the last occurrence of a certain bit value within a range of bits in a bit vector.
1095    * @tc.size: MediumTest
1096    * @tc.type: Function
1097    * @tc.level: Level 0
1098    */
HWTEST_F_L0(ContainersBitVectorTest,GetLastIndexOf_001)1099 HWTEST_F_L0(ContainersBitVectorTest, GetLastIndexOf_001)
1100 {
1101     JSHandle<JSAPIBitVector> bitVector = CreateJSAPIBitVector();
1102     {
1103         auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6);
1104         callInfo->SetFunction(JSTaggedValue::Undefined());
1105         callInfo->SetThis(bitVector.GetTaggedValue());
1106         callInfo->SetCallArg(0, JSTaggedValue(1));
1107         [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo);
1108         JSTaggedValue result = ContainersBitVector::Push(callInfo);
1109         TestHelper::TearDownFrame(thread, prev);
1110         EXPECT_EQ(result, JSTaggedValue::True());
1111         EXPECT_EQ(bitVector->GetLength(), 1);
1112     }
1113     {
1114         auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 10);
1115         callInfo->SetFunction(JSTaggedValue::Undefined());
1116         callInfo->SetThis(bitVector.GetTaggedValue());
1117         callInfo->SetCallArg(0, JSTaggedValue(1));
1118         callInfo->SetCallArg(1, JSTaggedValue(0));
1119         callInfo->SetCallArg(2, JSTaggedValue(1));
1120         [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo);
1121         JSTaggedValue result = ContainersBitVector::GetLastIndexOf(callInfo);
1122         TestHelper::TearDownFrame(thread, prev);
1123         EXPECT_EQ(result, JSTaggedValue(0));
1124     }
1125 }
1126 /**
1127    * @tc.number: _BitVector_getLastIndexOf_Func_002
1128    * @tc.name: test_getLastIndexOf
1129    * @tc.desc: Locates the last occurrence of a certain bit value within a range of bits in a bit vector.
1130    * @tc.size: MediumTest
1131    * @tc.type: Function
1132    * @tc.level: Level 2
1133    */
HWTEST_F_L0(ContainersBitVectorTest,GetLastIndexOf_002)1134 HWTEST_F_L0(ContainersBitVectorTest, GetLastIndexOf_002)
1135 {
1136     JSHandle<JSAPIBitVector> bitVector = CreateJSAPIBitVector();
1137     {
1138         auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6);
1139         callInfo->SetFunction(JSTaggedValue::Undefined());
1140         callInfo->SetThis(bitVector.GetTaggedValue());
1141         callInfo->SetCallArg(0, JSTaggedValue(1));
1142         [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo);
1143         JSTaggedValue result = ContainersBitVector::Push(callInfo);
1144         TestHelper::TearDownFrame(thread, prev);
1145         EXPECT_EQ(result, JSTaggedValue::True());
1146         EXPECT_EQ(bitVector->GetLength(), 1);
1147     }
1148     {
1149         auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 10);
1150         callInfo->SetFunction(JSTaggedValue::Undefined());
1151         callInfo->SetThis(bitVector.GetTaggedValue());
1152         callInfo->SetCallArg(0, JSTaggedValue(1));
1153         callInfo->SetCallArg(1, JSTaggedValue(1.1));
1154         callInfo->SetCallArg(2, JSTaggedValue(1));
1155         [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo);
1156         JSTaggedValue result = ContainersBitVector::GetLastIndexOf(callInfo);
1157         TestHelper::TearDownFrame(thread, prev);
1158         EXPECT_TRUE(thread->HasPendingException());
1159         EXPECT_EQ(result, JSTaggedValue::Exception());
1160         thread->ClearException();
1161     }
1162 }
1163 /**
1164    * @tc.number: _BitVector_getLastIndexOf_Func_003
1165    * @tc.name: test_getLastIndexOf
1166    * @tc.desc: Locates the last occurrence of a certain bit value within a range of bits in a bit vector.
1167    * @tc.size: MediumTest
1168    * @tc.type: Function
1169    * @tc.level: Level 1
1170    */
HWTEST_F_L0(ContainersBitVectorTest,GetLastIndexOf_003)1171 HWTEST_F_L0(ContainersBitVectorTest, GetLastIndexOf_003)
1172 {
1173     constexpr uint32_t NODE_NUMBERS = 64;
1174     JSHandle<JSAPIBitVector> bitVector = CreateJSAPIBitVector();
1175     for (uint32_t i = 0; i < NODE_NUMBERS; i++) {
1176         if (i >= 32) {
1177             auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6);
1178             callInfo->SetFunction(JSTaggedValue::Undefined());
1179             callInfo->SetThis(bitVector.GetTaggedValue());
1180             callInfo->SetCallArg(0, JSTaggedValue(1));
1181             [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo);
1182             ContainersBitVector::Push(callInfo);
1183             TestHelper::TearDownFrame(thread, prev);
1184         } else {
1185             auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6);
1186             callInfo->SetFunction(JSTaggedValue::Undefined());
1187             callInfo->SetThis(bitVector.GetTaggedValue());
1188             callInfo->SetCallArg(0, JSTaggedValue(0));
1189             [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo);
1190             ContainersBitVector::Push(callInfo);
1191             TestHelper::TearDownFrame(thread, prev);
1192         }
1193     }
1194     {
1195         auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 10);
1196         callInfo->SetFunction(JSTaggedValue::Undefined());
1197         callInfo->SetThis(bitVector.GetTaggedValue());
1198         callInfo->SetCallArg(0, JSTaggedValue(1));
1199         callInfo->SetCallArg(1, JSTaggedValue(0));
1200         callInfo->SetCallArg(2, JSTaggedValue(64));
1201         [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo);
1202         JSTaggedValue result = ContainersBitVector::GetLastIndexOf(callInfo);
1203         TestHelper::TearDownFrame(thread, prev);
1204         EXPECT_EQ(result, JSTaggedValue(63));
1205     }
1206     {
1207         auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 10);
1208         callInfo->SetFunction(JSTaggedValue::Undefined());
1209         callInfo->SetThis(bitVector.GetTaggedValue());
1210         callInfo->SetCallArg(0, JSTaggedValue(0));
1211         callInfo->SetCallArg(1, JSTaggedValue(0));
1212         callInfo->SetCallArg(2, JSTaggedValue(64));
1213         [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo);
1214         JSTaggedValue result = ContainersBitVector::GetLastIndexOf(callInfo);
1215         TestHelper::TearDownFrame(thread, prev);
1216         EXPECT_EQ(result, JSTaggedValue(31));
1217     }
1218 }
1219 /**
1220    * @tc.number: _BitVector_flipBitByIndex_Func_001
1221    * @tc.name: test_flipBitByIndex
1222    * @tc.desc: Flips the bit value by index in a bit vector.(Flip 0 to 1, flip 1 to 0).
1223    * @tc.size: MediumTest
1224    * @tc.type: Function
1225    * @tc.level: Level 0
1226    */
HWTEST_F_L0(ContainersBitVectorTest,FlipBitByIndex_001)1227 HWTEST_F_L0(ContainersBitVectorTest, FlipBitByIndex_001)
1228 {
1229     JSHandle<JSAPIBitVector> bitVector = CreateJSAPIBitVector();
1230     {
1231         auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6);
1232         callInfo->SetFunction(JSTaggedValue::Undefined());
1233         callInfo->SetThis(bitVector.GetTaggedValue());
1234         callInfo->SetCallArg(0, JSTaggedValue(1));
1235         [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo);
1236         JSTaggedValue result = ContainersBitVector::Push(callInfo);
1237         TestHelper::TearDownFrame(thread, prev);
1238         EXPECT_EQ(result, JSTaggedValue::True());
1239         EXPECT_EQ(bitVector->GetLength(), 1);
1240     }
1241     {
1242         auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6);
1243         callInfo->SetFunction(JSTaggedValue::Undefined());
1244         callInfo->SetThis(bitVector.GetTaggedValue());
1245         callInfo->SetCallArg(0, JSTaggedValue(0));
1246         [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo);
1247         ContainersBitVector::FlipBitByIndex(callInfo);
1248         TestHelper::TearDownFrame(thread, prev);
1249     }
1250     {
1251         auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6);
1252         callInfo->SetFunction(JSTaggedValue::Undefined());
1253         callInfo->SetThis(bitVector.GetTaggedValue());
1254         [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo);
1255         JSTaggedValue result = ContainersBitVector::Pop(callInfo);
1256         TestHelper::TearDownFrame(thread, prev);
1257         EXPECT_EQ(result, JSTaggedValue(0));
1258     }
1259 }
1260 /**
1261    * @tc.number: _BitVector_flipBitByIndex_Func_002
1262    * @tc.name: test_flipBitByIndex
1263    * @tc.desc: Flips the bit value by index in a bit vector.(Flip 0 to 1, flip 1 to 0).
1264    * @tc.size: MediumTest
1265    * @tc.type: Function
1266    * @tc.level: Level 2
1267    */
HWTEST_F_L0(ContainersBitVectorTest,FlipBitByIndex_2)1268 HWTEST_F_L0(ContainersBitVectorTest, FlipBitByIndex_2)
1269 {
1270     JSHandle<JSAPIBitVector> bitVector = CreateJSAPIBitVector();
1271     {
1272         auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6);
1273         callInfo->SetFunction(JSTaggedValue::Undefined());
1274         callInfo->SetThis(bitVector.GetTaggedValue());
1275         callInfo->SetCallArg(0, JSTaggedValue(1)); //input 1
1276 
1277         [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo);
1278         JSTaggedValue result = ContainersBitVector::Push(callInfo);
1279         TestHelper::TearDownFrame(thread, prev);
1280         EXPECT_EQ(result, JSTaggedValue::True());
1281         EXPECT_EQ(bitVector->GetLength(), 1);
1282     }
1283     {
1284         auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6);
1285         callInfo->SetFunction(JSTaggedValue::Undefined());
1286         callInfo->SetThis(bitVector.GetTaggedValue());
1287         callInfo->SetCallArg(0, JSTaggedValue(1.1));
1288         [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo);
1289         JSTaggedValue result = ContainersBitVector::FlipBitByIndex(callInfo);
1290         TestHelper::TearDownFrame(thread, prev);
1291         EXPECT_TRUE(thread->HasPendingException());
1292         EXPECT_EQ(result, JSTaggedValue::Exception());
1293         thread->ClearException();
1294     }
1295 }
1296 /**
1297    * @tc.number: _BitVector_flipBitByIndex_Func_003
1298    * @tc.name: test_flipBitByIndex
1299    * @tc.desc: Flips the bit value by index in a bit vector.(Flip 0 to 1, flip 1 to 0).
1300    * @tc.size: MediumTest
1301    * @tc.type: Function
1302    * @tc.level: Level 1
1303    */
HWTEST_F_L0(ContainersBitVectorTest,FlipBitByIndex_003)1304 HWTEST_F_L0(ContainersBitVectorTest, FlipBitByIndex_003)
1305 {
1306     JSHandle<JSAPIBitVector> bitVector = CreateJSAPIBitVector();
1307     Push(bitVector);
1308     constexpr uint32_t NODE_NUMBERS = 64;
1309     for (uint32_t i = 0; i < NODE_NUMBERS; i++) {
1310         auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6);
1311         callInfo->SetFunction(JSTaggedValue::Undefined());
1312         callInfo->SetThis(bitVector.GetTaggedValue());
1313         callInfo->SetCallArg(0, JSTaggedValue(i));
1314         [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo);
1315         ContainersBitVector::FlipBitByIndex(callInfo);
1316         TestHelper::TearDownFrame(thread, prev);
1317     }
1318     for (uint32_t i = 0; i < NODE_NUMBERS; i++) {
1319         if (i >= 32) {
1320             auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6);
1321             callInfo->SetFunction(JSTaggedValue::Undefined());
1322             callInfo->SetThis(bitVector.GetTaggedValue());
1323             [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo);
1324             JSTaggedValue result0 = ContainersBitVector::Pop(callInfo);
1325             TestHelper::TearDownFrame(thread, prev);
1326             EXPECT_EQ(result0, JSTaggedValue(1));
1327         } else {
1328             auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6);
1329             callInfo->SetFunction(JSTaggedValue::Undefined());
1330             callInfo->SetThis(bitVector.GetTaggedValue());
1331             [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo);
1332             JSTaggedValue result1 = ContainersBitVector::Pop(callInfo);
1333             TestHelper::TearDownFrame(thread, prev);
1334             EXPECT_EQ(result1, JSTaggedValue(0));
1335         }
1336     }
1337 }
1338 /**
1339    * @tc.number: _BitVector_flipBitsByRange_Func_001
1340    * @tc.name: test_flipBitsByRange
1341    * @tc.desc: Flips a range of bit values in a bit vector.(Flip 0 to 1, flip 1 to 0).
1342    * @tc.size: MediumTest
1343    * @tc.type: Function
1344    * @tc.level: Level 0
1345    */
HWTEST_F_L0(ContainersBitVectorTest,FlipBitsByRange_001)1346 HWTEST_F_L0(ContainersBitVectorTest, FlipBitsByRange_001)
1347 {
1348     JSHandle<JSAPIBitVector> bitVector = CreateJSAPIBitVector();
1349     {
1350         auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6);
1351         callInfo->SetFunction(JSTaggedValue::Undefined());
1352         callInfo->SetThis(bitVector.GetTaggedValue());
1353         callInfo->SetCallArg(0, JSTaggedValue(1));
1354         [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo);
1355         JSTaggedValue result = ContainersBitVector::Push(callInfo);
1356         TestHelper::TearDownFrame(thread, prev);
1357         EXPECT_EQ(result, JSTaggedValue::True());
1358         EXPECT_EQ(bitVector->GetLength(), 1);
1359     }
1360     {
1361         auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 10);
1362         callInfo->SetFunction(JSTaggedValue::Undefined());
1363         callInfo->SetThis(bitVector.GetTaggedValue());
1364         callInfo->SetCallArg(0, JSTaggedValue(0));
1365         callInfo->SetCallArg(1, JSTaggedValue(1));
1366         [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo);
1367         ContainersBitVector::FlipBitsByRange(callInfo);
1368         TestHelper::TearDownFrame(thread, prev);
1369     }
1370     {
1371         auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6);
1372         callInfo->SetFunction(JSTaggedValue::Undefined());
1373         callInfo->SetThis(bitVector.GetTaggedValue());
1374         [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo);
1375         JSTaggedValue result = ContainersBitVector::Pop(callInfo);
1376         TestHelper::TearDownFrame(thread, prev);
1377         EXPECT_EQ(result, JSTaggedValue(0));
1378     }
1379 }
1380 /**
1381    * @tc.number: _BitVector_flipBitsByRange_Func_002
1382    * @tc.name: test_flipBitsByRange
1383    * @tc.desc: Flips a range of bit values in a bit vector.(Flip 0 to 1, flip 1 to 0).
1384    * @tc.size: MediumTest
1385    * @tc.type: Function
1386    * @tc.level: Level 2
1387    */
HWTEST_F_L0(ContainersBitVectorTest,FlipBitsByRange_002)1388 HWTEST_F_L0(ContainersBitVectorTest, FlipBitsByRange_002)
1389 {
1390     JSHandle<JSAPIBitVector> bitVector = CreateJSAPIBitVector();
1391     {
1392         auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6);
1393         callInfo->SetFunction(JSTaggedValue::Undefined());
1394         callInfo->SetThis(bitVector.GetTaggedValue());
1395         callInfo->SetCallArg(0, JSTaggedValue(1));
1396         [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo);
1397         JSTaggedValue result = ContainersBitVector::Push(callInfo);
1398         TestHelper::TearDownFrame(thread, prev);
1399         EXPECT_EQ(result, JSTaggedValue::True());
1400         EXPECT_EQ(bitVector->GetLength(), 1);
1401     }
1402     {
1403         auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 10);
1404         callInfo->SetFunction(JSTaggedValue::Undefined());
1405         callInfo->SetThis(bitVector.GetTaggedValue());
1406         callInfo->SetCallArg(0, JSTaggedValue(1.1));
1407         callInfo->SetCallArg(1, JSTaggedValue(1));
1408         [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo);
1409         JSTaggedValue result = ContainersBitVector::FlipBitsByRange(callInfo);
1410         TestHelper::TearDownFrame(thread, prev);
1411         EXPECT_TRUE(thread->HasPendingException());
1412         EXPECT_EQ(result, JSTaggedValue::Exception());
1413         thread->ClearException();
1414     }
1415 }
1416 /**
1417    * @tc.number: _BitVector_flipBitsByRange_Func_003
1418    * @tc.name: test_flipBitsByRange
1419    * @tc.desc: Flips a range of bit values in a bit vector.(Flip 0 to 1, flip 1 to 0).
1420    * @tc.size: MediumTest
1421    * @tc.type: Function
1422    * @tc.level: Level 1
1423    */
HWTEST_F_L0(ContainersBitVectorTest,FlipBitsByRange_003)1424 HWTEST_F_L0(ContainersBitVectorTest, FlipBitsByRange_003)
1425 {
1426     JSHandle<JSAPIBitVector> bitVector = CreateJSAPIBitVector();
1427     Push(bitVector);
1428     {
1429         auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 10);
1430         callInfo->SetFunction(JSTaggedValue::Undefined());
1431         callInfo->SetThis(bitVector.GetTaggedValue());
1432         callInfo->SetCallArg(0, JSTaggedValue(0));
1433         callInfo->SetCallArg(1, JSTaggedValue(32));
1434         [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo);
1435         ContainersBitVector::FlipBitsByRange(callInfo);
1436         TestHelper::TearDownFrame(thread, prev);
1437     }
1438     {
1439         auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 10);
1440         callInfo->SetFunction(JSTaggedValue::Undefined());
1441         callInfo->SetThis(bitVector.GetTaggedValue());
1442         callInfo->SetCallArg(0, JSTaggedValue(32));
1443         callInfo->SetCallArg(1, JSTaggedValue(64));
1444         [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo);
1445         ContainersBitVector::FlipBitsByRange(callInfo);
1446         TestHelper::TearDownFrame(thread, prev);
1447     }
1448     constexpr uint32_t NODE_NUMBERS = 64;
1449     for (uint32_t i = 0; i < NODE_NUMBERS; i++) {
1450         if (i >= 32) {
1451             auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6);
1452             callInfo->SetFunction(JSTaggedValue::Undefined());
1453             callInfo->SetThis(bitVector.GetTaggedValue());
1454             [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo);
1455             JSTaggedValue result0 = ContainersBitVector::Pop(callInfo);
1456             TestHelper::TearDownFrame(thread, prev);
1457             EXPECT_EQ(result0, JSTaggedValue(1));
1458         } else {
1459             auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6);
1460             callInfo->SetFunction(JSTaggedValue::Undefined());
1461             callInfo->SetThis(bitVector.GetTaggedValue());
1462             [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo);
1463             JSTaggedValue result1 = ContainersBitVector::Pop(callInfo);
1464             TestHelper::TearDownFrame(thread, prev);
1465             EXPECT_EQ(result1, JSTaggedValue(0));
1466         }
1467     }
1468 }
1469 /**
1470    * @tc.number: _BitVector_GetIteratorObj_Func_001
1471    * @tc.name: test_GetIteratorObj
1472    * @tc.desc: Returns an iterator.Each item of the iterator is a Javascript Object.
1473    * @tc.size: MediumTest
1474    * @tc.type: Function
1475    * @tc.level: Level 0
1476    */
HWTEST_F_L0(ContainersBitVectorTest,GetIteratorObj)1477 HWTEST_F_L0(ContainersBitVectorTest, GetIteratorObj)
1478 {
1479     constexpr uint32_t NODE_NUMBERS = 8;
1480     JSHandle<JSAPIBitVector> bitVector = CreateJSAPIBitVector();
1481     for (uint32_t i = 0; i < NODE_NUMBERS; i++) {
1482         auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6);
1483         callInfo->SetFunction(JSTaggedValue::Undefined());
1484         callInfo->SetThis(bitVector.GetTaggedValue());
1485         callInfo->SetCallArg(0, JSTaggedValue(1));
1486         [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo);
1487         JSTaggedValue result = ContainersBitVector::Push(callInfo);
1488         TestHelper::TearDownFrame(thread, prev);
1489         EXPECT_EQ(result, JSTaggedValue::True());
1490         EXPECT_EQ(bitVector->GetSize(), static_cast<int>(i + 1));
1491     }
1492     auto callInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 4);
1493     callInfo1->SetFunction(JSTaggedValue::Undefined());
1494     callInfo1->SetThis(bitVector.GetTaggedValue());
1495     [[maybe_unused]] auto prev1 = TestHelper::SetupFrame(thread, callInfo1);
1496     JSHandle<JSTaggedValue> iterValues(thread, ContainersBitVector::GetIteratorObj(callInfo1));
1497     TestHelper::TearDownFrame(thread, prev1);
1498     JSMutableHandle<JSTaggedValue> result(thread, JSTaggedValue::Undefined());
1499     for (uint32_t i = 0; i < NODE_NUMBERS; i++) {
1500         auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 4);
1501         callInfo->SetFunction(JSTaggedValue::Undefined());
1502         callInfo->SetThis(iterValues.GetTaggedValue());
1503         [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo);
1504         result.Update(JSAPIBitVectorIterator::Next(callInfo));
1505         TestHelper::TearDownFrame(thread, prev);
1506         EXPECT_EQ(static_cast<int>(1), JSIterator::IteratorValue(thread, result)->GetInt());
1507     }
1508 }
1509 };
1510