/* * %injeqt copyright begin% * Copyright 2016 RafaƂ Malinowski (rafal.przemyslaw.malinowski@gmail.com) * %injeqt copyright end% * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include #include #include class injectable_super : public QObject { Q_OBJECT public: Q_INVOKABLE injectable_super() {} virtual ~injectable_super() {} }; class injectable_sub : public injectable_super { Q_OBJECT public: Q_INVOKABLE injectable_sub() {} virtual ~injectable_sub() {} }; class super_dependnecies : public QObject { Q_OBJECT public: injectable_super *v = nullptr; Q_INVOKABLE super_dependnecies() {} virtual ~super_dependnecies() {} private slots: INJEQT_SET void set_injectable_super(injectable_super *x) { v = x; } }; class sub_dependnecies : public QObject { Q_OBJECT public: injectable_sub *v = nullptr; Q_INVOKABLE sub_dependnecies() {} virtual ~sub_dependnecies() {} private slots: INJEQT_SET void set_injectable_sub(injectable_sub *x) { v = x; } }; class super_sub_dependency_test : public QObject { Q_OBJECT private: injeqt::injector get_injector() const; private slots: void should_set_valid_super_dependencies(); void should_set_valid_sub_dependencies(); }; injeqt::injector super_sub_dependency_test::get_injector() const { class m : public injeqt::module { public: m() { add_type(); add_type(); add_type(); } virtual ~m() {} }; auto modules = std::vector>{}; modules.emplace_back(std::unique_ptr{new m{}}); return injeqt::injector{std::move(modules)}; } void super_sub_dependency_test::should_set_valid_super_dependencies() { auto injector = get_injector(); auto c = injector.get(); auto sub = injector.get(); auto super = injector.get(); QVERIFY(c != nullptr); QVERIFY(sub != nullptr); QVERIFY(super != nullptr); QVERIFY(c->v == super); QVERIFY(c->v == sub); } void super_sub_dependency_test::should_set_valid_sub_dependencies() { auto injector = get_injector(); auto c = injector.get(); auto sub = injector.get(); auto super = injector.get(); QVERIFY(c != nullptr); QVERIFY(sub != nullptr); QVERIFY(super != nullptr); QVERIFY(c->v == super); QVERIFY(c->v == sub); } QTEST_APPLESS_MAIN(super_sub_dependency_test) #include "super-sub-dependency-test.moc"