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
26using namespace panda;
27using namespace panda::ecmascript;
28
29namespace panda::test {
30class JSAPIBitVectorTest : public testing::Test {
31public:
32    static void SetUpTestCase()
33    {
34        GTEST_LOG_(INFO) << "SetUpTestCase";
35    }
36
37    static void TearDownTestCase()
38    {
39        GTEST_LOG_(INFO) << "TearDownCase";
40    }
41
42    void SetUp() override
43    {
44        TestHelper::CreateEcmaVMWithScope(instance, thread, scope);
45    }
46
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:
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        }
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    };
73protected:
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        JSHandle<JSNativePointer> pointer = factory->NewJSNativePointer(newBitSetVector);
99        bitVector->SetNativePointer(thread, pointer);
100        return *bitVector;
101    }
102};
103
104HWTEST_F_L0(JSAPIBitVectorTest, CreateBitVector)
105{
106    JSAPIBitVector *bitVector = CreateBitVector();
107    EXPECT_TRUE(bitVector != nullptr);
108}
109
110/**
111 * @tc.name: Push
112 * @tc.desc:
113 * @tc.type: FUNC
114 * @tc.require:
115 */
116HWTEST_F_L0(JSAPIBitVectorTest, Push)
117{
118    uint32_t increasedLength = 5;
119    JSHandle<JSAPIBitVector> bitVector(thread, CreateBitVector());
120    for (uint32_t i = 0; i < increasedLength; i++) {
121        JSHandle<JSTaggedValue> value(thread, JSTaggedValue(1));
122        JSAPIBitVector::Push(thread, bitVector, value);
123    }
124    JSHandle<JSNativePointer> np(thread, bitVector->GetNativePointer());
125    auto elements =
126        reinterpret_cast<std::vector<std::bitset<JSAPIBitVector::BIT_SET_LENGTH>> *>(np->GetExternalPointer());
127    for (uint32_t i = 0; i < increasedLength; i++) {
128        EXPECT_EQ(TestClass::GetBit(elements, i), JSTaggedValue(1));
129    }
130}
131
132/**
133 * @tc.name: Pop
134 * @tc.desc:
135 * @tc.type: FUNC
136 * @tc.require:
137 */
138HWTEST_F_L0(JSAPIBitVectorTest, Pop)
139{
140    uint32_t increasedLength = 5;
141    JSHandle<JSAPIBitVector> bitVector(thread, CreateBitVector());
142    for (uint32_t i = 0; i < increasedLength; i++) {
143        JSHandle<JSTaggedValue> value(thread, JSTaggedValue(1));
144        JSAPIBitVector::Push(thread, bitVector, value);
145    }
146    for (uint32_t i = 0; i < increasedLength; i++) {
147        JSTaggedValue res = JSAPIBitVector::Pop(thread, bitVector);
148        EXPECT_EQ(res, JSTaggedValue(1));
149    }
150}
151
152/**
153 * @tc.name: Set
154 * @tc.desc:
155 * @tc.type: FUNC
156 * @tc.require:
157 */
158HWTEST_F_L0(JSAPIBitVectorTest, Set)
159{
160    uint32_t increasedLength = 5;
161    uint32_t index = 3;
162
163    JSHandle<JSAPIBitVector> bitVector(thread, CreateBitVector());
164    for (uint32_t i = 0; i < increasedLength; i++) {
165        JSHandle<JSTaggedValue> value(thread, JSTaggedValue(0));
166        JSAPIBitVector::Push(thread, bitVector, value);
167    }
168    JSHandle<JSNativePointer> np(thread, bitVector->GetNativePointer());
169    auto elements =
170        reinterpret_cast<std::vector<std::bitset<JSAPIBitVector::BIT_SET_LENGTH>> *>(np->GetExternalPointer());
171    JSTaggedValue res = bitVector->Set(thread, index, JSTaggedValue(1));
172    EXPECT_EQ(res, JSTaggedValue::Undefined());
173    EXPECT_EQ(TestClass::GetBit(elements, index), JSTaggedValue(1));
174}
175
176/**
177 * @tc.name: Get
178 * @tc.desc:
179 * @tc.type: FUNC
180 * @tc.require:
181 */
182HWTEST_F_L0(JSAPIBitVectorTest, Get)
183{
184    uint32_t increasedLength = 5;
185    JSHandle<JSAPIBitVector> bitVector(thread, CreateBitVector());
186    for (uint32_t i = 0; i < increasedLength; i++) {
187        JSHandle<JSTaggedValue> value(thread, JSTaggedValue(1));
188        JSAPIBitVector::Push(thread, bitVector, value);
189    }
190    for (uint32_t i = 0; i < increasedLength; i++) {
191        JSTaggedValue res = bitVector->Get(thread, i);
192        EXPECT_EQ(res, JSTaggedValue(1));
193    }
194}
195
196/**
197 * @tc.name: Has
198 * @tc.desc:
199 * @tc.type: FUNC
200 * @tc.require:
201 */
202HWTEST_F_L0(JSAPIBitVectorTest, Has)
203{
204    uint32_t increasedLength = 5;
205    JSHandle<JSAPIBitVector> bitVector(thread, CreateBitVector());
206    for (uint32_t i = 0; i < increasedLength; i++) {
207        JSHandle<JSTaggedValue> value(thread, JSTaggedValue(1));
208        JSAPIBitVector::Push(thread, bitVector, value);
209    }
210    JSHandle<JSTaggedValue> value(thread, JSTaggedValue(1));
211    JSHandle<JSTaggedValue> value1(thread, JSTaggedValue(0));
212    JSHandle<JSTaggedValue> value2(thread, JSTaggedValue(5));
213    bool res = JSAPIBitVector::Has(thread, bitVector, value, value1, value2);
214    EXPECT_TRUE(res);
215}
216
217/**
218 * @tc.name: Has_instance
219 * @tc.desc:
220 * @tc.type: FUNC
221 * @tc.require:
222 */
223HWTEST_F_L0(JSAPIBitVectorTest, Has_instance)
224{
225    uint32_t increasedLength = 5;
226    JSHandle<JSAPIBitVector> bitVector(thread, CreateBitVector());
227    for (uint32_t i = 0; i < increasedLength; i++) {
228        JSHandle<JSTaggedValue> value(thread, JSTaggedValue(1));
229        JSAPIBitVector::Push(thread, bitVector, value);
230    }
231    bool res = bitVector->Has(JSTaggedValue(1));
232    EXPECT_TRUE(res);
233}
234
235/**
236 * @tc.name: SetBitsByRange
237 * @tc.desc:
238 * @tc.type: FUNC
239 * @tc.require:
240 */
241HWTEST_F_L0(JSAPIBitVectorTest, SetBitsByRange)
242{
243    uint32_t increasedLength = 5;
244    uint32_t startIndex = 1;
245    uint32_t endIndex = 4;
246    JSHandle<JSAPIBitVector> bitVector(thread, CreateBitVector());
247    for (uint32_t i = 0; i < increasedLength; i++) {
248        JSHandle<JSTaggedValue> value(thread, JSTaggedValue(0));
249        JSAPIBitVector::Push(thread, bitVector, value);
250    }
251    JSHandle<JSTaggedValue> value(thread, JSTaggedValue(1));
252    JSHandle<JSTaggedValue> value1(thread, JSTaggedValue(startIndex));
253    JSHandle<JSTaggedValue> value2(thread, JSTaggedValue(endIndex));
254    JSTaggedValue res = JSAPIBitVector::SetBitsByRange(thread, bitVector, value, value1, value2);
255    EXPECT_EQ(res, JSTaggedValue::Undefined());
256
257    JSHandle<JSNativePointer> np(thread, bitVector->GetNativePointer());
258    auto elements =
259        reinterpret_cast<std::vector<std::bitset<JSAPIBitVector::BIT_SET_LENGTH>> *>(np->GetExternalPointer());
260    for (uint32_t i = startIndex; i < endIndex; i++) {
261        EXPECT_EQ(TestClass::GetBit(elements, i), JSTaggedValue(1));
262    }
263}
264
265/**
266 * @tc.name: GetBitsByRange
267 * @tc.desc:
268 * @tc.type: FUNC
269 * @tc.require:
270 */
271HWTEST_F_L0(JSAPIBitVectorTest, GetBitsByRange)
272{
273    uint32_t increasedLength = 5;
274    uint32_t startIndex = 1;
275    uint32_t endIndex = 4;
276    JSHandle<JSAPIBitVector> bitVector(thread, CreateBitVector());
277    for (uint32_t i = 0; i < increasedLength; i++) {
278        JSHandle<JSTaggedValue> value(thread, JSTaggedValue(1));
279        JSAPIBitVector::Push(thread, bitVector, value);
280    }
281    JSHandle<JSTaggedValue> value1(thread, JSTaggedValue(startIndex));
282    JSHandle<JSTaggedValue> value2(thread, JSTaggedValue(endIndex));
283    JSTaggedValue res = JSAPIBitVector::GetBitsByRange(thread, bitVector, value1, value2);
284    JSHandle<JSAPIBitVector> getBitVector(thread, res);
285    EXPECT_EQ(getBitVector->GetLength(), endIndex - startIndex);
286    for (uint32_t i = 0; i < endIndex - startIndex; i++) {
287        EXPECT_EQ(getBitVector->Get(thread, i), JSTaggedValue(1));
288    }
289}
290
291/**
292 * @tc.name: SetAllBits
293 * @tc.desc:
294 * @tc.type: FUNC
295 * @tc.require:
296 */
297HWTEST_F_L0(JSAPIBitVectorTest, SetAllBits)
298{
299    uint32_t increasedLength = 5;
300    JSHandle<JSAPIBitVector> bitVector(thread, CreateBitVector());
301    for (uint32_t i = 0; i < increasedLength; i++) {
302        JSHandle<JSTaggedValue> value(thread, JSTaggedValue(0));
303        JSAPIBitVector::Push(thread, bitVector, value);
304    }
305    JSHandle<JSTaggedValue> value(thread, JSTaggedValue(1));
306    JSTaggedValue res = JSAPIBitVector::SetAllBits(thread, bitVector, value);
307    EXPECT_EQ(res, JSTaggedValue::Undefined());
308    JSHandle<JSNativePointer> np(thread, bitVector->GetNativePointer());
309    auto elements =
310        reinterpret_cast<std::vector<std::bitset<JSAPIBitVector::BIT_SET_LENGTH>> *>(np->GetExternalPointer());
311    for (uint32_t i = 0; i < increasedLength; i++) {
312        EXPECT_EQ(TestClass::GetBit(elements, i), JSTaggedValue(1));
313    }
314}
315
316/**
317 * @tc.name: GetBitCountByRange
318 * @tc.desc:
319 * @tc.type: FUNC
320 * @tc.require:
321 */
322HWTEST_F_L0(JSAPIBitVectorTest, GetBitCountByRange)
323{
324    uint32_t increasedLength = 5;
325    uint32_t startIndex = 1;
326    uint32_t endIndex = 4;
327    JSHandle<JSAPIBitVector> bitVector(thread, CreateBitVector());
328    for (uint32_t i = 0; i < increasedLength; i++) {
329        JSHandle<JSTaggedValue> value(thread, JSTaggedValue(1));
330        JSAPIBitVector::Push(thread, bitVector, value);
331    }
332    JSHandle<JSTaggedValue> value(thread, JSTaggedValue(1));
333    JSHandle<JSTaggedValue> value1(thread, JSTaggedValue(startIndex));
334    JSHandle<JSTaggedValue> value2(thread, JSTaggedValue(endIndex));
335    JSTaggedValue res = JSAPIBitVector::GetBitCountByRange(thread, bitVector, value, value1, value2);
336    EXPECT_EQ(res, JSTaggedValue(3));
337}
338
339/**
340 * @tc.name: GetIndexOf
341 * @tc.desc:
342 * @tc.type: FUNC
343 * @tc.require:
344 */
345HWTEST_F_L0(JSAPIBitVectorTest, GetIndexOf)
346{
347    uint32_t increasedLength = 5;
348    uint32_t startIndex = 1;
349    uint32_t endIndex = 4;
350    JSHandle<JSAPIBitVector> bitVector(thread, CreateBitVector());
351    for (uint32_t i = 0; i < increasedLength; i++) {
352        JSHandle<JSTaggedValue> value(thread, JSTaggedValue(1));
353        JSAPIBitVector::Push(thread, bitVector, value);
354    }
355    JSHandle<JSTaggedValue> value(thread, JSTaggedValue(1));
356    JSHandle<JSTaggedValue> value1(thread, JSTaggedValue(startIndex));
357    JSHandle<JSTaggedValue> value2(thread, JSTaggedValue(endIndex));
358    int res = JSAPIBitVector::GetIndexOf(thread, bitVector, value, value1, value2);
359    EXPECT_EQ(res, startIndex);
360}
361
362/**
363 * @tc.name: GetLastIndexOf
364 * @tc.desc:
365 * @tc.type: FUNC
366 * @tc.require:
367 */
368HWTEST_F_L0(JSAPIBitVectorTest, GetLastIndexOf)
369{
370    uint32_t increasedLength = 5;
371    uint32_t startIndex = 1;
372    uint32_t endIndex = 4;
373    JSHandle<JSAPIBitVector> bitVector(thread, CreateBitVector());
374    for (uint32_t i = 0; i < increasedLength; i++) {
375        JSHandle<JSTaggedValue> value(thread, JSTaggedValue(1));
376        JSAPIBitVector::Push(thread, bitVector, value);
377    }
378    JSHandle<JSTaggedValue> value(thread, JSTaggedValue(1));
379    JSHandle<JSTaggedValue> value1(thread, JSTaggedValue(startIndex));
380    JSHandle<JSTaggedValue> value2(thread, JSTaggedValue(endIndex));
381    int res = JSAPIBitVector::GetLastIndexOf(thread, bitVector, value, value1, value2);
382    EXPECT_EQ(res, endIndex - 1);
383}
384
385/**
386 * @tc.name: FlipBitByIndex
387 * @tc.desc:
388 * @tc.type: FUNC
389 * @tc.require:
390 */
391HWTEST_F_L0(JSAPIBitVectorTest, FlipBitByIndex)
392{
393    uint32_t increasedLength = 5;
394    uint32_t index = 3;
395    JSHandle<JSAPIBitVector> bitVector(thread, CreateBitVector());
396    for (uint32_t i = 0; i < increasedLength; i++) {
397        JSHandle<JSTaggedValue> value(thread, JSTaggedValue(1));
398        JSAPIBitVector::Push(thread, bitVector, value);
399    }
400    JSTaggedValue res = JSAPIBitVector::FlipBitByIndex(thread, bitVector, index);
401
402    JSHandle<JSNativePointer> np(thread, bitVector->GetNativePointer());
403    auto elements =
404        reinterpret_cast<std::vector<std::bitset<JSAPIBitVector::BIT_SET_LENGTH>> *>(np->GetExternalPointer());
405    EXPECT_EQ(res, JSTaggedValue::Undefined());
406    EXPECT_EQ(TestClass::GetBit(elements, index), JSTaggedValue(0));
407}
408
409/**
410 * @tc.name: FlipBitsByRange
411 * @tc.desc:
412 * @tc.type: FUNC
413 * @tc.require:
414 */
415HWTEST_F_L0(JSAPIBitVectorTest, FlipBitsByRange)
416{
417    uint32_t increasedLength = 5;
418    uint32_t startIndex = 1;
419    uint32_t endIndex = 4;
420    JSHandle<JSAPIBitVector> bitVector(thread, CreateBitVector());
421    for (uint32_t i = 0; i < increasedLength; i++) {
422        JSHandle<JSTaggedValue> value(thread, JSTaggedValue(1));
423        JSAPIBitVector::Push(thread, bitVector, value);
424    }
425    JSHandle<JSTaggedValue> value1(thread, JSTaggedValue(startIndex));
426    JSHandle<JSTaggedValue> value2(thread, JSTaggedValue(endIndex));
427    JSTaggedValue res = JSAPIBitVector::FlipBitsByRange(thread, bitVector, value1, value2);
428    EXPECT_EQ(res, JSTaggedValue::Undefined());
429
430    JSHandle<JSNativePointer> np(thread, bitVector->GetNativePointer());
431    auto elements =
432        reinterpret_cast<std::vector<std::bitset<JSAPIBitVector::BIT_SET_LENGTH>> *>(np->GetExternalPointer());
433    for (uint32_t i = startIndex; i < endIndex; i++) {
434        EXPECT_EQ(TestClass::GetBit(elements, i), JSTaggedValue(0));
435    }
436}
437
438/**
439 * @tc.name: Resize
440 * @tc.desc:
441 * @tc.type: FUNC
442 * @tc.require:
443 */
444HWTEST_F_L0(JSAPIBitVectorTest, Resize)
445{
446    uint32_t increasedLength = 5;
447    int newLength = 10;
448    JSHandle<JSAPIBitVector> bitVector(thread, CreateBitVector());
449    for (uint32_t i = 0; i < increasedLength; i++) {
450        JSHandle<JSTaggedValue> value(thread, JSTaggedValue(1));
451        JSAPIBitVector::Push(thread, bitVector, value);
452    }
453
454    JSAPIBitVector::Resize(thread, bitVector, newLength);
455    EXPECT_EQ(bitVector->GetLength(), newLength);
456
457    JSHandle<JSNativePointer> np(thread, bitVector->GetNativePointer());
458    auto elements =
459        reinterpret_cast<std::vector<std::bitset<JSAPIBitVector::BIT_SET_LENGTH>> *>(np->GetExternalPointer());
460    for (uint32_t i = increasedLength; i < newLength; i++) {
461        EXPECT_EQ(TestClass::GetBit(elements, i), JSTaggedValue(0));
462    }
463}
464
465/**
466 * @tc.name: OwnKeys
467 * @tc.desc:
468 * @tc.type: FUNC
469 * @tc.require:
470 */
471HWTEST_F_L0(JSAPIBitVectorTest, OwnKeys)
472{
473    uint32_t increasedLength = 5;
474    JSHandle<JSAPIBitVector> bitVector(thread, CreateBitVector());
475    for (uint32_t i = 0; i < increasedLength; i++) {
476        JSHandle<JSTaggedValue> value(thread, JSTaggedValue(1));
477        JSAPIBitVector::Push(thread, bitVector, value);
478    }
479
480    JSHandle<TaggedArray> keys = JSAPIBitVector::OwnKeys(thread, bitVector);
481    ASSERT_TRUE(EcmaStringAccessor::StringsAreEqual(*(base::NumberHelper::NumberToString(thread, JSTaggedValue(0))),
482        EcmaString::Cast(keys->Get(0).GetTaggedObject())));
483}
484
485/**
486 * @tc.name: GetOwnProperty
487 * @tc.desc:
488 * @tc.type: FUNC
489 * @tc.require:
490 */
491HWTEST_F_L0(JSAPIBitVectorTest, GetOwnProperty)
492{
493    uint32_t increasedLength = 5;
494    JSHandle<JSAPIBitVector> bitVector(thread, CreateBitVector());
495    for (uint32_t i = 0; i < increasedLength; i++) {
496        JSHandle<JSTaggedValue> value(thread, JSTaggedValue(1));
497        JSAPIBitVector::Push(thread, bitVector, value);
498    }
499
500    for (uint32_t i = 0; i < increasedLength; i++) {
501        JSHandle<JSTaggedValue> key(thread, JSTaggedValue(i));
502        bool getOwnPropertyRes = JSAPIBitVector::GetOwnProperty(thread, bitVector, key);
503        EXPECT_EQ(getOwnPropertyRes, true);
504    }
505}
506
507/**
508 * @tc.name: GetIteratorObj
509 * @tc.desc:
510 * @tc.type: FUNC
511 * @tc.require:
512 */
513HWTEST_F_L0(JSAPIBitVectorTest, GetIteratorObj)
514{
515    JSHandle<JSAPIBitVector> bitVector(thread, CreateBitVector());
516    JSHandle<JSTaggedValue> iteratorObj(thread, JSAPIBitVector::GetIteratorObj(thread, bitVector));
517    EXPECT_TRUE(iteratorObj->IsJSAPIBitVectorIterator());
518}
519
520/**
521 * @tc.name: GetProperty
522 * @tc.desc:
523 * @tc.type: FUNC
524 * @tc.require:
525 */
526HWTEST_F_L0(JSAPIBitVectorTest, GetProperty)
527{
528    uint32_t increasedLength = 5;
529    JSHandle<JSAPIBitVector> bitVector(thread, CreateBitVector());
530    for (uint32_t i = 0; i < increasedLength; i++) {
531        JSHandle<JSTaggedValue> value(thread, JSTaggedValue(1));
532        JSAPIBitVector::Push(thread, bitVector, value);
533    }
534
535    for (uint32_t i = 0; i < increasedLength; i++) {
536        JSHandle<JSTaggedValue> key(thread, JSTaggedValue(i));
537        OperationResult getPropertyRes = JSAPIBitVector::GetProperty(thread, bitVector, key);
538        EXPECT_EQ(getPropertyRes.GetValue().GetTaggedValue(), JSTaggedValue(1));
539    }
540}
541
542/**
543 * @tc.name: SetProperty
544 * @tc.desc:
545 * @tc.type: FUNC
546 * @tc.require:
547 */
548HWTEST_F_L0(JSAPIBitVectorTest, SetProperty)
549{
550    uint32_t increasedLength = 5;
551    JSHandle<JSAPIBitVector> bitVector(thread, CreateBitVector());
552    for (uint32_t i = 0; i < increasedLength; i++) {
553        JSHandle<JSTaggedValue> value(thread, JSTaggedValue(0));
554        JSAPIBitVector::Push(thread, bitVector, value);
555    }
556
557    for (uint32_t i = 0; i < increasedLength; i++) {
558        JSHandle<JSTaggedValue> key(thread, JSTaggedValue(i));
559        JSHandle<JSTaggedValue> value(thread, JSTaggedValue(1));
560        bool setPropertyRes = JSAPIBitVector::SetProperty(thread, bitVector, key, value);
561        EXPECT_EQ(setPropertyRes, true);
562    }
563}
564}