view src/lib/test-utc-mktime.c @ 21389:59437f8764c6

global: Replaced all instances of memset(p, 0, sizeof(*p)) with the new i_zero() macro. Used the following script: C_FILES=`git ls-files *.c` H_FILES=`git ls-files *.h` for F in "$C_FILES $H_FILES"; do echo "$F" perl -p -i -e 's/safe_memset\(&\(?([^,]*)\)?,\s*0,\s*sizeof\(\g1\)\)/i_zero_safe(&$1)/g' $F perl -p -i -e 's/safe_memset\(([^,]*),\s*0,\s*sizeof\(\*\g1\)\)/i_zero_safe($1)/g' $F perl -p -i -e 's/memset\(&\(?([^,]*)\)?,\s*0,\s*sizeof\(\g1\)\)/i_zero(&$1)/g' $F perl -p -i -e 's/memset\(([^,]*),\s*0,\s*sizeof\(\*\g1\)\)/i_zero($1)/g' $F done
author Stephan Bosch <stephan.bosch@dovecot.fi>
date Wed, 11 Jan 2017 01:57:46 +0100
parents 0f22db71df7a
children 2e2563132d5f
line wrap: on
line source

/* Copyright (c) 2007-2016 Dovecot authors, see the included COPYING file */

#include "test-lib.h"
#include "utc-mktime.h"

struct test_utc_mktime_input {
	int year, month, day, hour, min, sec;
};

void test_utc_mktime(void)
{
	static struct test_utc_mktime_input input[] = {
#ifdef TIME_T_SIGNED
		{ 1969, 12, 31, 23, 59, 59 },
		{ 1901, 12, 13, 20, 45, 53 },
#endif
#if (TIME_T_MAX_BITS > 32 || !defined(TIME_T_SIGNED))
		{ 2106, 2, 7, 6, 28, 15 },
#endif
		{ 2007, 11, 7, 1, 7, 20 },
		{ 1970, 1, 1, 0, 0, 0 },
		{ 2038, 1, 19, 3, 14, 7 }
	};
	static time_t output[] = {
#ifdef TIME_T_SIGNED
		-1,
		-2147483647,
#endif
#if (TIME_T_MAX_BITS > 32 || !defined(TIME_T_SIGNED))
		4294967295,
#endif
		1194397640,
		0,
		2147483647
	};
	struct tm tm;
	unsigned int i;
	time_t t;
	bool success;

	for (i = 0; i < N_ELEMENTS(input); i++) {
		i_zero(&tm);
		tm.tm_year = input[i].year - 1900;
		tm.tm_mon = input[i].month - 1;
		tm.tm_mday = input[i].day;
		tm.tm_hour = input[i].hour;
		tm.tm_min = input[i].min;
		tm.tm_sec = input[i].sec;

		t = utc_mktime(&tm);
		success = t == output[i];
		test_out_reason(t_strdup_printf("utc_mktime(%d)", i), success,
				success ? NULL : t_strdup_printf("%ld != %ld",
						     (long)t, (long)output[i]));
	}
}