summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorLukas Vogel <lukedirtwalker@gmail.com>2018-03-13 15:59:14 +0100
committerLukas Vogel <lukedirtwalker@gmail.com>2018-03-15 10:04:55 +0100
commit5eb8d771b94dce458e7761131b8c0b85e3e127f4 (patch)
tree011fe01ff41f8893db342d5b70dec0f578e18a23 /tests
parent11cfe409dbe1bf9f82ab9ecbb7a2928a604dff3c (diff)
Introduce FileContent class
This can be used to parse the content of the password file in a common place. In a later commit we should replace the parsing in mainwindow and passworddialog.
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/util/tst_util.cpp38
-rw-r--r--tests/auto/util/util.pro8
2 files changed, 39 insertions, 7 deletions
diff --git a/tests/auto/util/tst_util.cpp b/tests/auto/util/tst_util.cpp
index bd1ba906..2a628dc9 100644
--- a/tests/auto/util/tst_util.cpp
+++ b/tests/auto/util/tst_util.cpp
@@ -1,6 +1,8 @@
#include "../../../src/util.h"
+#include "../../../src/filecontent.h"
#include <QCoreApplication>
#include <QtTest>
+#include <QList>
/**
* @brief The tst_util class is our first unit test
@@ -20,8 +22,13 @@ private Q_SLOTS:
void initTestCase();
void cleanupTestCase();
void normalizeFolderPath();
+ void fileContent();
};
+bool operator==(const NamedValue &a, const NamedValue &b) {
+ return a.name == b.name && a.value == b.value;
+}
+
/**
* @brief tst_util::tst_util basic constructor
*/
@@ -63,5 +70,36 @@ void tst_util::normalizeFolderPath() {
QDir::toNativeSeparators("test/"));
}
+void tst_util::fileContent() {
+ NamedValue key = {"key", "val"};
+ NamedValue key2 = {"key2", "val2"};
+ QString password = "password";
+
+ FileContent fc = FileContent::parse("password\n", {}, false);
+ QCOMPARE(fc.getPassword(), password);
+ QCOMPARE(fc.getNamedValues(), {});
+ QCOMPARE(fc.getRemainingData(), QString());
+
+ fc = FileContent::parse("password", {}, false);
+ QCOMPARE(fc.getPassword(), password);
+ QCOMPARE(fc.getNamedValues(), {});
+ QCOMPARE(fc.getRemainingData(), QString());
+
+ fc = FileContent::parse("password\nfoobar\n", {}, false);
+ QCOMPARE(fc.getPassword(), password);
+ QCOMPARE(fc.getNamedValues(), {});
+ QCOMPARE(fc.getRemainingData(), QString("foobar\n"));
+
+ fc = FileContent::parse("password\nkey: val\nkey2: val2", {"key2"}, false);
+ QCOMPARE(fc.getPassword(), password);
+ QCOMPARE(fc.getNamedValues(), {key2});
+ QCOMPARE(fc.getRemainingData(), QString("key: val"));
+
+ fc = FileContent::parse("password\nkey: val\nkey2: val2", {"key2"}, true);
+ QCOMPARE(fc.getPassword(), password);
+ QCOMPARE(fc.getNamedValues(), NamedValues({key, key2}));
+ QCOMPARE(fc.getRemainingData(), QString());
+}
+
QTEST_MAIN(tst_util)
#include "tst_util.moc"
diff --git a/tests/auto/util/util.pro b/tests/auto/util/util.pro
index 4f88ed0e..e47d464f 100644
--- a/tests/auto/util/util.pro
+++ b/tests/auto/util/util.pro
@@ -7,13 +7,7 @@ SOURCES += tst_util.cpp \
LIBS = -L"$$OUT_PWD/../../../src/$(OBJECTS_DIR)" -lqtpass $$LIBS
HEADERS += util.h \
- qtpasssettings.h \
- settingsconstants.h \
- pass.h \
- realpass.h \
- imitatepass.h \
- executor.h \
- simpletransaction.h
+ filecontent.h
OBJ_PATH += ../../../src/$(OBJECTS_DIR)