Debian Codegraph @

test/unit/provider-by-factory-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"cxx . . $ `<file>/test/unit/expect.h`/
22
23 #include <injeqt/exception/instantiation-failed.h>cxx . . $ `<file>/include/injeqt/exception/instantiation-failed.h`/
24 #include <injeqt/module.h>cxx . . $ `<file>/include/injeqt/module.h`/
25
26 #include "internal/factory-method.h"cxx . . $ `<file>/src/internal/factory-method.h`/
27 #include "internal/injector-core.h"cxx . . $ `<file>/src/internal/injector-core.h`/
28 #include "internal/provider-by-default-constructor.h"cxx . . $ `<file>/src/internal/provider-by-default-constructor.h`/
29 #include "internal/provider-by-factory.h"cxx . . $ `<file>/src/internal/provider-by-factory.h`/
30 #include "internal/types-by-name.h"cxx . . $ `<file>/src/internal/types-by-name.h`/
31
32 #include <QtTest/QtTest>
33 #include <memory>
34
35 using namespace injeqtcxx . . $ injeqt/::v1;
36 using namespace injeqtcxx . . $ injeqt/::internal;
37
38 class by_factory_typecxx . . $ by_factory_type# : public QObjectcxx . . $ QObject#
39 {
40 Q_OBJECTcxx . . $ `<external>/1208926524888476972/qobjectdefs.h:170:9`!
41
42 public:
43 Q_INVOKABLEcxx . . $ `<external>/1208926524888476972/qobjectdefs.h:124:9`! by_factory_typecxx . . $ by_factory_type#by_factory_type(49f6e7a06ebc5aa8).() {}
44
45 };
46
47 class factory_typecxx . . $ factory_type# : public QObjectcxx . . $ QObject#
48 {
49 Q_OBJECTcxx . . $ `<external>/1208926524888476972/qobjectdefs.h:170:9`!
50
51 public:
52 Q_INVOKABLEcxx . . $ `<external>/1208926524888476972/qobjectdefs.h:124:9`! factory_typecxx . . $ factory_type#factory_type(49f6e7a06ebc5aa8).() {}
53 Q_INVOKABLEcxx . . $ `<external>/1208926524888476972/qobjectdefs.h:124:9`! by_factory_typecxx . . $ by_factory_type# * createcxx . . $ factory_type#create(9776810f04e81099).() { return new by_factory_typecxx . . $ by_factory_type#{}; }
54
55 };
56
57 class invalid_factory_typecxx . . $ invalid_factory_type# : public QObjectcxx . . $ QObject#
58 {
59 Q_OBJECTcxx . . $ `<external>/1208926524888476972/qobjectdefs.h:170:9`!
60
61 public:
62 Q_INVOKABLEcxx . . $ `<external>/1208926524888476972/qobjectdefs.h:124:9`! invalid_factory_typecxx . . $ invalid_factory_type#invalid_factory_type(49f6e7a06ebc5aa8).() {}
63 Q_INVOKABLEcxx . . $ `<external>/1208926524888476972/qobjectdefs.h:124:9`! by_factory_typecxx . . $ by_factory_type# * createcxx . . $ invalid_factory_type#create(9776810f04e81099).() { return nullptr; }
64
65 };
66
67 class factory_modulecxx . . $ factory_module# : public modulecxx . . $ injeqt/v1/module#
68 {
69
70 public:
71 factory_modulecxx . . $ factory_module#factory_module(49f6e7a06ebc5aa8).() { add_typecxx . . $ injeqt/v1/module#add_type(49f6e7a06ebc5aa8).<factory_typecxx . . $ factory_type#>(); }
72 virtual ~cxx . . $ factory_module#`~factory_module`(49f6e7a06ebc5aa8).factory_modulecxx . . $ factory_module#() {}
73
74 };
75
76 class provider_by_factory_testcxx . . $ provider_by_factory_test# : public QObjectcxx . . $ QObject#
77 {
78 Q_OBJECTcxx . . $ `<external>/1208926524888476972/qobjectdefs.h:170:9`!
79
80 public:
81 provider_by_factory_testcxx . . $ provider_by_factory_test#provider_by_factory_test(49f6e7a06ebc5aa8).();
82
83 private slotscxx . . $ `<external>/1208926524888476972/qobjectdefs.h:88:14`!:
84 void should_return_always_the_same_objectcxx . . $ provider_by_factory_test#should_return_always_the_same_object(49f6e7a06ebc5aa8).();
85 void should_throw_instantiation_failed_when_invalid_factorycxx . . $ provider_by_factory_test#should_throw_instantiation_failed_when_invalid_factory(49f6e7a06ebc5aa8).();
86
87 private:
88 types_by_namecxx . . $ injeqt/internal/types_by_name# known_typescxx . . $ provider_by_factory_test#known_types.;
89
90 };
91
92 provider_by_factory_testcxx . . $ provider_by_factory_test#::provider_by_factory_testcxx . . $ provider_by_factory_test#provider_by_factory_test(49f6e7a06ebc5aa8).()
93 {
94 known_typescxx . . $ provider_by_factory_test#known_types. =cxx . . $ injeqt/internal/sorted_unique_vector#`operator=`(21c4a51877e06114). types_by_namecxx . . $ injeqt/internal/sorted_unique_vector#sorted_unique_vector(26e8deb829554aa).{stdcxx . . $ std/vector#vector(b1ea180184b47f03).::vectorcxx . . $ std/vector#<typecxx . . $ injeqt/v1/type#>{
95 make_typecxx . . $ injeqt/v1/make_type(10a1ed948a80d481).<by_factory_typecxx . . $ by_factory_type#>(),
96 make_typecxx . . $ injeqt/v1/make_type(10a1ed948a80d481).<factory_typecxx . . $ factory_type#>(),
97 make_typecxx . . $ injeqt/v1/make_type(10a1ed948a80d481).<invalid_factory_typecxx . . $ invalid_factory_type#>()
98 }};
99 }
100
101 void provider_by_factory_testcxx . . $ provider_by_factory_test#::should_return_always_the_same_objectcxx . . $ provider_by_factory_test#should_return_always_the_same_object(49f6e7a06ebc5aa8).()
102 {
103 auto fm = make_factory_methodcxx . . $ injeqt/internal/make_factory_method(de794affec8a70ca).(known_typescxx . . $ provider_by_factory_test#known_types., make_typecxx . . $ injeqt/v1/make_type(10a1ed948a80d481).<by_factory_typecxx . . $ by_factory_type#>(), make_typecxx . . $ injeqt/v1/make_type(10a1ed948a80d481).<factory_typecxx . . $ factory_type#>());
104 auto fp = stdcxx . . $ std/unique_ptr#unique_ptr(d6762fce684538e4).::unique_ptrcxx . . $ std/unique_ptr#<provider_by_factorycxx . . $ injeqt/internal/provider_by_factory#>{new provider_by_factorycxx . . $ injeqt/internal/provider_by_factory#{fm}};
105 auto p = fp.getcxx . . $ std/unique_ptr#get(ca399b2b6292c808).();
106
107 auto configuration = stdcxx . . $ std/vector#vector(b1ea180184b47f03).::vectorcxx . . $ std/vector#<stdcxx . . $ std/::unique_ptrcxx . . $ std/unique_ptr#<providercxx . . $ injeqt/internal/provider#>>{};
108 configuration.emplace_backcxx . . $ std/vector#emplace_back(b3d147e3bb711c35).(stdcxx . . $ std/::movecxx . . $ std/move(e7c6c0c8363dcc46).(fp));
109 configuration.emplace_backcxx . . $ std/vector#emplace_back(b3d147e3bb711c35).(stdcxx . . $ std/unique_ptr#unique_ptr(57bc6b0441bf5294).::unique_ptrcxx . . $ std/unique_ptr#<provider_by_default_constructorcxx . . $ injeqt/internal/provider_by_default_constructor#>{new provider_by_default_constructorcxx . . $ injeqt/internal/provider_by_default_constructor#{make_default_constructor_methodcxx . . $ injeqt/internal/make_default_constructor_method(84114e33f83ca37c).(make_typecxx . . $ injeqt/v1/make_type(10a1ed948a80d481).<factory_typecxx . . $ factory_type#>())}});
110 auto injector = injector_corecxx . . $ injeqt/internal/injector_core#injector_core(528a6fa5a342ea28).{types_by_namecxx . . $ injeqt/internal/sorted_unique_vector#sorted_unique_vector(49f6e7a06ebc5aa8).{}, stdcxx . . $ std/::movecxx . . $ std/move(e7c6c0c8363dcc46).(configuration)};
111
112 QCOMPAREcxx . . $ `<external>/8602788698586413231/qtestcase.h:86:9`!(p->provided_type(), make_type<by_factory_type>());
113 QCOMPAREcxx . . $ `<external>/8602788698586413231/qtestcase.h:86:9`!(p->required_types(), types{make_type<factory_type>()});
114 QCOMPAREcxx . . $ `<external>/8602788698586413231/qtestcase.h:86:9`!(p->factory(), fm);
115
116 auto o = p->providecxx . . $ injeqt/internal/provider_by_factory#provide(51123600412ca135).(injector);
117 QCOMPAREcxx . . $ `<external>/8602788698586413231/qtestcase.h:86:9`!(p->provide(injector), o);
118 QCOMPAREcxx . . $ `<external>/8602788698586413231/qtestcase.h:86:9`!(p->provide(injector), o);
119 QCOMPAREcxx . . $ `<external>/8602788698586413231/qtestcase.h:86:9`!(o->metaObject(), &by_factory_type::staticMetaObject);
120 }
121
122 void provider_by_factory_testcxx . . $ provider_by_factory_test#::should_throw_instantiation_failed_when_invalid_factorycxx . . $ provider_by_factory_test#should_throw_instantiation_failed_when_invalid_factory(49f6e7a06ebc5aa8).()
123 {
124 auto fm = make_factory_methodcxx . . $ injeqt/internal/make_factory_method(de794affec8a70ca).(known_typescxx . . $ provider_by_factory_test#known_types., make_typecxx . . $ injeqt/v1/make_type(10a1ed948a80d481).<by_factory_typecxx . . $ by_factory_type#>(), make_typecxx . . $ injeqt/v1/make_type(10a1ed948a80d481).<invalid_factory_typecxx . . $ invalid_factory_type#>());
125 auto fp = stdcxx . . $ std/unique_ptr#unique_ptr(d6762fce684538e4).::unique_ptrcxx . . $ std/unique_ptr#<provider_by_factorycxx . . $ injeqt/internal/provider_by_factory#>{new provider_by_factorycxx . . $ injeqt/internal/provider_by_factory#{fm}};
126 auto p = fp.getcxx . . $ std/unique_ptr#get(ca399b2b6292c808).();
127
128 auto configuration = stdcxx . . $ std/vector#vector(b1ea180184b47f03).::vectorcxx . . $ std/vector#<stdcxx . . $ std/::unique_ptrcxx . . $ std/unique_ptr#<providercxx . . $ injeqt/internal/provider#>>{};
129 configuration.emplace_backcxx . . $ std/vector#emplace_back(b3d147e3bb711c35).(stdcxx . . $ std/::movecxx . . $ std/move(e7c6c0c8363dcc46).(fp));
130 configuration.emplace_backcxx . . $ std/vector#emplace_back(b3d147e3bb711c35).(stdcxx . . $ std/unique_ptr#unique_ptr(57bc6b0441bf5294).::unique_ptrcxx . . $ std/unique_ptr#<provider_by_default_constructorcxx . . $ injeqt/internal/provider_by_default_constructor#>{new provider_by_default_constructorcxx . . $ injeqt/internal/provider_by_default_constructor#{make_default_constructor_methodcxx . . $ injeqt/internal/make_default_constructor_method(84114e33f83ca37c).(make_typecxx . . $ injeqt/v1/make_type(10a1ed948a80d481).<invalid_factory_typecxx . . $ invalid_factory_type#>())}});
131 auto injector = injector_corecxx . . $ injeqt/internal/injector_core#injector_core(528a6fa5a342ea28).{types_by_namecxx . . $ injeqt/internal/sorted_unique_vector#sorted_unique_vector(49f6e7a06ebc5aa8).{}, stdcxx . . $ std/::movecxx . . $ std/move(e7c6c0c8363dcc46).(configuration)};
132
133 QCOMPAREcxx . . $ `<external>/8602788698586413231/qtestcase.h:86:9`!(p->provided_type(), make_type<by_factory_type>());
134 QCOMPAREcxx . . $ `<external>/8602788698586413231/qtestcase.h:86:9`!(p->required_types(), types{make_type<invalid_factory_type>()});
135 QCOMPAREcxx . . $ `<external>/8602788698586413231/qtestcase.h:86:9`!(p->factory(), fm);
136
137 expectcxx . . $ expect(d99b926da2bbc072).<exceptioncxx . . $ injeqt/v1/exception/::instantiation_failedcxx . . $ injeqt/v1/exception/instantiation_failed#>({cxx . . $ std/vector#vector(9619226211e5a241)."by_factory_type"}, [cxx . . $ std/function#function(a4b4b0c4acad1616).&](){
138 p->providecxx . . $ injeqt/internal/provider_by_factory#provide(51123600412ca135).(injector);
139 });
140 }
141
142 QTEST_APPLESS_MAINcxx . . $ `<external>/4204159469433502174/qtest.h:442:9`!(provider_by_factory_test)
143 #include "provider-by-factory-test.moc"cxx . . $ `<file>/build/test/provider-by-factory-test_autogen/include/provider-by-factory-test.moc`/