1 /**
2 * Copyright (c) 2021-2025 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 <gtest/gtest.h>
17
18 #include "ets_coroutine.h"
19
20 #include "types/ets_class.h"
21 #include "types/ets_arraybuffer.h"
22 #include "tests/runtime/types/ets_test_mirror_classes.h"
23
24 namespace ark::ets::test {
25
26 class EtsArrayBufferTest : public testing::Test {
27 public:
EtsArrayBufferTest()28 EtsArrayBufferTest()
29 {
30 RuntimeOptions options;
31 options.SetShouldLoadBootPandaFiles(true);
32 options.SetShouldInitializeIntrinsics(false);
33 options.SetCompilerEnableJit(false);
34 options.SetGcType("epsilon");
35 options.SetLoadRuntimes({"ets"});
36
37 auto stdlib = std::getenv("PANDA_STD_LIB");
38 if (stdlib == nullptr) {
39 std::cerr << "PANDA_STD_LIB env variable should be set and point to mock_stdlib.abc" << std::endl;
40 std::abort();
41 }
42 options.SetBootPandaFiles({stdlib});
43
44 Runtime::Create(options);
45 EtsCoroutine *coroutine = EtsCoroutine::GetCurrent();
46 vm_ = coroutine->GetPandaVM();
47 }
48
~EtsArrayBufferTest()49 ~EtsArrayBufferTest() override
50 {
51 Runtime::Destroy();
52 }
53
54 NO_COPY_SEMANTIC(EtsArrayBufferTest);
55 NO_MOVE_SEMANTIC(EtsArrayBufferTest);
56
GetMembers()57 static std::vector<MirrorFieldInfo> GetMembers()
58 {
59 return std::vector<MirrorFieldInfo> {MIRROR_FIELD_INFO(EtsEscompatArrayBuffer, managedData_, "data"),
60 MIRROR_FIELD_INFO(EtsEscompatArrayBuffer, byteLength_, "_byteLength"),
61 MIRROR_FIELD_INFO(EtsEscompatArrayBuffer, nativeData_, "dataAddress"),
62 MIRROR_FIELD_INFO(EtsEscompatArrayBuffer, isResizable_, "isResizable")};
63 }
64
65 protected:
66 PandaEtsVM *vm_ = nullptr; // NOLINT(misc-non-private-member-variables-in-classes)
67 };
68
TEST_F(EtsArrayBufferTest,MemoryLayout)69 TEST_F(EtsArrayBufferTest, MemoryLayout)
70 {
71 EtsClass *klass = PlatformTypes(vm_)->escompatArrayBuffer;
72 MirrorFieldInfo::CompareMemberOffsets(klass, GetMembers());
73 }
74 } // namespace ark::ets::test
75