Added a test application for the parsedate() function.

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@4368 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2003-08-23 18:34:10 +00:00
parent cb19965e13
commit c6a70c8d1b
2 changed files with 79 additions and 0 deletions

View File

@ -5,7 +5,12 @@ SimpleTest DriverSettingsTest
: be
;
SimpleTest ParseDateTest
: ParseDateTest.cpp parsedate.cpp
;
# Tell Jam where to find these sources
SEARCH on [ FGristFiles
driver_settings.c
parsedate.cpp
] = [ FDirName $(OBOS_TOP) src kernel libroot os ] ;

View File

@ -0,0 +1,74 @@
/*
** Copyright 2003, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
** Distributed under the terms of the OpenBeOS License.
*/
#include <SupportDefs.h>
#include <parsedate.h>
#include <stdio.h>
// this file can also be compiled against the R5 parsedate() implementation
#ifndef PARSEDATE_INVALID_DATE
# define PARSEDATE_INVALID_DATE 4
# define PARSEDATE_MINUTE_RELATIVE_TIME 8
#endif
char *
parsedate_flags_to_string(time_t result, int flags)
{
if (result == -1) {
if (flags & PARSEDATE_INVALID_DATE)
return "invalid";
return "unknown";
}
if (flags & PARSEDATE_RELATIVE_TIME) {
if (flags & PARSEDATE_MINUTE_RELATIVE_TIME)
return "minute relative";
return "day relative";
}
return "absolute";
}
int
main(int argc, char **argv)
{
const char *dates[] = {
"last tuesday",
"today",
"next tuesday",
"1976-12-15",
"5.8.1976",
"last hour",
"1 hour",
"now",
"12/15/1976",
"",
"next monday 3:00",
"42 minutes",
"-15 minutes",
NULL
};
#if 0
time_t now = time(NULL);
for (int i = 0; i < 500000; i++) {
int flags = 0;
time_t result = parsedate_etc(dates[0], now, &flags);
}
#else
for (int32 i = 0; dates[i]; i++) {
int flags = 0;
time_t result = parsedate_etc(dates[i], -1, &flags);
printf("\"%s\" = %ld (%s) -> %s\n", dates[i], result,
parsedate_flags_to_string(result, flags), result == -1 ? "-" : ctime(&result));
}
#endif
return 0;
}