File indexing completed on 2024-04-28 04:21:08

0001 // SPDX-FileCopyrightText: 2020 The KPhotoAlbum development team
0002 // SPDX-FileCopyrightText: 2021 Johannes Zarl-Zierl <johannes@zarl-zierl.at>
0003 //
0004 // SPDX-License-Identifier: LicenseRef-KDE-Accepted-GPL
0005 
0006 #include "TestThumbnailCacheConverter.h"
0007 
0008 #include "ThumbnailCacheConverter.h"
0009 
0010 #include <QBuffer>
0011 #include <QTextStream>
0012 
0013 namespace
0014 {
0015 constexpr auto v4IndexHexData {
0016     "00000004" // version
0017     "00000003" // current file
0018     "00033714" // offset in file
0019     "00000003" // number of thumbnails
0020     "0000001600730070006900660066005F0032002E006A0070006700000000000038A900001DFD" // "spiff_2.jpg"
0021     "0000001C006E00650077005F0077006100760065005F0032002E006A0070006700000000000000000000229D" // "new_wave_2.jpg"
0022     "000000160062006C00610063006B00690065002E006A00700067000000000000462C00001F0B" // "blackie.jpg"
0023 };
0024 constexpr auto v5IndexHexData {
0025     "00000005" // version
0026     "000001c4" // v5: thumbnailsize
0027     "00000003" // current file
0028     "00033714" // offset in file
0029     "00000003" // number of thumbnails
0030     "0000001600730070006900660066005F0032002E006A0070006700000000000038A900001DFD" // "spiff_2.jpg"
0031     "0000001C006E00650077005F0077006100760065005F0032002E006A0070006700000000000000000000229D" // "new_wave_2.jpg"
0032     "000000160062006C00610063006B00690065002E006A00700067000000000000462C00001F0B" // "blackie.jpg"
0033 };
0034 }
0035 
0036 void KPATest::TestThumbnailCacheConverter::convertV5toV4()
0037 {
0038     QByteArray v5Index { QByteArray::fromHex(v5IndexHexData) };
0039     QBuffer v5input { &v5Index };
0040     v5input.open(QIODevice::ReadOnly);
0041 
0042     QByteArray v4Index {};
0043     QBuffer v4output { &v4Index };
0044     v4output.open(QIODevice::WriteOnly);
0045 
0046     QString errorOutput;
0047     QTextStream err { &errorOutput };
0048 
0049     KPAThumbnailTool::convertV5ToV4Cache(v5input, v4output, err);
0050     const QByteArray expectedV4Index { QByteArray::fromHex(v4IndexHexData) };
0051     QCOMPARE(v4Index, expectedV4Index);
0052     QVERIFY2(errorOutput.isEmpty(), "convertV5ToV4Cache() reported error!");
0053 }
0054 
0055 QTEST_MAIN(KPATest::TestThumbnailCacheConverter)
0056 
0057 // vi:expandtab:tabstop=4 shiftwidth=4:
0058 
0059 #include "moc_TestThumbnailCacheConverter.cpp"