File: 9old_test.t

package info (click to toggle)
libuuid-perl 0.37-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,092 kB
  • sloc: ansic: 2,374; perl: 580; makefile: 5
file content (114 lines) | stat: -rw-r--r-- 2,565 bytes parent folder | download
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
use warnings;
use Test::More tests => 40;
use UUID 'uuid';


UUID::generate( $bin );
is length $bin, 16;

UUID::generate_random( $bin );
is length $bin, 16;

UUID::generate_time( $bin );
is length $bin, 16;

UUID::unparse( $bin, $str );
is length $str, 36;
like $str, qr{^[-0-9a-f]+$}i;

$rc = UUID::parse( $str, $bin2 );
is $rc, 0;
is $bin, $bin2;

UUID::unparse_lower( $bin, $str1 );
UUID::unparse_upper( $bin, $str2 );
is length( $str1 ), 36;
is length( $str2 ), 36;
like $str1, qr/^[-a-f0-9]+$/;
like $str2, qr/^[-A-F0-9]+$/;
is lc( $str1 ), lc( $str2 );
ok $str1 ne $str2;

# content of uuid is unchanged if parse fails
UUID::generate( $bin );
$bin2 = $bin;
$str = 'Peter is a moose';
$rc = UUID::parse( $str, $bin );
is $rc, -1;
is $bin, $bin2;

UUID::generate( $bin );
$rc = UUID::is_null( $bin );
is $rc, 0;

UUID::clear( $bin );
is length( $bin ), 16;
is UUID::is_null( $bin ), 1;

# does copy work?
UUID::clear( $bin1 );
is UUID::is_null( $bin1 ), 1;
UUID::copy( $bin2, $bin1 );
is UUID::is_null( $bin2 ), 1;

$bin = 'bogus value';
is UUID::is_null( $bin ), 0; # != the null uuid, right?

$bin = '1234567890123456';
is UUID::is_null( $bin ), 0; # still not null

# make sure compare operands sane
UUID::generate( $bin1 );
$bin2 = 'x';
is abs(UUID::compare( $bin1, $bin2 )), 1;
is abs(UUID::compare( $bin2, $bin1 )), 1;
$bin2 = 'some silly ridiculously long string that couldnt possibly be a uuid';
is abs(UUID::compare( $bin1, $bin2 )), 1;
is abs(UUID::compare( $bin2, $bin1 )), 1;

# sane compare
$uuid=1;
UUID::generate( $uuid ); # this is wrong. dont want to fix it though.
ok 1;
$bin2 = '1234567890123456';
ok 1;
$tmp1 = UUID::compare( $bin1, $bin2 );
ok 1;
$tmp2 = UUID::compare( $bin2, $bin1 );
ok 1;
$tmp2 = -UUID::compare( $bin2, $bin1 );
is $tmp1, $tmp2;
is UUID::compare( $bin1, $bin2 ), -UUID::compare( $bin2, $bin1 );
$bin2 = $bin1;
is UUID::compare( $bin1, $bin2 ), 0;

# make sure we get back a null if src isnt sane
$bin1 = 'x';
UUID::copy( $bin2, $bin1 );
ok UUID::is_null( $bin2 );
$bin1 = 'another really really really long sting';
UUID::copy( $bin2, $bin1 );
ok UUID::is_null( $bin2 );

# sane copy
UUID::generate( $bin1 );
$bin2 = '1234567890123456';
UUID::copy( $bin2, $bin1 );
is UUID::compare( $bin1, $bin2 ), 0;

# make sure we get back the same scalar we passed in
$bin1 = '1234567890123456';
UUID::generate( $bin2 );
$save1 = \$bin2;
UUID::copy( $bin2, $bin1 );
$save2 = \$bin2;
is $save1, $save2;
is $$save1, $$save2;

$rc = uuid(); # make sure export works
is length($rc), 36;

$rc = UUID::uuid();
is length($rc), 36;

exit 0;