mirror of
https://github.com/openharmony/ark_js_runtime.git
synced 2026-08-26 18:06:39 -04:00
86cfe52253
Signed-off-by: wanyanglan <wanyanglan1@huawei.com> Change-Id: Iac7851492f10c0ef1303c621febb65e5fdd22e41
103 lines
2.9 KiB
C++
103 lines
2.9 KiB
C++
/*
|
|
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
#include "ecmascript/tests/test_helper.h"
|
|
|
|
#include "ecmascript/ecma_vm.h"
|
|
#include "ecmascript/object_factory.h"
|
|
#include "ecmascript/regexp/dyn_chunk.h"
|
|
|
|
namespace panda::test {
|
|
using namespace panda::ecmascript;
|
|
|
|
class DynChunkTest : public testing::Test {
|
|
public:
|
|
static void SetUpTestCase()
|
|
{
|
|
GTEST_LOG_(INFO) << "SetUpTestCase";
|
|
}
|
|
|
|
static void TearDownTestCase()
|
|
{
|
|
GTEST_LOG_(INFO) << "TearDownCase";
|
|
}
|
|
|
|
void SetUp() override
|
|
{
|
|
TestHelper::CreateEcmaVMWithScope(instance, thread, scope);
|
|
chunk_ = thread->GetEcmaVM()->GetChunk();
|
|
}
|
|
|
|
void TearDown() override
|
|
{
|
|
TestHelper::DestroyEcmaVMWithScope(instance, scope);
|
|
}
|
|
|
|
PandaVM *instance {nullptr};
|
|
JSThread *thread {nullptr};
|
|
EcmaHandleScope *scope {nullptr};
|
|
Chunk *chunk_ {nullptr};
|
|
};
|
|
|
|
HWTEST_F_L0(DynChunkTest, EmitAndGet)
|
|
{
|
|
DynChunk dynChunk = DynChunk(chunk_);
|
|
dynChunk.EmitChar(65);
|
|
dynChunk.EmitU16(66);
|
|
dynChunk.EmitU32(67);
|
|
ASSERT_EQ(dynChunk.GetSize(), 7);
|
|
ASSERT_EQ(dynChunk.GetAllocatedSize(), DynChunk::ALLOCATE_MIN_SIZE);
|
|
ASSERT_EQ(dynChunk.GetError(), false);
|
|
dynChunk.Insert(1, 1);
|
|
uint32_t val1 = dynChunk.GetU8(0);
|
|
uint32_t val2 = dynChunk.GetU16(2);
|
|
uint32_t val3 = dynChunk.GetU32(4);
|
|
ASSERT_EQ(val1, 65);
|
|
ASSERT_EQ(val2, 66);
|
|
ASSERT_EQ(val3, 67);
|
|
}
|
|
|
|
HWTEST_F_L0(DynChunkTest, EmitSelfAndGet)
|
|
{
|
|
DynChunk dynChunk = DynChunk(chunk_);
|
|
dynChunk.EmitChar(65);
|
|
dynChunk.EmitSelf(0, 1);
|
|
ASSERT_EQ(dynChunk.GetSize(), 2);
|
|
ASSERT_EQ(dynChunk.GetAllocatedSize(), DynChunk::ALLOCATE_MIN_SIZE);
|
|
ASSERT_EQ(dynChunk.GetError(), false);
|
|
uint32_t val1 = dynChunk.GetU8(0);
|
|
uint32_t val2 = dynChunk.GetU8(1);
|
|
ASSERT_EQ(val1, 65);
|
|
ASSERT_EQ(val2, 65);
|
|
}
|
|
|
|
HWTEST_F_L0(DynChunkTest, EmitStrAndGet)
|
|
{
|
|
DynChunk dynChunk = DynChunk(chunk_);
|
|
dynChunk.EmitStr("abc");
|
|
ASSERT_EQ(dynChunk.GetSize(), 4);
|
|
ASSERT_EQ(dynChunk.GetAllocatedSize(), DynChunk::ALLOCATE_MIN_SIZE);
|
|
ASSERT_EQ(dynChunk.GetError(), false);
|
|
uint32_t val1 = dynChunk.GetU8(0);
|
|
uint32_t val2 = dynChunk.GetU8(1);
|
|
uint32_t val3 = dynChunk.GetU8(2);
|
|
uint32_t val4 = dynChunk.GetU8(3);
|
|
ASSERT_EQ(val1, 97);
|
|
ASSERT_EQ(val2, 98);
|
|
ASSERT_EQ(val3, 99);
|
|
ASSERT_EQ(val4, 0);
|
|
}
|
|
} // namespace panda::test
|