1 /*
2   Copyright (C) 2003-2005, 2011-2013, 2016  Rocky Bernstein <rocky@gnu.org>
3   Copyright (C) 2008 Robert W. Fuller <hydrologiccycle@gmail.com>
4 
5   This program is free software: you can redistribute it and/or modify
6   it under the terms of the GNU General Public License as published by
7   the Free Software Foundation, either version 3 of the License, or
8   (at your option) any later version.
9 
10   This program is distributed in the hope that it will be useful,
11   but WITHOUT ANY WARRANTY; without even the implied warranty of
12   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   GNU General Public License for more details.
14 
15   You should have received a copy of the GNU General Public License
16   along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 /*
20    Regression test for cdio_get_pregap_lsn()
21 
22    To compile as a standalone program:
23    gcc -g3 -Wall -DHAVE_CONFIG_H -I.. -I../include testpregap.c ../lib/driver/.libs/libcdio.a -o testpregap
24 */
25 
26 #ifndef DATA_DIR
27 #define DATA_DIR "./data"
28 #endif
29 
30 #ifdef HAVE_CONFIG_H
31 #include "config.h"
32 #define __CDIO_CONFIG_H__ 1
33 #endif
34 
35 #ifdef HAVE_STDIO_H
36 #include <stdio.h>
37 #endif
38 #ifdef HAVE_SYS_TYPES_H
39 #include <sys/types.h>
40 #endif
41 #ifdef HAVE_STDLIB_H
42 #include <stdlib.h>
43 #endif
44 #ifdef HAVE_STRING_H
45 #include <string.h>
46 #endif
47 
48 #include <cdio/cdio.h>
49 #include <cdio/cd_types.h>
50 #include <cdio/logging.h>
51 
52 #ifndef DATA_DIR
53 #define DATA_DIR "./data"
54 #endif
55 
56 static void
log_handler(cdio_log_level_t level,const char message[])57 log_handler (cdio_log_level_t level, const char message[])
58 {
59   switch(level) {
60   case CDIO_LOG_DEBUG:
61   case CDIO_LOG_INFO:
62     return;
63   default:
64     printf("cdio %d message: %s\n", level, message);
65   }
66 }
67 
68 typedef struct _pregap_list_t {
69 
70   const char *image;
71   track_t track;
72   lsn_t pregap;
73 
74 } pregap_list_t;
75 
76 static pregap_list_t pregapList[] =
77 {
78     { DATA_DIR "/t2.toc", 1, 4425 },
79     { DATA_DIR "/t2.toc", 2, CDIO_INVALID_LSN },
80     { DATA_DIR "/p1.cue", 1, 0 },
81     { DATA_DIR "/p1.cue", 2, 150 },
82     { DATA_DIR "/p1.cue", 3, CDIO_INVALID_LSN },
83 /*    { "p1.nrg", 1, 0 }, Nero did not create the proper pre-gap - bleh */
84     { DATA_DIR "/p1.nrg", 2, 225 },
85     { DATA_DIR "/p1.nrg", 3, CDIO_INVALID_LSN }
86 };
87 
88 #define NELEMS(v) (sizeof(v) / sizeof(v[0]))
89 
90 int
main(int argc,const char * argv[])91 main(int argc, const char *argv[])
92 {
93   CdIo_t *cdObj;
94   const char *image;
95   lsn_t pregap;
96   int i;
97   int rc = 0;
98 
99   cdio_log_set_handler (log_handler);
100 
101   if (! (cdio_have_driver(DRIVER_NRG) && cdio_have_driver(DRIVER_BINCUE)
102    && cdio_have_driver(DRIVER_CDRDAO)) )  {
103     printf("-- You don't have enough drivers for this test\n");
104     exit(77);
105   }
106 
107   for (i = 0;  i < NELEMS(pregapList);  ++i) {
108 
109     image = pregapList[i].image;
110 
111     cdObj = cdio_open(image, DRIVER_UNKNOWN);
112     if (!cdObj) {
113       printf("-- unrecognized image: %s\n", image);
114       return 50;
115     }
116 
117     pregap = cdio_get_track_pregap_lsn(cdObj, pregapList[i].track);
118     if (pregap != pregapList[i].pregap) {
119       printf("%s should have had pregap of lsn=%d instead of lsn=%d\n",
120 	     image, pregapList[i].pregap, pregap);
121       rc = i + 1;
122     } else {
123       printf("-- %s had expected pregap\n", image);
124     }
125 
126     cdio_destroy(cdObj);
127   }
128 
129   return rc;
130 }
131