File indexing completed on 2024-07-14 05:34:01

0001 /*
0002  *   Copyright 2017  Jos van den Oever <jos@vandenoever.info>
0003  *
0004  *   This program is free software; you can redistribute it and/or
0005  *   modify it under the terms of the GNU General Public License as
0006  *   published by the Free Software Foundation; either version 2 of
0007  *   the License or (at your option) version 3 or any later version
0008  *   accepted by the membership of KDE e.V. (or its successor approved
0009  *   by the membership of KDE e.V.), which shall act as a proxy
0010  *   defined in Section 14 of version 3 of the license.
0011  *
0012  *   This program is distributed in the hope that it will be useful,
0013  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
0014  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0015  *   GNU General Public License for more details.
0016  *
0017  *   You should have received a copy of the GNU General Public License
0018  *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
0019  */
0020 
0021 #include "test_objects_rust.h"
0022 #include <QTest>
0023 #include <QSignalSpy>
0024 
0025 class TestRustObjects : public QObject
0026 {
0027     Q_OBJECT
0028 private slots:
0029     void testOneLevelConstructor();
0030     void testOneLevelStringGetter();
0031     void testOneLevelStringSetter();
0032     void testTwoLevelsConstructor();
0033     void testTwoLevelsStringGetter();
0034     void testTwoLevelsStringSetter();
0035 };
0036 
0037 void TestRustObjects::testOneLevelConstructor()
0038 {
0039     Person person;
0040 }
0041 
0042 void TestRustObjects::testOneLevelStringGetter()
0043 {
0044     Person person;
0045     person.object()->setDescription("Konqi");
0046 }
0047 
0048 void TestRustObjects::testOneLevelStringSetter()
0049 {
0050     // GIVEN
0051     Person person;
0052     QSignalSpy spy(person.object(), &InnerObject::descriptionChanged);
0053 
0054     // WHEN
0055     person.object()->setDescription("Konqi");
0056 
0057     // THEN
0058     QVERIFY(spy.isValid());
0059     QCOMPARE(spy.count(), 1);
0060     QCOMPARE(person.object()->description(), QString("Konqi"));
0061 }
0062 
0063 void TestRustObjects::testTwoLevelsConstructor()
0064 {
0065     Group group;
0066 }
0067 
0068 void TestRustObjects::testTwoLevelsStringGetter()
0069 {
0070     Group group;
0071     group.person()->object()->setDescription("Konqi");
0072 }
0073 
0074 void TestRustObjects::testTwoLevelsStringSetter()
0075 {
0076     // GIVEN
0077     Group group;
0078     QSignalSpy spy(group.person()->object(), &InnerObject::descriptionChanged);
0079 
0080     // WHEN
0081     group.person()->object()->setDescription("Konqi");
0082 
0083     // THEN
0084     QVERIFY(spy.isValid());
0085     QCOMPARE(spy.count(), 1);
0086     QCOMPARE(group.person()->object()->description(), QString("Konqi"));
0087 }
0088 
0089 QTEST_MAIN(TestRustObjects)
0090 #include "test_objects.moc"