3#include <QCoreApplication>
24 void contentRemainsSame();
26 void multilineRemainingData();
27 void cleanupTestCase();
28 void passwordDialogBasic();
29 void passwordDialogWithTemplate();
30 void qrCodePopupDeletesOnClose();
31 void qrCodePopupHasDeleteOnCloseAttribute();
32 void createQRCodePopupSetsDeleteOnClose();
33 void dialogWithoutDeleteOnCloseDoesNotAutoDelete();
36 void clipboardButtonDefaultText();
37 void clipboardButtonConstructorText();
38 void clipboardButtonGetSetText();
39 void clipboardButtonSetEmptyText();
40 void clipboardButtonSetAndGetRoundtrip();
41 void clipboardButtonClickEmitsSignal();
42 void clipboardButtonClickSignalCarriesText();
43 void clipboardButtonClickAfterSetTextCarriesNewText();
46 void qrCodeButtonDefaultText();
47 void qrCodeButtonConstructorText();
48 void qrCodeButtonGetSetText();
49 void qrCodeButtonSetEmptyText();
50 void qrCodeButtonSetAndGetRoundtrip();
51 void qrCodeButtonClickEmitsSignal();
52 void qrCodeButtonClickSignalCarriesText();
53 void qrCodeButtonClickAfterSetTextCarriesNewText();
56 void showPasswordButtonInitialEchoMode();
57 void showPasswordButtonClickTogglesEchoMode();
58 void showPasswordButtonDoubleClickRestoresEchoMode();
61 void progressIndicatorDefaultNotAnimated();
62 void progressIndicatorDefaultDelay();
63 void progressIndicatorDefaultNotDisplayedWhenStopped();
64 void progressIndicatorDefaultColor();
65 void progressIndicatorStartAnimation();
66 void progressIndicatorStopAnimation();
67 void progressIndicatorStartStopCycle();
68 void progressIndicatorSetAnimationDelay();
69 void progressIndicatorSetDisplayedWhenStopped();
70 void progressIndicatorSetColor();
71 void progressIndicatorSizeHint();
72 void progressIndicatorHeightForWidth();
73 void progressIndicatorStopWhenNotRunningIsHarmless();
74 void progressIndicatorStartTwiceDoesNotDuplicate();
77 void deselectableTreeViewConstruction();
78 void deselectableTreeViewHasEmptyClickedSignal();
86void tst_ui::contentRemainsSame() {
87 QScopedPointer<PasswordDialog> d(
89 d->setTemplate(
"",
false);
90 QString input =
"pw\n";
92 QCOMPARE(d->getPassword(), input);
94 d.reset(
new PasswordDialog(PasswordConfiguration{},
nullptr));
95 input =
"pw\nname: value\n";
97 QCOMPARE(d->getPassword(), input);
99 d.reset(
new PasswordDialog(PasswordConfiguration{},
nullptr));
100 d->setTemplate(
"name",
false);
102 QCOMPARE(d->getPassword(), input);
104 d.reset(
new PasswordDialog(PasswordConfiguration{},
nullptr));
105 d->setTemplate(
"name",
true);
107 QCOMPARE(d->getPassword(), input);
109 d.reset(
new PasswordDialog(PasswordConfiguration{},
nullptr));
110 d->setTemplate(
"",
false);
111 d->templateAll(
true);
113 QCOMPARE(d->getPassword(), input);
115 d.reset(
new PasswordDialog(PasswordConfiguration{},
nullptr));
116 d->setTemplate(
"",
true);
117 d->templateAll(
true);
119 QCOMPARE(d->getPassword(), input);
121 d.reset(
new PasswordDialog(PasswordConfiguration{},
nullptr));
122 d->setTemplate(
"name",
true);
123 d->templateAll(
true);
125 QCOMPARE(d->getPassword(), input);
128void tst_ui::initTestCase() {}
130void tst_ui::cleanupTestCase() {}
132void tst_ui::emptyPassword() {
133 QScopedPointer<PasswordDialog> d(
134 new PasswordDialog(PasswordConfiguration{},
nullptr));
135 d->setTemplate(
"",
false);
137 QString result = d->getPassword();
138 QVERIFY(result.isEmpty() || result ==
"\n");
141void tst_ui::multilineRemainingData() {
142 QScopedPointer<PasswordDialog> d(
143 new PasswordDialog(PasswordConfiguration{},
nullptr));
144 d->setTemplate(
"",
false);
145 QString input =
"secret\nline1\nline2\nline3\n";
147 QString result = d->getPassword();
148 QStringList lines = result.split(
"\n");
149 QVERIFY(lines.length() >= 4);
151 QString remaining = lines.join(
"\n") + (result.endsWith(
"\n") ?
"\n" :
"");
152 QVERIFY(remaining.contains(
"line1"));
153 QVERIFY(remaining.contains(
"line2"));
154 QVERIFY(remaining.contains(
"line3"));
157void tst_ui::passwordDialogBasic() {
158 PasswordConfiguration config;
160 QScopedPointer<PasswordDialog> d(
new PasswordDialog(config,
nullptr));
161 d->setTemplate(
"",
false);
162 d->setPass(
"testpassword");
163 QString result = d->getPassword();
164 QVERIFY(result.contains(
"testpassword"));
167void tst_ui::passwordDialogWithTemplate() {
168 PasswordConfiguration config;
169 QScopedPointer<PasswordDialog> d(
new PasswordDialog(config,
nullptr));
170 d->setTemplate(
"username",
false);
171 d->setPass(
"mypassword\nusername: testuser");
172 QString result = d->getPassword();
173 QVERIFY(result.contains(
"mypassword"));
182void tst_ui::qrCodePopupDeletesOnClose() {
183 QPointer<QDialog> popup(
184 new QDialog(
nullptr, Qt::Popup | Qt::FramelessWindowHint));
185 popup->setAttribute(Qt::WA_DeleteOnClose);
186 QVERIFY(!popup.isNull());
189 QCoreApplication::processEvents();
190 QTRY_VERIFY(popup.isNull());
198void tst_ui::qrCodePopupHasDeleteOnCloseAttribute() {
199 QDialog *popup =
new QDialog(
nullptr, Qt::Popup | Qt::FramelessWindowHint);
200 popup->setAttribute(Qt::WA_DeleteOnClose);
201 QVERIFY(popup->testAttribute(Qt::WA_DeleteOnClose));
210void tst_ui::createQRCodePopupSetsDeleteOnClose() {
213 QVERIFY(popup->testAttribute(Qt::WA_DeleteOnClose));
223void tst_ui::dialogWithoutDeleteOnCloseDoesNotAutoDelete() {
224 QPointer<QDialog> popup(
225 new QDialog(
nullptr, Qt::Popup | Qt::FramelessWindowHint));
227 QVERIFY(!popup->testAttribute(Qt::WA_DeleteOnClose));
230 QCoreApplication::processEvents();
234 "QDialog without WA_DeleteOnClose must NOT be deleted after close()");
240void tst_ui::clipboardButtonDefaultText() {
241 QPushButtonWithClipboard btn;
245void tst_ui::clipboardButtonConstructorText() {
246 QPushButtonWithClipboard btn(
"hello");
250void tst_ui::clipboardButtonGetSetText() {
251 QPushButtonWithClipboard btn(
"initial");
256void tst_ui::clipboardButtonSetEmptyText() {
257 QPushButtonWithClipboard btn(
"nonempty");
262void tst_ui::clipboardButtonSetAndGetRoundtrip() {
263 QPushButtonWithClipboard btn;
264 QString text =
"password123!@#";
269void tst_ui::clipboardButtonClickEmitsSignal() {
270 QPushButtonWithClipboard btn(
"test");
271 QSignalSpy spy(&btn, SIGNAL(clicked(QString)));
273 QCOMPARE(spy.count(), 1);
276void tst_ui::clipboardButtonClickSignalCarriesText() {
277 QPushButtonWithClipboard btn(
"mytext");
278 QSignalSpy spy(&btn, SIGNAL(clicked(QString)));
280 QCOMPARE(spy.count(), 1);
281 QList<QVariant> args = spy.takeFirst();
282 QCOMPARE(args.at(0).toString(), QString(
"mytext"));
285void tst_ui::clipboardButtonClickAfterSetTextCarriesNewText() {
286 QPushButtonWithClipboard btn(
"original");
288 QSignalSpy spy(&btn, SIGNAL(clicked(QString)));
290 QCOMPARE(spy.count(), 1);
291 QList<QVariant> args = spy.takeFirst();
292 QCOMPARE(args.at(0).toString(), QString(
"changed"));
297void tst_ui::qrCodeButtonDefaultText() {
298 QPushButtonAsQRCode btn;
302void tst_ui::qrCodeButtonConstructorText() {
303 QPushButtonAsQRCode btn(
"qrdata");
307void tst_ui::qrCodeButtonGetSetText() {
308 QPushButtonAsQRCode btn(
"first");
313void tst_ui::qrCodeButtonSetEmptyText() {
314 QPushButtonAsQRCode btn(
"nonempty");
319void tst_ui::qrCodeButtonSetAndGetRoundtrip() {
320 QPushButtonAsQRCode btn;
321 QString text =
"otpauth://totp/Example?secret=JBSWY3DPEHPK3PXP";
326void tst_ui::qrCodeButtonClickEmitsSignal() {
327 QPushButtonAsQRCode btn(
"somedata");
328 QSignalSpy spy(&btn, SIGNAL(clicked(QString)));
330 QCOMPARE(spy.count(), 1);
333void tst_ui::qrCodeButtonClickSignalCarriesText() {
334 QPushButtonAsQRCode btn(
"payload");
335 QSignalSpy spy(&btn, SIGNAL(clicked(QString)));
337 QCOMPARE(spy.count(), 1);
338 QList<QVariant> args = spy.takeFirst();
339 QCOMPARE(args.at(0).toString(), QString(
"payload"));
342void tst_ui::qrCodeButtonClickAfterSetTextCarriesNewText() {
343 QPushButtonAsQRCode btn(
"old");
345 QSignalSpy spy(&btn, SIGNAL(clicked(QString)));
347 QCOMPARE(spy.count(), 1);
348 QList<QVariant> args = spy.takeFirst();
349 QCOMPARE(args.at(0).toString(), QString(
"new"));
354void tst_ui::showPasswordButtonInitialEchoMode() {
356 line.setEchoMode(QLineEdit::Password);
357 QPushButtonShowPassword btn(&line);
359 QCOMPARE(line.echoMode(), QLineEdit::Password);
362void tst_ui::showPasswordButtonClickTogglesEchoMode() {
364 line.setEchoMode(QLineEdit::Password);
365 QPushButtonShowPassword btn(&line);
368 QCOMPARE(line.echoMode(), QLineEdit::Normal);
371void tst_ui::showPasswordButtonDoubleClickRestoresEchoMode() {
373 line.setEchoMode(QLineEdit::Password);
374 QPushButtonShowPassword btn(&line);
377 QCOMPARE(line.echoMode(), QLineEdit::Normal);
380 QCOMPARE(line.echoMode(), QLineEdit::Password);
385void tst_ui::progressIndicatorDefaultNotAnimated() {
386 QProgressIndicator indicator;
390void tst_ui::progressIndicatorDefaultDelay() {
391 QProgressIndicator indicator;
395void tst_ui::progressIndicatorDefaultNotDisplayedWhenStopped() {
396 QProgressIndicator indicator;
400void tst_ui::progressIndicatorDefaultColor() {
401 QProgressIndicator indicator;
402 QCOMPARE(indicator.
color(), QColor(Qt::black));
405void tst_ui::progressIndicatorStartAnimation() {
406 QProgressIndicator indicator;
413void tst_ui::progressIndicatorStopAnimation() {
414 QProgressIndicator indicator;
421void tst_ui::progressIndicatorStartStopCycle() {
422 QProgressIndicator indicator;
433void tst_ui::progressIndicatorSetAnimationDelay() {
434 QProgressIndicator indicator;
439void tst_ui::progressIndicatorSetDisplayedWhenStopped() {
440 QProgressIndicator indicator;
448void tst_ui::progressIndicatorSetColor() {
449 QProgressIndicator indicator;
452 QCOMPARE(indicator.
color(), red);
455void tst_ui::progressIndicatorSizeHint() {
456 QProgressIndicator indicator;
458 QCOMPARE(hint, QSize(20, 20));
461void tst_ui::progressIndicatorHeightForWidth() {
462 QProgressIndicator indicator;
468void tst_ui::progressIndicatorStopWhenNotRunningIsHarmless() {
469 QProgressIndicator indicator;
476void tst_ui::progressIndicatorStartTwiceDoesNotDuplicate() {
477 QProgressIndicator indicator;
489void tst_ui::deselectableTreeViewConstruction() {
491 QScopedPointer<DeselectableTreeView> view(
new DeselectableTreeView(
nullptr));
492 QVERIFY(view !=
nullptr);
495void tst_ui::deselectableTreeViewHasEmptyClickedSignal() {
497 QScopedPointer<DeselectableTreeView> view(
new DeselectableTreeView(
nullptr));
498 QSignalSpy spy(view.data(), SIGNAL(emptyClicked()));
499 QVERIFY(spy.isValid());
501 QCOMPARE(spy.count(), 0);
auto animationDelay() const -> int
Returns the delay between animation steps.
auto heightForWidth(int w) const -> int
QProgressIndicator::heightForWidth square ratio.
void stopAnimation()
Stops the spin animation.
auto isAnimated() const -> bool
Returns a Boolean value indicating whether the component is currently animated.
void startAnimation()
Starts the spin animation.
auto isDisplayedWhenStopped() const -> bool
Returns a Boolean value indicating whether the receiver shows itself even when it is not animating.
void setColor(const QColor &color)
Sets the color of the components to the given color.
void setDisplayedWhenStopped(bool state)
Sets whether the component hides itself when it is not animating.
virtual auto sizeHint() const -> QSize
QProgressIndicator::sizeHint default minimum size.
void setAnimationDelay(int delay)
Sets the delay between animation steps.
auto color() const -> const QColor &
Returns the color of the component.
static QDialog * createQRCodePopup(const QPixmap &image)
QtPass::createQRCodePopup creates a popup dialog with the given QR code image. This is extracted for ...
Holds the Password configuration settings.
int length
Length of the password.