2003-09-01 15:08:15 +00:00
|
|
|
|
/*
|
2006-03-18 03:19:16 +00:00
|
|
|
|
$Id: testiso9660.c,v 1.15 2006/03/18 03:19:16 rocky Exp $
|
2003-09-01 15:08:15 +00:00
|
|
|
|
|
2006-02-25 11:58:22 +00:00
|
|
|
|
Copyright (C) 2003, 2006 Rocky Bernstein <rocky@panix.com>
|
2003-09-01 15:08:15 +00:00
|
|
|
|
|
|
|
|
|
|
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>
|
2004-10-26 01:21:05 +00:00
|
|
|
|
#ifdef HAVE_STDLIB_H
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
#endif
|
2003-09-01 15:08:15 +00:00
|
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
#endif
|
|
|
|
|
|
#ifdef HAVE_STDIO_H
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
#endif
|
|
|
|
|
|
#include <cdio/iso9660.h>
|
|
|
|
|
|
|
2006-03-17 01:05:54 +00:00
|
|
|
|
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;
|
|
|
|
|
|
}
|
2006-03-17 16:46:52 +00:00
|
|
|
|
if (p_tm1 != p_tm2 && p_tm1 && p_tm2) {
|
2006-03-17 01:05:54 +00:00
|
|
|
|
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);
|
2006-03-18 01:00:07 +00:00
|
|
|
|
/* Argh... sometimes GMT is converted to UTC. So
|
|
|
|
|
|
Let's not call this a failure if everything else was okay.
|
|
|
|
|
|
*/
|
2006-03-17 01:05:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
#endif
|
|
|
|
|
|
return okay;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2003-09-01 15:08:15 +00:00
|
|
|
|
int
|
|
|
|
|
|
main (int argc, const char *argv[])
|
|
|
|
|
|
{
|
|
|
|
|
|
int c;
|
|
|
|
|
|
int i;
|
2006-02-25 11:58:22 +00:00
|
|
|
|
int i_bad = 0;
|
2003-09-01 15:08:15 +00:00
|
|
|
|
char dst[100];
|
|
|
|
|
|
char *dst_p;
|
|
|
|
|
|
int achars[] = {'!', '"', '%', '&', '(', ')', '*', '+', ',', '-', '.',
|
|
|
|
|
|
'/', '?', '<', '=', '>'};
|
2006-02-25 12:10:53 +00:00
|
|
|
|
|
|
|
|
|
|
/*********************************************
|
|
|
|
|
|
* Test ACHAR and DCHAR
|
|
|
|
|
|
*********************************************/
|
|
|
|
|
|
|
2003-09-01 15:08:15 +00:00
|
|
|
|
for (c='A'; c<='Z'; c++ ) {
|
2006-03-06 19:39:35 +00:00
|
|
|
|
if (!iso9660_is_dchar(c)) {
|
|
|
|
|
|
printf("Failed iso9660_is_dchar test on %c\n", c);
|
2006-02-25 11:58:22 +00:00
|
|
|
|
i_bad++;
|
2003-09-01 15:08:15 +00:00
|
|
|
|
}
|
2006-03-06 19:39:35 +00:00
|
|
|
|
if (!iso9660_is_achar(c)) {
|
|
|
|
|
|
printf("Failed iso9660_is_achar test on %c\n", c);
|
2006-02-25 11:58:22 +00:00
|
|
|
|
i_bad++;
|
2003-09-01 15:08:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2006-02-25 11:58:22 +00:00
|
|
|
|
|
|
|
|
|
|
if (i_bad) return i_bad;
|
|
|
|
|
|
|
2003-09-01 15:08:15 +00:00
|
|
|
|
for (c='0'; c<='9'; c++ ) {
|
2006-03-06 19:39:35 +00:00
|
|
|
|
if (!iso9660_is_dchar(c)) {
|
|
|
|
|
|
printf("Failed iso9660_is_dchar test on %c\n", c);
|
2006-02-25 11:58:22 +00:00
|
|
|
|
i_bad++;
|
2003-09-01 15:08:15 +00:00
|
|
|
|
}
|
2006-03-06 19:39:35 +00:00
|
|
|
|
if (!iso9660_is_achar(c)) {
|
|
|
|
|
|
printf("Failed iso9660_is_achar test on %c\n", c);
|
2006-02-25 11:58:22 +00:00
|
|
|
|
i_bad++;
|
2003-09-01 15:08:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2006-02-25 11:58:22 +00:00
|
|
|
|
if (i_bad) return i_bad;
|
|
|
|
|
|
|
2003-09-01 15:08:15 +00:00
|
|
|
|
for (i=0; i<=13; i++ ) {
|
|
|
|
|
|
c=achars[i];
|
2006-03-06 19:39:35 +00:00
|
|
|
|
if (iso9660_is_dchar(c)) {
|
|
|
|
|
|
printf("Should not pass iso9660_is_dchar test on %c\n", c);
|
2006-02-25 11:58:22 +00:00
|
|
|
|
i_bad++;
|
2003-09-01 15:08:15 +00:00
|
|
|
|
}
|
2006-03-06 19:39:35 +00:00
|
|
|
|
if (!iso9660_is_achar(c)) {
|
|
|
|
|
|
printf("Failed iso9660_is_achar test on symbol %c\n", c);
|
2006-02-25 11:58:22 +00:00
|
|
|
|
i_bad++;
|
2003-09-01 15:08:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2006-02-25 11:58:22 +00:00
|
|
|
|
if (i_bad) return i_bad;
|
|
|
|
|
|
|
2006-02-25 12:10:53 +00:00
|
|
|
|
/*********************************************
|
|
|
|
|
|
* Test iso9660_strncpy_pad
|
|
|
|
|
|
*********************************************/
|
|
|
|
|
|
|
2003-09-01 15:08:15 +00:00
|
|
|
|
dst_p = iso9660_strncpy_pad(dst, "1_3", 5, ISO9660_DCHARS);
|
|
|
|
|
|
if ( 0 != strncmp(dst, "1_3 ", 5) ) {
|
2006-02-25 11:58:22 +00:00
|
|
|
|
printf("Failed iso9660_strncpy_pad DCHARS\n");
|
2006-02-25 12:02:02 +00:00
|
|
|
|
return 31;
|
2003-09-01 15:08:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
dst_p = iso9660_strncpy_pad(dst, "ABC!123", 2, ISO9660_ACHARS);
|
|
|
|
|
|
if ( 0 != strncmp(dst, "AB", 2) ) {
|
2006-02-25 11:58:22 +00:00
|
|
|
|
printf("Failed iso9660_strncpy_pad ACHARS truncation\n");
|
2006-02-25 12:02:02 +00:00
|
|
|
|
return 32;
|
2003-09-01 15:08:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2006-02-25 12:10:53 +00:00
|
|
|
|
/*********************************************
|
|
|
|
|
|
* Test iso9660_dirname_valid_p
|
|
|
|
|
|
*********************************************/
|
|
|
|
|
|
|
2003-09-01 15:08:15 +00:00
|
|
|
|
if ( iso9660_dirname_valid_p("/NOGOOD") ) {
|
|
|
|
|
|
printf("/NOGOOD should fail iso9660_dirname_valid_p\n");
|
2006-02-25 12:02:02 +00:00
|
|
|
|
return 33;
|
2003-09-01 15:08:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
if ( iso9660_dirname_valid_p("LONGDIRECTORY/NOGOOD") ) {
|
|
|
|
|
|
printf("LONGDIRECTORY/NOGOOD should fail iso9660_dirname_valid_p\n");
|
2006-02-25 12:02:02 +00:00
|
|
|
|
return 34;
|
2003-09-01 15:08:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
if ( !iso9660_dirname_valid_p("OKAY/DIR") ) {
|
|
|
|
|
|
printf("OKAY/DIR should pass iso9660_dirname_valid_p\n");
|
2006-02-25 12:02:02 +00:00
|
|
|
|
return 35;
|
2003-09-01 15:08:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
if ( iso9660_dirname_valid_p("OKAY/FILE.EXT") ) {
|
|
|
|
|
|
printf("OKAY/FILENAME.EXT should fail iso9660_dirname_valid_p\n");
|
2006-02-25 12:02:02 +00:00
|
|
|
|
return 36;
|
2003-09-01 15:08:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2006-02-25 12:10:53 +00:00
|
|
|
|
/*********************************************
|
|
|
|
|
|
* Test iso9660_pathname_valid_p
|
|
|
|
|
|
*********************************************/
|
|
|
|
|
|
|
2003-09-01 15:08:15 +00:00
|
|
|
|
if ( !iso9660_pathname_valid_p("OKAY/FILE.EXT") ) {
|
|
|
|
|
|
printf("OKAY/FILE.EXT should pass iso9660_dirname_valid_p\n");
|
2006-02-25 12:02:02 +00:00
|
|
|
|
return 37;
|
2003-09-01 15:08:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
if ( iso9660_pathname_valid_p("OKAY/FILENAMETOOLONG.EXT") ) {
|
|
|
|
|
|
printf("OKAY/FILENAMETOOLONG.EXT should fail iso9660_dirname_valid_p\n");
|
2006-02-25 12:02:02 +00:00
|
|
|
|
return 38;
|
2003-09-01 15:08:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
if ( iso9660_pathname_valid_p("OKAY/FILE.LONGEXT") ) {
|
|
|
|
|
|
printf("OKAY/FILE.LONGEXT should fail iso9660_dirname_valid_p\n");
|
2006-02-25 12:02:02 +00:00
|
|
|
|
return 39;
|
2003-09-01 15:08:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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");
|
2004-10-26 01:21:05 +00:00
|
|
|
|
free(dst_p);
|
2006-02-25 12:02:02 +00:00
|
|
|
|
return 40;
|
2003-09-01 15:08:15 +00:00
|
|
|
|
}
|
2004-10-26 01:21:05 +00:00
|
|
|
|
free(dst_p);
|
2003-09-01 15:08:15 +00:00
|
|
|
|
|
2006-02-25 12:10:53 +00:00
|
|
|
|
/*********************************************
|
|
|
|
|
|
* Test get/set date
|
|
|
|
|
|
*********************************************/
|
|
|
|
|
|
|
2003-09-21 01:14:30 +00:00
|
|
|
|
{
|
|
|
|
|
|
struct tm *p_tm, tm;
|
|
|
|
|
|
iso9660_dtime_t dtime;
|
2006-03-17 01:05:54 +00:00
|
|
|
|
iso9660_ltime_t ltime;
|
2003-09-21 01:14:30 +00:00
|
|
|
|
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 ) {
|
2005-03-03 10:33:26 +00:00
|
|
|
|
printf("Local time retrieved with iso9660_get_dtime not same as\n");
|
|
|
|
|
|
printf("that set with iso9660_set_dtime().\n");
|
2006-02-25 12:02:02 +00:00
|
|
|
|
return 41;
|
2003-09-21 01:14:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
p_tm = gmtime(&now);
|
|
|
|
|
|
iso9660_set_dtime(p_tm, &dtime);
|
|
|
|
|
|
iso9660_get_dtime(&dtime, false, &tm);
|
|
|
|
|
|
if ( memcmp(p_tm, &tm, sizeof(tm)) != 0 ) {
|
2005-03-03 10:33:26 +00:00
|
|
|
|
printf("GMT time retrieved with iso9660_get_dtime() not same as that\n");
|
|
|
|
|
|
printf("set with iso9660_set_dtime().\n");
|
2006-02-25 12:02:02 +00:00
|
|
|
|
return 42;
|
2003-09-21 01:14:30 +00:00
|
|
|
|
}
|
2006-03-17 16:31:38 +00:00
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
time_t t1, t2;
|
2006-03-18 03:19:16 +00:00
|
|
|
|
#if FIXED
|
2006-03-17 16:31:38 +00:00
|
|
|
|
p_tm = localtime(&now);
|
|
|
|
|
|
t1 = mktime(p_tm);
|
|
|
|
|
|
iso9660_set_ltime(p_tm, <ime);
|
|
|
|
|
|
iso9660_get_ltime(<ime, &tm);
|
|
|
|
|
|
t2 = mktime(&tm);
|
2006-03-17 16:41:04 +00:00
|
|
|
|
if ( t1 != t2 && ! time_compare(p_tm, &tm) ) {
|
2006-03-17 16:31:38 +00:00
|
|
|
|
printf("local time retrieved with iso9660_get_ltime() not\n");
|
|
|
|
|
|
printf("same as that set with iso9660_set_ltime().\n");
|
|
|
|
|
|
return 43;
|
|
|
|
|
|
}
|
2006-03-18 03:19:16 +00:00
|
|
|
|
#endif
|
2006-03-17 01:05:54 +00:00
|
|
|
|
|
2006-03-17 16:31:38 +00:00
|
|
|
|
p_tm = gmtime(&now);
|
|
|
|
|
|
t1 = mktime(p_tm);
|
|
|
|
|
|
iso9660_set_ltime(p_tm, <ime);
|
|
|
|
|
|
iso9660_get_ltime(<ime, &tm);
|
|
|
|
|
|
t2 = mktime(&tm);
|
2006-03-17 16:41:04 +00:00
|
|
|
|
if ( t1 != t2 && ! time_compare(p_tm, &tm) ) {
|
2006-03-17 16:31:38 +00:00
|
|
|
|
printf("GMT time retrieved with iso9660_get_ltime() not\n");
|
|
|
|
|
|
printf("same as that set with iso9660_set_ltime().\n");
|
|
|
|
|
|
return 44;
|
|
|
|
|
|
}
|
2006-03-17 01:05:54 +00:00
|
|
|
|
}
|
2003-09-21 01:14:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2003-09-01 15:08:15 +00:00
|
|
|
|
return 0;
|
|
|
|
|
|
}
|