File indexing completed on 2024-05-19 05:14:14
0001 /* 0002 SPDX-FileCopyrightText: 2020 Volker Krause <vkrause@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "favoritelocationmodel.h" 0008 0009 #include <QAbstractItemModelTester> 0010 #include <QtTest/qtest.h> 0011 #include <QSignalSpy> 0012 #include <QStandardPaths> 0013 0014 class FavoriteLocationTest : public QObject 0015 { 0016 Q_OBJECT 0017 private Q_SLOTS: 0018 void initTestCase() 0019 { 0020 QStandardPaths::setTestModeEnabled(true); 0021 } 0022 0023 void testFavoriteLocationModel() 0024 { 0025 FavoriteLocationModel model; 0026 QAbstractItemModelTester modelTest(&model); 0027 0028 while (model.rowCount()) { 0029 model.removeLocation(0); 0030 } 0031 QCOMPARE(model.rowCount(), 0); 0032 0033 model.appendNewLocation(); 0034 QCOMPARE(model.rowCount(), 1); 0035 QVERIFY(!model.index(0, 0).data(Qt::DisplayRole).toString().isEmpty()); 0036 0037 QVERIFY(model.setData(model.index(0, 0), QStringLiteral("Test Name"), Qt::DisplayRole)); 0038 QCOMPARE(model.index(0, 0).data(Qt::DisplayRole).toString(), QLatin1StringView("Test Name")); 0039 0040 // verify persistence 0041 { 0042 FavoriteLocationModel model2; 0043 QCOMPARE(model2.rowCount(), 1); 0044 QCOMPARE(model2.index(0, 0).data(Qt::DisplayRole).toString(), QLatin1StringView("Test Name")); 0045 } 0046 0047 model.removeLocation(0); 0048 QCOMPARE(model.rowCount(), 0); 0049 0050 { 0051 FavoriteLocationModel model2; 0052 QCOMPARE(model2.rowCount(), 0); 0053 } 0054 } 0055 }; 0056 0057 QTEST_GUILESS_MAIN(FavoriteLocationTest) 0058 0059 #include "favoritelocationtest.moc"