File indexing completed on 2024-05-12 05:26:23
0001 #include <QTest> 0002 0003 #include <QString> 0004 #include <QQueue> 0005 0006 #include "store.h" 0007 #include "storage.h" 0008 #include "index.h" 0009 0010 /** 0011 * Test of the index implementation 0012 */ 0013 class IndexTest : public QObject 0014 { 0015 Q_OBJECT 0016 private slots: 0017 void initTestCase() 0018 { 0019 Sink::Storage::DataStore store("./testindex", "sink.dummy.testindex", Sink::Storage::DataStore::ReadWrite); 0020 store.removeFromDisk(); 0021 } 0022 0023 void cleanup() 0024 { 0025 Sink::Storage::DataStore store("./testindex", "sink.dummy.testindex", Sink::Storage::DataStore::ReadWrite); 0026 store.removeFromDisk(); 0027 } 0028 0029 void testIndex() 0030 { 0031 Index index("./testindex", "sink.dummy.testindex", Sink::Storage::DataStore::ReadWrite); 0032 // The first key is specifically a substring of the second key 0033 index.add("key", "value1"); 0034 index.add("keyFoo", "value2"); 0035 index.add("keyFoo", "value3"); 0036 0037 { 0038 QList<QByteArray> values; 0039 index.lookup(QByteArray("key"), [&values](const QByteArray &value) { values << value; return true; }, [](const Index::Error &error) { qWarning() << "Error: "; }); 0040 QCOMPARE(values.size(), 1); 0041 } 0042 { 0043 QList<QByteArray> values; 0044 index.lookup(QByteArray("keyFoo"), [&values](const QByteArray &value) { values << value; return true; }, [](const Index::Error &error) { qWarning() << "Error: "; }); 0045 QCOMPARE(values.size(), 2); 0046 } 0047 { 0048 QList<QByteArray> values; 0049 index.lookup(QByteArray("key3"), [&values](const QByteArray &value) { values << value; return true; }, [](const Index::Error &error) { qWarning() << "Error: "; }); 0050 QCOMPARE(values.size(), 0); 0051 } 0052 { 0053 QList<QByteArray> values; 0054 index.lookup(QByteArray("key"), [&values](const QByteArray &value) { values << value; return true; }, [](const Index::Error &error) { qWarning() << "Error: "; }, true); 0055 QCOMPARE(values.size(), 3); 0056 } 0057 { 0058 QList<QByteArray> values; 0059 index.lookup(QByteArray(""), [&values](const QByteArray &value) { values << value; return true; }, [](const Index::Error &error) { qWarning() << "Error: "; }, true); 0060 QCOMPARE(values.size(), 3); 0061 } 0062 } 0063 }; 0064 0065 QTEST_MAIN(IndexTest) 0066 #include "indextest.moc"