4#include <QFileSystemModel>
13 void dataRemovesGpgExtension();
14 void dataWithInvalidIndex();
15 void flagsWithValidIndex();
16 void flagsWithInvalidIndex();
20 void lessThanDirsFirst();
21 void supportedDropActions();
22 void supportedDragActions();
23 void filterAcceptsRowHidden();
24 void filterExcludesGitDirectory();
25 void filterAcceptsRowVisible();
26 void setModelAndStore();
27 void showThisWithNullFs();
29 void filterRegularExpression();
32void tst_storemodel::dataRemovesGpgExtension() {
33 QTemporaryDir tempDir;
34 QFile f(tempDir.path() +
"/test.gpg");
35 QVERIFY(f.open(QFile::WriteOnly));
39 fsm.setRootPath(tempDir.path());
44 QModelIndex sourceIndex = fsm.index(tempDir.path() +
"/test.gpg");
45 QModelIndex proxyIndex = sm.mapFromSource(sourceIndex);
46 QVariant displayData = sm.
data(proxyIndex, Qt::DisplayRole);
47 QVERIFY(displayData.isValid());
48 QVERIFY(displayData.canConvert<QString>());
49 QString name = displayData.toString();
50 QVERIFY(!name.endsWith(
".gpg"));
53void tst_storemodel::flagsWithValidIndex() {
54 QTemporaryDir tempDir;
55 QFile f(tempDir.path() +
"/test.gpg");
56 QVERIFY(f.open(QFile::WriteOnly));
60 fsm.setRootPath(tempDir.path());
65 QModelIndex sourceIndex = fsm.index(tempDir.path() +
"/test.gpg");
66 QModelIndex proxyIndex = sm.mapFromSource(sourceIndex);
67 Qt::ItemFlags flags = sm.
flags(proxyIndex);
68 QVERIFY(flags & Qt::ItemIsDragEnabled);
69 QVERIFY(flags & Qt::ItemIsDropEnabled);
72void tst_storemodel::flagsWithInvalidIndex() {
73 QTemporaryDir tempDir;
78 QModelIndex invalidIndex;
79 Qt::ItemFlags flags = sm.
flags(invalidIndex);
80 QVERIFY(flags & Qt::ItemIsDropEnabled);
83void tst_storemodel::mimeTypes() {
87 types.contains(
"application/vnd+qtpass.dragAndDropInfoPasswordStore"));
90void tst_storemodel::lessThan() {
91 QTemporaryDir tempDir;
92 QFile passwordA(tempDir.path() +
"/aaa.gpg");
93 QVERIFY(passwordA.open(QFile::WriteOnly));
95 QFile passwordB(tempDir.path() +
"/bbb.gpg");
96 QVERIFY(passwordB.open(QFile::WriteOnly));
100 fsm.setRootPath(tempDir.path());
105 QModelIndex indexA = fsm.index(tempDir.path() +
"/aaa.gpg");
106 QModelIndex indexB = fsm.index(tempDir.path() +
"/bbb.gpg");
108 QVERIFY(sm.
lessThan(indexA, indexB));
111void tst_storemodel::supportedDropActions() {
114 QVERIFY(actions & Qt::CopyAction);
115 QVERIFY(actions & Qt::MoveAction);
118void tst_storemodel::supportedDragActions() {
121 QVERIFY(actions & Qt::CopyAction);
122 QVERIFY(actions & Qt::MoveAction);
125void tst_storemodel::filterAcceptsRowHidden() {
126 QTemporaryDir tempDir;
127 QFile f(tempDir.path() +
"/secret.gpg");
128 QVERIFY(f.open(QFile::WriteOnly));
131 QFileSystemModel fsm;
132 fsm.setRootPath(tempDir.path());
137 sm.setFilterRegularExpression(
"nothing-matches-this");
138 QModelIndex index = fsm.index(tempDir.path() +
"/secret.gpg");
143void tst_storemodel::filterExcludesGitDirectory() {
144 QTemporaryDir tempDir;
145 QDir dir(tempDir.path());
146 QVERIFY(dir.mkdir(
".git"));
148 QFileSystemModel fsm;
149 fsm.setRootPath(tempDir.path());
154 QModelIndex gitIndex = fsm.index(tempDir.path() +
"/.git");
156 QVERIFY2(!result,
".git directory should be hidden");
159void tst_storemodel::filterAcceptsRowVisible() {
160 QTemporaryDir tempDir;
161 QFile passwordFile(tempDir.path() +
"/mypassword.gpg");
162 QVERIFY(passwordFile.open(QFile::WriteOnly));
163 passwordFile.close();
165 QFileSystemModel fsm;
166 fsm.setRootPath(tempDir.path());
171 sm.setFilterRegularExpression(
"password");
172 QModelIndex index = fsm.index(tempDir.path() +
"/mypassword.gpg");
177void tst_storemodel::dataWithInvalidIndex() {
178 QFileSystemModel fsm;
179 QTemporaryDir tempDir;
183 QModelIndex invalidIndex;
184 QVariant result = sm.
data(invalidIndex, Qt::DisplayRole);
185 QVERIFY(result.isNull());
188void tst_storemodel::mimeData() {
189 QTemporaryDir tempDir;
190 QFile testFile(tempDir.path() +
"/testfile.gpg");
191 QVERIFY(testFile.open(QFile::WriteOnly));
194 QFileSystemModel fsm;
195 fsm.setRootPath(tempDir.path());
200 QModelIndex sourceIndex = fsm.index(tempDir.path() +
"/testfile.gpg");
201 QModelIndex proxyIndex = sm.mapFromSource(sourceIndex);
202 QMimeData *data = sm.
mimeData(QModelIndexList() << proxyIndex);
203 QVERIFY(data !=
nullptr);
205 data->hasFormat(
"application/vnd+qtpass.dragAndDropInfoPasswordStore"));
209void tst_storemodel::lessThanDirsFirst() {
211 QSKIP(
"Directory sorting differs on macOS");
213 QTemporaryDir tempDir;
214 QVERIFY(QDir(tempDir.path()).mkdir(
"folder"));
215 QVERIFY(QDir(tempDir.path()).exists(
"folder"));
216 QFile file(tempDir.path() +
"/file.gpg");
217 QVERIFY(file.open(QFile::WriteOnly));
220 QFileSystemModel fsm;
221 fsm.setRootPath(tempDir.path());
226 QCoreApplication::processEvents();
227 QTRY_VERIFY(fsm.index(tempDir.path() +
"/folder").isValid());
228 QTRY_VERIFY(fsm.index(tempDir.path() +
"/file.gpg").isValid());
230 QModelIndex sourceFolderIdx = fsm.index(tempDir.path() +
"/folder");
231 QModelIndex sourceFileIdx = fsm.index(tempDir.path() +
"/file.gpg");
233 QVERIFY(sm.
lessThan(sourceFolderIdx, sourceFileIdx));
237void tst_storemodel::setModelAndStore() {
238 QFileSystemModel fsm;
241 QString storePath =
"/test/store";
244 QVERIFY(sm.sourceModel() == &fsm);
247void tst_storemodel::showThisWithNullFs() {
254void tst_storemodel::getStoreBasic() {
255 QTemporaryDir tempDir;
256 QVERIFY2(tempDir.isValid(),
"Temporary directory should be valid");
257 QFileSystemModel fsm;
261 QVERIFY2(store == tempDir.path(),
"Store path should match");
264void tst_storemodel::filterRegularExpression() {
266 sm.setFilterRegularExpression(QRegularExpression(
"test"));
267 QRegularExpression result = sm.filterRegularExpression();
268 QVERIFY2(result.pattern() ==
"test",
"Filter should match test");
272#include "tst_storemodel.moc"
QSortFilterProxyModel for filtering and displaying password store.
auto getStore() const -> QString
Get the password store root path.
auto data(const QModelIndex &index, int role) const -> QVariant override
Get display data for index.
auto mimeTypes() const -> QStringList override
Get supported MIME types for drag/drop.
auto filterAcceptsRow(int, const QModelIndex &) const -> bool override
Filter whether a row should be displayed.
auto mimeData(const QModelIndexList &indexes) const -> QMimeData *override
Create MIME data from indexes.
auto supportedDragActions() const -> Qt::DropActions override
Get supported drag actions.
auto showThis(const QModelIndex) const -> bool
Check if a specific index should be shown.
auto flags(const QModelIndex &index) const -> Qt::ItemFlags override
Get item flags for index.
auto lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const -> bool override
Compare two indices for sorting.
void setModelAndStore(QFileSystemModel *sourceModel, QString passStore)
Initialize model with source model and store path.
auto supportedDropActions() const -> Qt::DropActions override
Get supported drop actions.