diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 09:51:24 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 09:51:24 +0000 |
commit | f7548d6d28c313cf80e6f3ef89aed16a19815df1 (patch) | |
tree | a3f6f2a3f247293bee59ecd28e8cd8ceb6ca064a /pigeonhole/tests/extensions/date | |
parent | Initial commit. (diff) | |
download | dovecot-upstream.tar.xz dovecot-upstream.zip |
Adding upstream version 1:2.3.19.1+dfsg1.upstream/1%2.3.19.1+dfsg1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | pigeonhole/tests/extensions/date/basic.svtest | 73 | ||||
-rw-r--r-- | pigeonhole/tests/extensions/date/date-parts.svtest | 120 | ||||
-rw-r--r-- | pigeonhole/tests/extensions/date/zones.svtest | 76 |
3 files changed, 269 insertions, 0 deletions
diff --git a/pigeonhole/tests/extensions/date/basic.svtest b/pigeonhole/tests/extensions/date/basic.svtest new file mode 100644 index 0000000..5d0b33f --- /dev/null +++ b/pigeonhole/tests/extensions/date/basic.svtest @@ -0,0 +1,73 @@ +require "vnd.dovecot.testsuite"; +require "date"; +require "variables"; +require "relational"; + +test_set "message" text: +From: stephan@example.org +To: sirius@friep.example.com +Subject: Frop! +Date: Mon, 20 Jul 2009 21:44:43 +0300 +Delivery-Date: Mon, 22 Jul 2009 23:30:14 +0300 +Invalid-Date: Moo, 34 Juul 3060 25:30:42 +6600 +Wanna date? +. +; + +test "Defaults" { + if not date :originalzone "date" "std11" "mon, 20 jul 2009 21:44:43 +0300" { + test_fail "default comparator is not i;ascii-casemap"; + } + + if anyof ( date "date" "std11" "Mon", date "date" "std11" "*") { + test_fail "default match type appears to be :contains or :matches"; + } +} + +test "Count" { + if not date :count "eq" "date" "date" "1" { + test_fail "count of existing date header field is not 1"; + } + + if not date :count "eq" "resent-date" "date" "0" { + test_fail "count of non-existent date header field is not 0"; + } +} + +test "Invalid" { + if date :matches "invalid-date" "std11" "*" { + test_fail "matched invalid date: ${0}"; + } +} + +test "Comparison" { + if not date :originalzone :is "delivery-date" "date" "2009-07-22" { + if date :originalzone :matches "delivery-date" "date" "*" { set "date" "${1}"; } + test_fail "date is invalid: ${date}"; + } + if not date :originalzone :value "ge" "delivery-date" "date" "2009-07-22" { + test_fail "date comparison ge failed equal"; + } + + if not date :originalzone :value "ge" "delivery-date" "date" "2009-07-21" { + test_fail "date comparison ge failed greater"; + } + + if anyof (not date :originalzone :value "ge" "delivery-date" "date" "2009-06-22", + not date :originalzone :value "ge" "date" "date" "2006-07-22" ) { + test_fail "date comparison ge failed much greater"; + } + + if not date :originalzone :value "le" "delivery-date" "date" "2009-07-22" { + test_fail "date comparison le failed equal"; + } + + if not date :originalzone :value "le" "delivery-date" "date" "2009-07-23" { + test_fail "date comparison le failed less"; + } + + if anyof (not date :originalzone :value "le" "delivery-date" "date" "2009-09-22", + not date :originalzone :value "le" "date" "date" "2012-07-22" ) { + test_fail "date comparison ge failed much less"; + } +} diff --git a/pigeonhole/tests/extensions/date/date-parts.svtest b/pigeonhole/tests/extensions/date/date-parts.svtest new file mode 100644 index 0000000..edc565c --- /dev/null +++ b/pigeonhole/tests/extensions/date/date-parts.svtest @@ -0,0 +1,120 @@ +require "vnd.dovecot.testsuite"; +require "date"; +require "variables"; + +test_set "message" text: +From: stephan@example.org +To: sirius@friep.example.com +Subject: Frop! +Date: Mon, 20 Jul 2009 21:44:43 +0300 +Delivery-Date: Mon, 22 Jul 2009 23:30:14 +0300 + +Wanna date? +. +; + +/* "year" => the year, "0000" .. "9999". */ +test "Year" { + if not date :originalzone "date" "year" "2009" { + test_fail "failed to extract year part"; + } +} + +/* "month" => the month, "01" .. "12". */ +test "Month" { + if not date :originalzone "date" "month" "07" { + test_fail "failed to extract month part"; + } +} + +/* "day" => the day, "01" .. "31". */ +test "Day" { + if not date :originalzone "date" "day" "20" { + test_fail "failed to extract day part"; + } +} + +/* "date" => the date in "yyyy-mm-dd" format. */ +test "Date" { + if not date :originalzone "date" "date" "2009-07-20" { + test_fail "failed to extract date part"; + } +} + +/* "julian" => the Modified Julian Day, that is, the date + expressed as an integer number of days since + 00:00 UTC on November 17, 1858 (using the Gregorian + calendar). This corresponds to the regular + Julian Day minus 2400000.5. */ +test "Julian" { + if not date :originalzone "date" "julian" "55032" { + if date :matches :originalzone "date" "julian" "*" { } + test_fail "failed to extract julian part: ${0}"; + } + if not date :originalzone "delivery-date" "julian" "55034" { + if date :matches :originalzone "delivery-date" "julian" "*" { } + test_fail "failed to extract julian part: ${0}"; + } +} + +/* "hour" => the hour, "00" .. "23". */ +test "Hour" { + if not date :originalzone "date" "hour" "21" { + test_fail "failed to extract hour part"; + } +} + +/* "minute" => the minute, "00" .. "59". */ +test "Minute" { + if not date :originalzone "date" "minute" "44" { + test_fail "failed to extract minute part"; + } +} + +/* "second" => the second, "00" .. "60". */ +test "Second" { + if not date :originalzone "date" "second" "43" { + test_fail "failed to extract second part"; + } +} + +/* "time" => the time in "hh:mm:ss" format. */ +test "Time" { + if not date :originalzone "date" "time" "21:44:43" { + test_fail "failed to extract time part"; + } +} + +/* "iso8601" => the date and time in restricted ISO 8601 format. */ +test "ISO8601" { + if not date :originalzone "date" "iso8601" "2009-07-20T21:44:43+03:00" { + test_fail "failed to extract iso8601 part"; + } +} + +/* "std11" => the date and time in a format appropriate + for use in a Date: header field [RFC2822]. */ +test "STD11" { + if not date :originalzone "date" "std11" "Mon, 20 Jul 2009 21:44:43 +0300" { + test_fail "failed to extract std11 part"; + } +} + +/* "zone" => the time zone in use. */ +test "zone" { + if not date :originalzone "date" "zone" "+0300" { + test_fail "failed to extract zone part"; + } + + if not date :zone "+0200" "date" "zone" "+0200" { + test_fail "failed to extract zone part"; + } +} + +/* "weekday" => the day of the week expressed as an integer between + "0" and "6". "0" is Sunday, "1" is Monday, etc. */ +test "Weekday" { + if not date :originalzone "date" "weekday" "1" { + test_fail "failed to extract weekday part"; + } +} diff --git a/pigeonhole/tests/extensions/date/zones.svtest b/pigeonhole/tests/extensions/date/zones.svtest new file mode 100644 index 0000000..77adb77 --- /dev/null +++ b/pigeonhole/tests/extensions/date/zones.svtest @@ -0,0 +1,76 @@ +require "vnd.dovecot.testsuite"; +require "date"; +require "variables"; + +/* Extract local timezone first */ +test "Local-Zone" { + if not currentdate :matches "zone" "*" { + test_fail "matches '*' failed for zone part."; + } + set "local_zone" "${0}"; +} + +/* FIXME: using variables somehow fails here */ +if string "${local_zone}" "+0200" { +test_set "message" text: +From: stephan@example.org +To: sirius@friep.example.com +Subject: Frop! +Date: Mon, 20 Jul 2009 21:44:43 +0300 +Delivery-Date: Mon, 23 Jul 2009 05:30:14 +0800 + +Wanna date? +. +; +} else { +test_set "message" text: +From: stephan@example.org +To: sirius@friep.example.com +Subject: Frop! +Date: Mon, 20 Jul 2009 21:44:43 +0300 +Delivery-Date: Mon, 22 Jul 2009 23:30:14 +0200 + +Wanna date? +. +; +} + +test "Specified Zone" { + if not date :zone "+0200" "date" "zone" "+0200" { + if date :matches :zone "+0200" "date" "zone" "*" {} + test_fail "zone is incorrect: ${0}"; + } + + if not date :zone "+0200" "date" "time" "20:44:43" { + test_fail "zone is not applied"; + } +} + +test "Original Zone" { + if not date :originalzone "date" "zone" "+0300" { + if date :matches :originalzone "date" "zone" "*" {} + test_fail "zone is incorrect: ${0}"; + } + + if not date :originalzone "date" "time" "21:44:43" { + test_fail "time should be left untouched"; + } +} + +test "Local Zone Shift" { + if anyof ( + allof ( + string "${local_zone}" "+0200", + date "delivery-date" "iso8601" "2009-07-23T05:30:14+08:00"), + allof ( + not string "${local_zone}" "+0200", + date "delivery-date" "iso8601" "2009-07-22T23:30:14+02:00")) { + + if date :matches "delivery-date" "iso8601" "*" + { set "a" "${0}"; } + if date :originalzone :matches "delivery-date" "iso8601" "*" + { set "b" "${0}"; } + + test_fail "time not shifted to local zone: ${b} => ${a}"; + } +} |