Debian Codegraph @

test/integration/default-constructor-behavior-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 <injeqt/injector.h>
22 #include <injeqt/module.h>
23
24 #include <QtTest/QtTest>
25
26 class int_container : public QObject
27 {
28 Q_OBJECT
29
30 public:
31 int_container() {}
32 virtual ~int_container() {}
33 virtual int value() const = 0;
34
35 };
36
37 class nine_container : public int_container
38 {
39 Q_OBJECT
40
41 public:
42 Q_INVOKABLE nine_container() {}
43 virtual ~nine_container() {}
44 virtual int value() const override { return 9; }
45
46 };
47
48 class base_int_service : public QObject
49 {
50 Q_OBJECT
51
52 public:
53 Q_INVOKABLE base_int_service() {}
54 int value() const { return _int_container->value(); }
55
56 private slots:
57 INJEQT_SET void set_int_container(int_container *container)
58 {
59 _int_container = container;
60 }
61
62 private:
63 QPointer<int_container> _int_container;
64
65 };
66
67 class int_service : public base_int_service
68 {
69 Q_OBJECT
70
71 public:
72 Q_INVOKABLE int_service() {}
73
74 };
75
76 class default_constructor_behavior_test : public QObject
77 {
78 Q_OBJECT
79
80 private slots:
81 void should_create_proper_object_structure();
82
83 };
84
85 void default_constructor_behavior_test::should_create_proper_object_structure()
86 {
87 class m : public injeqt::module
88 {
89 public:
90 m()
91 {
92 add_type<int_service>();
93 add_type<nine_container>();
94 }
95 virtual ~m() {}
96 };
97
98 auto modules = std::vector<std::unique_ptr<injeqt::module>>{};
99 modules.emplace_back(std::unique_ptr<m>{new m{}});
100 auto injector = injeqt::injector{std::move(modules)};
101 auto service = injector.get<int_service>();
102 QCOMPARE(9, service->value());
103 }
104
105 QTEST_APPLESS_MAIN(default_constructor_behavior_test)
106 #include "default-constructor-behavior-test.moc"