diff options
author | Erik de Castro Lopo <erikd@miles> | 2005-05-17 11:44:38 +0000 |
---|---|---|
committer | Erik de Castro Lopo <erikd@miles> | 2005-05-17 11:44:38 +0000 |
commit | b9fdfad449d11caf9431eaea2aeb4f7e41228b45 (patch) | |
tree | 9d78624f6b1c815b8d605c633eff0312c4fe01df /regtest | |
parent | efcc3f7e4068cc3c0a6ee5314c82605716f58075 (diff) |
Add in regtest files.
Diffstat (limited to 'regtest')
-rw-r--r-- | regtest/Makefile | 25 | ||||
-rw-r--r-- | regtest/checksum.c | 12 | ||||
-rw-r--r-- | regtest/database.c | 32 | ||||
-rw-r--r-- | regtest/database.h | 41 | ||||
-rw-r--r-- | regtest/regtest.c | 114 |
5 files changed, 192 insertions, 32 deletions
diff --git a/regtest/Makefile b/regtest/Makefile new file mode 100644 index 0000000..1ab35f8 --- /dev/null +++ b/regtest/Makefile @@ -0,0 +1,25 @@ +TARGETS = sndfile-regtest + +CC = gcc + +CFLAGS = -W -Wall -Werror -Wstrict-prototypes -Wshadow + +SNDFILE_CFLAG = $(shell pkg-config --cflags sndfile) +SNDFILE_LIBS = $(shell pkg-config --libs sndfile) + +SQL_LIBS = -lsqlite3 + + +all: $(TARGETS) + +clean : + rm -rf $(TARGETS) *.o + +sndfile-regtest : checksum.o database.o regtest.o + $(CC) $+ $(SNDFILE_LIBS) $(SQL_LIBS) -o $@ + +# Do not edit or modify anything in this comment block. +# The arch-tag line is a file identity tag for the GNU Arch +# revision control system. +# +# arch-tag: ac4a9626-49ce-4bb4-9fb6-e43de0a23432 diff --git a/regtest/checksum.c b/regtest/checksum.c index 033a156..853d684 100644 --- a/regtest/checksum.c +++ b/regtest/checksum.c @@ -20,17 +20,17 @@ ** A simple checksum for short, int and float data. */ -#include "config.h" - #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <sndfile.h> - -#include "float_cast.h" +#define _ISOC9X_SOURCE 1 +#define _ISOC99_SOURCE 1 +#define __USE_ISOC9X 1 +#define __USE_ISOC99 1 +#include <math.h> -#include "regtest.h" +#include <sndfile.h> #define BIG_PRIME 999983 diff --git a/regtest/database.c b/regtest/database.c index 7830d68..fd02e1c 100644 --- a/regtest/database.c +++ b/regtest/database.c @@ -16,7 +16,6 @@ ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#include "config.h" #include <stdio.h> #include <stdlib.h> @@ -24,14 +23,11 @@ #include <string.h> #include <fcntl.h> #include <sys/stat.h> +#include <sqlite3.h> #include <sndfile.h> -#include "regtest.h" - -#if HAVE_SQLITE3 - -#include <sqlite3.h> +#include "database.h" typedef struct { sqlite3 *sql ; @@ -88,8 +84,7 @@ db_open (const char * db_name) int db_create (const char * db_name) { REGTEST_DB * db ; - const char *cmd ; - char * errmsg = NULL ; + char * errmsg = NULL, *cmd ; int err ; db = (REGTEST_DB *) db_open (db_name) ; @@ -185,8 +180,8 @@ db_add_file (REG_DB * db_handle, const char * filepath) snprintf (db->cmdbuf, sizeof (db->cmdbuf), "insert into sndfile " "(fname, fpath, srate, frames, channels, format, checksum, logbuf) values" - "('%s','%s',%d,'%ld', %d, '0x%08x', '0x%08x', '%s');", - db->filename, db->pathname, info.samplerate, (long) info.frames, info.channels, info.format, checksum, db->logbuf) ; + "('%s','%s',%d,'%lld', %d, '0x%08x', '0x%08x', '%s');", + db->filename, db->pathname, info.samplerate, info.frames, info.channels, info.format, checksum, db->logbuf) ; if (strlen (db->cmdbuf) >= sizeof (db->cmdbuf) - 1) { printf ("strlen (db->cmdbuf) too long.\n") ; @@ -368,7 +363,7 @@ check_file_by_ekey (REGTEST_DB * db, int ekey) if (strcmp (result [k], "frames") == 0) { if (strtoll (result [k + cols], NULL, 10) == info.frames) continue ; - printf ("\n\nError : frames doesn't match : %s == %ld\n", result [k + cols], (long) info.frames) ; + printf ("\n\nError : frames doesn't match : %s == %lld\n", result [k + cols], info.frames) ; } ; if (strcmp (result [k], "channels") == 0) @@ -477,21 +472,6 @@ callback (void *unused, int argc, char **argv, char **colname) return 0 ; } /* callback */ -#else - -int dummy (void) ; - -int -dummy (void) -{ /* - ** Empty dummy fnction so tha compiler doesn't winge about an - ** empty file. - */ - return 0 ; -} /* dummy */ - -#endif - /* ** Do not edit or modify anything in this comment block. diff --git a/regtest/database.h b/regtest/database.h new file mode 100644 index 0000000..6d6694a --- /dev/null +++ b/regtest/database.h @@ -0,0 +1,41 @@ +/* +** Copyright (C) 2005 Erik de Castro Lopo +** +** 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 2 of the License, 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., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +typedef struct REG_DB_tag REG_DB ; + +REG_DB * db_open (const char * db_name) ; + +int db_create (const char * dbname) ; + +int db_close (REG_DB * db_handle) ; + +int db_file_exists (REG_DB * db_handle, const char * filename) ; +int db_add_file (REG_DB * db_handle, const char * filename) ; +int db_check_file (REG_DB * db_handle, const char * filename) ; + +int db_list_all (REG_DB * db_handle) ; +int db_check_all (REG_DB * db_handle) ; +int db_del_entry (REG_DB * db_handle, const char * entry) ; + +/* +** Do not edit or modify anything in this comment block. +** The following line is a file identity tag for the GNU Arch +** revision control system. +** +** arch-tag: 80138e38-f373-48d3-8152-7f7882a62cd7 +*/ diff --git a/regtest/regtest.c b/regtest/regtest.c new file mode 100644 index 0000000..debf633 --- /dev/null +++ b/regtest/regtest.c @@ -0,0 +1,114 @@ +/* +** Copyright (C) 2005 Erik de Castro Lopo +** +** 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 2 of the License, 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., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include <sndfile.h> + +#include "database.h" + +enum +{ OPT_ADD_FILE = 0x0100, + OPT_CREATE_DB = 0x0200, + OPT_DEL_ENTRY = 0x0400, + OPT_LIST_ALL = 0x0800, + OPT_TEST_ALL = 0x1000, + OPT_VERBOSE = 0x2000 +} ; + +static void print_libsndfile_version (void) ; + +int +main (int argc, char * argv []) +{ static char *db_name = "./.sndfile-regtest.db" ; + REG_DB *reg_db ; + int k, retval ; + + if (argc < 2) + { printf ("\nUsage message goes here.\n\n") ; + exit (0) ; + } ; + + if (argc == 2 && strcmp (argv [1], "--create-db") == 0) + return db_create (db_name) ; + + reg_db = db_open (db_name) ; + + if (argc == 2) + { if (strcmp (argv [1], "--list-all") == 0) + return db_list_all (reg_db) ; + + if (strcmp (argv [1], "--check-all") == 0) + { print_libsndfile_version () ; + retval = db_check_all (reg_db) ; + puts ("\nDone.\n") ; + return retval ; + } ; + } ; + + if (argc == 3 && strcmp (argv [1], "--del-entry") == 0) + { db_del_entry (reg_db, argv [2]) ; + db_close (reg_db) ; + return 0 ; + } ; + + if (strcmp (argv [1], "--check-file") == 0) + { print_libsndfile_version () ; + + for (k = 2 ; k < argc ; k++) + db_check_file (reg_db, argv [k]) ; + db_close (reg_db) ; + return 0 ; + } ; + + if (strcmp (argv [1], "--add-file") == 0) + { print_libsndfile_version () ; + + for (k = 2 ; k < argc ; k++) + db_add_file (reg_db, argv [k]) ; + db_close (reg_db) ; + return 0 ; + } ; + + printf ("\nError : unhandled command line args :") ; + for (k = 1 ; k < argc ; k++) + printf (" %s", argv [k]) ; + puts ("\n") ; + + return 1 ; +} /* main */ + +static void +print_libsndfile_version (void) +{ char version [64] ; + + sf_command (NULL, SFC_GET_LIB_VERSION, version, sizeof (version)) ; + printf ("\nsndfile-regtest : using %s\n\n", version) ; +} /* print_lib_version */ + + + +/* +** Do not edit or modify anything in this comment block. +** The following line is a file identity tag for the GNU Arch +** revision control system. +** +** arch-tag: 7f318f08-9bfa-4249-856d-fe994819bdce +*/ |