File: test_asn1time.cpp

package info (click to toggle)
xca 2.9.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 8,328 kB
  • sloc: cpp: 30,584; sh: 341; xml: 74; makefile: 56; python: 34
file content (73 lines) | stat: -rw-r--r-- 1,466 bytes parent folder | download | duplicates (2)
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
65
66
67
68
69
70
71
72
73
/* 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"