| 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-ready.h" |
| 25 | |
| 26 | #include <QtTest/QtTest> |
| 27 | #include <memory> |
| 28 | |
| 29 | using namespace injeqt::v1; |
| 30 | using namespace injeqt::internal; |
| 31 | |
| 32 | class ready_type : public QObject |
| 33 | { |
| 34 | Q_OBJECT |
| 35 | }; |
| 36 | |
| 37 | class provider_ready_test : public QObject |
| 38 | { |
| 39 | Q_OBJECT |
| 40 | |
| 41 | private slots: |
| 42 | void should_return_always_the_same_object(); |
| 43 | |
| 44 | }; |
| 45 | |
| 46 | void provider_ready_test::should_return_always_the_same_object() |
| 47 | { |
| 48 | auto empty_injector1 = injector_core{}; |
| 49 | auto empty_injector2 = injector_core{}; |
| 50 | auto object = std::unique_ptr<QObject>(new ready_type()); |
| 51 | auto i = implementation{make_type<ready_type>(), object.get()}; |
| 52 | auto p = provider_ready{i}; |
| 53 | |
| 54 | QCOMPARE(p.provided_type(), make_type<ready_type>()); |
| 55 | QCOMPARE(p.required_types(), types{}); |
| 56 | QCOMPARE(p.ready_implementation(), i); |
| 57 | |
| 58 | QCOMPARE(p.provide(empty_injector1), object.get()); |
| 59 | QCOMPARE(p.provide(empty_injector2), object.get()); |
| 60 | } |
| 61 | |
| 62 | QTEST_APPLESS_MAIN(provider_ready_test) |
| 63 | #include "provider-ready-test.moc" |