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 EXPECT 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 "class_data_accessor-inl.h" 19 20 using namespace testing::ext; 21 22 namespace panda::pandasm { 23 class AssemblyEmitterTest : public testing::Test { 24 }; 25 26 static const std::string SLOT_NUMBER = "L_ESSlotNumberAnnotation;"; 27 static const std::string CONCURRENT_MODULE_REQUESTS = "L_ESConcurrentModuleRequestsAnnotation;"; 28 29 /** 30 * @tc.name: assembly_access_flag_test_001 31 * @tc.desc: Verify class access flag. 32 * @tc.type: FUNC 33 * @tc.require: file path and name 34 */ 35 HWTEST_F(AssemblyEmitterTest, assembly_access_flag_test_001, TestSize.Level1) 36 { 37 const std::string file_name = GRAPH_TEST_ABC_DIR "test_class_access_flags.abc"; 38 auto file_to_verify = panda_file::File::Open(file_name); 39 std::unique_ptr<const panda_file::File> file_; 40 file_.swap(file_to_verify); 41 42 const auto class_idx = file_->GetClasses(); 43 for (size_t i = 0; i < class_idx.size(); i++) { 44 uint32_t class_id = class_idx[i]; 45 ASSERT(class_id < file_->GetHeader()->file_size); 46 const panda_file::File::EntityId record_id {class_id}; 47 panda_file::ClassDataAccessor class_accessor {*file_, record_id}; 48 auto class_name = class_accessor.GetName(); 49 auto access_flag = class_accessor.GetAccessFlags(); 50 auto name = std::string(utf::Mutf8AsCString(class_name.data)); 51 if (name == SLOT_NUMBER || name == CONCURRENT_MODULE_REQUESTS) { 52 EXPECT_EQ(access_flag, ACC_PUBLIC | ACC_ANNOTATION); 53 } else { 54 EXPECT_EQ(access_flag, ACC_PUBLIC); 55 } 56 } 57 } 58 }