[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
add self-test of getdate module
From: |
Simon Josefsson |
Subject: |
add self-test of getdate module |
Date: |
Tue, 01 Jul 2008 15:00:11 +0200 |
User-agent: |
Gnus/5.110011 (No Gnus v0.11) Emacs/22.2 (gnu/linux) |
There seems to be some changes in the getdate module going on, and I
want to make sure some of the strings that I rely on will continue to
work so I installed a self test. Feel free to extend it.
Patching the getdate module could easily introduce unwanted
side-effects, so getting more complete self-tests seems useful.
/Simon
>From 5e673c40112701e37d600116ae4deda05db3d36f Mon Sep 17 00:00:00 2001
From: Simon Josefsson <address@hidden>
Date: Tue, 1 Jul 2008 14:55:29 +0200
Subject: [PATCH] Add self-test for getdate module.
* modules/getdate-tests: New file.
* tests/test-getdate.c: New file.
---
ChangeLog | 6 +++
modules/getdate-tests | 11 ++++++
tests/test-getdate.c | 89 +++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 106 insertions(+), 0 deletions(-)
create mode 100644 modules/getdate-tests
create mode 100644 tests/test-getdate.c
diff --git a/ChangeLog b/ChangeLog
index 7a8b2dd..b9076e2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2008-07-01 Simon Josefsson <address@hidden>
+
+ Add self-test for getdate module.
+ * modules/getdate-tests: New file.
+ * tests/test-getdate.c: New file.
+
2008-06-29 Bruno Haible <address@hidden>
* gnulib-tool (func_import): Put gnulib-comp.m4 into .cvsignore or
diff --git a/modules/getdate-tests b/modules/getdate-tests
new file mode 100644
index 0000000..4b5e344
--- /dev/null
+++ b/modules/getdate-tests
@@ -0,0 +1,11 @@
+Files:
+tests/test-getdate.c
+
+Depends-on:
+
+configure.ac:
+
+Makefile.am:
+TESTS += test-getdate
+check_PROGRAMS += test-getdate
+test_getdate_LDADD = $(LDADD) $(LIB_CLOCK_GETTIME)
diff --git a/tests/test-getdate.c b/tests/test-getdate.c
new file mode 100644
index 0000000..5bf3728
--- /dev/null
+++ b/tests/test-getdate.c
@@ -0,0 +1,89 @@
+/* Test of getdate() function.
+ Copyright (C) 2008 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software Foundation,
+ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
+
+/* Written by Simon Josefsson <address@hidden>, 2008. */
+
+#include <config.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "getdate.h"
+
+#define ASSERT(expr) \
+ do \
+ { \
+ if (!(expr)) \
+ { \
+ fprintf (stderr, "%s:%d: assertion failed\n", \
+ __FILE__, __LINE__); \
+ fflush (stderr); \
+ abort (); \
+ } \
+ } \
+ while (0)
+
+#ifdef DEBUG
+#define LOG(str, now, res) \
+ printf ("string `%s' diff %d %d\n", \
+ str, res.tv_sec - now.tv_sec, res.tv_nsec - now.tv_nsec);
+#else
+#define LOG(str, now, res) 0
+#endif
+
+int
+main (int argc, char **argv)
+{
+ bool ret;
+ struct timespec result;
+ struct timespec now;
+ const char *p;
+
+ now.tv_sec = 4711;
+ now.tv_nsec = 1267;
+ p = "now";
+ ASSERT (get_date (&result, p, &now));
+ LOG (p, now, result);
+ ASSERT (now.tv_sec == result.tv_sec && now.tv_nsec == result.tv_nsec);
+
+ now.tv_sec = 4711;
+ now.tv_nsec = 1267;
+ p = "tomorrow";
+ ASSERT (get_date (&result, p, &now));
+ LOG (p, now, result);
+ ASSERT (now.tv_sec + 24 * 60 * 60 == result.tv_sec
+ && now.tv_nsec == result.tv_nsec);
+
+ now.tv_sec = 4711;
+ now.tv_nsec = 1267;
+ p = "yesterday";
+ ASSERT (get_date (&result, p, &now));
+ LOG (p, now, result);
+ ASSERT (now.tv_sec - 24 * 60 * 60 == result.tv_sec
+ && now.tv_nsec == result.tv_nsec);
+
+ now.tv_sec = 4711;
+ now.tv_nsec = 1267;
+ p = "4 hours";
+ ASSERT (get_date (&result, p, &now));
+ LOG (p, now, result);
+ ASSERT (now.tv_sec + 4 * 60 * 60 == result.tv_sec
+ && now.tv_nsec == result.tv_nsec);
+
+ return 0;
+}
--
1.5.6
- add self-test of getdate module,
Simon Josefsson <=