mirror of
https://gitee.com/openharmony/arkcompiler_ets_runtime
synced 2024-11-23 10:09:54 +00:00
Revert '超大函数整改 PR_pr_6868'
issue:https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/IAF43I?from=project-issue Signed-off-by: 韦宝相 <weibaoxiang1@huawei.com>
This commit is contained in:
parent
9ae3bad8b0
commit
6d5e0563ea
@ -159,70 +159,6 @@ HWTEST_F_L0(JSAPIHashMapTest, HashMapRemoveAndHas)
|
||||
}
|
||||
}
|
||||
|
||||
void TestHashMapReplace(JSHandle<JSAPIHashMap> &hashMap,
|
||||
JSMutableHandle<JSTaggedValue> &key,
|
||||
JSMutableHandle<JSTaggedValue> &value,
|
||||
JSThread *thread,
|
||||
uint32_t nodeNumbers)
|
||||
{
|
||||
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
|
||||
std::string myKey("mykey");
|
||||
std::string myValue("myvalue");
|
||||
uint32_t half = nodeNumbers / 2;
|
||||
for (uint32_t i = 0; i < half; i++) {
|
||||
std::string iKey = myKey + std::to_string(i);
|
||||
std::string iValue = myValue + std::to_string(i + 1);
|
||||
key.Update(factory->NewFromStdString(iKey).GetTaggedValue());
|
||||
value.Update(factory->NewFromStdString(iValue).GetTaggedValue());
|
||||
// test replace
|
||||
bool success = hashMap->Replace(thread, key.GetTaggedValue(), value.GetTaggedValue());
|
||||
EXPECT_EQ(success, true);
|
||||
}
|
||||
}
|
||||
|
||||
void TestHashMapGetFirstHalf(JSHandle<JSAPIHashMap> &hashMap,
|
||||
JSMutableHandle<JSTaggedValue> &key,
|
||||
JSMutableHandle<JSTaggedValue> &value,
|
||||
JSThread *thread,
|
||||
uint32_t nodeNumbers)
|
||||
{
|
||||
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
|
||||
std::string myKey("mykey");
|
||||
std::string myValue("myvalue");
|
||||
uint32_t half = nodeNumbers / 2;
|
||||
for (uint32_t i = 0; i < half; i++) {
|
||||
std::string iKey = myKey + std::to_string(i);
|
||||
std::string iValue = myValue + std::to_string(i + 1);
|
||||
key.Update(factory->NewFromStdString(iKey).GetTaggedValue());
|
||||
value.Update(factory->NewFromStdString(iValue).GetTaggedValue());
|
||||
// test get
|
||||
JSTaggedValue gValue = hashMap->Get(thread, key.GetTaggedValue());
|
||||
EXPECT_EQ(gValue, value.GetTaggedValue());
|
||||
}
|
||||
}
|
||||
|
||||
void TestHashMapGetSecondHalf(JSHandle<JSAPIHashMap> &hashMap,
|
||||
JSMutableHandle<JSTaggedValue> &key,
|
||||
JSMutableHandle<JSTaggedValue> &value,
|
||||
JSThread *thread,
|
||||
uint32_t nodeNumbers)
|
||||
{
|
||||
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
|
||||
std::string myKey("mykey");
|
||||
std::string myValue("myvalue");
|
||||
uint32_t half = nodeNumbers / 2;
|
||||
for (uint32_t i = half; i < nodeNumbers; i++) {
|
||||
std::string iKey = myKey + std::to_string(i);
|
||||
std::string iValue = myValue + std::to_string(i);
|
||||
key.Update(factory->NewFromStdString(iKey).GetTaggedValue());
|
||||
value.Update(factory->NewFromStdString(iValue).GetTaggedValue());
|
||||
// test get
|
||||
JSTaggedValue gValue = hashMap->Get(thread, key.GetTaggedValue());
|
||||
EXPECT_EQ(gValue, value.GetTaggedValue());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
HWTEST_F_L0(JSAPIHashMapTest, HashMapReplaceAndClear)
|
||||
{
|
||||
constexpr uint32_t NODE_NUMBERS = 8;
|
||||
@ -236,16 +172,33 @@ HWTEST_F_L0(JSAPIHashMapTest, HashMapReplaceAndClear)
|
||||
auto pair = std::make_pair(myKey, myValue);
|
||||
Update(hashMap, key, value, pair, NODE_NUMBERS);
|
||||
EXPECT_EQ(hashMap->GetSize(), NODE_NUMBERS);
|
||||
|
||||
// test replace
|
||||
TestHashMapReplace(hashMap, key, value, thread, NODE_NUMBERS);
|
||||
|
||||
//test get
|
||||
TestHashMapGetFirstHalf(hashMap, key, value, thread, NODE_NUMBERS);
|
||||
|
||||
//test get
|
||||
TestHashMapGetSecondHalf(hashMap, key, value, thread, NODE_NUMBERS);
|
||||
|
||||
for (uint32_t i = 0; i < NODE_NUMBERS / 2; i++) {
|
||||
std::string iKey = myKey + std::to_string(i);
|
||||
std::string iValue = myValue + std::to_string(i + 1);
|
||||
key.Update(factory->NewFromStdString(iKey).GetTaggedValue());
|
||||
value.Update(factory->NewFromStdString(iValue).GetTaggedValue());
|
||||
// test replace
|
||||
bool success = hashMap->Replace(thread, key.GetTaggedValue(), value.GetTaggedValue());
|
||||
EXPECT_EQ(success, true);
|
||||
}
|
||||
for (uint32_t i = 0; i < NODE_NUMBERS / 2; i++) {
|
||||
std::string iKey = myKey + std::to_string(i);
|
||||
std::string iValue = myValue + std::to_string(i + 1);
|
||||
key.Update(factory->NewFromStdString(iKey).GetTaggedValue());
|
||||
value.Update(factory->NewFromStdString(iValue).GetTaggedValue());
|
||||
// test get
|
||||
JSTaggedValue gValue = hashMap->Get(thread, key.GetTaggedValue());
|
||||
EXPECT_EQ(gValue, value.GetTaggedValue());
|
||||
}
|
||||
for (uint32_t i = NODE_NUMBERS / 2; i < NODE_NUMBERS; i++) {
|
||||
std::string iKey = myKey + std::to_string(i);
|
||||
std::string iValue = myValue + std::to_string(i);
|
||||
key.Update(factory->NewFromStdString(iKey).GetTaggedValue());
|
||||
value.Update(factory->NewFromStdString(iValue).GetTaggedValue());
|
||||
// test get
|
||||
JSTaggedValue gValue = hashMap->Get(thread, key.GetTaggedValue());
|
||||
EXPECT_EQ(gValue, value.GetTaggedValue());
|
||||
}
|
||||
for (uint32_t i = 0; i < NODE_NUMBERS / 2; i++) {
|
||||
std::string iKey = myKey + std::to_string(i);
|
||||
key.Update(factory->NewFromStdString(iKey).GetTaggedValue());
|
||||
@ -269,44 +222,6 @@ HWTEST_F_L0(JSAPIHashMapTest, HashMapReplaceAndClear)
|
||||
}
|
||||
}
|
||||
|
||||
void TestHashMapKeyAndValue(JSHandle<JSAPIHashMap> &hashMap, JSThread *thread, uint32_t nodeNumbers)
|
||||
{
|
||||
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
|
||||
JSHandle<JSTaggedValue> indexKey(thread, JSTaggedValue(0));
|
||||
JSHandle<JSTaggedValue> elementKey(thread, JSTaggedValue(1));
|
||||
JSHandle<JSTaggedValue> iter(factory->NewJSAPIHashMapIterator(hashMap, IterationKind::KEY_AND_VALUE));
|
||||
JSMutableHandle<JSTaggedValue> iterResult(thread, JSTaggedValue::Undefined());
|
||||
JSMutableHandle<JSTaggedValue> result(thread, JSTaggedValue::Undefined());
|
||||
for (uint32_t i = 0; i < nodeNumbers; i++) {
|
||||
iterResult.Update(JSIterator::IteratorStep(thread, iter).GetTaggedValue());
|
||||
result.Update(JSIterator::IteratorValue(thread, iterResult).GetTaggedValue());
|
||||
JSHandle<JSTaggedValue> tmpKey = JSObject::GetProperty(thread, result, indexKey).GetValue();
|
||||
JSTaggedValue iterKeyFlag = hashMap->HasKey(thread, tmpKey.GetTaggedValue());
|
||||
EXPECT_EQ(JSTaggedValue::True(), iterKeyFlag);
|
||||
JSHandle<JSTaggedValue> tmpValue = JSObject::GetProperty(thread, result, elementKey).GetValue();
|
||||
JSTaggedValue iterValueFlag = JSAPIHashMap::HasValue(thread, hashMap, tmpValue);
|
||||
EXPECT_EQ(JSTaggedValue::True(), iterValueFlag);
|
||||
}
|
||||
}
|
||||
|
||||
void TestHashMapSet(JSHandle<JSAPIHashMap> &hashMap,
|
||||
JSThread *thread,
|
||||
JSHandle<JSTaggedValue> &keyIter,
|
||||
uint32_t nodeNumbers)
|
||||
{
|
||||
JSMutableHandle<JSTaggedValue> key(thread, JSTaggedValue::Undefined());
|
||||
JSMutableHandle<JSTaggedValue> keyIterResult(thread, JSTaggedValue::Undefined());
|
||||
key.Update(JSTaggedValue(nodeNumbers));
|
||||
JSAPIHashMap::Set(thread, hashMap, key, key);
|
||||
keyIterResult.Update(JSIterator::IteratorStep(thread, keyIter).GetTaggedValue());
|
||||
JSHandle<JSTaggedValue> tmpIterKey = JSIterator::IteratorValue(thread, keyIterResult);
|
||||
JSTaggedValue iterKeyFlag = hashMap->HasKey(thread, tmpIterKey.GetTaggedValue());
|
||||
EXPECT_EQ(JSTaggedValue::True(), iterKeyFlag);
|
||||
EXPECT_EQ(hashMap->GetSize(), nodeNumbers);
|
||||
keyIterResult.Update(JSIterator::IteratorStep(thread, keyIter).GetTaggedValue());
|
||||
EXPECT_EQ(JSTaggedValue::False(), keyIterResult.GetTaggedValue());
|
||||
}
|
||||
|
||||
HWTEST_F_L0(JSAPIHashMapTest, JSAPIHashMapIterator)
|
||||
{
|
||||
constexpr uint32_t NODE_NUMBERS = 8;
|
||||
@ -334,10 +249,22 @@ HWTEST_F_L0(JSAPIHashMapTest, JSAPIHashMapIterator)
|
||||
JSTaggedValue iterValueFlag = JSAPIHashMap::HasValue(thread, hashMap, tmpIterValue);
|
||||
EXPECT_EQ(JSTaggedValue::True(), iterValueFlag);
|
||||
}
|
||||
|
||||
// test key and value
|
||||
TestHashMapKeyAndValue(hashMap, thread, NODE_NUMBERS);
|
||||
|
||||
JSHandle<JSTaggedValue> indexKey(thread, JSTaggedValue(0));
|
||||
JSHandle<JSTaggedValue> elementKey(thread, JSTaggedValue(1));
|
||||
JSHandle<JSTaggedValue> iter(factory->NewJSAPIHashMapIterator(hashMap, IterationKind::KEY_AND_VALUE));
|
||||
JSMutableHandle<JSTaggedValue> iterResult(thread, JSTaggedValue::Undefined());
|
||||
JSMutableHandle<JSTaggedValue> result(thread, JSTaggedValue::Undefined());
|
||||
for (uint32_t i = 0; i < NODE_NUMBERS; i++) {
|
||||
iterResult.Update(JSIterator::IteratorStep(thread, iter).GetTaggedValue());
|
||||
result.Update(JSIterator::IteratorValue(thread, iterResult).GetTaggedValue());
|
||||
JSHandle<JSTaggedValue> tmpKey = JSObject::GetProperty(thread, result, indexKey).GetValue();
|
||||
JSTaggedValue iterKeyFlag = hashMap->HasKey(thread, tmpKey.GetTaggedValue());
|
||||
EXPECT_EQ(JSTaggedValue::True(), iterKeyFlag);
|
||||
JSHandle<JSTaggedValue> tmpValue = JSObject::GetProperty(thread, result, elementKey).GetValue();
|
||||
JSTaggedValue iterValueFlag = JSAPIHashMap::HasValue(thread, hashMap, tmpValue);
|
||||
EXPECT_EQ(JSTaggedValue::True(), iterValueFlag);
|
||||
}
|
||||
// test delete
|
||||
key.Update(JSTaggedValue(NODE_NUMBERS / 2));
|
||||
JSTaggedValue rValue = JSAPIHashMap::Remove(thread, hashMap, key.GetTaggedValue());
|
||||
@ -352,9 +279,16 @@ HWTEST_F_L0(JSAPIHashMapTest, JSAPIHashMapIterator)
|
||||
JSTaggedValue iterValueFlag = JSAPIHashMap::HasValue(thread, hashMap, tmpIterValue);
|
||||
EXPECT_EQ(JSTaggedValue::True(), iterValueFlag);
|
||||
}
|
||||
|
||||
// test set
|
||||
TestHashMapSet(hashMap, thread, keyIter, NODE_NUMBERS);
|
||||
key.Update(JSTaggedValue(NODE_NUMBERS));
|
||||
JSAPIHashMap::Set(thread, hashMap, key, key);
|
||||
keyIterResult.Update(JSIterator::IteratorStep(thread, keyIter).GetTaggedValue());
|
||||
JSHandle<JSTaggedValue> tmpIterKey = JSIterator::IteratorValue(thread, keyIterResult);
|
||||
JSTaggedValue iterKeyFlag = hashMap->HasKey(thread, tmpIterKey.GetTaggedValue());
|
||||
EXPECT_EQ(JSTaggedValue::True(), iterKeyFlag);
|
||||
EXPECT_EQ(hashMap->GetSize(), NODE_NUMBERS);
|
||||
keyIterResult.Update(JSIterator::IteratorStep(thread, keyIter).GetTaggedValue());
|
||||
EXPECT_EQ(JSTaggedValue::False(), keyIterResult.GetTaggedValue());
|
||||
}
|
||||
|
||||
HWTEST_F_L0(JSAPIHashMapTest, JSAPIHashMapIteratorRBTreeTest)
|
||||
|
@ -139,99 +139,6 @@ HWTEST_F_L0(JSAPITreeMapTest, TreeMapDeleteAndHas)
|
||||
}
|
||||
}
|
||||
|
||||
void TestTreeMapReplace(JSHandle<JSAPITreeMap> &tmap,
|
||||
JSMutableHandle<JSTaggedValue> &key,
|
||||
JSMutableHandle<JSTaggedValue> &value,
|
||||
JSThread *thread,
|
||||
int nodeNumbers)
|
||||
{
|
||||
std::string myKey("mykey");
|
||||
std::string myValue("myvalue");
|
||||
int firstHalfNum = nodeNumbers / 2;
|
||||
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
|
||||
for (int i = 0; i < firstHalfNum; i++) {
|
||||
std::string ikey = myKey + std::to_string(i);
|
||||
std::string ivalue = myValue + std::to_string(i + 1);
|
||||
key.Update(factory->NewFromStdString(ikey).GetTaggedValue());
|
||||
value.Update(factory->NewFromStdString(ivalue).GetTaggedValue());
|
||||
|
||||
// test replace
|
||||
bool success = JSAPITreeMap::Replace(thread, tmap, key, value);
|
||||
EXPECT_EQ(success, true);
|
||||
}
|
||||
}
|
||||
|
||||
void TestTreeMapGetAndHas(JSHandle<JSAPITreeMap> &tmap,
|
||||
JSMutableHandle<JSTaggedValue> &key,
|
||||
JSMutableHandle<JSTaggedValue> &value,
|
||||
JSThread *thread,
|
||||
int nodeNumbers)
|
||||
{
|
||||
std::string myKey("mykey");
|
||||
std::string myValue("myvalue");
|
||||
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
|
||||
for (int i = 0; i < nodeNumbers; i++) {
|
||||
std::string ikey = myKey + std::to_string(i);
|
||||
std::string ivalue = myValue + std::to_string(i);
|
||||
key.Update(factory->NewFromStdString(ikey).GetTaggedValue());
|
||||
value.Update(factory->NewFromStdString(ivalue).GetTaggedValue());
|
||||
|
||||
// test get
|
||||
JSTaggedValue gvalue = JSAPITreeMap::Get(thread, tmap, key);
|
||||
EXPECT_EQ(gvalue, JSTaggedValue::Undefined());
|
||||
|
||||
// test has
|
||||
bool hasKey = JSAPITreeMap::HasKey(thread, tmap, key);
|
||||
EXPECT_EQ(hasKey, false);
|
||||
bool hasValue = tmap->HasValue(thread, value);
|
||||
EXPECT_EQ(hasValue, false);
|
||||
}
|
||||
}
|
||||
|
||||
void TestTreeMapGetFirstHalf(JSHandle<JSAPITreeMap> &tmap,
|
||||
JSMutableHandle<JSTaggedValue> &key,
|
||||
JSMutableHandle<JSTaggedValue> &value,
|
||||
JSThread *thread,
|
||||
int nodeNumbers)
|
||||
{
|
||||
std::string myKey("mykey");
|
||||
std::string myValue("myvalue");
|
||||
int firstHalfNum = nodeNumbers / 2;
|
||||
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
|
||||
for (int i = 0; i < firstHalfNum; i++) {
|
||||
std::string ikey = myKey + std::to_string(i);
|
||||
std::string ivalue = myValue + std::to_string(i + 1);
|
||||
key.Update(factory->NewFromStdString(ikey).GetTaggedValue());
|
||||
value.Update(factory->NewFromStdString(ivalue).GetTaggedValue());
|
||||
|
||||
// test get
|
||||
JSTaggedValue gvalue = JSAPITreeMap::Get(thread, tmap, key);
|
||||
EXPECT_EQ(gvalue, value.GetTaggedValue());
|
||||
}
|
||||
}
|
||||
|
||||
void TestTreeMapGetSecondHalf(JSHandle<JSAPITreeMap> &tmap,
|
||||
JSMutableHandle<JSTaggedValue> &key,
|
||||
JSMutableHandle<JSTaggedValue> &value,
|
||||
JSThread *thread,
|
||||
int nodeNumbers)
|
||||
{
|
||||
std::string myKey("mykey");
|
||||
std::string myValue("myvalue");
|
||||
int firstHalfNum = nodeNumbers / 2;
|
||||
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
|
||||
for (int i = firstHalfNum; i < nodeNumbers; i++) {
|
||||
std::string ikey = myKey + std::to_string(i);
|
||||
std::string ivalue = myValue + std::to_string(i);
|
||||
key.Update(factory->NewFromStdString(ikey).GetTaggedValue());
|
||||
value.Update(factory->NewFromStdString(ivalue).GetTaggedValue());
|
||||
|
||||
// test get
|
||||
JSTaggedValue gvalue = JSAPITreeMap::Get(thread, tmap, key);
|
||||
EXPECT_EQ(gvalue, value.GetTaggedValue());
|
||||
}
|
||||
}
|
||||
|
||||
HWTEST_F_L0(JSAPITreeMapTest, TreeMapReplaceAndClear)
|
||||
{
|
||||
constexpr int NODE_NUMBERS = 8;
|
||||
@ -252,8 +159,16 @@ HWTEST_F_L0(JSAPITreeMapTest, TreeMapReplaceAndClear)
|
||||
}
|
||||
EXPECT_EQ(tmap->GetSize(), NODE_NUMBERS);
|
||||
|
||||
// test replace
|
||||
TestTreeMapReplace(tmap, key, value, thread, NODE_NUMBERS);
|
||||
for (int i = 0; i < NODE_NUMBERS / 2; i++) {
|
||||
std::string ikey = myKey + std::to_string(i);
|
||||
std::string ivalue = myValue + std::to_string(i + 1);
|
||||
key.Update(factory->NewFromStdString(ikey).GetTaggedValue());
|
||||
value.Update(factory->NewFromStdString(ivalue).GetTaggedValue());
|
||||
|
||||
// test replace
|
||||
bool success = JSAPITreeMap::Replace(thread, tmap, key, value);
|
||||
EXPECT_EQ(success, true);
|
||||
}
|
||||
|
||||
{
|
||||
std::string ikey = myKey + std::to_string(NODE_NUMBERS);
|
||||
@ -264,11 +179,27 @@ HWTEST_F_L0(JSAPITreeMapTest, TreeMapReplaceAndClear)
|
||||
EXPECT_FALSE(success);
|
||||
}
|
||||
|
||||
//test get
|
||||
TestTreeMapGetFirstHalf(tmap, key, value, thread, NODE_NUMBERS);
|
||||
for (int i = 0; i < NODE_NUMBERS / 2; i++) {
|
||||
std::string ikey = myKey + std::to_string(i);
|
||||
std::string ivalue = myValue + std::to_string(i + 1);
|
||||
key.Update(factory->NewFromStdString(ikey).GetTaggedValue());
|
||||
value.Update(factory->NewFromStdString(ivalue).GetTaggedValue());
|
||||
|
||||
//test get
|
||||
TestTreeMapGetSecondHalf(tmap, key, value, thread, NODE_NUMBERS);
|
||||
// test get
|
||||
JSTaggedValue gvalue = JSAPITreeMap::Get(thread, tmap, key);
|
||||
EXPECT_EQ(gvalue, value.GetTaggedValue());
|
||||
}
|
||||
|
||||
for (int i = NODE_NUMBERS / 2; i < NODE_NUMBERS; i++) {
|
||||
std::string ikey = myKey + std::to_string(i);
|
||||
std::string ivalue = myValue + std::to_string(i);
|
||||
key.Update(factory->NewFromStdString(ikey).GetTaggedValue());
|
||||
value.Update(factory->NewFromStdString(ivalue).GetTaggedValue());
|
||||
|
||||
// test get
|
||||
JSTaggedValue gvalue = JSAPITreeMap::Get(thread, tmap, key);
|
||||
EXPECT_EQ(gvalue, value.GetTaggedValue());
|
||||
}
|
||||
|
||||
for (int i = 0; i < NODE_NUMBERS / 2; i++) {
|
||||
std::string ikey = myKey + std::to_string(i);
|
||||
@ -278,8 +209,22 @@ HWTEST_F_L0(JSAPITreeMapTest, TreeMapReplaceAndClear)
|
||||
|
||||
JSAPITreeMap::Clear(thread, tmap);
|
||||
EXPECT_EQ(tmap->GetSize(), 0);
|
||||
// test get and has
|
||||
TestTreeMapGetAndHas(tmap, key, value, thread, NODE_NUMBERS);
|
||||
for (int i = 0; i < NODE_NUMBERS; i++) {
|
||||
std::string ikey = myKey + std::to_string(i);
|
||||
std::string ivalue = myValue + std::to_string(i);
|
||||
key.Update(factory->NewFromStdString(ikey).GetTaggedValue());
|
||||
value.Update(factory->NewFromStdString(ivalue).GetTaggedValue());
|
||||
|
||||
// test get
|
||||
JSTaggedValue gvalue = JSAPITreeMap::Get(thread, tmap, key);
|
||||
EXPECT_EQ(gvalue, JSTaggedValue::Undefined());
|
||||
|
||||
// test has
|
||||
bool hasKey = JSAPITreeMap::HasKey(thread, tmap, key);
|
||||
EXPECT_EQ(hasKey, false);
|
||||
bool hasValue = tmap->HasValue(thread, value);
|
||||
EXPECT_EQ(hasValue, false);
|
||||
}
|
||||
}
|
||||
|
||||
HWTEST_F_L0(JSAPITreeMapTest, JSAPITreeMapIterator)
|
||||
|
Loading…
Reference in New Issue
Block a user