1 /** 2 * Copyright (c) 2023 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 "mangling.h" 19 #include "assembly-function.h" 20 #include "extensions/extensions.h" 21 22 using namespace panda::pandasm; 23 using namespace testing::ext; 24 25 namespace panda::pandasm { 26 class ManglingTest : public testing::Test { 27 }; 28 29 /** 30 * @tc.name: mangling_test_001 31 * @tc.desc: Verify the MangleFunctionName function. 32 * @tc.type: FUNC 33 * @tc.require: issueNumber 34 */ 35 HWTEST_F(ManglingTest, mangling_test_001, TestSize.Level1) 36 { 37 std::vector<Function::Parameter> params; 38 panda::panda_file::SourceLang language {panda::panda_file::SourceLang::PANDA_ASSEMBLY}; 39 params.emplace_back(Type {"type1", 0}, language); 40 params.emplace_back(Type {"type2", 0}, language); 41 params.emplace_back(Type {"type3", 0}, language); 42 43 auto return_type = Type("type4", 0); 44 45 std::string name = "Asm.main"; 46 std::string ret = MangleFunctionName(name, std::move(params), return_type); 47 EXPECT_EQ(ret, "Asm.main:type1;type2;type3;type4;"); 48 } 49 50 /** 51 * @tc.name: mangling_test_002 52 * @tc.desc: Verify the DeMangleName function. 53 * @tc.type: FUNC 54 * @tc.require: issueNumber 55 */ 56 HWTEST_F(ManglingTest, mangling_test_002, TestSize.Level1) 57 { 58 std::string name = "Asm.main:type1;type2;type3;type4;"; 59 std::string ret = DeMangleName(name); 60 EXPECT_EQ(ret, "Asm.main"); 61 } 62 63 /** 64 * @tc.name: mangling_test_003 65 * @tc.desc: Verify the GetFunctionSignatureFromName function. 66 * @tc.type: FUNC 67 * @tc.require: issueNumber 68 */ 69 HWTEST_F(ManglingTest, mangling_test_003, TestSize.Level1) 70 { 71 std::vector<Function::Parameter> params; 72 panda::panda_file::SourceLang language {panda::panda_file::SourceLang::PANDA_ASSEMBLY}; 73 params.emplace_back(Type {"type1", 0}, language); 74 params.emplace_back(Type {"type2", 0}, language); 75 params.emplace_back(Type {"type3", 0}, language); 76 77 std::string name = "Asm.main"; 78 std::string ret = GetFunctionSignatureFromName(name, std::move(params)); 79 EXPECT_EQ(ret, "Asm.main:(type1,type2,type3)"); 80 } 81 82 /** 83 * @tc.name: mangling_test_004 84 * @tc.desc: Verify the GetFunctionNameFromSignature function. 85 * @tc.type: FUNC 86 * @tc.require: issueNumber 87 */ 88 HWTEST_F(ManglingTest, mangling_test_004, TestSize.Level1) 89 { 90 std::string name = "Asm.main:(type1,type2,type3,type4)"; 91 std::string ret = GetFunctionNameFromSignature(name); 92 IsSignatureOrMangled(ret); 93 EXPECT_EQ(ret, "Asm.main"); 94 } 95 }