File indexing completed on 2024-10-13 09:21:26
0001 /* GCompris - DatasetTest.cpp 0002 * 0003 * SPDX-FileCopyrightText: 2020 Johnny Jazeix <jazeix@gmail.com> 0004 * 0005 * Authors: 0006 * Johnny Jazeix <jazeix@gmail.com> 0007 * 0008 * SPDX-License-Identifier: GPL-3.0-or-later 0009 */ 0010 0011 #include <QTest> 0012 #include <QObject> 0013 #include <QSignalSpy> 0014 #include "src/core/Dataset.h" 0015 0016 #define DATASET_TEST_ATTRIBUTE(attributeName, accessorName, attributeType) \ 0017 { \ 0018 QFETCH(attributeType, attributeName); \ 0019 QSignalSpy spy(&activityinfo, &Dataset::attributeName ## Changed); \ 0020 QVERIFY(spy.isValid()); \ 0021 QVERIFY(spy.count() == 0); \ 0022 activityinfo.set ## accessorName(attributeName); \ 0023 QVERIFY(spy.count() == 1); \ 0024 QCOMPARE(activityinfo.attributeName(), attributeName); \ 0025 } 0026 0027 class CoreDatasetTest : public QObject 0028 { 0029 Q_OBJECT 0030 private Q_SLOTS: 0031 void DatasetTest(); 0032 void DatasetTest_data(); 0033 }; 0034 0035 void CoreDatasetTest::DatasetTest_data() 0036 { 0037 QTest::addColumn<QString>("objective"); 0038 QTest::addColumn<quint32>("difficulty"); 0039 QTest::addColumn<QVariant>("data"); 0040 QTest::addColumn<bool>("enabled"); 0041 0042 QTest::newRow("Dataset") << "objective 1" << (quint32)3 << QVariant("data") << false; 0043 QTest::newRow("Dataset_2") << "another objective" << (quint32)1 << QVariant(2.0) << true; 0044 } 0045 0046 void CoreDatasetTest::DatasetTest() 0047 { 0048 Dataset activityinfo; 0049 0050 QVERIFY(activityinfo.objective().isEmpty()); 0051 QCOMPARE(activityinfo.difficulty(), 0); 0052 QVERIFY(activityinfo.enabled()); 0053 0054 DATASET_TEST_ATTRIBUTE(objective, Objective, QString); 0055 DATASET_TEST_ATTRIBUTE(difficulty, Difficulty, quint32); 0056 DATASET_TEST_ATTRIBUTE(data, Data, QVariant); 0057 DATASET_TEST_ATTRIBUTE(enabled, Enabled, bool); 0058 } 0059 0060 QTEST_MAIN(CoreDatasetTest) 0061 #include "DatasetTest.moc"