File: 07.iso.t

package info (click to toggle)
libdevice-cdio-perl 0.3.0-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 3,248 kB
  • ctags: 2,564
  • sloc: ansic: 11,536; perl: 4,027; makefile: 69; sh: 3
file content (181 lines) | stat: -rwxr-xr-x 4,938 bytes parent folder | download | duplicates (5)
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
#!/usr/bin/env perl
# Test some low-level ISO9660 routines
# This is basically the same thing as libcdio's testiso9660.c

use strict;
use warnings;
use Config;
use lib '../lib';
use blib;

use perliso9660;
use Test::More tests => 15;
note 'Test low-level ISO9660 routines';

sub is_eq($$) {
    my ($a_ref, $b_ref) = @_;
    return 0 if @$a_ref != @$b_ref;
    for (my $i=0; $i<@$a_ref; $i++) {
	if ($a_ref->[$i] != $b_ref->[$i]) {
	    printf "position %d: %d != %d\n", $i, $a_ref->[$i], $b_ref->[$i];
	    return 0 ;
	}
    }
    return 1;
}

###################################
# Test ACHAR and DCHAR
###################################

my @achars = ('!', '"', '%', '&', '(', ')', '*', '+', ',', '-', '.',
	   '/', '?', '<', '=', '>');

my $bad = 0;
for (my $c=ord('A'); $c<=ord('Z'); $c++ ) {
    if (!perliso9660::is_dchar($c)) {
	printf "Failed iso9660_is_achar test on %c\n", $c;
	$bad++;
    }
    if (!perliso9660::is_achar($c)) {
	printf "Failed iso9660_is_achar test on %c\n", $c;
	$bad++;
    }
}

ok($bad==0, 'is_dchar & is_achar A..Z');

$bad=0;
for (my $c=ord('0'); $c<=ord('9'); $c++ ) {
    if (!perliso9660::is_dchar($c)) {
	printf "Failed iso9660_is_dchar test on %c\n", $c;
	$bad++;
    }
    if (!perliso9660::is_achar($c)) {
	printf "Failed iso9660_is_achar test on %c\n", $c;
	$bad++;
    }
}

ok($bad==0, 'is_dchar & is_achar 0..9');

$bad=0;
for (my $i=0; $i<=13; $i++ ) {
    my $c=ord($achars[$i]);
    if (perliso9660::is_dchar($c)) {
	printf "Should not pass is_dchar test on %c\n", $c;
	$bad++;
    }
    if (!perliso9660::is_achar($c)) {
	printf "Failed is_achar test on symbol %c\n", $c;
	$bad++;
    }
}

ok($bad==0, 'is_dchar & is_achar symbols');

my $dst;
#####################################
# Test perliso9660::strncpy_pad
#####################################

SKIP: 
{
    # skip("strncpy_pad broken too often. Volunteers for fixing?.", 2);
	# if 'cygwin' eq $Config{osname};

    $dst = perliso9660::strncpy_pad("1_3", 5, $perliso9660::DCHARS);
    ok($dst eq "1_3  ", "strncpy_pad DCHARS");
    
    $dst = perliso9660::strncpy_pad("ABC!123", 2, $perliso9660::ACHARS);
    ok($dst eq "AB", "strncpy_pad ACHARS truncation");
}

#####################################
# Test perliso9660::dirname_valid_p 
#####################################

$bad=0;
if ( perliso9660::dirname_valid_p("/NOGOOD") ) {
    printf("/NOGOOD should fail perliso9660::dirname_valid_p\n");
    $bad++;
}
ok($bad==0, 'perliso9660::dirname_valid_p - invalid name - bad symbol');

$bad=0;
if ( perliso9660::dirname_valid_p("LONGDIRECTORY/NOGOOD") ) {
    printf("LONGDIRECTORY/NOGOOD should fail perliso9660::dirname_valid_p\n");
    $bad++;
}
ok($bad==0, 'perliso9660::dirname_valid_p - invalid long name');

$bad=0;
if ( !perliso9660::dirname_valid_p("OKAY/DIR") ) {
    printf("OKAY/DIR should pass perliso9660::dirname_valid_p\n");
    $bad++;
}
ok($bad==0, 'perliso9660::dirname_valid_p - valid with directory');

$bad=0;
if ( perliso9660::dirname_valid_p("OKAY/FILE.EXT") ) {
    printf("OKAY/FILENAME.EXT should fail perliso9660::dirname_valid_p\n");
    $bad++;
}
ok($bad==0, 'perliso9660::dirname_valid_p - invalid with .EXT');

#####################################
# Test perliso9660::pathname_valid_p
#####################################

$bad=0;
if ( !perliso9660::pathname_valid_p("OKAY/FILE.EXT") ) {
    printf("OKAY/FILE.EXT should pass perliso9660::dirname_valid_p\n");
    $bad++;
}
ok($bad==0, 'perliso9660::pathname_valid_p - valid');

$bad=0;
if ( perliso9660::pathname_valid_p("OKAY/FILENAMETOOLONG.EXT") ) {
    printf("OKAY/FILENAMETOOLONG.EXT should fail perliso9660::dirname_valid_p\n");
    $bad++;
}
ok($bad==0, 'perliso9660::pathname_valid_p - invalid, long basename');

$bad=0;
if ( perliso9660::pathname_valid_p("OKAY/FILE.LONGEXT") ) {
    printf("OKAY/FILE.LONGEXT should fail perliso9660::dirname_valid_p\n");
    $bad++;
}
ok($bad==0, 'perliso9660::pathname_valid_p - invalid, long extension');

$bad=0;
$dst = perliso9660::pathname_isofy("this/file.ext", 1);
if ($dst ne "this/file.ext;1") {
    printf("Failed iso9660_pathname_isofy\n");
    $bad++;
}
ok($bad==0, 'perliso9660::pathname_isofy');

my @tm = localtime(0);
my $dtime = perliso9660::set_dtime($tm[0], $tm[1], $tm[2], $tm[3], $tm[4],
				   $tm[5]);
my ($bool, @new_tm) = perliso9660::get_dtime($dtime, 0);

ok(is_eq(\@new_tm, \@tm), 'get_dtime(set_dtime())');

# @tm = gmtime(0);
# my $ltime = perliso9660::set_ltime($tm[0], $tm[1], $tm[2], $tm[3], $tm[4],
# 				   $tm[5]);
# ($bool, @new_tm) =  perliso9660::get_ltime($ltime);
# ok(is_eq(\@new_tm, \@tm), 'get_ltime(set_ltime())');

@tm = gmtime();
my $ltime = perliso9660::set_ltime($tm[0], $tm[1], $tm[2], $tm[3], $tm[4],
				   $tm[5]);
($bool, @new_tm) =  perliso9660::get_ltime($ltime);
if($new_tm[8] =! $tm[8]) { #isdst flag
    diag(' isdst flags differ '. $new_tm[8]. ' '.$tm[8]);
    $new_tm[8] = $tm[8];
}
ok(is_eq(\@new_tm, \@tm), 'get_ltime(set_ltime())');