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 #ifndef TEST_UNIT_PUBLIC_AST_VERIFIER_TEST_H 17 #define TEST_UNIT_PUBLIC_AST_VERIFIER_TEST_H 18 19 #include "ast_verifier/ASTVerifier.h" 20 #include "test/utils/panda_executable_path_getter.h" 21 22 #include <gtest/gtest.h> 23 24 class ASTVerifierTest : public testing::Test { 25 public: ASTVerifierTest()26 ASTVerifierTest() 27 { 28 impl_ = es2panda_GetImpl(ES2PANDA_LIB_VERSION); 29 auto es2pandaPath = test::utils::PandaExecutablePathGetter {}.Get(); 30 // NOLINTNEXTLINE(modernize-avoid-c-arrays) 31 char const *argv[] = {es2pandaPath.c_str()}; 32 cfg_ = impl_->CreateConfig(1, argv); 33 allocator_ = new ark::ArenaAllocator(ark::SpaceType::SPACE_TYPE_COMPILER); 34 } ~ASTVerifierTest()35 ~ASTVerifierTest() override 36 { 37 delete allocator_; 38 impl_->DestroyConfig(cfg_); 39 } 40 Allocator()41 ark::ArenaAllocator *Allocator() 42 { 43 return allocator_; 44 } 45 46 NO_COPY_SEMANTIC(ASTVerifierTest); 47 NO_MOVE_SEMANTIC(ASTVerifierTest); 48 49 protected: 50 template <typename Type> Tree(Type * node)51 Type *Tree(Type *node) 52 { 53 return node; 54 } 55 56 template <typename Type, typename... Args> Node(Args &&...args)57 Type *Node(Args &&...args) 58 { 59 return allocator_->New<Type>(std::forward<Args>(args)...); 60 } 61 62 template <typename Type, typename... Args> Nodes(Args &&...args)63 ark::ArenaVector<Type *> Nodes(Args &&...args) 64 { 65 auto v = ark::ArenaVector<Type *> {allocator_->Adapter()}; 66 v.insert(v.end(), {std::forward<Args>(args)...}); 67 return v; 68 } 69 70 // NOLINTBEGIN(misc-non-private-member-variables-in-classes) 71 es2panda_Impl const *impl_; 72 es2panda_Config *cfg_; 73 ark::ArenaAllocator *allocator_; 74 // NOLINTEND(misc-non-private-member-variables-in-classes) 75 }; 76 77 #endif // TEST_UNIT_PUBLIC_AST_VERIFIER_TEST_H 78