1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
|
/*
Copyright (C) 2008-2009, 2011, 2013 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"
#define __CDIO_CONFIG_H__ 1
#endif
#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
#ifdef HAVE_SYS_UTSNAME_H
#include <sys/utsname.h>
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef HAVE_STRING_H
#include <string.h>
#endif
#include <cdio/cdio.h>
#include <cdio/cd_types.h>
#include <cdio/logging.h>
#ifndef DATA_DIR
#define DATA_DIR "./data"
#endif
#ifndef __MINGW32__
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;
}
#endif
int
main(int argc, const char *argv[])
{
#if defined(__MINGW32__)
printf("testgetdevices test skipped until drive recording testing issues resolved\n");
return 77;
#else
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)
{
fprintf(stderr, "Bogus driver number -1 should be rejected\n");
return 5;
}
#ifdef HAVE_SYS_UTSNAME_H
{
struct utsname utsname;
if (0 == uname(&utsname))
{
if (0 == strncmp("Linux", utsname.sysname, sizeof("Linux")))
{
if (!cdio_have_driver(DRIVER_LINUX))
{
fprintf(stderr,
"You should have been able to get GNU/Linux driver\n");
return 6;
} else {
printf("-- Good! You have the GNU/Linux driver installed.\n");
}
}
else if (0 == strncmp("CYGWIN", utsname.sysname, sizeof("CYGWIN")))
{
if (!cdio_have_driver(DRIVER_WIN32))
{
fprintf(stderr,
"You should have been able to get Win32 driver\n");
return 6;
} else {
printf("-- Good! You have the Win32 driver installed.\n");
}
}
else if (0 == strncmp("Darwin", utsname.sysname, sizeof("Darwin")))
{
if (!cdio_have_driver(DRIVER_OSX))
{
fprintf(stderr,
"You should have been able to get OS/X driver\n");
return 6;
} else {
printf("-- Good! You have the OS/X driver installed.\n");
}
}
else if (0 == strncmp("NetBSD", utsname.sysname, sizeof("NetBSD")))
{
if (!cdio_have_driver(DRIVER_NETBSD))
{
fprintf(stderr,
"You should have been able to get NetBSD driver\n");
return 6;
} else {
printf("-- Good! You have the OS/X driver installed.\n");
}
}
}
}
#endif
if (! (cdio_have_driver(DRIVER_NRG) && cdio_have_driver(DRIVER_BINCUE)) ) {
printf("You don't have enough drivers for this test\n");
exit(77);
}
bincue_images = cdio_get_devices(DRIVER_BINCUE);
for (imgs=bincue_images; *imgs != NULL; imgs++) {
printf("-- bincue image %s\n", *imgs);
}
if (ret != 0) return ret;
if (0 == chdir(DATA_DIR)) {
int invalid_images = 0;
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;
}
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]);
invalid_images += 1;
}
}
printf("invaid images is %d\n", invalid_images);
ret = invalid_images != 2;
}
cdio_free_device_list(nrg_images);
cdio_free_device_list(bincue_images);
return ret;
#endif
}
|