1 /*
2 Copyright (C) 2013 Rocky Bernstein <rocky@gnu.org>
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 /*
19 Regression test for lib/driver/track.c
20
21 To compile as standalone program:
22 gcc -g3 -Wall -DHAVE_CONFIG_H -I../.. -I../../include track.c ../../lib/driver/.libs/libcdio.a -o track
23 */
24
25 #ifdef HAVE_CONFIG_H
26 #include "config.h"
27 #define __CDIO_CONFIG_H__ 1
28 #endif
29
30 #ifdef HAVE_STDIO_H
31 #include <stdio.h>
32 #endif
33 #ifdef HAVE_SYS_TYPES_H
34 #include <sys/types.h>
35 #endif
36 #ifdef HAVE_STDLIB_H
37 #include <stdlib.h>
38 #endif
39 #ifdef HAVE_STRING_H
40 #include <string.h>
41 #endif
42
43 #include <cdio/cdio.h>
44 #include <cdio/cd_types.h>
45 #include <cdio/logging.h>
46
47 #ifndef DATA_DIR
48 #define DATA_DIR "../data"
49 #endif
50
51 static void
log_handler(cdio_log_level_t level,const char message[])52 log_handler (cdio_log_level_t level, const char message[])
53 {
54 switch(level) {
55 case CDIO_LOG_DEBUG:
56 case CDIO_LOG_INFO:
57 return;
58 default:
59 printf("cdio %d message: %s\n", level, message);
60 }
61 }
62
63 int
main(int argc,const char * argv[])64 main(int argc, const char *argv[])
65 {
66 CdIo_t *cdObj;
67 track_t i_track;
68 lsn_t lsn;
69
70 cdio_log_set_handler (log_handler);
71
72 if (cdio_have_driver(DRIVER_BINCUE)) {
73 cdObj = cdio_open(DATA_DIR "/cdda.cue", DRIVER_UNKNOWN);
74 } else if (cdio_have_driver(DRIVER_CDRDAO)) {
75 cdObj = cdio_open(DATA_DIR "/cdda.toc", DRIVER_UNKNOWN);
76 } else {
77 printf("-- You don't have enough drivers for this test\n");
78 return 77;
79 }
80
81 i_track = cdio_get_track(cdObj, 1000);
82 if (i_track != CDIO_INVALID_TRACK) {
83 printf("LSN 1000 is too large should have gotten CDIO_INVALID_TRACK back\n");
84 return 1;
85 }
86
87 for(lsn=0; lsn<10; lsn++) {
88 i_track = cdio_get_track(cdObj, lsn);
89 if (i_track != 1) {
90 printf("LSN %d should return 1. Got %d\n", lsn, i_track);
91 return 3;
92 }
93 }
94
95 i_track = cdio_get_track(cdObj, 302);
96 if (i_track != CDIO_CDROM_LEADOUT_TRACK) {
97 printf("LSN %d should return leadout. Got %d\n", 302, i_track);
98 return 4;
99 }
100
101 for(lsn=301; lsn > 300; lsn--) {
102 i_track = cdio_get_track(cdObj, lsn);
103 if (i_track != 1) {
104 printf("LSN %d should return 1. Got %d\n", lsn, i_track);
105 return 4;
106 }
107 }
108
109 cdio_destroy(cdObj);
110
111 return 0;
112 }
113