Changeset View
Changeset View
Standalone View
Standalone View
autotests/udsentrytest.cpp
Show All 16 Lines | 1 | /* This file is part of the KDE project | |||
---|---|---|---|---|---|
17 | Boston, MA 02110-1301, USA. | 17 | Boston, MA 02110-1301, USA. | ||
18 | */ | 18 | */ | ||
19 | 19 | | |||
20 | #include "udsentrytest.h" | 20 | #include "udsentrytest.h" | ||
21 | 21 | | |||
22 | #include <QTest> | 22 | #include <QTest> | ||
23 | #include <QVector> | 23 | #include <QVector> | ||
24 | #include <QDataStream> | 24 | #include <QDataStream> | ||
25 | #include <QTemporaryFile> | ||||
25 | 26 | | |||
27 | #include <kfileitem.h> | ||||
26 | #include <udsentry.h> | 28 | #include <udsentry.h> | ||
27 | 29 | | |||
28 | struct UDSTestField { | 30 | struct UDSTestField { | ||
29 | UDSTestField() {} | 31 | UDSTestField() {} | ||
30 | 32 | | |||
31 | UDSTestField(uint uds, const QString &value) : | 33 | UDSTestField(uint uds, const QString &value) : | ||
32 | m_uds(uds), | 34 | m_uds(uds), | ||
33 | m_string(value) | 35 | m_string(value) | ||
▲ Show 20 Lines • Show All 182 Lines • ▼ Show 20 Line(s) | 217 | } else { | |||
216 | Q_ASSERT(uds & KIO::UDSEntry::UDS_NUMBER); | 218 | Q_ASSERT(uds & KIO::UDSEntry::UDS_NUMBER); | ||
217 | QCOMPARE(entry.numberValue(uds), field.m_long); | 219 | QCOMPARE(entry.numberValue(uds), field.m_long); | ||
218 | } | 220 | } | ||
219 | } | 221 | } | ||
220 | } | 222 | } | ||
221 | } | 223 | } | ||
222 | } | 224 | } | ||
223 | 225 | | |||
226 | /** | ||||
227 | * Test to verify that move semantics work. This is only useful when ran through a profiling or debugging tool. | ||||
dfaure: ... or gdb, or perf, or with debug output in the cpp file, or .... | |||||
dfaure: typo: it's debugging, with an 'e' | |||||
228 | */ | ||||
229 | void UDSEntryTest::testMove() | ||||
230 | { | ||||
231 | // Create a temporaty file. Just to make a UDSEntry further down. | ||||
dfaure: Typo: tempora*r*y | |||||
232 | QTemporaryFile file; | ||||
233 | QVERIFY(file.open()); | ||||
dfaure: That one, however, could be QVERIFY(), that's what it's for ;) | |||||
234 | const QByteArray filePath = QFile::encodeName(file.fileName()); | ||||
dfaure: QFile::encodeName() is the proper way | |||||
235 | const QString fileName = QFileInfo(file.fileName()).fileName(); | ||||
That's rather overkill (and a wrong use of the QUrl API). You want to use QFileInfo for this. dfaure: That's rather overkill (and a wrong use of the QUrl API). You want to use QFileInfo for this. | |||||
The comment is marked as done, but the code that was pushed still uses QUrl. dfaure: The comment is marked as done, but the code that was pushed still uses QUrl. | |||||
236 | QCOMPARE(fileName.isEmpty(), false); | ||||
237 | | ||||
238 | // We have a file now. Get the stat data from it and make the UDSEntry. | ||||
239 | QT_STATBUF statBuf; | ||||
240 | QCOMPARE(QT_LSTAT(filePath.constData(), &statBuf), 0); | ||||
dfaure: Whenever you write QVERIFY(a==b), it should be QCOMPARE(a, b) | |||||
241 | KIO::UDSEntry entry(statBuf, fileName); | ||||
242 | | ||||
243 | // Verify that the name in the UDSEntry is the same as we've got from the fileName var. | ||||
244 | QCOMPARE(entry.stringValue(KIO::UDSEntry::UDS_NAME), fileName); | ||||
245 | | ||||
246 | // That was the boilerplate code. Now for move semantics. | ||||
247 | // First: move assignment. | ||||
248 | { | ||||
249 | // First a copy as we need to keep the entry for the next test. | ||||
250 | KIO::UDSEntry entryCopy = entry; | ||||
251 | | ||||
252 | // Now move-assignement (two lines to prevent compiler optimization) | ||||
253 | KIO::UDSEntry movedEntry; | ||||
254 | movedEntry = std::move(entryCopy); | ||||
255 | | ||||
256 | // And verify that this works. | ||||
dfaure: typo: verify | |||||
257 | QCOMPARE(movedEntry.stringValue(KIO::UDSEntry::UDS_NAME), fileName); | ||||
258 | } | ||||
259 | | ||||
260 | // Move constructor | ||||
261 | { | ||||
262 | // First a copy again | ||||
263 | KIO::UDSEntry entryCopy = entry; | ||||
264 | | ||||
265 | // Now move-assignement | ||||
266 | KIO::UDSEntry movedEntry(std::move(entryCopy)); | ||||
267 | | ||||
268 | // And verify that this works. | ||||
dfaure: same typo | |||||
269 | QCOMPARE(movedEntry.stringValue(KIO::UDSEntry::UDS_NAME), fileName); | ||||
swap it around: what you test on the left, what you expect on the right. This makes error messages more readable. (same above, of course) dfaure: swap it around: what you test on the left, what you expect on the right. This makes error… | |||||
dfaure: Same here, this was not fixed in the commit that was pushed. | |||||
270 | } | ||||
271 | } | ||||
272 | | ||||
224 | QTEST_MAIN(UDSEntryTest) | 273 | QTEST_MAIN(UDSEntryTest) |
... or gdb, or perf, or with debug output in the cpp file, or ....