Debian Codegraph @

test/unit/provider-by-default-constructor-configuration-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
23 #include <injeqt/exception/default-constructor-not-found.h>
24 #include <injeqt/exception/qobject-type.h>
25
26 #include "internal/injector-core.h"
27 #include "internal/provider-by-default-constructor-configuration.h"
28
29 #include <QtTest/QtTest>
30 #include <memory>
31
32 using namespace injeqt::v1;
33 using namespace injeqt::internal;
34
35 class default_constructor_type : public QObject
36 {
37 Q_OBJECT
38
39 public:
40 Q_INVOKABLE default_constructor_type() {}
41
42 };
43
44 class not_default_constructor_type : public QObject
45 {
46 Q_OBJECT
47 };
48
49 class provider_by_default_constructor_configuration_test : public QObject
50 {
51 Q_OBJECT
52
53 private slots:
54 void should_accept_qobject_type_and_throw_on_create();
55 void should_accept_type_without_default_constructor_and_throw_on_create();
56 void should_accept_valid_configuration();
57
58 };
59
60 void provider_by_default_constructor_configuration_test::should_accept_qobject_type_and_throw_on_create()
61 {
62 auto pc = provider_by_default_constructor_configuration{make_type<QObject>()};
63
64 expect<exception::qobject_type>([&](){
65 pc.create_provider({});
66 });
67 }
68
69 void provider_by_default_constructor_configuration_test::should_accept_type_without_default_constructor_and_throw_on_create()
70 {
71 auto pc = provider_by_default_constructor_configuration{make_type<not_default_constructor_type>()};
72
73 expect<exception::default_constructor_not_found>([&](){
74 pc.create_provider({});
75 });
76 }
77
78 void provider_by_default_constructor_configuration_test::should_accept_valid_configuration()
79 {
80 auto i = injector_core{};
81 auto pc = provider_by_default_constructor_configuration{make_type<default_constructor_type>()};
82 auto p = pc.create_provider({});
83
84 QVERIFY(nullptr != p->provide(i));
85 }
86
87 QTEST_APPLESS_MAIN(provider_by_default_constructor_configuration_test)
88 #include "provider-by-default-constructor-configuration-test.moc"