summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org.ua>2011-08-05 11:32:27 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2011-08-05 11:32:27 (GMT)
commit02f5d1c3e066af4ef00085a433f37d9a6d1a636f (patch) (side-by-side diff)
tree9f88e92606662ce08f6fb78320358b41618198ea
parent92a4099a3c02a200c4ee8d776808fa9dc0f9978c (diff)
downloadgdbm-02f5d1c3e066af4ef00085a433f37d9a6d1a636f.tar.gz
gdbm-02f5d1c3e066af4ef00085a433f37d9a6d1a636f.tar.bz2
New files.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--tests/.cvsignore4
-rw-r--r--tests/dbmcreate00.at30
-rw-r--r--tests/dbmdel00.at40
-rw-r--r--tests/dbmdel01.at32
-rw-r--r--tests/dbmdel02.at29
-rw-r--r--tests/dtdel.c96
-rw-r--r--tests/dtdump.c97
-rw-r--r--tests/dtload.c151
-rw-r--r--tests/progname.h32
9 files changed, 511 insertions, 0 deletions
diff --git a/tests/.cvsignore b/tests/.cvsignore
index de9d411..8950eb4 100644
--- a/tests/.cvsignore
+++ b/tests/.cvsignore
@@ -5,6 +5,10 @@ Makefile
Makefile.in
atconfig
atlocal
+dtdel
+dtdump
+dtfetch
+dtload
gtdel
gtdump
gtfetch
diff --git a/tests/dbmcreate00.at b/tests/dbmcreate00.at
new file mode 100644
index 0000000..157bd35
--- a/dev/null
+++ b/tests/dbmcreate00.at
@@ -0,0 +1,30 @@
+# 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([create database: dbm interface])
+AT_KEYWORDS([dbm create create00 dbmcreate00])
+
+AT_CHECK([
+AT_COMPAT_PREREQ
+AT_SORT_PREREQ
+num2word 1:1000 > input
+dtload test < input
+dtdump test | sort -k1,2 -n > output
+diff -u input output
+])
+
+AT_CLEANUP
+
diff --git a/tests/dbmdel00.at b/tests/dbmdel00.at
new file mode 100644
index 0000000..8ff08dc
--- a/dev/null
+++ b/tests/dbmdel00.at
@@ -0,0 +1,40 @@
+# 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 (dbm)])
+AT_KEYWORDS([dbm delete delete00 dbmdel00])
+
+AT_CHECK([
+AT_COMPAT_PREREQ
+AT_SORT_PREREQ
+num2word 1:10 | dtload test
+dtdel test 8
+dtdump test | 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/dbmdel01.at b/tests/dbmdel01.at
new file mode 100644
index 0000000..1b537a1
--- a/dev/null
+++ b/tests/dbmdel01.at
@@ -0,0 +1,32 @@
+# 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 (dbm): non existing record])
+AT_KEYWORDS([dbm delete delete01 dbmdel01])
+
+AT_CHECK([
+AT_COMPAT_PREREQ
+AT_SORT_PREREQ
+num2word 1:10 | dtload test
+dtdel test 11
+],
+[2],
+[],
+[dtdel: cannot delete 11: Item not found
+])
+
+AT_CLEANUP
+
diff --git a/tests/dbmdel02.at b/tests/dbmdel02.at
new file mode 100644
index 0000000..9b08974
--- a/dev/null
+++ b/tests/dbmdel02.at
@@ -0,0 +1,29 @@
+# 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 (dbm): all records])
+AT_KEYWORDS([dbm delete delete02 dbmdel02])
+
+AT_CHECK([
+AT_COMPAT_PREREQ
+num2word 1:10 | dtload test
+dtdel test 1 2 3 4 5 6 7 8 9 10
+dtdump test
+],
+[0])
+
+AT_CLEANUP
+
diff --git a/tests/dtdel.c b/tests/dtdel.c
new file mode 100644
index 0000000..b7d0112
--- a/dev/null
+++ b/tests/dtdel.c
@@ -0,0 +1,96 @@
+/* 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 "dbm.h"
+#include "progname.h"
+
+int
+main (int argc, char **argv)
+{
+ const char *progname = canonical_progname (argv[0]);
+ char *dbname;
+ datum key;
+ int flags = 0;
+ 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;
+
+ if (dbminit (dbname))
+ {
+ fprintf (stderr, "dbminit failed\n");
+ exit (1);
+ }
+
+ while (--argc)
+ {
+ char *arg = *++argv;
+
+ key.dptr = arg;
+ key.dsize = strlen (arg) + !!data_z;
+
+ if (delete(key))
+ {
+ fprintf (stderr, "%s: cannot delete %s: %s\n",
+ progname, arg, gdbm_strerror (gdbm_errno));
+ rc = 2;
+ }
+ }
+ dbmclose ();
+ exit (rc);
+}
diff --git a/tests/dtdump.c b/tests/dtdump.c
new file mode 100644
index 0000000..4e0aa3e
--- a/dev/null
+++ b/tests/dtdump.c
@@ -0,0 +1,97 @@
+/* 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 "dbm.h"
+#include "progname.h"
+
+int
+main (int argc, char **argv)
+{
+ const char *progname = canonical_progname (argv[0]);
+ char *dbname;
+ datum key;
+ datum data;
+ int delim = '\t';
+
+ while (--argc)
+ {
+ char *arg = *++argv;
+
+ if (strcmp (arg, "-h") == 0)
+ {
+ printf ("usage: %s [-delim=CHR] DBFILE\n", progname);
+ exit (0);
+ }
+ else if (strncmp (arg, "-delim=", 7) == 0)
+ delim = arg[7];
+ 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 != 1)
+ {
+ fprintf (stderr, "%s: wrong arguments\n", progname);
+ exit (1);
+ }
+ dbname = *argv;
+
+ if (dbminit (dbname))
+ {
+ fprintf (stderr, "dbminit failed\n");
+ exit (1);
+ }
+
+ for (key = firstkey (); key.dptr; key = nextkey (key))
+ {
+ int i;
+
+ for (i = 0; i < key.dsize && key.dptr[i]; i++)
+ {
+ if (key.dptr[i] == delim || key.dptr[i] == '\\')
+ fputc ('\\', stdout);
+ fputc (key.dptr[i], stdout);
+ }
+
+ fputc (delim, stdout);
+
+ data = fetch (key);
+ i = data.dsize;
+ if (data.dptr[i-1] == 0)
+ i--;
+
+ fwrite (data.dptr, i, 1, stdout);
+
+ fputc ('\n', stdout);
+ }
+
+ dbmclose ();
+ exit (0);
+}
diff --git a/tests/dtload.c b/tests/dtload.c
new file mode 100644
index 0000000..6ebd638
--- a/dev/null
+++ b/tests/dtload.c
@@ -0,0 +1,151 @@
+/* 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 <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <errno.h>
+#include "dbm.h"
+#include "progname.h"
+
+#define PAGSUF ".pag"
+
+int
+main (int argc, char **argv)
+{
+ const char *progname = canonical_progname (argv[0]);
+ char *dbname;
+ int line = 0;
+ char buf[1024];
+ datum key;
+ datum data;
+ int delim = '\t';
+ int data_z = 0;
+
+ while (--argc)
+ {
+ char *arg = *++argv;
+
+ if (strcmp (arg, "-h") == 0)
+ {
+ printf ("usage: %s [-null] [-delim=CHR] DBFILE\n", progname);
+ exit (0);
+ }
+ else if (strcmp (arg, "-null") == 0)
+ data_z = 1;
+ else if (strncmp (arg, "-delim=", 7) == 0)
+ delim = arg[7];
+ 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 != 1)
+ {
+ fprintf (stderr, "%s: wrong arguments\n", progname);
+ exit (1);
+ }
+
+ /* Check if .pag file exists. Create it if it doesn't, as DBM
+ cannot do it itself. */
+
+ dbname = malloc (strlen (*argv) + sizeof (PAGSUF));
+ if (!dbname)
+ abort ();
+
+ strcat (strcpy (dbname, *argv), PAGSUF);
+
+ if (access (dbname, F_OK))
+ {
+ int fd = creat (dbname, 0644);
+ if (fd < 0)
+ {
+ fprintf (stderr, "%s: ", progname);
+ perror (dbname);
+ exit (1);
+ }
+ close (fd);
+ }
+ free (dbname);
+
+ if (dbminit (*argv))
+ {
+ fprintf (stderr, "dbminit failed\n");
+ exit (1);
+ }
+
+ while (fgets (buf, sizeof buf, stdin))
+ {
+ size_t i, j;
+ size_t len = strlen (buf);
+
+ if (buf[len - 1] != '\n')
+ {
+ fprintf (stderr, "%s: %d: line too long\n",
+ progname, line);
+ continue;
+ }
+
+ buf[--len] = 0;
+
+ line++;
+
+ for (i = j = 0; i < len; i++)
+ {
+ if (buf[i] == '\\')
+ i++;
+ else if (buf[i] == delim)
+ break;
+ else
+ buf[j++] = buf[i];
+ }
+
+ if (buf[i] != delim)
+ {
+ fprintf (stderr, "%s: %d: malformed line\n",
+ progname, line);
+ continue;
+ }
+
+ key.dptr = buf;
+ key.dsize = j + data_z;
+ data.dptr = buf + j + 1;
+ data.dsize = strlen (buf + j + 1) + data_z;
+ if (store (key, data) != 0)
+ {
+ fprintf (stderr, "%s: %d: item not inserted\n",
+ progname, line);
+ exit (1);
+ }
+ }
+ dbmclose ();
+ exit (0);
+}
diff --git a/tests/progname.h b/tests/progname.h
new file mode 100644
index 0000000..47dea1e
--- a/dev/null
+++ b/tests/progname.h
@@ -0,0 +1,32 @@
+/* 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/>.
+*/
+
+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;
+}
+

Return to:

Send suggestions and report system problems to the System administrator.