aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tests/.cvsignore1
-rw-r--r--tests/Makefile.am11
-rw-r--r--tests/delete00.at39
-rw-r--r--tests/delete01.at31
-rw-r--r--tests/delete02.at28
-rw-r--r--tests/gtdel.c112
-rw-r--r--tests/gtdump.c2
-rw-r--r--tests/gtfetch.c2
-rw-r--r--tests/testsuite.at7
9 files changed, 228 insertions, 5 deletions
diff --git a/tests/.cvsignore b/tests/.cvsignore
index c2e03e5..b611e77 100644
--- a/tests/.cvsignore
+++ b/tests/.cvsignore
@@ -5,6 +5,7 @@ Makefile
Makefile.in
atconfig
atlocal
+gtdel
gtdump
gtfetch
gtload
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 7b6c9ee..dc39cad 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -45,6 +45,9 @@ $(srcdir)/package.m4: $(top_srcdir)/configure.ac $(srcdir)/Makefile
TESTSUITE_AT = \
create00.at\
+ delete00.at\
+ delete01.at\
+ delete02.at\
fetch00.at\
fetch01.at\
version.at
@@ -70,17 +73,19 @@ check-local: atconfig atlocal $(TESTSUITE)
#installcheck-local:
# $(SHELL) $(TESTSUITE) AUTOTEST_PATH=$(exec_prefix)/bin
-## ------------ ##
-## num2word ##
-## ------------ ##
+## --------------- ##
+## num2word et al. ##
+## --------------- ##
check_PROGRAMS = \
+ gtdel\
gtdump\
gtfetch\
gtload\
num2word
INCLUDES = -I$(top_srcdir)/src -I$(top_builddir)/src
+gtdel_LDADD = ../src/libgdbm.la
gtload_LDADD = ../src/libgdbm.la
gtdump_LDADD = ../src/libgdbm.la
gtfetch_LDADD = ../src/libgdbm.la
diff --git a/tests/delete00.at b/tests/delete00.at
new file mode 100644
index 0000000..a64d636
--- /dev/null
+++ b/tests/delete00.at
@@ -0,0 +1,39 @@
+# This file is part of GDBM. -*- autoconf -*-
+# Copyright (C) 2011 Free Software Foundation, Inc.
+#
+# GDBM 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 2, or (at your option)
+# any later version.
+#
+# GDBM 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 GDBM. If not, see <http://www.gnu.org/licenses/>. */
+
+AT_SETUP([delete a record])
+AT_KEYWORDS([delete delete00.at])
+
+AT_CHECK([
+AT_SORT_PREREQ
+num2word 1:10 | gtload test.db
+gtdel test.db 8
+gtdump test.db | sort -k1,2 -n
+],
+[0],
+[1 one
+2 two
+3 three
+4 four
+5 five
+6 six
+7 seven
+9 nine
+10 ten
+])
+
+AT_CLEANUP
+
diff --git a/tests/delete01.at b/tests/delete01.at
new file mode 100644
index 0000000..1142d42
--- /dev/null
+++ b/tests/delete01.at
@@ -0,0 +1,31 @@
+# This file is part of GDBM. -*- autoconf -*-
+# Copyright (C) 2011 Free Software Foundation, Inc.
+#
+# GDBM 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 2, or (at your option)
+# any later version.
+#
+# GDBM 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 GDBM. If not, see <http://www.gnu.org/licenses/>. */
+
+AT_SETUP([delete: non existing record])
+AT_KEYWORDS([delete delete01.at])
+
+AT_CHECK([
+AT_SORT_PREREQ
+num2word 1:10 | gtload test.db
+gtdel test.db 11
+],
+[2],
+[],
+[gtdel: cannot delete 11: Item not found
+])
+
+AT_CLEANUP
+
diff --git a/tests/delete02.at b/tests/delete02.at
new file mode 100644
index 0000000..9ce4099
--- /dev/null
+++ b/tests/delete02.at
@@ -0,0 +1,28 @@
+# This file is part of GDBM. -*- autoconf -*-
+# Copyright (C) 2011 Free Software Foundation, Inc.
+#
+# GDBM 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 2, or (at your option)
+# any later version.
+#
+# GDBM 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 GDBM. If not, see <http://www.gnu.org/licenses/>. */
+
+AT_SETUP([delete: all records])
+AT_KEYWORDS([delete delete02.at])
+
+AT_CHECK([
+num2word 1:10 | gtload test.db
+gtdel test.db 1 2 3 4 5 6 7 8 9 10
+gtdump test.db
+],
+[0])
+
+AT_CLEANUP
+
diff --git a/tests/gtdel.c b/tests/gtdel.c
new file mode 100644
index 0000000..6826532
--- /dev/null
+++ b/tests/gtdel.c
@@ -0,0 +1,112 @@
+/* This file is part of GDBM test suite.
+ Copyright (C) 2011 Free Software Foundation, Inc.
+
+ GDBM 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 2, or (at your option)
+ any later version.
+
+ GDBM 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 GDBM. If not, see <http://www.gnu.org/licenses/>.
+*/
+#include "autoconf.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "gdbm.h"
+
+const char *
+canonical_progname (const char *str)
+{
+ const char *p;
+
+ p = strrchr (str, '/');
+ if (p)
+ p++;
+ else
+ p = str;
+ if (strncmp (p, "lt-", 3) == 0)
+ p += 3;
+ return p;
+}
+
+int
+main (int argc, char **argv)
+{
+ const char *progname = canonical_progname (argv[0]);
+ const char *dbname;
+ datum key;
+ int flags = 0;
+ GDBM_FILE dbf;
+ int data_z = 0;
+ int rc = 0;
+
+ while (--argc)
+ {
+ char *arg = *++argv;
+
+ if (strcmp (arg, "-h") == 0)
+ {
+ printf ("usage: %s [-null] [-nolock] [-nommap] [-sync] DBFILE KEY [KEY...]\n",
+ progname);
+ exit (0);
+ }
+ else if (strcmp (arg, "-null") == 0)
+ data_z = 1;
+ else if (strcmp (arg, "-nolock") == 0)
+ flags |= GDBM_NOLOCK;
+ else if (strcmp (arg, "-nommap") == 0)
+ flags |= GDBM_NOMMAP;
+ else if (strcmp (arg, "-sync") == 0)
+ flags |= GDBM_SYNC;
+ else if (strcmp (arg, "--") == 0)
+ {
+ --argc;
+ ++argv;
+ break;
+ }
+ else if (arg[0] == '-')
+ {
+ fprintf (stderr, "%s: unknown option %s\n", progname, arg);
+ exit (1);
+ }
+ else
+ break;
+ }
+
+ if (argc < 2)
+ {
+ fprintf (stderr, "%s: wrong arguments\n", progname);
+ exit (1);
+ }
+ dbname = *argv;
+
+ dbf = gdbm_open (dbname, 0, GDBM_WRITER|flags, 0, NULL);
+ if (!dbf)
+ {
+ fprintf (stderr, "gdbm_open failed: %s\n", gdbm_strerror (gdbm_errno));
+ exit (1);
+ }
+
+ while (--argc)
+ {
+ char *arg = *++argv;
+
+ key.dptr = arg;
+ key.dsize = strlen (arg) + !!data_z;
+
+ if (gdbm_delete(dbf, key))
+ {
+ fprintf (stderr, "%s: cannot delete %s: %s\n",
+ progname, arg, gdbm_strerror (gdbm_errno));
+ rc = 2;
+ }
+ }
+ gdbm_close (dbf);
+ exit (rc);
+}
diff --git a/tests/gtdump.c b/tests/gtdump.c
index 2d3049a..7030cfd 100644
--- a/tests/gtdump.c
+++ b/tests/gtdump.c
@@ -90,7 +90,7 @@ main (int argc, char **argv)
dbf = gdbm_open (dbname, 0, GDBM_READER|flags, 00664, NULL);
if (!dbf)
{
- fprintf (stderr, "gdbm_open failed: %s", gdbm_strerror (gdbm_errno));
+ fprintf (stderr, "gdbm_open failed: %s\n", gdbm_strerror (gdbm_errno));
exit (1);
}
diff --git a/tests/gtfetch.c b/tests/gtfetch.c
index a50b83e..e7ff542 100644
--- a/tests/gtfetch.c
+++ b/tests/gtfetch.c
@@ -104,7 +104,7 @@ main (int argc, char **argv)
dbf = gdbm_open (dbname, 0, GDBM_READER|flags, 00664, NULL);
if (!dbf)
{
- fprintf (stderr, "gdbm_open failed: %s", gdbm_strerror (gdbm_errno));
+ fprintf (stderr, "gdbm_open failed: %s\n", gdbm_strerror (gdbm_errno));
exit (1);
}
diff --git a/tests/testsuite.at b/tests/testsuite.at
index 5dae7f6..99c53dd 100644
--- a/tests/testsuite.at
+++ b/tests/testsuite.at
@@ -27,7 +27,14 @@ dnl # Begin tests
AT_INIT
m4_include([version.at])
+
m4_include([create00.at])
+
m4_include([fetch00.at])
m4_include([fetch01.at])
+
+m4_include([delete00.at])
+m4_include([delete01.at])
+m4_include([delete02.at])
+
# End of testsuite.at

Return to:

Send suggestions and report system problems to the System administrator.