File indexing completed on 2024-05-26 04:09:58
0001 /* 0002 SPDX-FileCopyrightText: 2012 Stefan Majewsky <majewsky@gmx.net> 0003 0004 SPDX-License-Identifier: LGPL-2.0-only 0005 */ 0006 0007 #include "kgamepropertytest.h" 0008 0009 // own 0010 #include <config-tests.h> 0011 // Qt 0012 #include <QTest> 0013 0014 void tst_KGamePropertyTest::initTestCase() 0015 { 0016 // Do nothing. 0017 } 0018 0019 void tst_KGamePropertyTest::testHandler() 0020 { 0021 mCnt_Send = 0; 0022 mCnt_Emit = 0; 0023 0024 // (TESTS_PATH"kgamesvgdigitstest.svg") 0025 mHandler = new KGamePropertyHandler(this); 0026 0027 mHandler->registerHandler(1000 /* ID */, this, SLOT(sendProperty(int, QDataStream &, bool *)), SLOT(emitSignal(KGamePropertyBase *))); 0028 0029 var1.registerData(10 /* ID */, mHandler, QStringLiteral("VAR1")); 0030 var1.setLocal(-1); 0031 var2.registerData(11 /* ID */, mHandler, QStringLiteral("VAR2")); 0032 var2.setLocal(QStringLiteral("Hallo")); 0033 0034 // Check VAR 1 0035 int checkI = var1; 0036 QVERIFY(checkI == -1); 0037 var1 = 42; 0038 QVERIFY(var1 == 42); 0039 0040 // Check VAR 2 0041 QString checkS = var2; 0042 QVERIFY(checkS == QString("Hallo")); 0043 0044 // Check names 0045 QString nameS = mHandler->propertyName(10); 0046 QVERIFY(nameS.contains(QLatin1String("VAR1"))); 0047 nameS = mHandler->propertyName(11); 0048 QVERIFY(nameS.contains(QLatin1String("VAR2"))); 0049 0050 // Check IDs 0051 QVERIFY(var1.id() == 10); 0052 QVERIFY(var2.id() == 11); 0053 0054 // Flush handler 0055 mHandler->flush(); 0056 0057 // Check size and clear 0058 QMultiHash<int, KGamePropertyBase *> dict1 = mHandler->dict(); 0059 QVERIFY(dict1.size() == 2); 0060 mHandler->clear(); 0061 QMultiHash<int, KGamePropertyBase *> dict2 = mHandler->dict(); 0062 QVERIFY(dict2.size() == 0); 0063 0064 // Check all count statistic 0065 QVERIFY(mCnt_Emit == 3); 0066 QVERIFY(mCnt_Send == 2); 0067 } 0068 0069 void tst_KGamePropertyTest::sendProperty(int, QDataStream &, bool *sent) 0070 { 0071 *sent = true; 0072 mCnt_Send++; 0073 } 0074 void tst_KGamePropertyTest::emitSignal(KGamePropertyBase *) 0075 { 0076 mCnt_Emit++; 0077 } 0078 0079 void tst_KGamePropertyTest::cleanupTestCase() 0080 { 0081 // Do nothing. 0082 } 0083 0084 QTEST_MAIN(tst_KGamePropertyTest) 0085 0086 #include "moc_kgamepropertytest.cpp"