xca/lib/test_asn1time.cpp
Christian Hohnstaedt ee48266625 Update OpenSSL versions
Stay with QT 6.6.3 on Windows, because windeployqt
does not deploy the gcc libs with QT 6.7.2
Stay with QT 6.6.3 on MacOS, because the info/warning
message does not show an icon
2024-08-20 11:00:21 +02:00

74 lines
1.4 KiB
C++

/* vi: set sw=4 ts=4:
*
* Copyright (C) 2023 Christian Hohnstaedt.
*
* All rights reserved.
*/
#include <QTest>
#include <QLocale>
#include <QTimeZone>
#include "asn1time.h"
#include <stdlib.h>
#include <time.h>
class test_asn1time: public QObject
{
Q_OBJECT
private slots:
void construct_op();
void output();
};
void test_asn1time::construct_op()
{
a1time b, a("20191125153015Z");
QVERIFY(a.isValid());
QVERIFY(!a.isUndefined());
QVERIFY(b != a);
QVERIFY(b > a);
b = a;
QCOMPARE(b , a);
a1time c(a.get());
QCOMPARE(c , a);
a1time d(a.get_utc());
QCOMPARE(d , a.toUTC());
}
void test_asn1time::output()
{
QLocale::setDefault(QLocale::C);
#if !defined(Q_OS_WIN32)
setenv("TZ","UTC", 1);
tzset();
#endif
a1time a("20191125153015Z");
QCOMPARE(a.toString("yyyy MM"), "2019 11");
QCOMPARE(a.toSortable(), "2019-11-25");
QCOMPARE(a.toPlain(), "20191125153015Z");
QCOMPARE(a.toPlainUTC(), "191125153015Z");
#if !defined(Q_OS_WIN32)
a.setTimeZone(QTimeZone("UTC"));
#if (QT_VERSION >= QT_VERSION_CHECK(6, 7, 0))
#define UTC "GMT"
#else
#define UTC "UTC"
#endif
QCOMPARE(a.toPretty(), "Monday, 25 November 2019 15:30:15 " UTC);
a.setTimeZone(QTimeZone("Europe/Berlin"));
QCOMPARE(a.toPretty(), "Monday, 25 November 2019 14:30:15 " UTC);
a.setTimeZone(QTimeZone("UTC+07:00"));
QCOMPARE(a.toPretty(), "Monday, 25 November 2019 08:30:15 " UTC);
#endif
}
QTEST_MAIN(test_asn1time)
#include "test_asn1time.moc"