Debian Codegraph @

test/unit/provider-by-default-constructor-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 "internal/injector-core.h"
24 #include "internal/provider-by-default-constructor.h"
25
26 #include <QtTest/QtTest>
27 #include <memory>
28
29 using namespace injeqt::v1;
30 using namespace injeqt::internal;
31
32 class default_constructor_type : public QObject
33 {
34 Q_OBJECT
35
36 public:
37 Q_INVOKABLE default_constructor_type() {}
38
39 };
40
41 class provider_by_default_constructor_test : public QObject
42 {
43 Q_OBJECT
44
45 private slots:
46 void should_return_always_the_same_object();
47
48 };
49
50 void provider_by_default_constructor_test::should_return_always_the_same_object()
51 {
52 auto empty_injector1 = injector_core{};
53 auto empty_injector2 = injector_core{};
54 auto c = make_default_constructor_method(make_type<default_constructor_type>());
55 auto p = std::unique_ptr<provider_by_default_constructor>{new provider_by_default_constructor{c}};
56
57 QCOMPARE(p->provided_type(), make_type<default_constructor_type>());
58 QCOMPARE(p->required_types(), types{});
59 QCOMPARE(p->constructor(), c);
60
61 auto o = p->provide(empty_injector1);
62 QCOMPARE(p->provide(empty_injector1), o);
63 QCOMPARE(p->provide(empty_injector2), o);
64 QCOMPARE(o->metaObject(), &default_constructor_type::staticMetaObject);
65 }
66
67 QTEST_APPLESS_MAIN(provider_by_default_constructor_test)
68 #include "provider-by-default-constructor-test.moc"