File tree Expand file tree Collapse file tree 3 files changed +230
-1
lines changed
Expand file tree Collapse file tree 3 files changed +230
-1
lines changed Original file line number Diff line number Diff line change @@ -5,4 +5,5 @@ add_library(CppMetricsTestProject STATIC
55 functionmccabe.cpp
66 typemccabe.cpp
77 lackofcohesion.cpp
8- bumpyroad.cpp)
8+ bumpyroad.cpp
9+ afferentcoupling.cpp)
Original file line number Diff line number Diff line change 1+ #include < memory>
2+ #include < vector>
3+
4+ // Member types
5+ class A {};
6+ class A_D {
7+ A a;
8+ };
9+
10+ class A2 {};
11+ class A2_D {
12+ A2* a2;
13+ };
14+
15+ class A3 {};
16+ class A3_D {
17+ A3& a3;
18+ };
19+
20+ class A4 {};
21+ class A4_D {
22+ std::vector<A4> a4_vec;
23+ };
24+
25+ class A5 {};
26+ class A5_D {
27+ std::unique_ptr<A5> a5_ptr;
28+ };
29+ // ==========
30+
31+ // Function parameters
32+ class B {};
33+ class B_D {
34+ void foo (B b);
35+ };
36+
37+ class B2 {};
38+ class B2_D {
39+ void foo (B2* b);
40+ };
41+
42+ class B3 {};
43+ class B3_D {
44+ void foo (B3& b);
45+ };
46+
47+ class B4 {};
48+ class B4_D {
49+ void foo (std::vector<B4>& b4_vec);
50+ };
51+
52+ class B5 {};
53+ class B5_D {
54+ void foo (std::unique_ptr<B5>& b5_ptr);
55+ };
56+
57+ class B6 {};
58+ class B6_D {
59+ void foo (int , bool , B6* b);
60+ };
61+
62+ class B7 {};
63+ class B7_D {
64+ void foo (int , bool , B7* b);
65+ };
66+
67+ class B8 {};
68+ class B8_D {
69+ void foo (int , bool );
70+ void foo (int , bool , B8* b);
71+ };
72+ // ==========
73+
74+ // Function local variables
75+ class C {};
76+ class C_D {
77+ void foo ()
78+ {
79+ C c;
80+ }
81+ };
82+
83+ class C2 {};
84+ class C2_D {
85+ void foo ()
86+ {
87+ auto c2 = C2 ();
88+ }
89+ };
90+
91+ class C3 {};
92+ class C3_D {
93+ void foo ()
94+ {
95+ std::vector<C3> c3_vec;
96+ }
97+ };
98+ // ==========
99+
100+ // Out-of-class member functions
101+ class D {};
102+ class D_D {
103+ void foo ();
104+ };
105+
106+ void D_D::foo ()
107+ {
108+ D d;
109+ }
110+
111+ class D2 {};
112+ class D2_D {
113+ void foo ();
114+ };
115+
116+ void D2_D::foo ()
117+ {
118+ std::unique_ptr<D2> d2_ptr;
119+ }
120+ // ==========
121+
122+ // Multiple usage of the same type
123+ class E {};
124+ class E_D {
125+ E* e;
126+
127+ void foo ()
128+ {
129+ E e;
130+ }
131+
132+ void bar (std::vector<E> e_vec);
133+ };
134+ // ==========
135+
136+ // Inheritance
137+ class F {};
138+ class F_D : public F {};
139+ // ==========
140+
141+ // Multi inheritance
142+ class G {};
143+ class G_C {};
144+ class G_D : public G_C , public G {};
145+ // ==========
146+
147+ // Multiple dependant types
148+ class H {};
149+ class H_D1 {
150+ H h;
151+ };
152+
153+ class H_D2 {
154+ void foo ()
155+ {
156+ std::vector<H> h_vec;
157+ }
158+ };
159+
160+ // ----------
161+
162+ class H2 {};
163+ class H2_D1 {
164+ H2 h2;
165+ void bar (std::unique_ptr<H2> h2_ptr);
166+ };
167+
168+ class H2_D2 {
169+ H2* h2_ptr;
170+
171+ void foo ()
172+ {
173+ std::vector<H2> h2_vec;
174+ }
175+ };
176+ // ==========
Original file line number Diff line number Diff line change @@ -268,3 +268,55 @@ INSTANTIATE_TEST_SUITE_P(
268268 ParameterizedLackOfCohesionTest,
269269 ::testing::ValuesIn (paramLackOfCohesion)
270270);
271+
272+ // Afferent coupling
273+
274+ typedef std::pair<std::string, unsigned int > AfferentParam;
275+ class ParameterizedAfferentCouplingTest
276+ : public CppMetricsParserTest,
277+ public ::testing::WithParamInterface<AfferentParam>
278+ {};
279+
280+ std::vector<AfferentParam> paramAfferent = {
281+ {" A" , 1 },
282+ {" A2" , 1 },
283+ {" A3" , 1 },
284+ {" A4" , 1 },
285+ {" A5" , 1 },
286+ {" B" , 1 },
287+ {" B2" , 1 },
288+ {" B3" , 1 },
289+ {" B4" , 1 },
290+ {" B5" , 1 },
291+ {" B6" , 1 },
292+ {" B7" , 1 },
293+ {" B8" , 1 },
294+ {" C" , 1 },
295+ {" C2" , 1 },
296+ {" C3" , 1 },
297+ {" E" , 1 },
298+ {" F" , 1 },
299+ {" G" , 1 },
300+ {" H" , 2 },
301+ {" H2" , 2 },
302+ };
303+
304+ TEST_P (ParameterizedAfferentCouplingTest, TypeAfferentTest) {
305+ _transaction ([&, this ]() {
306+
307+ const auto record = _db->query_value <model::CppRecord>(
308+ odb::query<model::CppRecord>::qualifiedName == GetParam ().first );
309+
310+ const auto metric = _db->query_value <model::CppAstNodeMetrics>(
311+ odb::query<model::CppAstNodeMetrics>::astNodeId == record.astNodeId &&
312+ odb::query<model::CppAstNodeMetrics>::type == model::CppAstNodeMetrics::AFFERENT_TYPE);
313+
314+ EXPECT_EQ (GetParam ().second , metric.value );
315+ });
316+ }
317+
318+ INSTANTIATE_TEST_SUITE_P (
319+ ParameterizedAfferentCouplingTestSuite,
320+ ParameterizedAfferentCouplingTest,
321+ ::testing::ValuesIn (paramAfferent)
322+ );
You can’t perform that action at this time.
0 commit comments