1 /* -*- C -*-
2   Copyright (C) 2009, 2011, 2014 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    Unit test for lib/driver/osx.c
20 */
21 #ifdef HAVE_CONFIG_H
22 #include "config.h"
23 #define __CDIO_CONFIG_H__ 1
24 #endif
25 
26 #ifdef HAVE_STDIO_H
27 #include <stdio.h>
28 #endif
29 #ifdef HAVE_SYS_TYPES_H
30 #include <sys/types.h>
31 #endif
32 #ifdef HAVE_STDLIB_H
33 #include <stdlib.h>
34 #endif
35 #ifdef HAVE_STRING_H
36 #include <string.h>
37 #endif
38 
39 #include <cdio/cdio.h>
40 #include <cdio/logging.h>
41 
42 int
main(int argc,const char * argv[])43 main(int argc, const char *argv[])
44 {
45   CdIo_t *p_cdio;
46   char **ppsz_drives=NULL;
47   int n=0;
48 
49   cdio_loglevel_default = (argc > 1) ? CDIO_LOG_DEBUG : CDIO_LOG_INFO;
50   /* snprintf(psz_nrgfile, sizeof(psz_nrgfile)-1,
51 	     "%s/%s", TEST_DIR, cue_file[i]);
52   */
53   if (!cdio_have_driver(DRIVER_OSX)) return(77);
54   ppsz_drives = cdio_get_devices(DRIVER_DEVICE);
55   if (!ppsz_drives) {
56       printf("Can't find a CD-ROM drive. Skipping test.\n");
57       exit(77);
58   }
59 
60   do {
61     p_cdio = cdio_open_osx(ppsz_drives[n]);
62     if (p_cdio) {
63       const char *psz_source = cdio_get_arg(p_cdio, "source");
64       const char *psz_access_mode = cdio_get_arg(p_cdio, "access-mode");
65       discmode_t  discmode = cdio_get_discmode(p_cdio);
66       if (0 != strncmp(psz_source, ppsz_drives[0],
67 		       strlen(ppsz_drives[0]))) {
68 	  fprintf(stderr,
69 		  "Got %s; should get back %s, the name we opened.\n",
70 		  psz_source, ppsz_drives[0]);
71 	  exit(1);
72       }
73       if (0 != strncmp(psz_access_mode, "OS X", strlen("OS X"))) {
74 	  fprintf(stderr,
75 		  "Got %s; Should get back %s, the access mode requested.\n",
76 		  psz_access_mode, "OS X");
77 	  exit(2);
78       }
79       if (CDIO_DISC_MODE_ERROR == discmode) {
80 	  fprintf(stderr,
81 		  "Error getting disc mode for device %s.\n",
82 		  ppsz_drives[n]);
83 	  exit(3);
84       }
85     }
86 
87     cdio_destroy(p_cdio);
88   }
89   while (ppsz_drives[++n] != NULL);
90 
91   cdio_free_device_list(ppsz_drives);
92 
93   return 0;
94 }
95