File indexing completed on 2023-05-30 12:24:34
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_functions_rust.h" 0022 #include <QTest> 0023 #include <QSignalSpy> 0024 0025 class TestRustObject : public QObject 0026 { 0027 Q_OBJECT 0028 private slots: 0029 void testConstructor(); 0030 void testStringFunction(); 0031 void testSimpleFunction(); 0032 void testVoidFunction(); 0033 void testAppendFunction(); 0034 void testQuoteFunction(); 0035 void testQuoteBytesFunction(); 0036 }; 0037 0038 void TestRustObject::testConstructor() 0039 { 0040 Person person; 0041 } 0042 0043 void TestRustObject::testSimpleFunction() 0044 { 0045 // GIVEN 0046 Person person; 0047 person.setUserName("Konqi"); 0048 0049 // THEN 0050 QCOMPARE(person.userName(), QString("Konqi")); 0051 QCOMPARE((int)person.vowelsInName(), 2); 0052 } 0053 0054 void TestRustObject::testVoidFunction() 0055 { 0056 // GIVEN 0057 Person person; 0058 person.setUserName("Konqi"); 0059 0060 // THEN 0061 person.doubleName(); 0062 QCOMPARE(person.userName(), QString("KonqiKonqi")); 0063 } 0064 0065 void TestRustObject::testAppendFunction() 0066 { 0067 // GIVEN 0068 Person person; 0069 person.setUserName("Konqi"); 0070 0071 // THEN 0072 person.append("!", 3); 0073 QCOMPARE(person.userName(), QString("Konqi!!!")); 0074 } 0075 0076 void TestRustObject::testQuoteFunction() 0077 { 0078 // GIVEN 0079 Person person; 0080 person.setUserName("Konqi"); 0081 0082 // THEN 0083 auto r = person.quote("<<", ">>"); 0084 QCOMPARE(r, QString("<<Konqi>>")); 0085 } 0086 0087 void TestRustObject::testQuoteBytesFunction() 0088 { 0089 // GIVEN 0090 Person person; 0091 person.setUserName("Konqi"); 0092 0093 // THEN 0094 auto r = person.quoteBytes("<<", ">>"); 0095 QCOMPARE(r, QByteArray("<<Konqi>>")); 0096 } 0097 0098 void TestRustObject::testStringFunction() 0099 { 0100 // GIVEN 0101 Person person; 0102 person.setUserName("Konqi"); 0103 0104 // THEN 0105 QCOMPARE(person.greet("John"), QString("Hello John, my name is Konqi, how is it going?")); 0106 } 0107 0108 QTEST_MAIN(TestRustObject) 0109 #include "test_functions.moc"