diff --git a/example/.gitignore b/example/.gitignore index bda21de8..dfb999cc 100644 --- a/example/.gitignore +++ b/example/.gitignore @@ -1,6 +1,7 @@ /*.o /.deps /.libs +/*~ /Makefile /Makefile.in /audio diff --git a/lib/driver/.gitignore b/lib/driver/.gitignore index e09f35a4..b9caaf7d 100644 --- a/lib/driver/.gitignore +++ b/lib/driver/.gitignore @@ -2,6 +2,7 @@ /*.o /.deps /.libs +/*.c~ /Makefile /Makefile.in /libcdio.la diff --git a/lib/driver/device.c b/lib/driver/device.c index c0910348..561865a0 100644 --- a/lib/driver/device.c +++ b/lib/driver/device.c @@ -857,6 +857,9 @@ cdio_have_atapi(CdIo_t *p_cdio) bool cdio_have_driver(driver_id_t driver_id) { + if (driver_id < CDIO_MIN_DRIVER || + driver_id > CDIO_MAX_DRIVER) + return false; return (*CdIo_all_drivers[driver_id].have_driver)(); } diff --git a/test/.gitignore b/test/.gitignore index 5cb4c56b..f646559d 100644 --- a/test/.gitignore +++ b/test/.gitignore @@ -1,4 +1,5 @@ /*.o +/*~ /.deps /.libs /Makefile @@ -17,6 +18,8 @@ /testassert /testbincue /testbincue.c +/testdefault +/testgetdevices /testischar /testiso9660 /testisocd diff --git a/test/Makefile.am b/test/Makefile.am index 8d79e2ed..689216b9 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -28,7 +28,7 @@ testparanoia=testparanoia testparanoia_LDADD = $(LIBCDIO_PARANOIA_LIBS) $(LIBCDIO_CDDA_LIBS) $(LIBCDIO_LIBS) $(LTLIBICONV) endif -hack = check_sizeof testassert testbincue testischar \ +hack = check_sizeof testassert testbincue testgetdevices testischar \ testisocd testisocd2 testiso9660 \ testnrg $(testparanoia) testtoc testpregap @@ -39,6 +39,7 @@ INCLUDES = -I$(top_srcdir) $(LIBCDIO_CFLAGS) $(LIBISO9660_CFLAGS) check_sizeof_LDADD = $(LIBISO9660_LIBS) $(LIBCDIO_LIBS) $(LTLIBICONV) testassert_LDADD = $(LIBCDIO_LIBS) $(LTLIBICONV) testdefault_LDADD = $(LIBCDIO_LIBS) $(LTLIBICONV) +testgetdevices_LDADD= $(LIBCDIO_LIBS) $(LTLIBICONV) testischar_LDADD = $(LIBISO9660_LIBS) $(LIBCDIO_LIBS) $(LTLIBICONV) testiso9660_LDADD = $(LIBISO9660_LIBS) $(LIBCDIO_LIBS) $(LTLIBICONV) diff --git a/test/testdefault.c b/test/testdefault.c index 303a863f..e30accdc 100644 --- a/test/testdefault.c +++ b/test/testdefault.c @@ -80,6 +80,13 @@ main(int argc, const char *argv[]) cdio_log_set_handler (log_handler); + if (cdio_have_driver(-1) != false) + { + printf("Bogus driver number -1 should be regexted\n"); + return 5; + } + + if (! (cdio_have_driver(DRIVER_NRG) && cdio_have_driver(DRIVER_BINCUE)) ) { printf("You don't have enough drivers for this test\n"); exit(77); @@ -189,12 +196,8 @@ main(int argc, const char *argv[]) } cdio_free_device_list(nrg_images); - free(nrg_images); cdio_free_device_list(bincue_images); - free(bincue_images); cdio_free_device_list(imgs); - free(imgs); - return 0; } diff --git a/test/testgetdevices.c b/test/testgetdevices.c new file mode 100644 index 00000000..61760661 --- /dev/null +++ b/test/testgetdevices.c @@ -0,0 +1,124 @@ +/* + Copyright (C) 2008 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 . +*/ + +/* + Regression test for cdio_get_devices, cdio_get_devices_with_cap(), + and cdio_free_device_list() +*/ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif +#include +#include +#include + +#ifdef HAVE_STDIO_H +#include +#endif +#ifdef HAVE_SYS_TYPES_H +#include +#endif +#ifdef HAVE_STDLIB_H +#include +#endif +#include + +static void +log_handler (cdio_log_level_t level, const char message[]) +{ + switch(level) { + case CDIO_LOG_DEBUG: + case CDIO_LOG_INFO: + return; + default: + printf("cdio %d message: %s\n", level, message); + } +} + +static bool +is_in(char **file_list, const char *file) +{ + char **p; + for (p = file_list; p != NULL && *p != NULL; p++) { + if (strcmp(*p, file) == 0) { + printf("File %s found as expected\n", file); + return true; + } + } + printf("Can't find file %s in list\n", file); + return false; +} + +int +main(int argc, const char *argv[]) +{ + char **nrg_images=NULL; + char **bincue_images=NULL; + char **imgs; + unsigned int i; + int ret=0; + + const char *cue_files[2] = {"cdda.cue", "isofs-m1.cue"}; + const char *nrg_files[1] = {"videocd.nrg"}; + + cdio_log_set_handler (log_handler); + + if (cdio_have_driver(-1) != false) + { + printf("Bogus driver number -1 should be regexted\n"); + return 5; + } + + + if (! (cdio_have_driver(DRIVER_NRG) && cdio_have_driver(DRIVER_BINCUE)) ) { + printf("You don't have enough drivers for this test\n"); + exit(77); + } + + nrg_images = cdio_get_devices(DRIVER_NRG); + + for (imgs=nrg_images; *imgs != NULL; imgs++) { + printf("NRG image %s\n", *imgs); + } + + if (!is_in(nrg_images, nrg_files[0])) { + cdio_free_device_list(nrg_images); + return 10; + } + + bincue_images = cdio_get_devices(DRIVER_BINCUE); + + for (imgs=bincue_images; *imgs != NULL; imgs++) { + printf("bincue image %s\n", *imgs); + } + + for (i=0; i<2; i++) { + if (is_in(bincue_images, cue_files[i])) { + printf("%s parses as a CDRWIN BIN/CUE csheet.\n", cue_files[i]); + } else { + printf("%s doesn't parse as a CDRWIN BIN/CUE csheet.\n", cue_files[i]); + ret = i+1; + } + } + + if (ret != 0) return ret; + + cdio_free_device_list(nrg_images); + cdio_free_device_list(bincue_images); + return 0; + +}