forked from Ericsson/CodeCompass
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcpppropertiesservicetest.cpp
More file actions
145 lines (116 loc) · 3.68 KB
/
cpppropertiesservicetest.cpp
File metadata and controls
145 lines (116 loc) · 3.68 KB
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#define GTEST_HAS_TR1_TUPLE 1
#define GTEST_USE_OWN_TR1_TUPLE 0
#include <gtest/gtest.h>
#include <service/cppservice.h>
#include <util/dbutil.h>
#include <util/logutil.h>
#include "servicehelper.h"
using namespace cc;
class CppPropertiesServiceTest : public ::testing::Test
{
public:
CppPropertiesServiceTest() :
_db(cc::util::connectDatabase(dbConnectionString)),
_transaction(_db),
_cppservice(new CppServiceHandler(
_db,
std::make_shared<std::string>(""),
cc::webserver::ServerContext(std::string(),
boost::program_options::variables_map()))),
_helper(_db, _cppservice)
{
_simpleClassHeader = _helper.getFileId("simpleclass.h");
_simpleClassSrc = _helper.getFileId("simpleclass.cpp");
_nestedClassHeader = _helper.getFileId("nestedclass.h");
_nestedClassSrc = _helper.getFileId("nestedclass.cpp");
_inheritanceClassHeader = _helper.getFileId("inheritance.h");
_inheritanceClassSrc = _helper.getFileId("inheritance.cpp");
}
void checkProperties(model::FileId fid_, int line_, int col_,
std::map<std::string, std::string>& expectedLines_)
{
std::map<std::string, std::string> props;
AstNodeInfo anFrom = _helper.getAstNodeInfoByPos(line_, col_, fid_);
_transaction([&, this]()
{
_cppservice->getProperties(props, anFrom.id);
});
if (props.size() < expectedLines_.size())
LOG(debug) << "Position: " << line_ << ":" << col_;
EXPECT_LE(expectedLines_.size(), props.size());
for (const auto& prop : props)
{
if (expectedLines_[prop.first] != prop.second)
LOG(error)
<< "AstNode properties " << prop.first
<< " doesn't match. Expected value is: " << expectedLines_[prop.first]
<< ". Current value is: " << prop.second << "!";
EXPECT_EQ(expectedLines_[prop.first], prop.second);
}
}
protected:
std::shared_ptr<odb::database> _db;
cc::util::OdbTransaction _transaction;
std::shared_ptr<CppServiceHandler> _cppservice;
cc::service::test::ServiceHelper _helper;
model::FileId _simpleClassHeader;
model::FileId _simpleClassSrc;
model::FileId _nestedClassHeader;
model::FileId _nestedClassSrc;
model::FileId _inheritanceClassHeader;
model::FileId _inheritanceClassSrc;
};
TEST_F(CppPropertiesServiceTest, ClassPropertiesTest)
{
{
std::map<std::string, std::string> expected =
{
{"Name", "SimpleClass"},
{"Context", "Namespace"},
{"Qualified name", "cc::test::SimpleClass"}
};
checkProperties(_simpleClassHeader, 9, 10, expected);
}
{
std::map<std::string, std::string> expected =
{
{"Name", "NestedClass"},
{"Context", "Namespace"},
{"Qualified name", "cc::test::NestedClass"},
{"POD type", "true"}
};
checkProperties(_nestedClassHeader, 9, 10, expected);
}
{
std::map<std::string, std::string> expected =
{
{"Name", "InnerClass"},
{"Context", "Record"},
{"Qualified name", "cc::test::NestedClass::InnerClass"},
{"POD type", "true"}
};
checkProperties(_nestedClassHeader, 13, 15, expected);
}
}
TEST_F(CppPropertiesServiceTest, InheritancePropertiesTest)
{
{
std::map<std::string, std::string> expected =
{
{"Name", "BaseClass1"},
{"Context", "Namespace"},
{"Qualified name", "cc::test::BaseClass1"},
{"Abstract type", "true"}
};
checkProperties(_inheritanceClassHeader, 9, 10, expected);
}
{
std::map<std::string, std::string> expected =
{
{"Name", "DerivedClass"},
{"Context", "Namespace"},
{"Qualified name", "cc::test::DerivedClass"}
};
checkProperties(_inheritanceClassHeader, 31, 15, expected);
}
}