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
|
#!perl -T
use strict;
use warnings;
use Test::More;
use Carp;
use UUID::Tiny qw(:std);
if ($^O eq 'MSWin32') {
plan skip_all => 'Pipe-open not supported on MSWin32';
}
else {
plan tests => 6
}
my %uuid;
my $first_time_uuid = create_uuid_as_string(UUID_TIME);
my $first_rand_uuid = create_uuid_as_string(UUID_RANDOM);
use IO::Handle;
if (my $pid = open my $child, "-|") {
my $child_data;
# Check uniqueness of time based UUIDs ...
chomp($child_data = <$child>);
my $time_uuid = create_uuid_as_string(UUID_TIME);
ok(
!equal_uuids($first_time_uuid, $time_uuid),
'First time based UUID differs from parent one.'
);
ok(
!equal_uuids($child_data, $time_uuid),
'Time based UUIDs of parent and child differ.'
);
# Check integrity of parent clock sequence ...
ok(
(
time_of_uuid($first_time_uuid) < time_of_uuid($time_uuid)
&& clk_seq_of_uuid($first_time_uuid)
== clk_seq_of_uuid($time_uuid)
) || (
clk_seq_of_uuid($first_time_uuid)
!= clk_seq_of_uuid($time_uuid)
),
'Integrity of parent clock sequence OK.'
);
# Check uniqueness of clock sequence ...
isnt(
clk_seq_of_uuid($child_data),
clk_seq_of_uuid($time_uuid),
'Clock sequence of child differs.'
);
# Check uniqueness of random UUIDs ...
chomp($child_data = <$child>);
my $random_uuid = create_uuid_as_string(UUID_RANDOM);
isnt( $first_rand_uuid, $random_uuid, 'Parent random UUIDs differ.' );
isnt( $child_data, $random_uuid, 'Child and parent random UUIDs differ.' );
close $child;
}
else {
croak "Error on fork(): $!" unless defined $pid;
STDOUT->autoflush(1);
# Generate time based UUID for comparison ...
print STDOUT create_uuid_as_string(UUID_TIME), "\n";
# Generate random UUID for comparison ...
print STDOUT create_uuid_as_string(UUID_RANDOM), "\n";
exit;
}
|