1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
#include "../../../src/passworddialog.h"
#include "passwordconfiguration.h"
#include <QCoreApplication>
#include <QtTest>
/**
* @brief The tst_ui class is our first unit test
*/
class tst_ui : public QObject {
Q_OBJECT
private Q_SLOTS:
void contentRemainsSame();
};
/**
* @brief tst_ui::contentRemainsSame test that content set with
* PasswordDialog::setPassword is repeated when calling
* PasswordDialog::getPassword.
*/
void tst_ui::contentRemainsSame() {
QScopedPointer<PasswordDialog> d(
new PasswordDialog(PasswordConfiguration{}, nullptr));
d->setTemplate("", false);
QString input = "pw\n";
d->setPass(input);
QCOMPARE(d->getPassword(), input);
d.reset(new PasswordDialog(PasswordConfiguration{}, nullptr));
input = "pw\nname: value\n";
d->setPass(input);
QCOMPARE(d->getPassword(), input);
d.reset(new PasswordDialog(PasswordConfiguration{}, nullptr));
d->setTemplate("name", false);
d->setPass(input);
QCOMPARE(d->getPassword(), input);
d.reset(new PasswordDialog(PasswordConfiguration{}, nullptr));
d->setTemplate("name", true);
d->setPass(input);
QCOMPARE(d->getPassword(), input);
d.reset(new PasswordDialog(PasswordConfiguration{}, nullptr));
d->setTemplate("", false);
d->templateAll(true);
d->setPass(input);
QCOMPARE(d->getPassword(), input);
d.reset(new PasswordDialog(PasswordConfiguration{}, nullptr));
d->setTemplate("", true);
d->templateAll(true);
d->setPass(input);
QCOMPARE(d->getPassword(), input);
d.reset(new PasswordDialog(PasswordConfiguration{}, nullptr));
d->setTemplate("name", true);
d->templateAll(true);
d->setPass(input);
QCOMPARE(d->getPassword(), input);
}
QTEST_MAIN(tst_ui)
#include "tst_ui.moc"
|