Wasn't checking the range of the device id in cdio_have_driver. Add regression test for checking this too.
More git administrivia.
This commit is contained in:
1
example/.gitignore
vendored
1
example/.gitignore
vendored
@@ -1,6 +1,7 @@
|
|||||||
/*.o
|
/*.o
|
||||||
/.deps
|
/.deps
|
||||||
/.libs
|
/.libs
|
||||||
|
/*~
|
||||||
/Makefile
|
/Makefile
|
||||||
/Makefile.in
|
/Makefile.in
|
||||||
/audio
|
/audio
|
||||||
|
|||||||
1
lib/driver/.gitignore
vendored
1
lib/driver/.gitignore
vendored
@@ -2,6 +2,7 @@
|
|||||||
/*.o
|
/*.o
|
||||||
/.deps
|
/.deps
|
||||||
/.libs
|
/.libs
|
||||||
|
/*.c~
|
||||||
/Makefile
|
/Makefile
|
||||||
/Makefile.in
|
/Makefile.in
|
||||||
/libcdio.la
|
/libcdio.la
|
||||||
|
|||||||
@@ -857,6 +857,9 @@ cdio_have_atapi(CdIo_t *p_cdio)
|
|||||||
bool
|
bool
|
||||||
cdio_have_driver(driver_id_t driver_id)
|
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)();
|
return (*CdIo_all_drivers[driver_id].have_driver)();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
3
test/.gitignore
vendored
3
test/.gitignore
vendored
@@ -1,4 +1,5 @@
|
|||||||
/*.o
|
/*.o
|
||||||
|
/*~
|
||||||
/.deps
|
/.deps
|
||||||
/.libs
|
/.libs
|
||||||
/Makefile
|
/Makefile
|
||||||
@@ -17,6 +18,8 @@
|
|||||||
/testassert
|
/testassert
|
||||||
/testbincue
|
/testbincue
|
||||||
/testbincue.c
|
/testbincue.c
|
||||||
|
/testdefault
|
||||||
|
/testgetdevices
|
||||||
/testischar
|
/testischar
|
||||||
/testiso9660
|
/testiso9660
|
||||||
/testisocd
|
/testisocd
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ testparanoia=testparanoia
|
|||||||
testparanoia_LDADD = $(LIBCDIO_PARANOIA_LIBS) $(LIBCDIO_CDDA_LIBS) $(LIBCDIO_LIBS) $(LTLIBICONV)
|
testparanoia_LDADD = $(LIBCDIO_PARANOIA_LIBS) $(LIBCDIO_CDDA_LIBS) $(LIBCDIO_LIBS) $(LTLIBICONV)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
hack = check_sizeof testassert testbincue testischar \
|
hack = check_sizeof testassert testbincue testgetdevices testischar \
|
||||||
testisocd testisocd2 testiso9660 \
|
testisocd testisocd2 testiso9660 \
|
||||||
testnrg $(testparanoia) testtoc testpregap
|
testnrg $(testparanoia) testtoc testpregap
|
||||||
|
|
||||||
@@ -39,6 +39,7 @@ INCLUDES = -I$(top_srcdir) $(LIBCDIO_CFLAGS) $(LIBISO9660_CFLAGS)
|
|||||||
check_sizeof_LDADD = $(LIBISO9660_LIBS) $(LIBCDIO_LIBS) $(LTLIBICONV)
|
check_sizeof_LDADD = $(LIBISO9660_LIBS) $(LIBCDIO_LIBS) $(LTLIBICONV)
|
||||||
testassert_LDADD = $(LIBCDIO_LIBS) $(LTLIBICONV)
|
testassert_LDADD = $(LIBCDIO_LIBS) $(LTLIBICONV)
|
||||||
testdefault_LDADD = $(LIBCDIO_LIBS) $(LTLIBICONV)
|
testdefault_LDADD = $(LIBCDIO_LIBS) $(LTLIBICONV)
|
||||||
|
testgetdevices_LDADD= $(LIBCDIO_LIBS) $(LTLIBICONV)
|
||||||
testischar_LDADD = $(LIBISO9660_LIBS) $(LIBCDIO_LIBS) $(LTLIBICONV)
|
testischar_LDADD = $(LIBISO9660_LIBS) $(LIBCDIO_LIBS) $(LTLIBICONV)
|
||||||
testiso9660_LDADD = $(LIBISO9660_LIBS) $(LIBCDIO_LIBS) $(LTLIBICONV)
|
testiso9660_LDADD = $(LIBISO9660_LIBS) $(LIBCDIO_LIBS) $(LTLIBICONV)
|
||||||
|
|
||||||
|
|||||||
@@ -80,6 +80,13 @@ main(int argc, const char *argv[])
|
|||||||
|
|
||||||
cdio_log_set_handler (log_handler);
|
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)) ) {
|
if (! (cdio_have_driver(DRIVER_NRG) && cdio_have_driver(DRIVER_BINCUE)) ) {
|
||||||
printf("You don't have enough drivers for this test\n");
|
printf("You don't have enough drivers for this test\n");
|
||||||
exit(77);
|
exit(77);
|
||||||
@@ -189,12 +196,8 @@ main(int argc, const char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
cdio_free_device_list(nrg_images);
|
cdio_free_device_list(nrg_images);
|
||||||
free(nrg_images);
|
|
||||||
cdio_free_device_list(bincue_images);
|
cdio_free_device_list(bincue_images);
|
||||||
free(bincue_images);
|
|
||||||
cdio_free_device_list(imgs);
|
cdio_free_device_list(imgs);
|
||||||
free(imgs);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
124
test/testgetdevices.c
Normal file
124
test/testgetdevices.c
Normal file
@@ -0,0 +1,124 @@
|
|||||||
|
/*
|
||||||
|
Copyright (C) 2008 Rocky Bernstein <rocky@gnu.org>
|
||||||
|
|
||||||
|
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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
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 <cdio/cdio.h>
|
||||||
|
#include <cdio/cd_types.h>
|
||||||
|
#include <cdio/logging.h>
|
||||||
|
|
||||||
|
#ifdef HAVE_STDIO_H
|
||||||
|
#include <stdio.h>
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_SYS_TYPES_H
|
||||||
|
#include <sys/types.h>
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_STDLIB_H
|
||||||
|
#include <stdlib.h>
|
||||||
|
#endif
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user