• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include <cstdlib>
17 #include <filesystem>
18 #include <gtest/gtest.h>
19 #include <iostream>
20 #include <string>
21 
22 #include "disassembler.h"
23 
24 using namespace testing::ext;
25 namespace panda::disasm {
26 
27 static const std::string SOURCE_FILE_PATH = GRAPH_TEST_ABC_DIR "line-number1.abc";
28 static const std::string FILE_NAME = "line-number1.abc";
29 static const std::string CHECK_MESSAGE = "# source binary: " + FILE_NAME;
30 
31 class DisassemblerGetFileNameTest : public testing::Test {
32 public:
SetUpTestCase(void)33     static void SetUpTestCase(void)
34     {
35         std::filesystem::path file_name{ FILE_NAME };
36         std::filesystem::path src_file_name{ SOURCE_FILE_PATH };
37     };
38 
TearDownTestCase(void)39     static void TearDownTestCase(void) {};
40 
SetUp()41     void SetUp() {};
TearDown()42     void TearDown() {};
43 
Find(std::stringstream & ss,const std::string & dst)44     bool Find(std::stringstream &ss, const std::string &dst)
45     {
46         return ss.str().find(dst) != std::string::npos;
47     }
48 };
49 
50 /**
51 * @tc.name: disassembler_getfilename_test_001
52 * @tc.desc: test disasm with relative path.
53 * @tc.type: FUNC
54 * @tc.require: file path and name
55 */
56 HWTEST_F(DisassemblerGetFileNameTest, disassembler_getfilename_test_001, TestSize.Level1)
57 {
58     panda::disasm::Disassembler disasm {};
59     disasm.Disassemble(SOURCE_FILE_PATH, false, false);
60     std::stringstream ss {};
61     disasm.Serialize(ss);
62     EXPECT_TRUE(Find(ss, CHECK_MESSAGE));
63 }
64 
65 /**
66 * @tc.name: disassembler_getfilename_test_003
67 * @tc.desc: test disasm with absolute path.
68 * @tc.type: FUNC
69 * @tc.require: file path and name
70 */
71 HWTEST_F(DisassemblerGetFileNameTest, disassembler_getfilename_test_003, TestSize.Level1)
72 {
73     panda::disasm::Disassembler disasm {};
74     disasm.Disassemble(std::filesystem::absolute(SOURCE_FILE_PATH).u8string(), false, false);
75     std::stringstream ss {};
76     disasm.Serialize(ss);
77     EXPECT_TRUE(Find(ss, CHECK_MESSAGE));
78 }
79 };
80