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" 28using namespace panda::ecmascript; 29using namespace panda::ecmascript::containers; 30namespace panda::test { 31class ContainersBitVectorTest : public testing::Test { 32public: 33 static void SetUpTestCase() 34 { 35 GTEST_LOG_(INFO) << "SetUpTestCase"; 36 } 37 static void TearDownTestCase() 38 { 39 GTEST_LOG_(INFO) << "TearDownCase"; 40 } 41 void SetUp() override 42 { 43 TestHelper::CreateEcmaVMWithScope(instance, thread, scope); 44 } 45 void TearDown() override 46 { 47 TestHelper::DestroyEcmaVMWithScope(instance, scope); 48 } 49 EcmaVM* instance { nullptr }; 50 EcmaHandleScope* scope { nullptr }; 51 JSThread* thread { nullptr }; 52 53protected: 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 } 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 } 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 } 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 */ 132HWTEST_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(JSHandle<JSObject>::Cast(bitVector)); 148 JSTaggedValue funcProto = newTarget->GetFunctionPrototype(); 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 */ 163HWTEST_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 */ 187HWTEST_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 */ 220HWTEST_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 */ 255HWTEST_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 */ 292HWTEST_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 */ 313HWTEST_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 */ 356HWTEST_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 */ 393HWTEST_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 */ 448HWTEST_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 */ 490HWTEST_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 */ 531HWTEST_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 */ 572HWTEST_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(thread, JSAPIBitVector::Cast(result.GetTaggedObject())->GetNativePointer()); 597 auto elements = 598 reinterpret_cast<std::vector<std::bitset<JSAPIBitVector::BIT_SET_LENGTH>> *>(np->GetExternalPointer()); 599 EXPECT_EQ((*elements)[0].test(0), 1); 600 } 601} 602/** 603 * @tc.number: _BitVector_getBitsByRange_Func_002 604 * @tc.name: test_getBitsByRange 605 * @tc.desc: Returns the bit values in a range of indices in a bit vector. 606 * @tc.size: MediumTest 607 * @tc.type: Function 608 * @tc.level: Level 2 609 */ 610HWTEST_F_L0(ContainersBitVectorTest, GetBitsByRange_002) 611{ 612 JSHandle<JSAPIBitVector> bitVector = CreateJSAPIBitVector(); 613 { 614 auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); 615 callInfo->SetFunction(JSTaggedValue::Undefined()); 616 callInfo->SetThis(bitVector.GetTaggedValue()); 617 callInfo->SetCallArg(0, JSTaggedValue(1)); 618 [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); 619 JSTaggedValue result = ContainersBitVector::Push(callInfo); 620 TestHelper::TearDownFrame(thread, prev); 621 EXPECT_EQ(result, JSTaggedValue::True()); 622 EXPECT_EQ(bitVector->GetLength(), 1); 623 } 624 { 625 auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 8); 626 callInfo->SetFunction(JSTaggedValue::Undefined()); 627 callInfo->SetThis(bitVector.GetTaggedValue()); 628 callInfo->SetCallArg(0, JSTaggedValue(1.1)); 629 callInfo->SetCallArg(1, JSTaggedValue(1.1)); 630 [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); 631 JSTaggedValue result = ContainersBitVector::GetBitsByRange(callInfo); 632 TestHelper::TearDownFrame(thread, prev); 633 EXPECT_TRUE(thread->HasPendingException()); 634 EXPECT_EQ(result, JSTaggedValue::Exception()); 635 thread->ClearException(); 636 } 637} 638/** 639 * @tc.number: _BitVector_getBitsByRange_Func_003 640 * @tc.name: test_getBitsByRange 641 * @tc.desc: Returns the bit values in a range of indices in a bit vector. 642 * @tc.size: MediumTest 643 * @tc.type: Function 644 * @tc.level: Level 1 645 */ 646HWTEST_F_L0(ContainersBitVectorTest, GetBitsByRange_003) 647{ 648 JSHandle<JSAPIBitVector> bitVector = CreateJSAPIBitVector(); 649 Push(bitVector); 650 { 651 auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 8); 652 callInfo->SetFunction(JSTaggedValue::Undefined()); 653 callInfo->SetThis(bitVector.GetTaggedValue()); 654 callInfo->SetCallArg(0, JSTaggedValue(0)); //range 0 to 31 655 callInfo->SetCallArg(1, JSTaggedValue(31)); 656 657 [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); 658 JSTaggedValue result = ContainersBitVector::GetBitsByRange(callInfo); 659 TestHelper::TearDownFrame(thread, prev); 660 661 JSHandle<JSNativePointer> np(thread, JSAPIBitVector::Cast(result.GetTaggedObject())->GetNativePointer()); 662 auto elements = 663 reinterpret_cast<std::vector<std::bitset<JSAPIBitVector::BIT_SET_LENGTH>> *>(np->GetExternalPointer()); 664 EXPECT_EQ((*elements)[0].test(0), 0); 665 } 666 { 667 auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 8); 668 callInfo->SetFunction(JSTaggedValue::Undefined()); 669 callInfo->SetThis(bitVector.GetTaggedValue()); 670 callInfo->SetCallArg(0, JSTaggedValue(32)); 671 callInfo->SetCallArg(1, JSTaggedValue(64)); 672 [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); 673 JSTaggedValue result = ContainersBitVector::GetBitsByRange(callInfo); 674 TestHelper::TearDownFrame(thread, prev); 675 676 JSHandle<JSNativePointer> np(thread, JSAPIBitVector::Cast(result.GetTaggedObject())->GetNativePointer()); 677 auto elements = 678 reinterpret_cast<std::vector<std::bitset<JSAPIBitVector::BIT_SET_LENGTH>> *>(np->GetExternalPointer()); 679 EXPECT_EQ((*elements)[0].test(0), 1); 680 } 681} 682/** 683 * @tc.number: _BitVector_resize_Func_001 684 * @tc.name: test_resize 685 * @tc.desc: Resize the bitVector's length. 686 * @tc.size: MediumTest 687 * @tc.type: Function 688 * @tc.level: Level 0 689 */ 690HWTEST_F_L0(ContainersBitVectorTest, Resize_01) 691{ 692 constexpr uint32_t NODE_NUMBERS = 8; 693 JSHandle<JSAPIBitVector> bitVector = CreateJSAPIBitVector(); 694 for (uint32_t i = 0; i < NODE_NUMBERS; i++) { 695 auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); 696 callInfo->SetFunction(JSTaggedValue::Undefined()); 697 callInfo->SetThis(bitVector.GetTaggedValue()); 698 callInfo->SetCallArg(0, JSTaggedValue(1)); 699 [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); 700 JSTaggedValue result = ContainersBitVector::Push(callInfo); 701 TestHelper::TearDownFrame(thread, prev); 702 EXPECT_EQ(result, JSTaggedValue::True()); 703 EXPECT_EQ(bitVector->GetLength(), i + 1); 704 } 705 for (uint32_t i = 0; i < NODE_NUMBERS; i++) { 706 auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); 707 callInfo->SetFunction(JSTaggedValue::Undefined()); 708 callInfo->SetThis(bitVector.GetTaggedValue()); 709 callInfo->SetCallArg(0, JSTaggedValue(5)); 710 [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); 711 ContainersBitVector::Resize(callInfo); 712 TestHelper::TearDownFrame(thread, prev); 713 } 714 EXPECT_EQ(bitVector->GetLength(), 5); 715} 716/** 717 * @tc.number: _BitVector_resize_Func_002 718 * @tc.name: test_resize 719 * @tc.desc: Resize the bitVector's length. 720 * @tc.size: MediumTest 721 * @tc.type: Function 722 * @tc.level: Level 0 723 */ 724HWTEST_F_L0(ContainersBitVectorTest, Resize_02) 725{ 726 constexpr uint32_t NODE_NUMBERS = 8; 727 JSHandle<JSAPIBitVector> bitVector = CreateJSAPIBitVector(); 728 for (uint32_t i = 0; i < NODE_NUMBERS; i++) { 729 auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); 730 callInfo->SetFunction(JSTaggedValue::Undefined()); 731 callInfo->SetThis(bitVector.GetTaggedValue()); 732 callInfo->SetCallArg(0, JSTaggedValue(1)); 733 [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); 734 JSTaggedValue result = ContainersBitVector::Push(callInfo); 735 TestHelper::TearDownFrame(thread, prev); 736 EXPECT_EQ(result, JSTaggedValue::True()); 737 EXPECT_EQ(bitVector->GetLength(), i + 1); 738 } 739 for (uint32_t i = 0; i < NODE_NUMBERS; i++) { 740 auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); 741 callInfo->SetFunction(JSTaggedValue::Undefined()); 742 callInfo->SetThis(bitVector.GetTaggedValue()); 743 callInfo->SetCallArg(0, JSTaggedValue(8)); 744 [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); 745 ContainersBitVector::Resize(callInfo); 746 TestHelper::TearDownFrame(thread, prev); 747 } 748 EXPECT_EQ(bitVector->GetLength(), 8); 749} 750/** 751 * @tc.number: _BitVector_resize_Func_003 752 * @tc.name: test_resize 753 * @tc.desc: Resize the bitVector's length. 754 * @tc.size: MediumTest 755 * @tc.type: Function 756 * @tc.level: Level 0 757 */ 758HWTEST_F_L0(ContainersBitVectorTest, Resize_03) 759{ 760 constexpr uint32_t NODE_NUMBERS = 8; 761 JSHandle<JSAPIBitVector> bitVector = CreateJSAPIBitVector(); 762 for (uint32_t i = 0; i < NODE_NUMBERS; i++) { 763 auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); 764 callInfo->SetFunction(JSTaggedValue::Undefined()); 765 callInfo->SetThis(bitVector.GetTaggedValue()); 766 callInfo->SetCallArg(0, JSTaggedValue(1)); 767 [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); 768 JSTaggedValue result = ContainersBitVector::Push(callInfo); 769 TestHelper::TearDownFrame(thread, prev); 770 EXPECT_EQ(result, JSTaggedValue::True()); 771 EXPECT_EQ(bitVector->GetLength(), i + 1); 772 } 773 for (uint32_t i = 0; i < NODE_NUMBERS; i++) { 774 auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); 775 callInfo->SetFunction(JSTaggedValue::Undefined()); 776 callInfo->SetThis(bitVector.GetTaggedValue()); 777 callInfo->SetCallArg(0, JSTaggedValue(10)); 778 [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); 779 ContainersBitVector::Resize(callInfo); 780 TestHelper::TearDownFrame(thread, prev); 781 } 782 EXPECT_EQ(bitVector->GetLength(), 10); 783 for (uint32_t i = 0; i < 2; i++) { 784 auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 4); 785 callInfo->SetFunction(JSTaggedValue::Undefined()); 786 callInfo->SetThis(bitVector.GetTaggedValue()); 787 [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); 788 JSTaggedValue result = ContainersBitVector::Pop(callInfo); 789 TestHelper::TearDownFrame(thread, prev); 790 EXPECT_EQ(result, JSTaggedValue(0)); 791 } 792} 793/** 794 * @tc.number: _BitVector_resize_Func_004 795 * @tc.name: test_resize 796 * @tc.desc: Resize the bitVector's length. 797 * @tc.size: MediumTest 798 * @tc.type: Function 799 * @tc.level: Level 2 800 */ 801HWTEST_F_L0(ContainersBitVectorTest, Resize_04) 802{ 803 constexpr uint32_t NODE_NUMBERS = 8; 804 JSHandle<JSAPIBitVector> bitVector = CreateJSAPIBitVector(); 805 for (uint32_t i = 0; i < NODE_NUMBERS; i++) { 806 auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); 807 callInfo->SetFunction(JSTaggedValue::Undefined()); 808 callInfo->SetThis(bitVector.GetTaggedValue()); 809 callInfo->SetCallArg(0, JSTaggedValue(1)); 810 [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); 811 JSTaggedValue result = ContainersBitVector::Push(callInfo); 812 TestHelper::TearDownFrame(thread, prev); 813 EXPECT_EQ(result, JSTaggedValue::True()); 814 EXPECT_EQ(bitVector->GetLength(), i + 1); 815 } 816 for (uint32_t i = 0; i < NODE_NUMBERS; i++) { 817 auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); 818 callInfo->SetFunction(JSTaggedValue::Undefined()); 819 callInfo->SetThis(bitVector.GetTaggedValue()); 820 callInfo->SetCallArg(0, JSTaggedValue(1.1)); 821 [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); 822 JSTaggedValue result = ContainersBitVector::Resize(callInfo); 823 TestHelper::TearDownFrame(thread, prev); 824 EXPECT_TRUE(thread->HasPendingException()); 825 EXPECT_EQ(result, JSTaggedValue::Exception()); 826 thread->ClearException(); 827 } 828} 829/** 830 * @tc.number: _BitVector_getBitCountByRange_Func_001 831 * @tc.name: test_getBitCountByRange 832 * @tc.desc: Counts the number of times a certain bit element occurs within a range of bits in a bit vector. 833 * @tc.size: MediumTest 834 * @tc.type: Function 835 * @tc.level: Level 0 836 */ 837HWTEST_F_L0(ContainersBitVectorTest, GetBitCountByRange_001) 838{ 839 JSHandle<JSAPIBitVector> bitVector = CreateJSAPIBitVector(); 840 { 841 auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); 842 callInfo->SetFunction(JSTaggedValue::Undefined()); 843 callInfo->SetThis(bitVector.GetTaggedValue()); 844 callInfo->SetCallArg(0, JSTaggedValue(1)); 845 [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); 846 JSTaggedValue result = ContainersBitVector::Push(callInfo); 847 TestHelper::TearDownFrame(thread, prev); 848 EXPECT_EQ(result, JSTaggedValue::True()); 849 EXPECT_EQ(bitVector->GetLength(), 1); 850 } 851 { 852 auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 10); 853 callInfo->SetFunction(JSTaggedValue::Undefined()); 854 callInfo->SetThis(bitVector.GetTaggedValue()); 855 callInfo->SetCallArg(0, JSTaggedValue(1)); 856 callInfo->SetCallArg(1, JSTaggedValue(0)); 857 callInfo->SetCallArg(2, JSTaggedValue(1)); 858 [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); 859 JSTaggedValue result = ContainersBitVector::GetBitCountByRange(callInfo); 860 TestHelper::TearDownFrame(thread, prev); 861 EXPECT_EQ(result, JSTaggedValue(1)); 862 } 863} 864/** 865 * @tc.number: _BitVector_getBitCountByRange_Func_002 866 * @tc.name: test_getBitCountByRange 867 * @tc.desc: Counts the number of times a certain bit element occurs within a range of bits in a bit vector. 868 * @tc.size: MediumTest 869 * @tc.type: Function 870 * @tc.level: Level 2 871 */ 872HWTEST_F_L0(ContainersBitVectorTest, GetBitCountByRange_002) 873{ 874 JSHandle<JSAPIBitVector> bitVector = CreateJSAPIBitVector(); 875 { 876 auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); 877 callInfo->SetFunction(JSTaggedValue::Undefined()); 878 callInfo->SetThis(bitVector.GetTaggedValue()); 879 callInfo->SetCallArg(0, JSTaggedValue(1)); 880 [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); 881 JSTaggedValue result = ContainersBitVector::Push(callInfo); 882 TestHelper::TearDownFrame(thread, prev); 883 EXPECT_EQ(result, JSTaggedValue::True()); 884 EXPECT_EQ(bitVector->GetLength(), 1); 885 } 886 { 887 auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 10); 888 callInfo->SetFunction(JSTaggedValue::Undefined()); 889 callInfo->SetThis(bitVector.GetTaggedValue()); 890 callInfo->SetCallArg(0, JSTaggedValue(1)); 891 callInfo->SetCallArg(1, JSTaggedValue(1.1)); 892 callInfo->SetCallArg(2, JSTaggedValue(1)); 893 [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); 894 JSTaggedValue result = ContainersBitVector::GetBitCountByRange(callInfo); 895 TestHelper::TearDownFrame(thread, prev); 896 EXPECT_TRUE(thread->HasPendingException()); 897 EXPECT_EQ(result, JSTaggedValue::Exception()); 898 thread->ClearException(); 899 } 900} 901/** 902 * @tc.number: _BitVector_getBitCountByRange_Func_003 903 * @tc.name: test_getBitCountByRange 904 * @tc.desc: Counts the number of times a certain bit element occurs within a range of bits in a bit vector. 905 * @tc.size: MediumTest 906 * @tc.type: Function 907 * @tc.level: Level 1 908 */ 909HWTEST_F_L0(ContainersBitVectorTest, GetBitCountByRange_003) 910{ 911 constexpr uint32_t NODE_NUMBERS = 64; 912 JSHandle<JSAPIBitVector> bitVector = CreateJSAPIBitVector(); 913 for (uint32_t i = 0; i < NODE_NUMBERS; i++) { 914 if (i >= 32) { 915 auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); 916 callInfo->SetFunction(JSTaggedValue::Undefined()); 917 callInfo->SetThis(bitVector.GetTaggedValue()); 918 callInfo->SetCallArg(0, JSTaggedValue(1)); 919 [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); 920 ContainersBitVector::Push(callInfo); 921 TestHelper::TearDownFrame(thread, prev); 922 } else { 923 auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); 924 callInfo->SetFunction(JSTaggedValue::Undefined()); 925 callInfo->SetThis(bitVector.GetTaggedValue()); 926 callInfo->SetCallArg(0, JSTaggedValue(0)); 927 [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); 928 ContainersBitVector::Push(callInfo); 929 TestHelper::TearDownFrame(thread, prev); 930 } 931 } 932 { 933 auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 10); 934 callInfo->SetFunction(JSTaggedValue::Undefined()); 935 callInfo->SetThis(bitVector.GetTaggedValue()); 936 callInfo->SetCallArg(0, JSTaggedValue(1)); 937 callInfo->SetCallArg(1, JSTaggedValue(0)); 938 callInfo->SetCallArg(2, JSTaggedValue(64)); 939 [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); 940 JSTaggedValue result = ContainersBitVector::GetBitCountByRange(callInfo); 941 TestHelper::TearDownFrame(thread, prev); 942 EXPECT_EQ(result, JSTaggedValue(32)); 943 } 944 { 945 auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 10); 946 callInfo->SetFunction(JSTaggedValue::Undefined()); 947 callInfo->SetThis(bitVector.GetTaggedValue()); 948 callInfo->SetCallArg(0, JSTaggedValue(0)); 949 callInfo->SetCallArg(1, JSTaggedValue(0)); 950 callInfo->SetCallArg(2, JSTaggedValue(64)); 951 [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); 952 JSTaggedValue result = ContainersBitVector::GetBitCountByRange(callInfo); 953 TestHelper::TearDownFrame(thread, prev); 954 EXPECT_EQ(result, JSTaggedValue(32)); 955 } 956} 957/** 958 * @tc.number: _BitVector_getIndexOf_Func_001 959 * @tc.name: test_getIndexOf 960 * @tc.desc: Locates the first occurrence of a certain bit value within a range of bits in a bit vector. 961 * @tc.size: MediumTest 962 * @tc.type: Function 963 * @tc.level: Level 0 964 */ 965HWTEST_F_L0(ContainersBitVectorTest, GetIndexOf_001) 966{ 967 JSHandle<JSAPIBitVector> bitVector = CreateJSAPIBitVector(); 968 { 969 auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); 970 callInfo->SetFunction(JSTaggedValue::Undefined()); 971 callInfo->SetThis(bitVector.GetTaggedValue()); 972 callInfo->SetCallArg(0, JSTaggedValue(1)); 973 [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); 974 JSTaggedValue result = ContainersBitVector::Push(callInfo); 975 TestHelper::TearDownFrame(thread, prev); 976 EXPECT_EQ(result, JSTaggedValue::True()); 977 EXPECT_EQ(bitVector->GetLength(), 1); 978 } 979 { 980 auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 10); 981 callInfo->SetFunction(JSTaggedValue::Undefined()); 982 callInfo->SetThis(bitVector.GetTaggedValue()); 983 callInfo->SetCallArg(0, JSTaggedValue(1)); 984 callInfo->SetCallArg(1, JSTaggedValue(0)); 985 callInfo->SetCallArg(2, JSTaggedValue(1)); 986 [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); 987 JSTaggedValue result = ContainersBitVector::GetIndexOf(callInfo); 988 TestHelper::TearDownFrame(thread, prev); 989 EXPECT_EQ(result, JSTaggedValue(0)); 990 } 991} 992/** 993 * @tc.number: _BitVector_getIndexOf_Func_002 994 * @tc.name: test_getIndexOf 995 * @tc.desc: Locates the first occurrence of a certain bit value within a range of bits in a bit vector. 996 * @tc.size: MediumTest 997 * @tc.type: Function 998 * @tc.level: Level 2 999 */ 1000HWTEST_F_L0(ContainersBitVectorTest, GetIndexOf_002) 1001{ 1002 JSHandle<JSAPIBitVector> bitVector = CreateJSAPIBitVector(); 1003 { 1004 auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); 1005 callInfo->SetFunction(JSTaggedValue::Undefined()); 1006 callInfo->SetThis(bitVector.GetTaggedValue()); 1007 callInfo->SetCallArg(0, JSTaggedValue(1)); 1008 [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); 1009 JSTaggedValue result = ContainersBitVector::Push(callInfo); 1010 TestHelper::TearDownFrame(thread, prev); 1011 EXPECT_EQ(result, JSTaggedValue::True()); 1012 EXPECT_EQ(bitVector->GetLength(), 1); 1013 } 1014 { 1015 auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 10); 1016 callInfo->SetFunction(JSTaggedValue::Undefined()); 1017 callInfo->SetThis(bitVector.GetTaggedValue()); 1018 callInfo->SetCallArg(0, JSTaggedValue(1)); 1019 callInfo->SetCallArg(1, JSTaggedValue(1.1)); 1020 callInfo->SetCallArg(2, JSTaggedValue(1)); 1021 [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); 1022 JSTaggedValue result = ContainersBitVector::GetIndexOf(callInfo); 1023 TestHelper::TearDownFrame(thread, prev); 1024 EXPECT_TRUE(thread->HasPendingException()); 1025 EXPECT_EQ(result, JSTaggedValue::Exception()); 1026 thread->ClearException(); 1027 } 1028} 1029/** 1030 * @tc.number: _BitVector_getIndexOf_Func_003 1031 * @tc.name: test_getIndexOf 1032 * @tc.desc: Locates the first occurrence of a certain bit value within a range of bits in a bit vector. 1033 * @tc.size: MediumTest 1034 * @tc.type: Function 1035 * @tc.level: Level 1 1036 */ 1037HWTEST_F_L0(ContainersBitVectorTest, GetIndexOf_003) 1038{ 1039 constexpr uint32_t NODE_NUMBERS = 64; 1040 JSHandle<JSAPIBitVector> bitVector = CreateJSAPIBitVector(); 1041 for (uint32_t i = 0; i < NODE_NUMBERS; i++) { 1042 if (i >= 32) { 1043 auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); 1044 callInfo->SetFunction(JSTaggedValue::Undefined()); 1045 callInfo->SetThis(bitVector.GetTaggedValue()); 1046 callInfo->SetCallArg(0, JSTaggedValue(1)); 1047 [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); 1048 ContainersBitVector::Push(callInfo); 1049 TestHelper::TearDownFrame(thread, prev); 1050 } else { 1051 auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); 1052 callInfo->SetFunction(JSTaggedValue::Undefined()); 1053 callInfo->SetThis(bitVector.GetTaggedValue()); 1054 callInfo->SetCallArg(0, JSTaggedValue(0)); 1055 [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); 1056 ContainersBitVector::Push(callInfo); 1057 TestHelper::TearDownFrame(thread, prev); 1058 } 1059 } 1060 { 1061 auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 10); 1062 callInfo->SetFunction(JSTaggedValue::Undefined()); 1063 callInfo->SetThis(bitVector.GetTaggedValue()); 1064 callInfo->SetCallArg(0, JSTaggedValue(1)); 1065 callInfo->SetCallArg(1, JSTaggedValue(0)); 1066 callInfo->SetCallArg(2, JSTaggedValue(64)); 1067 [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); 1068 JSTaggedValue result = ContainersBitVector::GetIndexOf(callInfo); 1069 TestHelper::TearDownFrame(thread, prev); 1070 EXPECT_EQ(result, JSTaggedValue(32)); 1071 } 1072 { 1073 auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 10); 1074 callInfo->SetFunction(JSTaggedValue::Undefined()); 1075 callInfo->SetThis(bitVector.GetTaggedValue()); 1076 callInfo->SetCallArg(0, JSTaggedValue(0)); 1077 callInfo->SetCallArg(1, JSTaggedValue(0)); 1078 callInfo->SetCallArg(2, JSTaggedValue(64)); 1079 [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); 1080 JSTaggedValue result = ContainersBitVector::GetIndexOf(callInfo); 1081 TestHelper::TearDownFrame(thread, prev); 1082 EXPECT_EQ(result, JSTaggedValue(0)); 1083 } 1084} 1085/** 1086 * @tc.number: _BitVector_getLastIndexOf_Func_001 1087 * @tc.name: test_getLastIndexOf 1088 * @tc.desc: Locates the last occurrence of a certain bit value within a range of bits in a bit vector. 1089 * @tc.size: MediumTest 1090 * @tc.type: Function 1091 * @tc.level: Level 0 1092 */ 1093HWTEST_F_L0(ContainersBitVectorTest, GetLastIndexOf_001) 1094{ 1095 JSHandle<JSAPIBitVector> bitVector = CreateJSAPIBitVector(); 1096 { 1097 auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); 1098 callInfo->SetFunction(JSTaggedValue::Undefined()); 1099 callInfo->SetThis(bitVector.GetTaggedValue()); 1100 callInfo->SetCallArg(0, JSTaggedValue(1)); 1101 [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); 1102 JSTaggedValue result = ContainersBitVector::Push(callInfo); 1103 TestHelper::TearDownFrame(thread, prev); 1104 EXPECT_EQ(result, JSTaggedValue::True()); 1105 EXPECT_EQ(bitVector->GetLength(), 1); 1106 } 1107 { 1108 auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 10); 1109 callInfo->SetFunction(JSTaggedValue::Undefined()); 1110 callInfo->SetThis(bitVector.GetTaggedValue()); 1111 callInfo->SetCallArg(0, JSTaggedValue(1)); 1112 callInfo->SetCallArg(1, JSTaggedValue(0)); 1113 callInfo->SetCallArg(2, JSTaggedValue(1)); 1114 [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); 1115 JSTaggedValue result = ContainersBitVector::GetLastIndexOf(callInfo); 1116 TestHelper::TearDownFrame(thread, prev); 1117 EXPECT_EQ(result, JSTaggedValue(0)); 1118 } 1119} 1120/** 1121 * @tc.number: _BitVector_getLastIndexOf_Func_002 1122 * @tc.name: test_getLastIndexOf 1123 * @tc.desc: Locates the last occurrence of a certain bit value within a range of bits in a bit vector. 1124 * @tc.size: MediumTest 1125 * @tc.type: Function 1126 * @tc.level: Level 2 1127 */ 1128HWTEST_F_L0(ContainersBitVectorTest, GetLastIndexOf_002) 1129{ 1130 JSHandle<JSAPIBitVector> bitVector = CreateJSAPIBitVector(); 1131 { 1132 auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); 1133 callInfo->SetFunction(JSTaggedValue::Undefined()); 1134 callInfo->SetThis(bitVector.GetTaggedValue()); 1135 callInfo->SetCallArg(0, JSTaggedValue(1)); 1136 [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); 1137 JSTaggedValue result = ContainersBitVector::Push(callInfo); 1138 TestHelper::TearDownFrame(thread, prev); 1139 EXPECT_EQ(result, JSTaggedValue::True()); 1140 EXPECT_EQ(bitVector->GetLength(), 1); 1141 } 1142 { 1143 auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 10); 1144 callInfo->SetFunction(JSTaggedValue::Undefined()); 1145 callInfo->SetThis(bitVector.GetTaggedValue()); 1146 callInfo->SetCallArg(0, JSTaggedValue(1)); 1147 callInfo->SetCallArg(1, JSTaggedValue(1.1)); 1148 callInfo->SetCallArg(2, JSTaggedValue(1)); 1149 [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); 1150 JSTaggedValue result = ContainersBitVector::GetLastIndexOf(callInfo); 1151 TestHelper::TearDownFrame(thread, prev); 1152 EXPECT_TRUE(thread->HasPendingException()); 1153 EXPECT_EQ(result, JSTaggedValue::Exception()); 1154 thread->ClearException(); 1155 } 1156} 1157/** 1158 * @tc.number: _BitVector_getLastIndexOf_Func_003 1159 * @tc.name: test_getLastIndexOf 1160 * @tc.desc: Locates the last occurrence of a certain bit value within a range of bits in a bit vector. 1161 * @tc.size: MediumTest 1162 * @tc.type: Function 1163 * @tc.level: Level 1 1164 */ 1165HWTEST_F_L0(ContainersBitVectorTest, GetLastIndexOf_003) 1166{ 1167 constexpr uint32_t NODE_NUMBERS = 64; 1168 JSHandle<JSAPIBitVector> bitVector = CreateJSAPIBitVector(); 1169 for (uint32_t i = 0; i < NODE_NUMBERS; i++) { 1170 if (i >= 32) { 1171 auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); 1172 callInfo->SetFunction(JSTaggedValue::Undefined()); 1173 callInfo->SetThis(bitVector.GetTaggedValue()); 1174 callInfo->SetCallArg(0, JSTaggedValue(1)); 1175 [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); 1176 ContainersBitVector::Push(callInfo); 1177 TestHelper::TearDownFrame(thread, prev); 1178 } else { 1179 auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); 1180 callInfo->SetFunction(JSTaggedValue::Undefined()); 1181 callInfo->SetThis(bitVector.GetTaggedValue()); 1182 callInfo->SetCallArg(0, JSTaggedValue(0)); 1183 [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); 1184 ContainersBitVector::Push(callInfo); 1185 TestHelper::TearDownFrame(thread, prev); 1186 } 1187 } 1188 { 1189 auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 10); 1190 callInfo->SetFunction(JSTaggedValue::Undefined()); 1191 callInfo->SetThis(bitVector.GetTaggedValue()); 1192 callInfo->SetCallArg(0, JSTaggedValue(1)); 1193 callInfo->SetCallArg(1, JSTaggedValue(0)); 1194 callInfo->SetCallArg(2, JSTaggedValue(64)); 1195 [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); 1196 JSTaggedValue result = ContainersBitVector::GetLastIndexOf(callInfo); 1197 TestHelper::TearDownFrame(thread, prev); 1198 EXPECT_EQ(result, JSTaggedValue(63)); 1199 } 1200 { 1201 auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 10); 1202 callInfo->SetFunction(JSTaggedValue::Undefined()); 1203 callInfo->SetThis(bitVector.GetTaggedValue()); 1204 callInfo->SetCallArg(0, JSTaggedValue(0)); 1205 callInfo->SetCallArg(1, JSTaggedValue(0)); 1206 callInfo->SetCallArg(2, JSTaggedValue(64)); 1207 [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); 1208 JSTaggedValue result = ContainersBitVector::GetLastIndexOf(callInfo); 1209 TestHelper::TearDownFrame(thread, prev); 1210 EXPECT_EQ(result, JSTaggedValue(31)); 1211 } 1212} 1213/** 1214 * @tc.number: _BitVector_flipBitByIndex_Func_001 1215 * @tc.name: test_flipBitByIndex 1216 * @tc.desc: Flips the bit value by index in a bit vector.(Flip 0 to 1, flip 1 to 0). 1217 * @tc.size: MediumTest 1218 * @tc.type: Function 1219 * @tc.level: Level 0 1220 */ 1221HWTEST_F_L0(ContainersBitVectorTest, FlipBitByIndex_001) 1222{ 1223 JSHandle<JSAPIBitVector> bitVector = CreateJSAPIBitVector(); 1224 { 1225 auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); 1226 callInfo->SetFunction(JSTaggedValue::Undefined()); 1227 callInfo->SetThis(bitVector.GetTaggedValue()); 1228 callInfo->SetCallArg(0, JSTaggedValue(1)); 1229 [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); 1230 JSTaggedValue result = ContainersBitVector::Push(callInfo); 1231 TestHelper::TearDownFrame(thread, prev); 1232 EXPECT_EQ(result, JSTaggedValue::True()); 1233 EXPECT_EQ(bitVector->GetLength(), 1); 1234 } 1235 { 1236 auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); 1237 callInfo->SetFunction(JSTaggedValue::Undefined()); 1238 callInfo->SetThis(bitVector.GetTaggedValue()); 1239 callInfo->SetCallArg(0, JSTaggedValue(0)); 1240 [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); 1241 ContainersBitVector::FlipBitByIndex(callInfo); 1242 TestHelper::TearDownFrame(thread, prev); 1243 } 1244 { 1245 auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); 1246 callInfo->SetFunction(JSTaggedValue::Undefined()); 1247 callInfo->SetThis(bitVector.GetTaggedValue()); 1248 [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); 1249 JSTaggedValue result = ContainersBitVector::Pop(callInfo); 1250 TestHelper::TearDownFrame(thread, prev); 1251 EXPECT_EQ(result, JSTaggedValue(0)); 1252 } 1253} 1254/** 1255 * @tc.number: _BitVector_flipBitByIndex_Func_002 1256 * @tc.name: test_flipBitByIndex 1257 * @tc.desc: Flips the bit value by index in a bit vector.(Flip 0 to 1, flip 1 to 0). 1258 * @tc.size: MediumTest 1259 * @tc.type: Function 1260 * @tc.level: Level 2 1261 */ 1262HWTEST_F_L0(ContainersBitVectorTest, FlipBitByIndex_2) 1263{ 1264 JSHandle<JSAPIBitVector> bitVector = CreateJSAPIBitVector(); 1265 { 1266 auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); 1267 callInfo->SetFunction(JSTaggedValue::Undefined()); 1268 callInfo->SetThis(bitVector.GetTaggedValue()); 1269 callInfo->SetCallArg(0, JSTaggedValue(1)); //input 1 1270 1271 [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); 1272 JSTaggedValue result = ContainersBitVector::Push(callInfo); 1273 TestHelper::TearDownFrame(thread, prev); 1274 EXPECT_EQ(result, JSTaggedValue::True()); 1275 EXPECT_EQ(bitVector->GetLength(), 1); 1276 } 1277 { 1278 auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); 1279 callInfo->SetFunction(JSTaggedValue::Undefined()); 1280 callInfo->SetThis(bitVector.GetTaggedValue()); 1281 callInfo->SetCallArg(0, JSTaggedValue(1.1)); 1282 [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); 1283 JSTaggedValue result = ContainersBitVector::FlipBitByIndex(callInfo); 1284 TestHelper::TearDownFrame(thread, prev); 1285 EXPECT_TRUE(thread->HasPendingException()); 1286 EXPECT_EQ(result, JSTaggedValue::Exception()); 1287 thread->ClearException(); 1288 } 1289} 1290/** 1291 * @tc.number: _BitVector_flipBitByIndex_Func_003 1292 * @tc.name: test_flipBitByIndex 1293 * @tc.desc: Flips the bit value by index in a bit vector.(Flip 0 to 1, flip 1 to 0). 1294 * @tc.size: MediumTest 1295 * @tc.type: Function 1296 * @tc.level: Level 1 1297 */ 1298HWTEST_F_L0(ContainersBitVectorTest, FlipBitByIndex_003) 1299{ 1300 JSHandle<JSAPIBitVector> bitVector = CreateJSAPIBitVector(); 1301 Push(bitVector); 1302 constexpr uint32_t NODE_NUMBERS = 64; 1303 for (uint32_t i = 0; i < NODE_NUMBERS; i++) { 1304 auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); 1305 callInfo->SetFunction(JSTaggedValue::Undefined()); 1306 callInfo->SetThis(bitVector.GetTaggedValue()); 1307 callInfo->SetCallArg(0, JSTaggedValue(i)); 1308 [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); 1309 ContainersBitVector::FlipBitByIndex(callInfo); 1310 TestHelper::TearDownFrame(thread, prev); 1311 } 1312 for (uint32_t i = 0; i < NODE_NUMBERS; i++) { 1313 if (i >= 32) { 1314 auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); 1315 callInfo->SetFunction(JSTaggedValue::Undefined()); 1316 callInfo->SetThis(bitVector.GetTaggedValue()); 1317 [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); 1318 JSTaggedValue result0 = ContainersBitVector::Pop(callInfo); 1319 TestHelper::TearDownFrame(thread, prev); 1320 EXPECT_EQ(result0, JSTaggedValue(1)); 1321 } else { 1322 auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); 1323 callInfo->SetFunction(JSTaggedValue::Undefined()); 1324 callInfo->SetThis(bitVector.GetTaggedValue()); 1325 [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); 1326 JSTaggedValue result1 = ContainersBitVector::Pop(callInfo); 1327 TestHelper::TearDownFrame(thread, prev); 1328 EXPECT_EQ(result1, JSTaggedValue(0)); 1329 } 1330 } 1331} 1332/** 1333 * @tc.number: _BitVector_flipBitsByRange_Func_001 1334 * @tc.name: test_flipBitsByRange 1335 * @tc.desc: Flips a range of bit values in a bit vector.(Flip 0 to 1, flip 1 to 0). 1336 * @tc.size: MediumTest 1337 * @tc.type: Function 1338 * @tc.level: Level 0 1339 */ 1340HWTEST_F_L0(ContainersBitVectorTest, FlipBitsByRange_001) 1341{ 1342 JSHandle<JSAPIBitVector> bitVector = CreateJSAPIBitVector(); 1343 { 1344 auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); 1345 callInfo->SetFunction(JSTaggedValue::Undefined()); 1346 callInfo->SetThis(bitVector.GetTaggedValue()); 1347 callInfo->SetCallArg(0, JSTaggedValue(1)); 1348 [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); 1349 JSTaggedValue result = ContainersBitVector::Push(callInfo); 1350 TestHelper::TearDownFrame(thread, prev); 1351 EXPECT_EQ(result, JSTaggedValue::True()); 1352 EXPECT_EQ(bitVector->GetLength(), 1); 1353 } 1354 { 1355 auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 10); 1356 callInfo->SetFunction(JSTaggedValue::Undefined()); 1357 callInfo->SetThis(bitVector.GetTaggedValue()); 1358 callInfo->SetCallArg(0, JSTaggedValue(0)); 1359 callInfo->SetCallArg(1, JSTaggedValue(1)); 1360 [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); 1361 ContainersBitVector::FlipBitsByRange(callInfo); 1362 TestHelper::TearDownFrame(thread, prev); 1363 } 1364 { 1365 auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); 1366 callInfo->SetFunction(JSTaggedValue::Undefined()); 1367 callInfo->SetThis(bitVector.GetTaggedValue()); 1368 [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); 1369 JSTaggedValue result = ContainersBitVector::Pop(callInfo); 1370 TestHelper::TearDownFrame(thread, prev); 1371 EXPECT_EQ(result, JSTaggedValue(0)); 1372 } 1373} 1374/** 1375 * @tc.number: _BitVector_flipBitsByRange_Func_002 1376 * @tc.name: test_flipBitsByRange 1377 * @tc.desc: Flips a range of bit values in a bit vector.(Flip 0 to 1, flip 1 to 0). 1378 * @tc.size: MediumTest 1379 * @tc.type: Function 1380 * @tc.level: Level 2 1381 */ 1382HWTEST_F_L0(ContainersBitVectorTest, FlipBitsByRange_002) 1383{ 1384 JSHandle<JSAPIBitVector> bitVector = CreateJSAPIBitVector(); 1385 { 1386 auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); 1387 callInfo->SetFunction(JSTaggedValue::Undefined()); 1388 callInfo->SetThis(bitVector.GetTaggedValue()); 1389 callInfo->SetCallArg(0, JSTaggedValue(1)); 1390 [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); 1391 JSTaggedValue result = ContainersBitVector::Push(callInfo); 1392 TestHelper::TearDownFrame(thread, prev); 1393 EXPECT_EQ(result, JSTaggedValue::True()); 1394 EXPECT_EQ(bitVector->GetLength(), 1); 1395 } 1396 { 1397 auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 10); 1398 callInfo->SetFunction(JSTaggedValue::Undefined()); 1399 callInfo->SetThis(bitVector.GetTaggedValue()); 1400 callInfo->SetCallArg(0, JSTaggedValue(1.1)); 1401 callInfo->SetCallArg(1, JSTaggedValue(1)); 1402 [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); 1403 JSTaggedValue result = ContainersBitVector::FlipBitsByRange(callInfo); 1404 TestHelper::TearDownFrame(thread, prev); 1405 EXPECT_TRUE(thread->HasPendingException()); 1406 EXPECT_EQ(result, JSTaggedValue::Exception()); 1407 thread->ClearException(); 1408 } 1409} 1410/** 1411 * @tc.number: _BitVector_flipBitsByRange_Func_003 1412 * @tc.name: test_flipBitsByRange 1413 * @tc.desc: Flips a range of bit values in a bit vector.(Flip 0 to 1, flip 1 to 0). 1414 * @tc.size: MediumTest 1415 * @tc.type: Function 1416 * @tc.level: Level 1 1417 */ 1418HWTEST_F_L0(ContainersBitVectorTest, FlipBitsByRange_003) 1419{ 1420 JSHandle<JSAPIBitVector> bitVector = CreateJSAPIBitVector(); 1421 Push(bitVector); 1422 { 1423 auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 10); 1424 callInfo->SetFunction(JSTaggedValue::Undefined()); 1425 callInfo->SetThis(bitVector.GetTaggedValue()); 1426 callInfo->SetCallArg(0, JSTaggedValue(0)); 1427 callInfo->SetCallArg(1, JSTaggedValue(32)); 1428 [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); 1429 ContainersBitVector::FlipBitsByRange(callInfo); 1430 TestHelper::TearDownFrame(thread, prev); 1431 } 1432 { 1433 auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 10); 1434 callInfo->SetFunction(JSTaggedValue::Undefined()); 1435 callInfo->SetThis(bitVector.GetTaggedValue()); 1436 callInfo->SetCallArg(0, JSTaggedValue(32)); 1437 callInfo->SetCallArg(1, JSTaggedValue(64)); 1438 [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); 1439 ContainersBitVector::FlipBitsByRange(callInfo); 1440 TestHelper::TearDownFrame(thread, prev); 1441 } 1442 constexpr uint32_t NODE_NUMBERS = 64; 1443 for (uint32_t i = 0; i < NODE_NUMBERS; i++) { 1444 if (i >= 32) { 1445 auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); 1446 callInfo->SetFunction(JSTaggedValue::Undefined()); 1447 callInfo->SetThis(bitVector.GetTaggedValue()); 1448 [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); 1449 JSTaggedValue result0 = ContainersBitVector::Pop(callInfo); 1450 TestHelper::TearDownFrame(thread, prev); 1451 EXPECT_EQ(result0, JSTaggedValue(1)); 1452 } else { 1453 auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); 1454 callInfo->SetFunction(JSTaggedValue::Undefined()); 1455 callInfo->SetThis(bitVector.GetTaggedValue()); 1456 [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); 1457 JSTaggedValue result1 = ContainersBitVector::Pop(callInfo); 1458 TestHelper::TearDownFrame(thread, prev); 1459 EXPECT_EQ(result1, JSTaggedValue(0)); 1460 } 1461 } 1462} 1463/** 1464 * @tc.number: _BitVector_GetIteratorObj_Func_001 1465 * @tc.name: test_GetIteratorObj 1466 * @tc.desc: Returns an iterator.Each item of the iterator is a Javascript Object. 1467 * @tc.size: MediumTest 1468 * @tc.type: Function 1469 * @tc.level: Level 0 1470 */ 1471HWTEST_F_L0(ContainersBitVectorTest, GetIteratorObj) 1472{ 1473 constexpr uint32_t NODE_NUMBERS = 8; 1474 JSHandle<JSAPIBitVector> bitVector = CreateJSAPIBitVector(); 1475 for (uint32_t i = 0; i < NODE_NUMBERS; i++) { 1476 auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); 1477 callInfo->SetFunction(JSTaggedValue::Undefined()); 1478 callInfo->SetThis(bitVector.GetTaggedValue()); 1479 callInfo->SetCallArg(0, JSTaggedValue(1)); 1480 [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); 1481 JSTaggedValue result = ContainersBitVector::Push(callInfo); 1482 TestHelper::TearDownFrame(thread, prev); 1483 EXPECT_EQ(result, JSTaggedValue::True()); 1484 EXPECT_EQ(bitVector->GetSize(), static_cast<int>(i + 1)); 1485 } 1486 auto callInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 4); 1487 callInfo1->SetFunction(JSTaggedValue::Undefined()); 1488 callInfo1->SetThis(bitVector.GetTaggedValue()); 1489 [[maybe_unused]] auto prev1 = TestHelper::SetupFrame(thread, callInfo1); 1490 JSHandle<JSTaggedValue> iterValues(thread, ContainersBitVector::GetIteratorObj(callInfo1)); 1491 TestHelper::TearDownFrame(thread, prev1); 1492 JSMutableHandle<JSTaggedValue> result(thread, JSTaggedValue::Undefined()); 1493 for (uint32_t i = 0; i < NODE_NUMBERS; i++) { 1494 auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 4); 1495 callInfo->SetFunction(JSTaggedValue::Undefined()); 1496 callInfo->SetThis(iterValues.GetTaggedValue()); 1497 [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); 1498 result.Update(JSAPIBitVectorIterator::Next(callInfo)); 1499 TestHelper::TearDownFrame(thread, prev); 1500 EXPECT_EQ(static_cast<int>(1), JSIterator::IteratorValue(thread, result)->GetInt()); 1501 } 1502} 1503};