[01b3b9]: test / testiso9660.c Maximize Restore History

Download this file

testiso9660.c    286 lines (257 with data), 8.1 kB

  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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
/*
$Id: testiso9660.c,v 1.14 2006/03/18 01:00:07 rocky Exp $
Copyright (C) 2003, 2006 Rocky Bernstein <rocky@panix.com>
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 2 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, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* Tests ISO9660 library routines. */
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <ctype.h>
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#ifdef HAVE_STRING_H
#include <string.h>
#endif
#ifdef HAVE_STDIO_H
#include <stdio.h>
#endif
#include <cdio/iso9660.h>
static bool
time_compare(struct tm *p_tm1, struct tm *p_tm2)
{
bool okay = true;
if (!p_tm1) {
printf("get time is NULL\n");
return false;
}
if (!p_tm2) {
printf("set time is NULL\n");
return false;
}
if (p_tm1->tm_year != p_tm2->tm_year) {
printf("Years aren't equal. get: %d, set %d\n",
p_tm1->tm_year, p_tm2->tm_year);
okay=false;
}
if (p_tm1->tm_mon != p_tm2->tm_mon) {
printf("Months aren't equal. get: %d, set %d\n",
p_tm1->tm_mon, p_tm2->tm_mon);
okay=false;
}
if (p_tm1->tm_mday != p_tm2->tm_mday) {
printf("Month days aren't equal. get: %d, set %d\n",
p_tm1->tm_mday, p_tm2->tm_mday);
okay=false;
}
if (p_tm1->tm_min != p_tm2->tm_min) {
printf("minute aren't equal. get: %d, set %d\n",
p_tm1->tm_min, p_tm2->tm_min);
okay=false;
}
if (p_tm1->tm_hour != p_tm2->tm_hour) {
printf("hours aren't equal. get: %d, set %d\n",
p_tm1->tm_hour, p_tm2->tm_hour);
okay=false;
}
if (p_tm1->tm_sec != p_tm2->tm_sec) {
printf("seconds aren't equal. get: %d, set %d\n",
p_tm1->tm_sec, p_tm2->tm_sec);
okay=false;
}
if (p_tm1->tm_wday != p_tm2->tm_wday) {
printf("Week days aren't equal. get: %d, set %d\n",
p_tm1->tm_wday, p_tm2->tm_wday);
okay=false;
}
if (p_tm1->tm_yday != p_tm2->tm_yday) {
printf("Year days aren't equal. get: %d, set %d\n",
p_tm1->tm_yday, p_tm2->tm_yday);
okay=false;
}
if (p_tm1->tm_isdst != p_tm2->tm_isdst) {
printf("Is daylight savings times aren't equal. get: %d, set %d\n",
p_tm1->tm_isdst, p_tm2->tm_isdst);
okay=false;
}
#ifdef HAVE_TM_GMTOFF
if (p_tm1->tm_gmtoff != p_tm2->tm_gmtoff) {
printf("GMT offsets aren't equal. get: %ld, set %ld\n",
p_tm1->tm_gmtoff, p_tm2->tm_gmtoff);
okay=false;
}
if (p_tm1 != p_tm2 && p_tm1 && p_tm2) {
if (strcmp(p_tm1->tm_zone, p_tm2->tm_zone) != 0) {
printf("Time Zone values. get: %s, set %s\n",
p_tm1->tm_zone, p_tm2->tm_zone);
/* Argh... sometimes GMT is converted to UTC. So
Let's not call this a failure if everything else was okay.
*/
}
}
#endif
return okay;
}
int
main (int argc, const char *argv[])
{
int c;
int i;
int i_bad = 0;
char dst[100];
char *dst_p;
int achars[] = {'!', '"', '%', '&', '(', ')', '*', '+', ',', '-', '.',
'/', '?', '<', '=', '>'};
/*********************************************
* Test ACHAR and DCHAR
*********************************************/
for (c='A'; c<='Z'; c++ ) {
if (!iso9660_is_dchar(c)) {
printf("Failed iso9660_is_dchar test on %c\n", c);
i_bad++;
}
if (!iso9660_is_achar(c)) {
printf("Failed iso9660_is_achar test on %c\n", c);
i_bad++;
}
}
if (i_bad) return i_bad;
for (c='0'; c<='9'; c++ ) {
if (!iso9660_is_dchar(c)) {
printf("Failed iso9660_is_dchar test on %c\n", c);
i_bad++;
}
if (!iso9660_is_achar(c)) {
printf("Failed iso9660_is_achar test on %c\n", c);
i_bad++;
}
}
if (i_bad) return i_bad;
for (i=0; i<=13; i++ ) {
c=achars[i];
if (iso9660_is_dchar(c)) {
printf("Should not pass iso9660_is_dchar test on %c\n", c);
i_bad++;
}
if (!iso9660_is_achar(c)) {
printf("Failed iso9660_is_achar test on symbol %c\n", c);
i_bad++;
}
}
if (i_bad) return i_bad;
/*********************************************
* Test iso9660_strncpy_pad
*********************************************/
dst_p = iso9660_strncpy_pad(dst, "1_3", 5, ISO9660_DCHARS);
if ( 0 != strncmp(dst, "1_3 ", 5) ) {
printf("Failed iso9660_strncpy_pad DCHARS\n");
return 31;
}
dst_p = iso9660_strncpy_pad(dst, "ABC!123", 2, ISO9660_ACHARS);
if ( 0 != strncmp(dst, "AB", 2) ) {
printf("Failed iso9660_strncpy_pad ACHARS truncation\n");
return 32;
}
/*********************************************
* Test iso9660_dirname_valid_p
*********************************************/
if ( iso9660_dirname_valid_p("/NOGOOD") ) {
printf("/NOGOOD should fail iso9660_dirname_valid_p\n");
return 33;
}
if ( iso9660_dirname_valid_p("LONGDIRECTORY/NOGOOD") ) {
printf("LONGDIRECTORY/NOGOOD should fail iso9660_dirname_valid_p\n");
return 34;
}
if ( !iso9660_dirname_valid_p("OKAY/DIR") ) {
printf("OKAY/DIR should pass iso9660_dirname_valid_p\n");
return 35;
}
if ( iso9660_dirname_valid_p("OKAY/FILE.EXT") ) {
printf("OKAY/FILENAME.EXT should fail iso9660_dirname_valid_p\n");
return 36;
}
/*********************************************
* Test iso9660_pathname_valid_p
*********************************************/
if ( !iso9660_pathname_valid_p("OKAY/FILE.EXT") ) {
printf("OKAY/FILE.EXT should pass iso9660_dirname_valid_p\n");
return 37;
}
if ( iso9660_pathname_valid_p("OKAY/FILENAMETOOLONG.EXT") ) {
printf("OKAY/FILENAMETOOLONG.EXT should fail iso9660_dirname_valid_p\n");
return 38;
}
if ( iso9660_pathname_valid_p("OKAY/FILE.LONGEXT") ) {
printf("OKAY/FILE.LONGEXT should fail iso9660_dirname_valid_p\n");
return 39;
}
dst_p = iso9660_pathname_isofy ("this/file.ext", 1);
if ( 0 != strncmp(dst_p, "this/file.ext;1", 16) ) {
printf("Failed iso9660_pathname_isofy\n");
free(dst_p);
return 40;
}
free(dst_p);
/*********************************************
* Test get/set date
*********************************************/
{
struct tm *p_tm, tm;
iso9660_dtime_t dtime;
iso9660_ltime_t ltime;
time_t now = time(NULL);
memset(&dtime, 0, sizeof(dtime));
p_tm = localtime(&now);
iso9660_set_dtime(p_tm, &dtime);
iso9660_get_dtime(&dtime, true, &tm);
if ( memcmp(p_tm, &tm, sizeof(tm)) != 0 ) {
printf("Local time retrieved with iso9660_get_dtime not same as\n");
printf("that set with iso9660_set_dtime().\n");
return 41;
}
p_tm = gmtime(&now);
iso9660_set_dtime(p_tm, &dtime);
iso9660_get_dtime(&dtime, false, &tm);
if ( memcmp(p_tm, &tm, sizeof(tm)) != 0 ) {
printf("GMT time retrieved with iso9660_get_dtime() not same as that\n");
printf("set with iso9660_set_dtime().\n");
return 42;
}
{
time_t t1, t2;
p_tm = localtime(&now);
t1 = mktime(p_tm);
iso9660_set_ltime(p_tm, &ltime);
iso9660_get_ltime(&ltime, &tm);
t2 = mktime(&tm);
if ( t1 != t2 && ! time_compare(p_tm, &tm) ) {
printf("local time retrieved with iso9660_get_ltime() not\n");
printf("same as that set with iso9660_set_ltime().\n");
return 43;
}
p_tm = gmtime(&now);
t1 = mktime(p_tm);
iso9660_set_ltime(p_tm, &ltime);
iso9660_get_ltime(&ltime, &tm);
t2 = mktime(&tm);
if ( t1 != t2 && ! time_compare(p_tm, &tm) ) {
printf("GMT time retrieved with iso9660_get_ltime() not\n");
printf("same as that set with iso9660_set_ltime().\n");
return 44;
}
}
}
return 0;
}