diff --git a/test/driver/.gitignore b/test/driver/.gitignore index 0f68f9db..64c3320a 100644 --- a/test/driver/.gitignore +++ b/test/driver/.gitignore @@ -8,6 +8,7 @@ /bincue /bincue /bincue.c +/cdrdao /cdrdao.c /follow_symlink /freebsd diff --git a/test/driver/Makefile.am b/test/driver/Makefile.am index 47f6150e..03897faf 100644 --- a/test/driver/Makefile.am +++ b/test/driver/Makefile.am @@ -16,9 +16,11 @@ INCLUDES = -I$(top_srcdir) $(LIBCDIO_CFLAGS) $(LIBISO9660_CFLAGS) DATA_DIR = $(abs_top_srcdir)/test/data +bincue_SOURCES = helper.c bincue.c bincue_LDADD = $(LIBCDIO_LIBS) $(LTLIBICONV) bincue_CFLAGS = -DDATA_DIR=\"$(DATA_DIR)\" +cdrdao_SOURCES = helper.c cdrdao.c cdrdao_LDADD = $(LIBCDIO_LIBS) $(LTLIBICONV) cdrdao_CFLAGS = -DDATA_DIR=\"$(DATA_DIR)\" @@ -28,12 +30,14 @@ freebsd_CFLAGS = -DDATA_DIR=\"$(DATA_DIR)\" realpath_LDADD = $(LIBCDIO_LIBS) $(LTLIBICONV) realpath_CFLAGS = -DDATA_DIR=\"$(DATA_DIR)\" +gnu_linux_SOURCES= helper.c gnu_linux.c gnu_linux_LDADD = $(LIBCDIO_LIBS) $(LTLIBICONV) gnu_linux_CFLAGS = -DDATA_DIR=\"$(DATA_DIR)\" mmc_LDADD = $(LIBCDIO_LIBS) $(LTLIBICONV) mmc_CFLAGS = -DDATA_DIR=\"$(DATA_DIR)\" +nrg_SOURCES = helper.c nrg.c nrg_LDADD = $(LIBCDIO_LIBS) $(LTLIBICONV) nrg_CFLAGS = -DDATA_DIR=\"$(DATA_DIR)\" @@ -54,6 +58,7 @@ TESTS = $(check_PROGRAMS) EXTRA_DIST = \ bincue.c.in \ + helper.c \ cdrdao.c.in \ nrg.c.in diff --git a/test/driver/bincue.c.in b/test/driver/bincue.c.in index 5d6f9540..49dddd25 100644 --- a/test/driver/bincue.c.in +++ b/test/driver/bincue.c.in @@ -33,7 +33,12 @@ #ifdef HAVE_STDLIB_H #include #endif +#ifdef HAVE_STRING_H #include +#endif + +#include "helper.h" + #ifndef DATA_DIR #define DATA_DIR "@abs_top_srcdir@/test/data" @@ -117,6 +122,11 @@ main(int argc, const char *argv[]) #endif { psz_device = cdio_get_default_device(p_cdio); + + check_mmc_supported(p_cdio, 1); + check_access_mode(p_cdio, "image"); + // check_get_arg_source(p_cdio, psz_device); + /* Could chdir to srcdir to hedge the bet? */ if (psz_device) free(psz_device); @@ -127,41 +137,6 @@ main(int argc, const char *argv[]) drc = cdio_set_speed(p_cdio, 5); } - { - const char *psz_response = cdio_get_arg(p_cdio, "mmc-supported?"); - if ( psz_response == NULL || - ((0 != strncmp("false", psz_response, sizeof("false")))) ) { - fprintf(stderr, - "cdio_get_arg(\"mmc-supported?\") should return \"false\"; got: \"%s\".\n", - psz_response); - exit(3); - } - } - - { - const char *psz_access_mode = cdio_get_arg(p_cdio, "access-mode"); - if ( psz_access_mode == NULL || - ((0 != strncmp("image", psz_access_mode, sizeof("image")))) ) { - fprintf(stderr, - "cdio_get_arg(\"access-mode?\") should return \"image\"; got: \"%s\".\n", - psz_access_mode); - exit(4); - } - } - - { - const char *psz_source = cdio_get_arg(p_cdio, "source"); - const char *psz_device = cdio_get_default_device(p_cdio); - if ( psz_source == NULL || - (0 != strcmp(psz_device, psz_device)) ) { - fprintf(stderr, - "cdio_get_arg(\"source\") should return \"%s\"; got: \"%s\".\n", - psz_source, psz_device); - exit(5); - } - } - - cdio_destroy(p_cdio); } diff --git a/test/driver/cdrdao.c.in b/test/driver/cdrdao.c.in index 92e6b921..63735868 100644 --- a/test/driver/cdrdao.c.in +++ b/test/driver/cdrdao.c.in @@ -33,7 +33,11 @@ #ifdef HAVE_STDLIB_H #include #endif +#ifdef HAVE_STRING_H #include +#endif + +#include "helper.h" #ifndef DATA_DIR #define DATA_DIR "@abs_top_srcdir@/test/data" @@ -90,8 +94,8 @@ main(int argc, const char *argv[]) snprintf(psz_tocfile, sizeof(psz_tocfile)-1, "%s/%s", DATA_DIR, toc_file[i]); if (!cdio_is_tocfile(psz_tocfile)) { - printf("Incorrect: %s doesn't parse as a cdrdao TOC file.\n", - toc_file[i]); + fprintf(stderr, + "Incorrect: %s doesn't parse as a cdrdao TOC file.\n", toc_file[i]); ret=i+1; } else { if (verbose) @@ -108,12 +112,33 @@ main(int argc, const char *argv[]) printf("Correct: %s doesn't parse as a cdrdao TOC file.\n", badtoc_file[i]); } else { - printf("Incorrect: %s parses as a cdrdao TOC file.\n", - badtoc_file[i]); + fprintf(stderr, + "Incorrect: %s parses as a cdrdao TOC file.\n", + badtoc_file[i]); ret+=50*i+1; break; } } + + { + CdIo_t *p_cdio; + snprintf(psz_tocfile, sizeof(psz_tocfile)-1, + "%s/%s", DATA_DIR, "cdda.toc"); + + p_cdio = cdio_open (psz_tocfile, DRIVER_CDRDAO); + if (!p_cdio) { + fprintf(stderr, "Can't open %s as a cdrdao TOC file.\n", + psz_tocfile); + exit(5); + } + + check_mmc_supported(p_cdio, 1); + check_access_mode(p_cdio, "image"); + check_get_arg_source(p_cdio, psz_tocfile); + cdio_destroy(p_cdio); + } + + } return ret; diff --git a/test/driver/gnu_linux.c b/test/driver/gnu_linux.c index d3755340..a81ff17e 100644 --- a/test/driver/gnu_linux.c +++ b/test/driver/gnu_linux.c @@ -33,7 +33,11 @@ #ifdef HAVE_STDLIB_H #include #endif +#ifdef HAVE_STRING_H #include +#endif + +#include "helper.h" int main(int argc, const char *argv[]) @@ -54,52 +58,25 @@ main(int argc, const char *argv[]) p_cdio = cdio_open_linux(ppsz_drives[0]); if (p_cdio) { - const char *psz_source = cdio_get_arg(p_cdio, "source"); - if (0 != strncmp(psz_source, ppsz_drives[0], - strlen(ppsz_drives[0]))) { - fprintf(stderr, - "Got %s; should get back %s, the name we opened.\n", - psz_source, ppsz_drives[0]); - exit(1); + const char *psz_source = NULL, *scsi_tuple; + + check_get_arg_source(p_cdio, ppsz_drives[0]); + check_mmc_supported(p_cdio, 3); + + scsi_tuple = cdio_get_arg(p_cdio, "scsi-tuple"); + if (scsi_tuple == NULL) { + fprintf(stderr, "cdio_get_arg(\"scsi-tuple\") returns NULL.\n"); + exit(3); } - } - - { - const char *psz_response = cdio_get_arg(p_cdio, "mmc-supported?"); - if ( psz_response == NULL || - ((0 != strncmp("true", psz_response, sizeof("true"))) && - (0 != strncmp("false", psz_response, sizeof("false")))) ) { - fprintf(stderr, - "cdio_get_arg(\"mmc-supported?\") should return \"true\" or \"false\"; got: \"%s\".\n", - psz_response); - exit(2); - } + if (cdio_loglevel_default == CDIO_LOG_DEBUG) + printf("Drive '%s' has cdio_get_arg(\"scsi-tuple\") = '%s'\n", + psz_source, scsi_tuple); + cdio_destroy(p_cdio); } - { - const char *psz_source = NULL, *scsi_tuple; - - scsi_tuple = cdio_get_arg(p_cdio, "scsi-tuple"); - if (scsi_tuple == NULL) { - fprintf(stderr, "cdio_get_arg(\"scsi-tuple\") returns NULL.\n"); - exit(3); - } - if (cdio_loglevel_default == CDIO_LOG_DEBUG) - printf("Drive '%s' has cdio_get_arg(\"scsi-tuple\") = '%s'\n", - psz_source, scsi_tuple); - } - - cdio_destroy(p_cdio); p_cdio = cdio_open_am_linux(ppsz_drives[0], "MMC_RDWR"); if (p_cdio) { - const char *psz_access_mode = cdio_get_arg(p_cdio, "access-mode"); - - if (0 != strncmp(psz_access_mode, "MMC_RDWR", strlen("MMC_RDWR"))) { - fprintf(stderr, - "Got \"%s\"; Should get back \"%s\", the access mode requested.\n", - psz_access_mode, "MMC_RDWR"); - exit(4); - } + check_access_mode(p_cdio, "MMC_RDWR"); } cdio_destroy(p_cdio); diff --git a/test/driver/helper.c b/test/driver/helper.c new file mode 100644 index 00000000..aaef82a1 --- /dev/null +++ b/test/driver/helper.c @@ -0,0 +1,78 @@ +/* -*- C -*- + Copyright (C) 2010 Rocky Bernstein + + 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 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, see . +*/ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif +#ifdef HAVE_STDIO_H +#include +#endif +#ifdef HAVE_STRING_H +#include +#endif +#ifdef HAVE_STDLIB_H +#include +#endif + +#include +#include "helper.h" + +void check_access_mode(CdIo_t *p_cdio, const char *psz_expected_access_mode) +{ + const char *psz_access_mode = cdio_get_arg(p_cdio, "access-mode"); + if ( psz_access_mode == NULL || + (0 != strcmp(psz_expected_access_mode, psz_access_mode)) ) { + fprintf(stderr, + "cdio_get_arg(\"access-mode?\") should return \"%s\"; got: \"%s\".\n", + psz_expected_access_mode, psz_access_mode); + exit(10); + } +} + +void check_get_arg_source(CdIo_t *p_cdio, const char *psz_expected_source) + { + const char *psz_source = cdio_get_arg(p_cdio, "source"); + if ( psz_source == NULL || + (0 != strcmp(psz_expected_source, psz_source)) ) { + fprintf(stderr, + "cdio_get_arg(\"source\") should return \"%s\"; got: \"%s\".\n", + psz_expected_source, psz_source); + exit(40); + } + } + +/* i_expected: 1 => expect false + 2 => expect true + 3 => expect true or false + */ +void check_mmc_supported(CdIo_t *p_cdio, int i_expected) { + const char *psz_response = cdio_get_arg(p_cdio, "mmc-supported?"); + if ( psz_response == NULL ) { + fprintf(stderr, + "cdio_get_arg(\"mmc-supported?\") returned NULL\n"); + exit(30); + } else if ( (0 == (i_expected & 1)) && + (0 == strncmp("false", psz_response, sizeof("false"))) ) { + fprintf(stderr, + "cdio_get_arg(\"mmc-supported?\") should not return \"false\""); + exit(31); + } else if ( (0 == (i_expected & 2)) && + (0 == strncmp("true", psz_response, sizeof("true"))) ) { + fprintf(stderr, + "cdio_get_arg(\"mmc-supported?\") should not return \"true\""); + exit(32); + } +} diff --git a/test/driver/helper.h b/test/driver/helper.h new file mode 100644 index 00000000..7483eefe --- /dev/null +++ b/test/driver/helper.h @@ -0,0 +1,21 @@ +/* -*- C -*- + Copyright (C) 2010 Rocky Bernstein + + 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 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, see . +*/ +void check_access_mode(CdIo_t *p_cdio, const char *psz_expected_access_mode); +void check_get_arg_source(CdIo_t *p_cdio, const char *psz_expected_source); +void check_mmc_supported(CdIo_t *p_cdio, int i_expected); + + diff --git a/test/driver/nrg.c.in b/test/driver/nrg.c.in index ee14428c..ffa16af7 100644 --- a/test/driver/nrg.c.in +++ b/test/driver/nrg.c.in @@ -35,7 +35,11 @@ #ifdef HAVE_STDLIB_H #include #endif +#ifdef HAVE_STRING_H #include +#endif + +#include "helper.h" #ifndef DATA_DIR #define DATA_DIR "@abs_top_srcdir@/test/data" @@ -85,39 +89,9 @@ main(int argc, const char *argv[]) } } - { - const char *psz_response = cdio_get_arg(p_cdio, "mmc-supported?"); - if ( psz_response == NULL || - ((0 != strncmp("false", psz_response, sizeof("false")))) ) { - fprintf(stderr, - "cdio_get_arg(\"mmc-supported?\") should return \"false\"; got: \"%s\".\n", - psz_response); - exit(3); - } - } - - { - const char *psz_access_mode = cdio_get_arg(p_cdio, "access-mode"); - if ( psz_access_mode == NULL || - ((0 != strncmp("image", psz_access_mode, sizeof("image")))) ) { - fprintf(stderr, - "cdio_get_arg(\"access-mode?\") should return \"image\"; got: \"%s\".\n", - psz_access_mode); - exit(4); - } - } - - - { - const char *psz_source = cdio_get_arg(p_cdio, "source"); - if ( psz_source == NULL || - (0 != strcmp(psz_nrgfile, psz_source)) ) { - fprintf(stderr, - "cdio_get_arg(\"source\") should return \"%s\"; got: \"%s\".\n", - psz_source, psz_nrgfile); - exit(4); - } - } + check_mmc_supported(p_cdio, 1); + check_access_mode(p_cdio, "image"); + check_get_arg_source(p_cdio, psz_nrgfile); cdio_destroy(p_cdio);