From 02f5d1c3e066af4ef00085a433f37d9a6d1a636f Mon Sep 17 00:00:00 2001 From: Sergey Poznyakoff Date: Fri, 5 Aug 2011 11:32:27 +0000 Subject: New files. --- tests/.cvsignore | 4 ++ tests/dbmcreate00.at | 30 ++++++++++ tests/dbmdel00.at | 40 ++++++++++++++ tests/dbmdel01.at | 32 +++++++++++ tests/dbmdel02.at | 29 ++++++++++ tests/dtdel.c | 96 ++++++++++++++++++++++++++++++++ tests/dtdump.c | 97 +++++++++++++++++++++++++++++++++ tests/dtload.c | 151 +++++++++++++++++++++++++++++++++++++++++++++++++++ tests/progname.h | 32 +++++++++++ 9 files changed, 511 insertions(+) create mode 100644 tests/dbmcreate00.at create mode 100644 tests/dbmdel00.at create mode 100644 tests/dbmdel01.at create mode 100644 tests/dbmdel02.at create mode 100644 tests/dtdel.c create mode 100644 tests/dtdump.c create mode 100644 tests/dtload.c create mode 100644 tests/progname.h (limited to 'tests') 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 --- /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 . */ + +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 --- /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 . */ + +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 --- /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 . */ + +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 --- /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 . */ + +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 --- /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 . +*/ +#include "autoconf.h" +#include +#include +#include +#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 --- /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 . +*/ +#include "autoconf.h" +#include +#include +#include +#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 --- /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 . +*/ +#include "autoconf.h" +#include +#include +#include +#include +#include +#include +#include +#include +#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 --- /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 . +*/ + +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; +} + -- cgit v1.2.1