More complete date helper and tests

This commit is contained in:
Pierre Pronchery 2012-11-14 19:14:03 +01:00
parent 2b7aa649b5
commit ca2789995f
4 changed files with 14 additions and 6 deletions

View File

@ -33,7 +33,8 @@ time_t mailer_helper_get_date(char const * date, struct tm * tm)
if(date != NULL)
/* FIXME check the standard(s) again */
if(_date_do(date, "%a, %d %b %Y %T %z", tm) == 0
if(_date_do(date, "%a, %d %b %Y %T %z (%z)", tm) == 0
|| _date_do(date, "%a, %d %b %Y %T %z", tm) == 0
|| _date_do(date, "%d %b %Y %T %z", tm) == 0
|| _date_do(date, "%d/%m/%Y %T %z", tm) == 0
|| _date_do(date, "%d/%m/%Y %T", tm) == 0
@ -52,6 +53,10 @@ static int _date_do(char const * date, char const * format, struct tm * tm)
memset(tm, 0, sizeof(*tm));
if((p = strptime(date, format, tm)) != NULL && *p == '\0')
return 0;
/* check if we obtained enough information */
if(p != NULL && tm->tm_year != 0 && tm->tm_mday != 0)
/* XXX _apparently_ yes */
return 0;
return -1;
}

View File

@ -19,7 +19,7 @@ all: $(TARGETS)
date_OBJS = date.o
date_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(CFLAGSF) $(CFLAGS)
date_LDFLAGS = $(LDFLAGSF) $(LDFLAGS) -L ../src -Wl,-rpath,../src -lMailer
date_LDFLAGS = $(LDFLAGSF) $(LDFLAGS)
date: $(date_OBJS)
$(CC) -o date $(date_OBJS) $(date_LDFLAGS)
@ -41,7 +41,7 @@ imap4: $(imap4_OBJS)
tests.log: date email imap4
./tests.sh -P "$(PREFIX)" -- "tests.log"
date.o: date.c ../src/libMailer.a
date.o: date.c ../src/helper.c
$(CC) $(date_CFLAGS) -c date.c
email.o: email.c ../src/libMailer.a

View File

@ -17,7 +17,7 @@
#include <stdio.h>
#include <string.h>
#include "Mailer.h"
#include "../src/helper.c"
/* date */
@ -49,6 +49,10 @@ int main(int argc, char * argv[])
ret += _date(argv[0], expected, expected);
ret += _date(argv[0], expected, "10 Nov 2011 10:11:12 -0000");
ret += _date(argv[0], expected,
"Thu, 10 Nov 2011 10:11:12 -0000 (CET)");
ret += _date(argv[0], expected,
"Thu, 10 Nov 2011 10:11:12 +0000");
ret += _date(argv[0], NULL, "");
ret += _date(argv[0], NULL, NULL);
return (ret == 0) ? 0 : ret + 1;

View File

@ -8,10 +8,9 @@ dist=Makefile,tests.sh
[date]
type=binary
sources=date.c
ldflags=-L ../src -Wl,-rpath,../src -lMailer
[date.c]
depends=../src/libMailer.a
depends=../src/helper.c
[email]
type=binary