| 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 "utils.h" |
| 22 | |
| 23 | #include "internal/dependency.h" |
| 24 | |
| 25 | #include <QtTest/QtTest> |
| 26 | |
| 27 | using namespace injeqt::internal; |
| 28 | using namespace injeqt::v1; |
| 29 | |
| 30 | class type_1 : public QObject |
| 31 | { |
| 32 | Q_OBJECT |
| 33 | }; |
| 34 | |
| 35 | class type_2 : public QObject |
| 36 | { |
| 37 | Q_OBJECT |
| 38 | }; |
| 39 | |
| 40 | class type_with_dependency : public QObject |
| 41 | { |
| 42 | Q_OBJECT |
| 43 | |
| 44 | public slots: |
| 45 | INJEQT_SET void setter_1(type_1 *) { } |
| 46 | INJEQT_SET void setter_1b(type_1 *) { } |
| 47 | INJEQT_SET void setter_2(type_2 *) { } |
| 48 | |
| 49 | }; |
| 50 | |
| 51 | class dependency_test : public QObject |
| 52 | { |
| 53 | Q_OBJECT |
| 54 | |
| 55 | private slots: |
| 56 | void should_create_valid_dependency(); |
| 57 | void should_properly_compare(); |
| 58 | |
| 59 | }; |
| 60 | |
| 61 | void dependency_test::should_create_valid_dependency() |
| 62 | { |
| 63 | auto s = make_test_setter_method<type_with_dependency, type_1>("setter_1(type_1*)"); |
| 64 | auto d = dependency{s}; |
| 65 | QCOMPARE(d.required_type(), make_type<type_1>()); |
| 66 | QCOMPARE(d.setter(), s); |
| 67 | } |
| 68 | |
| 69 | void dependency_test::should_properly_compare() |
| 70 | { |
| 71 | auto s1a = dependency{make_test_setter_method<type_with_dependency, type_1>("setter_1(type_1*)")}; |
| 72 | auto s1b = dependency{make_test_setter_method<type_with_dependency, type_1>("setter_1(type_1*)")}; |
| 73 | auto s2a = dependency{make_test_setter_method<type_with_dependency, type_1>("setter_1b(type_1*)")}; |
| 74 | auto s2b = dependency{make_test_setter_method<type_with_dependency, type_1>("setter_1b(type_1*)")}; |
| 75 | auto s3a = dependency{make_test_setter_method<type_with_dependency, type_2>("setter_2(type_2*)")}; |
| 76 | auto s3b = dependency{make_test_setter_method<type_with_dependency, type_2>("setter_2(type_2*)")}; |
| 77 | |
| 78 | test_compare<dependency>({{s1a, s1b}, {s2a, s2b}, {s3a, s3b}}); |
| 79 | } |
| 80 | |
| 81 | QTEST_APPLESS_MAIN(dependency_test) |
| 82 | #include "dependency-test.moc" |