forked from avast/retdec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodule_tests.cpp
97 lines (77 loc) · 1.95 KB
/
module_tests.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/**
* @file tests/ctypes/module_tests.cpp
* @brief Tests for the @c module module.
* @copyright (c) 2017 Avast Software, licensed under the MIT license
*/
#include <memory>
#include <gtest/gtest.h>
#include "retdec/ctypes/context.h"
#include "retdec/ctypes/function.h"
#include "retdec/ctypes/integral_type.h"
#include "retdec/ctypes/module.h"
#include "retdec/ctypes/parameter.h"
using namespace ::testing;
namespace retdec {
namespace ctypes {
namespace tests {
class ModuleTests : public Test {
public:
ModuleTests():
context(std::make_shared<Context>()),
intType(IntegralType::create(context, "int", 32)),
f(Function::create(context, "f", intType, emptyParams)),
module(Module(context)) {}
protected:
std::shared_ptr<Context> context;
std::shared_ptr<Type> intType;
Function::Parameters emptyParams;
std::shared_ptr<Function> f;
Module module;
};
TEST_F(ModuleTests,
HasFunctionWithNameReturnsTrueWhenFunctionIsThere)
{
module.addFunction(f);
EXPECT_TRUE(module.hasFunctionWithName(f->getName()));
}
TEST_F(ModuleTests,
HasFunctionWithNameReturnsFalseWhenFunctionIsNotThere)
{
EXPECT_FALSE(module.hasFunctionWithName(f->getName()));
}
TEST_F(ModuleTests,
GetFunctionWithNameReturnsCorrectFunction)
{
module.addFunction(f);
EXPECT_EQ(f, module.getFunctionWithName(f->getName()));
}
TEST_F(ModuleTests,
GetFunctionWithNameReturnsNullWhenFunctionIsNotInModule)
{
EXPECT_EQ(nullptr, module.getFunctionWithName("someName"));
}
#if DEATH_TESTS_ENABLED
TEST_F(ModuleTests,
AddFunctionCrashesOnNull)
{
EXPECT_DEATH(
module.addFunction(nullptr),
"violated precondition - function cannot be null"
);
}
#endif
TEST_F(ModuleTests,
AddFunctionSuccessfullyAddsNewFunction)
{
module.addFunction(f);
EXPECT_TRUE(module.hasFunctionWithName(f->getName()));
}
TEST_F(ModuleTests,
GetContextReturnsCorrectContext)
{
auto module = Module(context);
EXPECT_EQ(context, module.getContext());
}
} // namespace tests
} // namespace ctypes
} // namespace retdec