Start to DRY driver unit tests.
This commit is contained in:
1
test/driver/.gitignore
vendored
1
test/driver/.gitignore
vendored
@@ -8,6 +8,7 @@
|
||||
/bincue
|
||||
/bincue
|
||||
/bincue.c
|
||||
/cdrdao
|
||||
/cdrdao.c
|
||||
/follow_symlink
|
||||
/freebsd
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -33,7 +33,12 @@
|
||||
#ifdef HAVE_STDLIB_H
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
#ifdef HAVE_STRING_H
|
||||
#include <string.h>
|
||||
#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);
|
||||
|
||||
}
|
||||
|
||||
@@ -33,7 +33,11 @@
|
||||
#ifdef HAVE_STDLIB_H
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
#ifdef HAVE_STRING_H
|
||||
#include <string.h>
|
||||
#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;
|
||||
|
||||
@@ -33,7 +33,11 @@
|
||||
#ifdef HAVE_STDLIB_H
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
#ifdef HAVE_STRING_H
|
||||
#include <string.h>
|
||||
#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);
|
||||
}
|
||||
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_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);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
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);
|
||||
|
||||
78
test/driver/helper.c
Normal file
78
test/driver/helper.c
Normal file
@@ -0,0 +1,78 @@
|
||||
/* -*- C -*-
|
||||
Copyright (C) 2010 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/>.
|
||||
*/
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
#ifdef HAVE_STDIO_H
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
#ifdef HAVE_STRING_H
|
||||
#include <string.h>
|
||||
#endif
|
||||
#ifdef HAVE_STDLIB_H
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
|
||||
#include <cdio/cdio.h>
|
||||
#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);
|
||||
}
|
||||
}
|
||||
21
test/driver/helper.h
Normal file
21
test/driver/helper.h
Normal file
@@ -0,0 +1,21 @@
|
||||
/* -*- C -*-
|
||||
Copyright (C) 2010 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/>.
|
||||
*/
|
||||
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);
|
||||
|
||||
|
||||
@@ -35,7 +35,11 @@
|
||||
#ifdef HAVE_STDLIB_H
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
#ifdef HAVE_STRING_H
|
||||
#include <string.h>
|
||||
#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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user