| 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/type.h> |
| 22 | |
| 23 | #include "internal/interfaces-utils.h" |
| 24 | |
| 25 | #include <QtTest/QtTest> |
| 26 | |
| 27 | using namespace injeqt::internal; |
| 28 | using namespace injeqt::v1; |
| 29 | |
| 30 | class direct_successor : public QObject |
| 31 | { |
| 32 | Q_OBJECT |
| 33 | }; |
| 34 | |
| 35 | class indirect_successor_1 : public direct_successor |
| 36 | { |
| 37 | Q_OBJECT |
| 38 | }; |
| 39 | |
| 40 | class indirect_successor_2 : public indirect_successor_1 |
| 41 | { |
| 42 | Q_OBJECT |
| 43 | }; |
| 44 | |
| 45 | class interfaces_utils_test : public QObject |
| 46 | { |
| 47 | Q_OBJECT |
| 48 | |
| 49 | public: |
| 50 | interfaces_utils_test(); |
| 51 | |
| 52 | private slots: |
| 53 | void should_find_nothing_in_qobject(); |
| 54 | void should_find_one_in_direct_successor(); |
| 55 | void should_find_two_in_indirect_successor_1(); |
| 56 | void should_find_three_in_indirect_successor_2(); |
| 57 | |
| 58 | private: |
| 59 | type qobject_type; |
| 60 | type direct_successor_type; |
| 61 | type indirect_successor_1_type; |
| 62 | type indirect_successor_2_type; |
| 63 | |
| 64 | }; |
| 65 | |
| 66 | interfaces_utils_test::interfaces_utils_test() : |
| 67 | qobject_type{type(&QObject::staticMetaObject)}, |
| 68 | direct_successor_type{make_type<direct_successor>()}, |
| 69 | indirect_successor_1_type{make_type<indirect_successor_1>()}, |
| 70 | indirect_successor_2_type{make_type<indirect_successor_2>()} |
| 71 | { |
| 72 | } |
| 73 | |
| 74 | void interfaces_utils_test::should_find_nothing_in_qobject() |
| 75 | { |
| 76 | auto interfaces = extract_interfaces(qobject_type); |
| 77 | QCOMPARE(interfaces.size(), size_t{0}); |
| 78 | QVERIFY(!implements(qobject_type, qobject_type)); |
| 79 | } |
| 80 | |
| 81 | void interfaces_utils_test::should_find_one_in_direct_successor() |
| 82 | { |
| 83 | auto interfaces = extract_interfaces(direct_successor_type); |
| 84 | QCOMPARE(interfaces, (types{direct_successor_type})); |
| 85 | QVERIFY(implements(direct_successor_type, direct_successor_type)); |
| 86 | } |
| 87 | |
| 88 | void interfaces_utils_test::should_find_two_in_indirect_successor_1() |
| 89 | { |
| 90 | auto interfaces = extract_interfaces(indirect_successor_1_type); |
| 91 | QCOMPARE(interfaces, (types{direct_successor_type, indirect_successor_1_type})); |
| 92 | QVERIFY(!implements(indirect_successor_1_type, qobject_type)); |
| 93 | QVERIFY(implements(indirect_successor_1_type, direct_successor_type)); |
| 94 | QVERIFY(implements(indirect_successor_1_type, indirect_successor_1_type)); |
| 95 | QVERIFY(!implements(indirect_successor_1_type, indirect_successor_2_type)); |
| 96 | } |
| 97 | |
| 98 | void interfaces_utils_test::should_find_three_in_indirect_successor_2() |
| 99 | { |
| 100 | auto interfaces = extract_interfaces(indirect_successor_2_type); |
| 101 | QCOMPARE(interfaces, (types{direct_successor_type, indirect_successor_1_type, indirect_successor_2_type})); |
| 102 | QVERIFY(implements(direct_successor_type, direct_successor_type)); |
| 103 | QVERIFY(!implements(indirect_successor_2_type, qobject_type)); |
| 104 | QVERIFY(implements(indirect_successor_2_type, direct_successor_type)); |
| 105 | QVERIFY(implements(indirect_successor_2_type, indirect_successor_1_type)); |
| 106 | QVERIFY(implements(indirect_successor_2_type, indirect_successor_2_type)); |
| 107 | } |
| 108 | |
| 109 | QTEST_APPLESS_MAIN(interfaces_utils_test); |
| 110 | |
| 111 | #include "interfaces-utils-test.moc" |