Debian Codegraph @

test/unit/module-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 "../mocks/mocked-provider.h"
22 #include "expect.h"
23 #include "utils.h"
24
25 #include <injeqt/module.h>
26
27 #include <QtTest/QtTest>
28 #include <string>
29
30 using namespace injeqt::internal;
31 using namespace injeqt::v1;
32
33 class not_default_constructible_type : public QObject
34 {
35 Q_OBJECT
36 };
37
38 class not_default_constructible_type_subtype : public not_default_constructible_type
39 {
40 Q_OBJECT
41 };
42
43 class default_constructible_type : public QObject
44 {
45 Q_OBJECT
46 public:
47 Q_INVOKABLE default_constructible_type() {}
48 };
49
50 class factory_type : public QObject
51 {
52 Q_OBJECT
53 public:
54 Q_INVOKABLE default_constructible_type * create() const { return nullptr; }
55 };
56
57 class factory_subtype_type : public QObject
58 {
59 Q_OBJECT
60 public:
61 Q_INVOKABLE not_default_constructible_type_subtype * create() const { return nullptr; }
62 };
63
64 class factory_double_type : public QObject
65 {
66 Q_OBJECT
67 public:
68 Q_INVOKABLE not_default_constructible_type * create1() const { return nullptr; }
69 Q_INVOKABLE not_default_constructible_type * create2() const { return nullptr; }
70 };
71
72 class module_test : public QObject
73 {
74 Q_OBJECT
75
76 private slots:
77 void should_accept_empty_module();
78 void should_accept_null_ready_object();
79 void should_accept_qobject_ready_object();
80 void should_accept_valid_ready_object();
81 void should_accept_subtype_ready_object();
82 void should_accept_supertype_ready_object();
83 void should_accept_qobject_type();
84 void should_accept_not_default_constructible_type();
85 void should_accept_default_constructible_type();
86 void should_accept_qobject_factory_type();
87 void should_accept_qobject_created_type();
88 void should_accept_valid_factory_type();
89 void should_accept_supertype_factory_type();
90 void should_accept_subtype_factory_type();
91 void should_accept_double_factory_type();
92
93 };
94
95 void module_test::should_accept_empty_module()
96 {
97 class test_module : public module { };
98
99 test_module{};
100 }
101
102 void module_test::should_accept_null_ready_object()
103 {
104 class test_module : public module
105 {
106 public:
107 test_module()
108 {
109 add_ready_object<not_default_constructible_type>(nullptr);
110 }
111 };
112
113 test_module{};
114 }
115
116 void module_test::should_accept_qobject_ready_object()
117 {
118 class test_module : public module
119 {
120 public:
121 test_module()
122 {
123 not_default_constructible_type object;
124 add_ready_object<QObject>(&object);
125 }
126 };
127
128 test_module{};
129 }
130
131 void module_test::should_accept_valid_ready_object()
132 {
133 class test_module : public module
134 {
135 public:
136 test_module()
137 {
138 not_default_constructible_type object;
139 add_ready_object<not_default_constructible_type>(&object);
140 }
141 };
142
143 test_module{};
144 }
145
146 void module_test::should_accept_subtype_ready_object()
147 {
148 class test_module : public module
149 {
150 public:
151 test_module()
152 {
153 not_default_constructible_type_subtype object;
154 add_ready_object<not_default_constructible_type>(&object);
155 }
156 };
157
158 test_module{};
159 }
160
161 void module_test::should_accept_supertype_ready_object()
162 {
163 class test_module : public module
164 {
165 public:
166 test_module()
167 {
168 not_default_constructible_type object;
169 add_ready_object<not_default_constructible_type_subtype>(&object);
170 }
171 };
172
173 test_module{};
174 }
175
176 void module_test::should_accept_qobject_type()
177 {
178 class test_module : public module
179 {
180 public:
181 test_module()
182 {
183 add_type<QObject>();
184 }
185 };
186
187 test_module{};
188 }
189
190 void module_test::should_accept_not_default_constructible_type()
191 {
192 class test_module : public module
193 {
194 public:
195 test_module()
196 {
197 add_type<not_default_constructible_type>();
198 }
199 };
200
201 test_module{};
202 }
203
204 void module_test::should_accept_default_constructible_type()
205 {
206 class test_module : public module
207 {
208 public:
209 test_module()
210 {
211 add_type<default_constructible_type>();
212 }
213 };
214
215 test_module{};
216 }
217
218 void module_test::should_accept_qobject_factory_type()
219 {
220 class test_module : public module
221 {
222 public:
223 test_module()
224 {
225 add_factory<not_default_constructible_type, QObject>();
226 }
227 };
228
229 test_module{};
230 }
231
232 void module_test::should_accept_qobject_created_type()
233 {
234 class test_module : public module
235 {
236 public:
237 test_module()
238 {
239 add_factory<QObject, factory_type>();
240 }
241 };
242
243 test_module{};
244 }
245
246 void module_test::should_accept_valid_factory_type()
247 {
248 class test_module : public module
249 {
250 public:
251 test_module()
252 {
253 add_factory<not_default_constructible_type, factory_type>();
254 add_factory<not_default_constructible_type_subtype, factory_subtype_type>();
255 }
256 };
257
258 test_module{};
259 }
260
261 void module_test::should_accept_subtype_factory_type()
262 {
263 class test_module : public module
264 {
265 public:
266 test_module()
267 {
268 add_factory<not_default_constructible_type_subtype, factory_type>();
269 }
270 };
271
272 test_module{};
273 }
274
275 void module_test::should_accept_supertype_factory_type()
276 {
277 class test_module : public module
278 {
279 public:
280 test_module()
281 {
282 add_factory<not_default_constructible_type, factory_subtype_type>();
283 }
284 };
285
286 test_module{};
287 }
288
289 void module_test::should_accept_double_factory_type()
290 {
291 class test_module : public module
292 {
293 public:
294 test_module()
295 {
296 add_factory<not_default_constructible_type, factory_double_type>();
297 }
298 };
299
300 test_module{};
301 }
302
303 QTEST_APPLESS_MAIN(module_test)
304 #include "module-test.moc"