mirror of
https://github.com/chris2511/xca.git
synced 2026-09-12 19:51:05 +05:00
Add tests for the DateTime input for validity times.
Test the correct behavior of the "Midnight" and setDiff methods. Especially to keep the time when switching from hidden time (midnoght) back to shown time.
This commit is contained in:
parent
a53e0a96aa
commit
68b14617cc
@ -1,6 +1,6 @@
|
||||
|
||||
list(APPEND srcs PwDialogMock.h importPEM.cpp main.cpp main.h
|
||||
newKey.cpp pem.cpp export.cpp renewal.cpp)
|
||||
newKey.cpp pem.cpp export.cpp renewal.cpp validity.cpp)
|
||||
|
||||
list(TRANSFORM srcs PREPEND ${PROJECT_SOURCE_DIR}/test/)
|
||||
|
||||
|
||||
@ -35,6 +35,7 @@ class test_main: public QObject
|
||||
void importPEM();
|
||||
void exportFormat();
|
||||
void revoke();
|
||||
void testValidity();
|
||||
|
||||
public:
|
||||
template <class T> static T *findWindow(const QString &name)
|
||||
|
||||
55
test/validity.cpp
Normal file
55
test/validity.cpp
Normal file
@ -0,0 +1,55 @@
|
||||
/* vi: set sw=4 ts=4:
|
||||
*
|
||||
* Copyright (C) 2023 Christian Hohnstaedt.
|
||||
*
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
#include <QTest>
|
||||
|
||||
#include "widgets/MainWindow.h"
|
||||
#include "widgets/validity.h"
|
||||
|
||||
#include "main.h"
|
||||
|
||||
void test_main::testValidity()
|
||||
{
|
||||
try {
|
||||
|
||||
Validity *start = new Validity(mainwin);
|
||||
Validity *end = new Validity(mainwin);
|
||||
|
||||
QCOMPARE(start->displayFormat(), "yyyy-MM-dd hh:mm 'GMT'");
|
||||
QCOMPARE(end->displayFormat(), "yyyy-MM-dd hh:mm 'GMT'");
|
||||
end->setEndDate(true);
|
||||
start->hideTime(true);
|
||||
end->hideTime(true);
|
||||
QCOMPARE(start->displayFormat(), "yyyy-MM-dd 00:00 'GMT'");
|
||||
QCOMPARE(end->displayFormat(), "yyyy-MM-dd 23:59 'GMT'");
|
||||
|
||||
start->setDate(a1time("20130921094317Z"));
|
||||
end->setDiff(start, 7, 0);
|
||||
QCOMPARE(start->getDate().toPlain(), "20130921000000Z");
|
||||
QCOMPARE(end->getDate().toPlain(), "20130927235959Z");
|
||||
start->hideTime(false);
|
||||
end->hideTime(false);
|
||||
QCOMPARE(start->getDate().toPlain(), "20130921094300Z");
|
||||
QCOMPARE(end->getDate().toPlain(), "20130928094300Z");
|
||||
start->hideTime(false);
|
||||
QCOMPARE(start->getDate().toPlain(), "20130921094300Z");
|
||||
start->hideTime(true);
|
||||
end->hideTime(true);
|
||||
QCOMPARE(start->getDate().toPlain(), "20130921000000Z");
|
||||
QCOMPARE(end->getDate().toPlain(), "20130927235959Z");
|
||||
|
||||
end->setDiff(start, 2, 1);
|
||||
QCOMPARE(end->getDate().toPlain(), "20131120235959Z");
|
||||
end->hideTime(true);
|
||||
QCOMPARE(end->getDate().toPlain(), "20131120235959Z");
|
||||
end->hideTime(false);
|
||||
QCOMPARE(end->getDate().toPlain(), "20131121094300Z");
|
||||
|
||||
} catch (...) {
|
||||
QVERIFY2(false, "Exception thrown");
|
||||
}
|
||||
}
|
||||
@ -57,7 +57,6 @@ void Validity::localTime(int state)
|
||||
break;
|
||||
}
|
||||
updateFormatString();
|
||||
setMyTime(time());
|
||||
}
|
||||
|
||||
void Validity::hideTimeCheck(int state)
|
||||
@ -112,6 +111,7 @@ void Validity::updateFormatString()
|
||||
void Validity::setDate(const a1time &a)
|
||||
{
|
||||
setDateTime(a);
|
||||
setMyTime(a.time());
|
||||
}
|
||||
|
||||
void Validity::setDiff(const Validity *start, int number, int range)
|
||||
@ -134,8 +134,7 @@ void Validity::setDiff(const Validity *start, int number, int range)
|
||||
|
||||
void Validity::setNow()
|
||||
{
|
||||
setDateTime(a1time::now());
|
||||
setMyTime(time());
|
||||
setDate(a1time());
|
||||
}
|
||||
|
||||
void Validity::setMyTime(const QTime &time)
|
||||
@ -143,3 +142,8 @@ void Validity::setMyTime(const QTime &time)
|
||||
mytime = time;
|
||||
}
|
||||
|
||||
void Validity::setEndDate(bool ed)
|
||||
{
|
||||
endDate = ed;
|
||||
hideTime(midnight);
|
||||
}
|
||||
|
||||
@ -28,10 +28,8 @@ class Validity : public QDateTimeEdit
|
||||
void setDate(const a1time &a);
|
||||
void setDiff(const Validity *start, int number, int range);
|
||||
void hideTime(bool hide);
|
||||
void setEndDate(bool ed)
|
||||
{
|
||||
endDate = ed;
|
||||
}
|
||||
void setEndDate(bool ed);
|
||||
|
||||
protected slots:
|
||||
void setMyTime(const QTime & time);
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user