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