Changeset View
Changeset View
Standalone View
Standalone View
autotests/trackmetadatamodeltest.cpp
Show All 10 Lines | |||||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
12 | * Lesser General Public License for more details. | 12 | * Lesser General Public License for more details. | ||
13 | * | 13 | * | ||
14 | * You should have received a copy of the GNU Lesser General Public License | 14 | * You should have received a copy of the GNU Lesser General Public License | ||
15 | * along with this program. If not, see <https://www.gnu.org/licenses/>. | 15 | * along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
16 | */ | 16 | */ | ||
17 | 17 | | |||
18 | #include "models/trackmetadatamodel.h" | 18 | #include "models/trackmetadatamodel.h" | ||
19 | | ||||
19 | #include "qabstractitemmodeltester.h" | 20 | #include "qabstractitemmodeltester.h" | ||
21 | #include "databasetestdata.h" | ||||
20 | 22 | | |||
21 | #include <QDebug> | 23 | #include <QDebug> | ||
22 | 24 | | |||
23 | #include <QtTest> | 25 | #include <QtTest> | ||
24 | 26 | | |||
25 | class TrackMetadataModelTests: public QObject | 27 | class TrackMetadataModelTests: public QObject, public DatabaseTestData | ||
26 | { | 28 | { | ||
27 | Q_OBJECT | 29 | Q_OBJECT | ||
28 | 30 | | |||
29 | private Q_SLOTS: | 31 | private Q_SLOTS: | ||
30 | 32 | | |||
31 | void initTestCase() | 33 | void initTestCase() | ||
32 | { | 34 | { | ||
33 | } | 35 | } | ||
Show All 28 Lines | 38 | { | |||
62 | QCOMPARE(endResetSpy.count(), 1); | 64 | QCOMPARE(endResetSpy.count(), 1); | ||
63 | QCOMPARE(beginInsertRowsSpy.count(), 0); | 65 | QCOMPARE(beginInsertRowsSpy.count(), 0); | ||
64 | QCOMPARE(endInsertRowsSpy.count(), 0); | 66 | QCOMPARE(endInsertRowsSpy.count(), 0); | ||
65 | QCOMPARE(dataChangedSpy.count(), 0); | 67 | QCOMPARE(dataChangedSpy.count(), 0); | ||
66 | QCOMPARE(beginRemovedRowsSpy.count(), 0); | 68 | QCOMPARE(beginRemovedRowsSpy.count(), 0); | ||
67 | QCOMPARE(endRemovedRowsSpy.count(), 0); | 69 | QCOMPARE(endRemovedRowsSpy.count(), 0); | ||
68 | QCOMPARE(myModel.rowCount(), 1); | 70 | QCOMPARE(myModel.rowCount(), 1); | ||
69 | } | 71 | } | ||
72 | | ||||
73 | void modifyTrackInDatabase() | ||||
74 | { | ||||
75 | QTemporaryFile databaseFile; | ||||
76 | databaseFile.open(); | ||||
77 | | ||||
78 | qDebug() << "addOneTrackWithoutAlbumArtist" << databaseFile.fileName(); | ||||
79 | | ||||
80 | DatabaseInterface musicDb; | ||||
81 | | ||||
82 | musicDb.init(QStringLiteral("testDb"), databaseFile.fileName()); | ||||
83 | | ||||
84 | musicDb.insertTracksList(mNewTracks, mNewCovers); | ||||
85 | | ||||
86 | TrackMetadataModel myModel; | ||||
87 | QAbstractItemModelTester testModel(&myModel); | ||||
88 | | ||||
89 | QSignalSpy beginResetSpy(&myModel, &TrackMetadataModel::modelAboutToBeReset); | ||||
90 | QSignalSpy endResetSpy(&myModel, &TrackMetadataModel::modelReset); | ||||
91 | QSignalSpy beginInsertRowsSpy(&myModel, &TrackMetadataModel::rowsAboutToBeInserted); | ||||
92 | QSignalSpy endInsertRowsSpy(&myModel, &TrackMetadataModel::rowsInserted); | ||||
93 | QSignalSpy dataChangedSpy(&myModel, &TrackMetadataModel::dataChanged); | ||||
94 | QSignalSpy beginRemovedRowsSpy(&myModel, &TrackMetadataModel::rowsAboutToBeRemoved); | ||||
95 | QSignalSpy endRemovedRowsSpy(&myModel, &TrackMetadataModel::rowsRemoved); | ||||
96 | | ||||
97 | QCOMPARE(beginResetSpy.count(), 0); | ||||
98 | QCOMPARE(endResetSpy.count(), 0); | ||||
99 | QCOMPARE(beginInsertRowsSpy.count(), 0); | ||||
100 | QCOMPARE(endInsertRowsSpy.count(), 0); | ||||
101 | QCOMPARE(dataChangedSpy.count(), 0); | ||||
102 | QCOMPARE(beginRemovedRowsSpy.count(), 0); | ||||
103 | QCOMPARE(endRemovedRowsSpy.count(), 0); | ||||
104 | QCOMPARE(myModel.rowCount(), 0); | ||||
105 | | ||||
106 | myModel.setDatabase(&musicDb); | ||||
107 | | ||||
108 | auto trackId = musicDb.trackIdFromFileName(QUrl::fromLocalFile(QStringLiteral("/$1"))); | ||||
109 | | ||||
110 | myModel.initializeByTrackId(trackId); | ||||
111 | | ||||
112 | QCOMPARE(beginResetSpy.count(), 1); | ||||
113 | QCOMPARE(endResetSpy.count(), 1); | ||||
114 | QCOMPARE(beginInsertRowsSpy.count(), 0); | ||||
115 | QCOMPARE(endInsertRowsSpy.count(), 0); | ||||
116 | QCOMPARE(dataChangedSpy.count(), 0); | ||||
117 | QCOMPARE(beginRemovedRowsSpy.count(), 0); | ||||
118 | QCOMPARE(endRemovedRowsSpy.count(), 0); | ||||
119 | QCOMPARE(myModel.rowCount(), 11); | ||||
120 | | ||||
121 | musicDb.trackHasStartedPlaying(QUrl::fromLocalFile(QStringLiteral("/$2")), QDateTime::currentDateTime()); | ||||
122 | | ||||
123 | QCOMPARE(beginResetSpy.count(), 1); | ||||
124 | QCOMPARE(endResetSpy.count(), 1); | ||||
125 | QCOMPARE(beginInsertRowsSpy.count(), 0); | ||||
126 | QCOMPARE(endInsertRowsSpy.count(), 0); | ||||
127 | QCOMPARE(dataChangedSpy.count(), 0); | ||||
128 | QCOMPARE(beginRemovedRowsSpy.count(), 0); | ||||
129 | QCOMPARE(endRemovedRowsSpy.count(), 0); | ||||
130 | QCOMPARE(myModel.rowCount(), 11); | ||||
131 | | ||||
132 | musicDb.trackHasStartedPlaying(QUrl::fromLocalFile(QStringLiteral("/$1")), QDateTime::currentDateTime()); | ||||
133 | | ||||
134 | QCOMPARE(beginResetSpy.count(), 2); | ||||
135 | QCOMPARE(endResetSpy.count(), 2); | ||||
136 | QCOMPARE(beginInsertRowsSpy.count(), 0); | ||||
137 | QCOMPARE(endInsertRowsSpy.count(), 0); | ||||
138 | QCOMPARE(dataChangedSpy.count(), 0); | ||||
139 | QCOMPARE(beginRemovedRowsSpy.count(), 0); | ||||
140 | QCOMPARE(endRemovedRowsSpy.count(), 0); | ||||
141 | QCOMPARE(myModel.rowCount(), 12); | ||||
142 | } | ||||
70 | }; | 143 | }; | ||
71 | 144 | | |||
72 | QTEST_GUILESS_MAIN(TrackMetadataModelTests) | 145 | QTEST_GUILESS_MAIN(TrackMetadataModelTests) | ||
73 | 146 | | |||
74 | 147 | | |||
75 | #include "trackmetadatamodeltest.moc" | 148 | #include "trackmetadatamodeltest.moc" |