test-message-date.c revision baf3e87e186453fda13bd21f7cbcb2efc8492e8b
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd/* Copyright (c) 2007-2016 Dovecot authors, see the included COPYING file */
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd#include "lib.h"
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd#include "message-date.h"
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd#include "test-common.h"
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bndstruct test_message_date_output {
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd time_t time;
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd int tz_offset;
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd bool ret;
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen};
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowenstatic void test_message_date_parse(void)
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen{
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd static const char *input[] = {
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd#ifdef TIME_T_SIGNED
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd "Thu, 01 Jan 1970 01:59:59 +0200",
d229f940abfb2490dee17979e9a5ff31b7012eb5rbowen "Fri, 13 Dec 1901 20:45:53 +0000",
3f08db06526d6901aa08c110b5bc7dde6bc39905nd#endif
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd#if (TIME_T_MAX_BITS > 32 || !defined(TIME_T_SIGNED))
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd "Sun, 07 Feb 2106 06:28:15 +0000",
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd#endif
3f08db06526d6901aa08c110b5bc7dde6bc39905nd "Wed, 07 Nov 2007 01:07:20 +0200",
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd "Wed, 07 Nov 2007 01:07:20",
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd "Thu, 01 Jan 1970 02:00:00 +0200",
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd "Tue, 19 Jan 2038 03:14:07 +0000",
ad74a0524a06bfe11b7de9e3b4ce7233ab3bd3f7nd "Tue, 19 Jan 2038"
d28579afd45cc42da1422161721fb12f9cf366b9nd };
ad74a0524a06bfe11b7de9e3b4ce7233ab3bd3f7nd static struct test_message_date_output output[] = {
1ac39787115a288f5e848344b1b1e8dccb1c58f1nd#ifdef TIME_T_SIGNED
f086b4b402fa9a2fefc7dda85de2a3cc1cd0a654rjung { -1, 2*60, TRUE },
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd { -2147483647, 0, TRUE },
4b575a6b6704b516f22d65a3ad35696d7b9ba372rpluem#endif
4b575a6b6704b516f22d65a3ad35696d7b9ba372rpluem#if (TIME_T_MAX_BITS > 32 || !defined(TIME_T_SIGNED))
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd { 4294967295U, 0, TRUE },
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd#endif
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd { 1194390440, 2*60, TRUE },
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd { 1194397640, 0, TRUE },
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd { 0, 2*60, TRUE },
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd { 2147483647, 0, TRUE },
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd { 0, 0, FALSE }
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd };
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd unsigned int i;
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd bool success;
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd time_t t;
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd int tz;
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd bool ret;
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd for (i = 0; i < N_ELEMENTS(input); i++) {
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd ret = message_date_parse((const unsigned char *)input[i],
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd strlen(input[i]), &t, &tz);
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd success = (!ret && !output[i].ret) ||
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd (ret == output[i].ret && t == output[i].time &&
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd tz == output[i].tz_offset);
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd test_out(t_strdup_printf("message_date_parse(%d)", i), success);
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd }
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd}
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bndint main(void)
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd{
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd static void (*const test_functions[])(void) = {
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd test_message_date_parse,
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd NULL
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd };
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd return test_run(test_functions);
1462ff536f1b939bb337766b2056109c29664c4erbowen}
5652dbe450e4fcfdf36d4cfb42d7f2345ded29a4maczniak