Debian Codegraph @

test/unit/type-role-test.cpp

raw symbols SCIP
1 /*
2 * %injeqt copyright begin%
3 * Copyright 2014 Rafał Malinowski ([email protected])
4 * %injeqt copyright end%
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #include "expect.h"
22 #include "utils.h"
23
24 #include "internal/type-role.h"
25
26 #include <QtTest/QtTest>
27 #include <string>
28
29 using namespace injeqt::internal;
30 using namespace injeqt::v1;
31
32 #define ROLE_1 "role1"
33 #define ROLE_2 "role2"
34
35 class no_role_type : public QObject
36 {
37 Q_OBJECT
38 };
39
40 class role_1_type : public no_role_type
41 {
42 Q_OBJECT
43 INJEQT_TYPE_ROLE(ROLE_1)
44 };
45
46 class role_1_inherited_type : public role_1_type
47 {
48 Q_OBJECT
49 };
50
51 class role_1_double_type : public no_role_type
52 {
53 Q_OBJECT
54 INJEQT_TYPE_ROLE(ROLE_1)
55 INJEQT_TYPE_ROLE(ROLE_1)
56 };
57
58 class role_2_inherited_from_role_1_type : public role_1_type
59 {
60 Q_OBJECT
61 INJEQT_TYPE_ROLE(ROLE_2)
62 };
63
64 class role_1_and_2_type : public no_role_type
65 {
66 Q_OBJECT
67 INJEQT_TYPE_ROLE(ROLE_1)
68 INJEQT_TYPE_ROLE(ROLE_2)
69 };
70
71 class type_role_test : public QObject
72 {
73 Q_OBJECT
74
75 private slots:
76 void should_have_no_role_by_default();
77 void should_have_one_role_when_directly_declared();
78 void should_have_one_role_when_declared_in_supertype();
79 void should_have_one_role_when_declared_twice();
80 void should_have_two_roles_when_added_in_subtype();
81 void should_have_two_roles_when_directly_declared();
82
83 };
84
85 void type_role_test::should_have_no_role_by_default()
86 {
87 QVERIFY(!has_type_role<no_role_type>(ROLE_1));
88 QVERIFY(!has_type_role<no_role_type>(ROLE_2));
89 }
90
91 void type_role_test::should_have_one_role_when_directly_declared()
92 {
93 QVERIFY(has_type_role<role_1_type>(ROLE_1));
94 QVERIFY(!has_type_role<role_1_type>(ROLE_2));
95 }
96
97 void type_role_test::should_have_one_role_when_declared_in_supertype()
98 {
99 QVERIFY(has_type_role<role_1_inherited_type>(ROLE_1));
100 QVERIFY(!has_type_role<role_1_inherited_type>(ROLE_2));
101 }
102
103 void type_role_test::should_have_one_role_when_declared_twice()
104 {
105 QVERIFY(has_type_role<role_1_double_type>(ROLE_1));
106 QVERIFY(!has_type_role<role_1_double_type>(ROLE_2));
107 }
108
109 void type_role_test::should_have_two_roles_when_added_in_subtype()
110 {
111 QVERIFY(has_type_role<role_2_inherited_from_role_1_type>(ROLE_1));
112 QVERIFY(has_type_role<role_2_inherited_from_role_1_type>(ROLE_2));
113 }
114
115 void type_role_test::should_have_two_roles_when_directly_declared()
116 {
117 QVERIFY(has_type_role<role_1_and_2_type>(ROLE_1));
118 QVERIFY(has_type_role<role_1_and_2_type>(ROLE_2));
119 }
120
121 QTEST_APPLESS_MAIN(type_role_test)
122 #include "type-role-test.moc"