Changeset View
Changeset View
Standalone View
Standalone View
autotests/integration/querytest.cpp
Show First 20 Lines • Show All 65 Lines • ▼ Show 20 Line(s) | 60 | auto touchFile = [](const QString& path) { | |||
---|---|---|---|---|---|
66 | return filePathToId(QFile::encodeName(path)); | 66 | return filePathToId(QFile::encodeName(path)); | ||
67 | }; | 67 | }; | ||
68 | 68 | | |||
69 | m_id1 = touchFile(dir->path() + "/file1.txt"); | 69 | m_id1 = touchFile(dir->path() + "/file1.txt"); | ||
70 | m_id2 = touchFile(dir->path() + "/file2"); | 70 | m_id2 = touchFile(dir->path() + "/file2"); | ||
71 | m_id3 = touchFile(dir->path() + "/file3"); | 71 | m_id3 = touchFile(dir->path() + "/file3"); | ||
72 | m_id4 = touchFile(dir->path() + "/file4"); | 72 | m_id4 = touchFile(dir->path() + "/file4"); | ||
73 | m_id7 = touchFile(dir->path() + "/file7_lazy"); | 73 | m_id7 = touchFile(dir->path() + "/file7_lazy"); | ||
74 | m_id8 = touchFile(dir->path() + "/file8_dog"); | ||||
74 | 75 | | |||
75 | m_id5 = touchFile(dir->path() + "/tagFile1"); | 76 | m_id5 = touchFile(dir->path() + "/tagFile1"); | ||
76 | m_id6 = touchFile(dir->path() + "/tagFile2"); | 77 | m_id6 = touchFile(dir->path() + "/tagFile2"); | ||
77 | } | 78 | } | ||
78 | 79 | | |||
79 | void init() { | 80 | void init() { | ||
80 | dbDir = new QTemporaryDir(); | 81 | dbDir = new QTemporaryDir(); | ||
81 | db = new Database(dbDir->path()); | 82 | db = new Database(dbDir->path()); | ||
Show All 30 Lines | 112 | { | |||
112 | Document doc; | 113 | Document doc; | ||
113 | doc.setUrl(QFile::encodeName(url)); | 114 | doc.setUrl(QFile::encodeName(url)); | ||
114 | 115 | | |||
115 | QString fileName = url.mid(url.lastIndexOf('/') + 1); | 116 | QString fileName = url.mid(url.lastIndexOf('/') + 1); | ||
116 | 117 | | |||
117 | TermGenerator tg(doc); | 118 | TermGenerator tg(doc); | ||
118 | tg.indexText(text); | 119 | tg.indexText(text); | ||
119 | tg.indexFileNameText(fileName); | 120 | tg.indexFileNameText(fileName); | ||
121 | tg.indexFileNameText(fileName, QByteArrayLiteral("F")); | ||||
120 | doc.setId(id); | 122 | doc.setId(id); | ||
121 | doc.setMTime(1); | 123 | doc.setMTime(1); | ||
122 | doc.setCTime(2); | 124 | doc.setCTime(2); | ||
123 | 125 | | |||
124 | tr->addDocument(doc); | 126 | tr->addDocument(doc); | ||
125 | } | 127 | } | ||
126 | 128 | | |||
129 | void renameDocument(Transaction* tr, quint64 id, const QString& newName) | ||||
130 | { | ||||
131 | Document doc; | ||||
132 | | ||||
133 | TermGenerator tg(doc); | ||||
134 | tg.indexFileNameText(newName); | ||||
135 | tg.indexFileNameText(newName, QByteArrayLiteral("F")); | ||||
136 | doc.setId(id); | ||||
137 | | ||||
138 | tr->replaceDocument(doc, FileNameTerms); | ||||
139 | } | ||||
140 | | ||||
127 | void insertTagDocuments(); | 141 | void insertTagDocuments(); | ||
128 | void addTagDocument(Transaction* tr,const QStringList& tags, quint64 id, const QString& url) | 142 | void addTagDocument(Transaction* tr,const QStringList& tags, quint64 id, const QString& url) | ||
129 | { | 143 | { | ||
130 | Document doc; | 144 | Document doc; | ||
131 | doc.setUrl(QFile::encodeName(url)); | 145 | doc.setUrl(QFile::encodeName(url)); | ||
132 | 146 | | |||
133 | QString fileName = url.mid(url.lastIndexOf('/') + 1); | 147 | QString fileName = url.mid(url.lastIndexOf('/') + 1); | ||
134 | 148 | | |||
Show All 12 Lines | |||||
147 | 161 | | |||
148 | quint64 m_id1; | 162 | quint64 m_id1; | ||
149 | quint64 m_id2; | 163 | quint64 m_id2; | ||
150 | quint64 m_id3; | 164 | quint64 m_id3; | ||
151 | quint64 m_id4; | 165 | quint64 m_id4; | ||
152 | quint64 m_id5; | 166 | quint64 m_id5; | ||
153 | quint64 m_id6; | 167 | quint64 m_id6; | ||
154 | quint64 m_id7; | 168 | quint64 m_id7; | ||
169 | quint64 m_id8; | ||||
155 | }; | 170 | }; | ||
156 | 171 | | |||
157 | 172 | | |||
158 | void QueryTest::insertDocuments() | 173 | void QueryTest::insertDocuments() | ||
159 | { | 174 | { | ||
160 | Transaction tr(db, Transaction::ReadWrite); | 175 | Transaction tr(db, Transaction::ReadWrite); | ||
161 | addDocument(&tr, QStringLiteral("The quick brown fox jumped over the crazy dog"), m_id1, dir->path() + "/file1.txt"); | 176 | addDocument(&tr, QStringLiteral("The quick brown fox jumped over the crazy dog"), m_id1, dir->path() + "/file1.txt"); | ||
162 | addDocument(&tr, QStringLiteral("The quick brown fox jumped over the lazy dog"), m_id7, dir->path() + "/file7_lazy"); | 177 | addDocument(&tr, QStringLiteral("The quick brown fox jumped over the lazy dog"), m_id7, dir->path() + "/file7_lazy"); | ||
178 | addDocument(&tr, QStringLiteral("A quick brown fox ran around a easy dog"), m_id8, dir->path() + "/file8_dog"); | ||||
163 | addDocument(&tr, QStringLiteral("The night is dark and full of terror"), m_id2, dir->path() + "/file2"); | 179 | addDocument(&tr, QStringLiteral("The night is dark and full of terror"), m_id2, dir->path() + "/file2"); | ||
164 | addDocument(&tr, QStringLiteral("Don't feel sorry for yourself. Only assholes do that"), m_id3, dir->path() + "/file3"); | 180 | addDocument(&tr, QStringLiteral("Don't feel sorry for yourself. Only assholes do that"), m_id3, dir->path() + "/file3"); | ||
165 | addDocument(&tr, QStringLiteral("Only the dead stay 17 forever. crazy"), m_id4, dir->path() + "/file4"); | 181 | addDocument(&tr, QStringLiteral("Only the dead stay 17 forever. crazy"), m_id4, dir->path() + "/file4"); | ||
182 | | ||||
183 | renameDocument(&tr, m_id8, QStringLiteral("file8_easy")); | ||||
166 | tr.commit(); | 184 | tr.commit(); | ||
167 | } | 185 | } | ||
168 | 186 | | |||
169 | void QueryTest::insertTagDocuments() | 187 | void QueryTest::insertTagDocuments() | ||
170 | { | 188 | { | ||
171 | Transaction tr(db, Transaction::ReadWrite); | 189 | Transaction tr(db, Transaction::ReadWrite); | ||
172 | addTagDocument(&tr, {"One", "Two", "Three", "Four", "F1"}, m_id5, dir->path() + "/tagFile1"); | 190 | addTagDocument(&tr, {"One", "Two", "Three", "Four", "F1"}, m_id5, dir->path() + "/tagFile1"); | ||
173 | addTagDocument(&tr, {"One", "Two-Three", "Four", "F2"}, m_id6, dir->path() + "/tagFile2"); | 191 | addTagDocument(&tr, {"One", "Two-Three", "Four", "F2"}, m_id6, dir->path() + "/tagFile2"); | ||
▲ Show 20 Lines • Show All 51 Lines • ▼ Show 20 Line(s) | 240 | { | |||
225 | QTest::addColumn<QString>("failReason"); | 243 | QTest::addColumn<QString>("failReason"); | ||
226 | 244 | | |||
227 | auto addRow = [](const char* name, const QByteArrayList& phrase, | 245 | auto addRow = [](const char* name, const QByteArrayList& phrase, | ||
228 | const QVector<quint64> matchIds, const QString& failureReason) | 246 | const QVector<quint64> matchIds, const QString& failureReason) | ||
229 | { QTest::addRow("%s", name) << phrase << matchIds << failureReason; }; | 247 | { QTest::addRow("%s", name) << phrase << matchIds << failureReason; }; | ||
230 | 248 | | |||
231 | addRow("Crazy dog", {"crazy", "dog"}, SortedIdVector{ m_id1 }, ""); | 249 | addRow("Crazy dog", {"crazy", "dog"}, SortedIdVector{ m_id1 }, ""); | ||
232 | addRow("Lazy dog", {"lazy", "dog"}, SortedIdVector{ m_id7 }, ""); | 250 | addRow("Lazy dog", {"lazy", "dog"}, SortedIdVector{ m_id7 }, ""); | ||
233 | addRow("Brown fox", {"brown", "fox"}, SortedIdVector{ m_id1, m_id7 }, ""); | 251 | addRow("Brown fox", {"brown", "fox"}, SortedIdVector{ m_id1, m_id7, m_id8 }, ""); | ||
234 | addRow("Crazy dog file 1", {"file1"}, SortedIdVector{ m_id1 }, ""); | 252 | addRow("Crazy dog file 1", {"file1"}, SortedIdVector{ m_id1 }, ""); | ||
235 | addRow("Crazy dog file 2", {"file1", "txt"}, SortedIdVector{ m_id1 }, ""); | 253 | addRow("Crazy dog file 2", {"file1", "txt"}, SortedIdVector{ m_id1 }, ""); | ||
236 | addRow("Lazy dog file 1", {"file7"}, SortedIdVector{ m_id7 }, ""); | 254 | addRow("Lazy dog file 1", {"file7"}, SortedIdVector{ m_id7 }, ""); | ||
237 | addRow("Lazy dog file 2", {"file7", "lazy"}, SortedIdVector{ m_id7 }, "Content shadows filename"); | 255 | addRow("Lazy dog file 2", {"file7", "lazy"}, SortedIdVector{ m_id7 }, "Content shadows filename"); | ||
256 | addRow("Lazy dog file 3", {"dog"}, SortedIdVector{ m_id1, m_id7, m_id8 }, "Filename shadows content"); | ||||
238 | } | 257 | } | ||
239 | 258 | | |||
240 | void QueryTest::testTermPhrase() | 259 | void QueryTest::testTermPhrase() | ||
241 | { | 260 | { | ||
242 | QFETCH(QByteArrayList, phrase); | 261 | QFETCH(QByteArrayList, phrase); | ||
243 | QFETCH(QVector<quint64>, matchIds); | 262 | QFETCH(QVector<quint64>, matchIds); | ||
244 | QFETCH(QString, failReason); | 263 | QFETCH(QString, failReason); | ||
245 | 264 | | |||
▲ Show 20 Lines • Show All 81 Lines • Show Last 20 Lines |