• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2021-2022 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 <iostream>
17#include <string>
18
19#include <gtest/gtest.h>
20#include "disassembler.h"
21
22using namespace panda::disasm;
23
24#cmakedefine DISASM_BIN_DIR "@DISASM_BIN_DIR@/"
25
26TEST(functions_test, empty_function)
27{
28    Disassembler d {};
29
30    std::stringstream ss {};
31    d.Disassemble(std::string(DISASM_BIN_DIR) + "empty_function.bc");
32    d.Serialize(ss, false);
33
34    ASSERT_TRUE(ss.str().find(".function void A(i32 a0) <static> {\n}") != std::string::npos);
35}
36
37TEST(functions_test, overloading_tests_1)
38{
39    Disassembler d {};
40
41    std::stringstream ss {};
42    d.Disassemble(std::string(DISASM_BIN_DIR) + "overloading.bc");
43    d.Serialize(ss, false);
44
45    ASSERT_NE(ss.str().find(".function void f() <static> {\n}"), std::string::npos);
46    ASSERT_NE(ss.str().find(".function void f(u1 a0, i8 a1) <static> {\n}"), std::string::npos);
47    ASSERT_NE(ss.str().find(".function void f(u1 a0) <static> {\n}"), std::string::npos);
48    ASSERT_NE(ss.str().find("call.short f:()\n\t"
49                            "call.short f:(u1), v1\n\t"
50                            "call.short f:(u1,i8), v1, v1"),
51              std::string::npos);
52}
53
54#undef DISASM_BIN_DIR
55