QtPass 1.4.0
Multi-platform GUI for pass, the standard unix password manager.
Loading...
Searching...
No Matches
tst_util.cpp
Go to the documentation of this file.
1#include "../../../src/filecontent.h"
2#include "../../../src/util.h"
3#include <QCoreApplication>
4#include <QList>
5#include <QtTest>
6
10class tst_util : public QObject {
11 Q_OBJECT
12
13public:
15 ~tst_util() override;
16
17public Q_SLOTS:
18 void init();
19 void cleanup();
20
21private Q_SLOTS:
22 void initTestCase();
23 void cleanupTestCase();
24 void normalizeFolderPath();
25 void fileContent();
26};
27
28bool operator==(const NamedValue &a, const NamedValue &b) {
29 return a.name == b.name && a.value == b.value;
30}
31
35tst_util::tst_util() = default;
36
40tst_util::~tst_util() = default;
41
46
51
55void tst_util::initTestCase() {}
56
60void tst_util::cleanupTestCase() {}
61
66void tst_util::normalizeFolderPath() {
67 QCOMPARE(Util::normalizeFolderPath("test"),
68 QDir::toNativeSeparators("test/"));
69 QCOMPARE(Util::normalizeFolderPath("test/"),
70 QDir::toNativeSeparators("test/"));
71}
72
73void tst_util::fileContent() {
74 NamedValue key = {"key", "val"};
75 NamedValue key2 = {"key2", "val2"};
76 QString password = "password";
77
78 FileContent fc = FileContent::parse("password\n", {}, false);
79 QCOMPARE(fc.getPassword(), password);
80 QCOMPARE(fc.getNamedValues(), {});
81 QCOMPARE(fc.getRemainingData(), QString());
82
83 fc = FileContent::parse("password", {}, false);
84 QCOMPARE(fc.getPassword(), password);
85 QCOMPARE(fc.getNamedValues(), {});
86 QCOMPARE(fc.getRemainingData(), QString());
87
88 fc = FileContent::parse("password\nfoobar\n", {}, false);
89 QCOMPARE(fc.getPassword(), password);
90 QCOMPARE(fc.getNamedValues(), {});
91 QCOMPARE(fc.getRemainingData(), QString("foobar\n"));
92
93 fc = FileContent::parse("password\nkey: val\nkey2: val2", {"key2"}, false);
94 QCOMPARE(fc.getPassword(), password);
95 QCOMPARE(fc.getNamedValues(), {key2});
96 QCOMPARE(fc.getRemainingData(), QString("key: val"));
97
98 fc = FileContent::parse("password\nkey: val\nkey2: val2", {"key2"}, true);
99 QCOMPARE(fc.getPassword(), password);
100 QCOMPARE(fc.getNamedValues(), NamedValues({key, key2}));
101 QCOMPARE(fc.getRemainingData(), QString());
102}
103
104QTEST_MAIN(tst_util)
105#include "tst_util.moc"
QString getRemainingData() const
Definition: filecontent.cpp:40
QString getPassword() const
Definition: filecontent.cpp:36
NamedValues getNamedValues() const
Definition: filecontent.cpp:38
static FileContent parse(const QString &fileContent, const QStringList &templateFields, bool allFields)
parse parses the given fileContent in a FileContent object. The password is accessible through getPas...
Definition: filecontent.cpp:7
The NamedValues class is mostly a list of NamedValue but also has a method to take a specific NamedVa...
Definition: filecontent.h:17
static QString normalizeFolderPath(QString path)
Util::normalizeFolderPath let's always end folders with a QDir::separator()
Definition: util.cpp:79
The tst_util class is our first unit test.
Definition: tst_util.cpp:10
void cleanup()
tst_util::cleanup unit test cleanup method
Definition: tst_util.cpp:50
tst_util()
tst_util::tst_util basic constructor
void init()
tst_util::init unit test init method
Definition: tst_util.cpp:45
~tst_util() override
tst_util::~tst_util basic destructor
QString name
Definition: filecontent.h:9
QString value
Definition: filecontent.h:10
bool operator==(const NamedValue &a, const NamedValue &b)
Definition: tst_util.cpp:28