File indexing completed on 2024-12-08 10:14:50

0001 /*
0002     SPDX-FileCopyrightText: 2023 Stefan BrĂ¼ns <stefan.bruens@rwth-aachen.de>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "filemetadatamergedatatest.h"
0008 #include "filemetadatautil_p.h"
0009 
0010 #include <QTest>
0011 
0012 #include <tuple>
0013 
0014 QTEST_MAIN(FileMetadataMergeDataTest)
0015 
0016 void FileMetadataMergeDataTest::testMergeData()
0017 {
0018     QFETCH(QList<QVariantMap>, filesData);
0019     QFETCH(QVariantMap, expected);
0020 
0021     QVariantMap data;
0022 
0023     Baloo::Private::mergeCommonData(data, filesData);
0024 
0025     QCOMPARE(data.keys(), expected.keys());
0026     QCOMPARE(data, expected);
0027 }
0028 
0029 void FileMetadataMergeDataTest::testMergeData_data()
0030 {
0031     QTest::addColumn<QList<QVariantMap>>("filesData");
0032     QTest::addColumn<QVariantMap>("expected");
0033 
0034     // Wrapper to allow initialization without explicit types
0035     auto addRow = [](const char* name, const QList<QVariantMap>& data, const QVariantMap& result) {
0036         QTest::addRow("%s", name) << data << result;
0037     };
0038 
0039     auto sDuration = QStringLiteral("duration");
0040     auto sCCount = QStringLiteral("characterCount");
0041     auto sWCount = QStringLiteral("wordCount");
0042     auto sLCount = QStringLiteral("lineCount");
0043 
0044     auto sWidth = QStringLiteral("width");
0045     auto sHeight = QStringLiteral("height");
0046 
0047     // Trivial
0048     addRow("nodata", {{}}, {});
0049 
0050     // Various check for totalizing props like duration, character count
0051     addRow("totalizing", { {{sDuration, 100}} }, {{sDuration, 100}} );
0052 
0053     addRow("totalizing media", { {{sDuration, 100}},   // file1
0054                                  {{sDuration, 200}} }, // file2
0055            {{sDuration, 300}} );  // sum
0056 
0057     addRow("totalizing mixed", { {{sDuration, 100}},   // file1
0058                                  {{sDuration, 200}},   // file2
0059                                  {} },                 // file3 without duration
0060            {} );
0061 
0062 
0063     addRow("totalizing text allcommon", { {{sCCount, 100}, {sWCount, 20}},    // file1
0064                                           {{sCCount, 200}, {sWCount, 30}} },  // file2
0065            {{sCCount, 300}, {sWCount, 50}} );
0066     addRow("totalizing text only chars", { {{sCCount, 100}, {sWCount, 20}, {sLCount, 5}},    // file1
0067                                            {{sCCount, 200},                {sLCount, 7}},    // file2
0068                                            {{sCCount, 300}, {sWCount, 30}}               },  // file3
0069            {{sCCount, 600}} );
0070 
0071     // Various check props requiring same values
0072     addRow("same size", { {{sWidth, 100}, {sHeight, 60}},    // file1
0073                           {{sWidth, 100}, {sHeight, 60}},    // file2
0074                           {{sWidth, 100}, {sHeight, 60}} },  // file3
0075            {{sWidth, 100}, {sHeight, 60}} );
0076 
0077     addRow("same width", { {{sWidth, 100}, {sHeight, 10}},    // file1
0078                            {{sWidth, 100}, {sHeight, 10}},    // file2
0079                            {{sWidth, 100}, {sHeight,  1}} },  // file3
0080            {{sWidth, 100}} );
0081 }
0082 
0083 #include "moc_filemetadatamergedatatest.cpp"