Initial import

This commit is contained in:
Laurence Withers 2006-10-14 20:10:01 +01:00
commit 0214b3b06a
32 changed files with 1683 additions and 0 deletions

1
src/tests/.params Normal file
View file

@ -0,0 +1 @@
c tests tests libiso8601

3
src/tests/build.default Normal file
View file

@ -0,0 +1,3 @@
source src/tests/build.tests
# kate: replace-trailing-space-save true; space-indent true; tab-width 4;
# vim: expandtab:ts=4:sw=4

43
src/tests/build.tests Normal file
View file

@ -0,0 +1,43 @@
# These are external variables, and shouldn't clash with anything else
# tests_BUILT
#
build_target libiso8601 || return 1
if [ -z ${tests_BUILT} ]
then
LIBS="${libiso8601} "
EXTRAS="" # @TODO@ libs, cflags
echo "Building test programs..."
do_cmd mkdir -p obj/tests || return 1
for SRC in src/tests/*.c
do
TEST="obj/tests/$(basename ${SRC} | sed -e 's,.c$,,')"
MODIFIED=0
for file in ${LIBS} ${SRC} src/tests/build.tests
do
if [ ${file} -nt ${TEST} ]
then
MODIFIED=1
break
fi
done
if [ ${MODIFIED} -ne 0 ]
then
do_cmd ${CC} -Iobj ${CFLAGS} -o ${TEST} ${SRC} ${LIBS} ${EXTRAS} || return 1
print_success "Built ${TEST}"
else
print_success "${TEST} is up to date"
fi
done
print_success "All tests built"
tests_BUILT=1
fi
# kate: replace-trailing-space-save true; space-indent true; tab-width 4;
# vim: expandtab:ts=4:sw=4

151
src/tests/calconv.c Normal file
View file

@ -0,0 +1,151 @@
/* libiso8601/src/tests/calconv.c
*
* (c)2006, Laurence Withers, <l@lwithers.me.uk>.
* Released under the GNU GPLv2. See file COPYING or
* http://www.gnu.org/copyleft/gpl.html for details.
*/
#include "iso8601.h"
#include <errno.h>
#include <stdio.h>
#include <string.h>
const int _days_in_month_common[] = {
31,
28,
31,
30,
31,
30,
31,
31,
30,
31,
30,
31
};
const int _days_in_month_leap[] = {
31,
29,
31,
30,
31,
30,
31,
31,
30,
31,
30,
31
};
int try_year(int year)
{
static int daycount = 0;
const int* mc;
int m, d, y2, m2, d2, ret = 0;
struct iso8601_date dt;
mc = iso8601_isleap(year) ? _days_in_month_leap : _days_in_month_common;
for(m = 0; m < 12; ++m) {
for(d = 0; d < mc[m]; ++d) {
if(iso8601_from_cal(&dt, year, m + 1, d + 1)) {
++ret;
printf("[cal2date ] %04d-%02d-%02d: %s (%d)\n",
year, m + 1, d + 1, strerror(errno), errno);
} else if(dt.day != daycount) {
++ret;
printf("[discontinuity] %04d-%02d-%02d: got day=%d, expected day=%d\n",
year, m + 1, d + 1, dt.day, daycount);
} else if(iso8601_to_cal(&y2, &m2, &d2, &dt), year != y2 || m + 1 != m2 || d + 1 != d2) {
++ret;
printf("[date2cal ] %04d-%02d-%02d ==> %04d-%02d-%02d (%d)\n",
year, m + 1, d + 1, y2, m2, d2, daycount);
}
++daycount;
}
}
return ret;
}
int try_neg_year(int year)
{
static int daycount = 365;
const int* mc;
int m, d, y2, m2, d2, ret = 0;
struct iso8601_date dt;
mc = iso8601_isleap(year) ? _days_in_month_leap : _days_in_month_common;
for(m = 11; m >= 0; --m) {
for(d = mc[m]; d; --d) {
if(iso8601_from_cal(&dt, year, m + 1, d)) {
++ret;
printf("[cal2date ] %04d-%02d-%02d: %s (%d)\n",
year, m + 1, d, strerror(errno), errno);
} else if(dt.day != daycount) {
++ret;
printf("[discontinuity] %04d-%02d-%02d: got day=%d, expected day=%d\n",
year, m + 1, d, dt.day, daycount);
} else if(iso8601_to_cal(&y2, &m2, &d2, &dt), year != y2 || m + 1 != m2 || d != d2) {
++ret;
printf("[date2cal ] %04d-%02d-%02d ==> %04d-%02d-%02d (%d)\n",
year, m + 1, d, y2, m2, d2, daycount);
}
--daycount;
}
}
return ret;
}
// stuff repeats on a 400-year cycle, so we really shouldn't need to worry too much about this
#define MAX_YEAR_COUNT 2400
int main(int argc, char* argv[])
{
int ret = 0, year;
if(argc == 2 && !strcmp(argv[1], "--print-summary")) {
printf("Calendar date / day number conversion test.\n");
return 0;
}
for(year = 0; year <= MAX_YEAR_COUNT; ++year) {
ret += try_year(year);
if(ret > 20) return ret;
}
for(year = 0; year >= -MAX_YEAR_COUNT; --year) {
ret += try_neg_year(year);
if(ret > 20) return ret;
}
return ret;
}
/* options for text editors
kate: replace-trailing-space-save true; space-indent true; tab-width 4;
vim: expandtab:ts=4:sw=4
*/

36
src/tests/template Normal file
View file

@ -0,0 +1,36 @@
/* libiso8601/src/tests/???.c
*
* (c)2006, Laurence Withers, <l@lwithers.me.uk>.
* Released under the GNU GPLv2. See file COPYING or
* http://www.gnu.org/copyleft/gpl.html for details.
*/
#include "iso8601.h"
#include <stdio.h>
#include <string.h>
int main(int argc, char* argv[])
{
int ret = 0;
if(argc == 2 && !strcmp(argv[1], "--print-summary")) {
printf("One line summary.\n");
return 0;
}
if(argc == 1) {
// empty argument list
}
// TODO
return ret;
}
/* options for text editors
kate: replace-trailing-space-save true; space-indent true; tab-width 4;
vim: expandtab:ts=4:sw=4
*/