File: | t/SIP_Sip.t |
Coverage: | 100.0% |
line | stmt | bran | cond | sub | time | code |
---|---|---|---|---|---|---|
1 | #!/usr/bin/perl | |||||
2 | # | |||||
3 | # This Koha test module is a stub! | |||||
4 | # Add more tests here!!! | |||||
5 | ||||||
6 | 1 1 1 | 1.33283540373153e+15 52 80 | use strict; | |||
7 | 1 1 1 | 41 34 72 | use warnings; | |||
8 | ||||||
9 | 1 1 1 | 316 19742 83 | use Test::More tests => 8; | |||
10 | ||||||
11 | BEGIN { | |||||
12 | 1 1 1 | 2404 1073 108 | use FindBin; | |||
13 | 1 1 1 | 230 1037 32 | use lib "$FindBin::Bin/../C4/SIP"; | |||
14 | 1 | 160 | use_ok('C4::SIP::Sip'); | |||
15 | } | |||||
16 | ||||||
17 | 1 | 247754 | my $date_time = Sip::timestamp(); | |||
18 | 1 | 48 | like( $date_time, qr/^\d{8} \d{6}$/, 'Timestamp format no param'); | |||
19 | ||||||
20 | 1 | 614 | my $t = time(); | |||
21 | ||||||
22 | 1 | 7 | $date_time = Sip::timestamp($t); | |||
23 | 1 | 9 | like( $date_time, qr/^\d{8} \d{6}$/, 'Timestamp format secs'); | |||
24 | ||||||
25 | 1 | 404 | $date_time = Sip::timestamp('2011-01-12'); | |||
26 | 1 | 8 | ok( $date_time eq '20110112 235900', 'Timestamp iso date string'); | |||
27 | ||||||
28 | 1 | 432 | my $myChecksum = Sip::Checksum::checksum("12345"); | |||
29 | 1 | 1 | my $checker = 65281; | |||
30 | 1 | 6 | my $stringChecksum = Sip::Checksum::checksum("teststring"); | |||
31 | 1 | 1 | my $stringChecker = 64425; | |||
32 | ||||||
33 | 1 | 9 | is( $myChecksum, $checker, "Checksum: $myChecksum matches expected output"); | |||
34 | 1 | 1090 | is( $stringChecksum, $stringChecker, "Checksum: $stringChecksum matches expected output"); | |||
35 | ||||||
36 | 1 | 477 | my $testdata = "abcdAZ"; | |||
37 | 1 | 6 | my $something = Sip::Checksum::checksum($testdata); | |||
38 | ||||||
39 | 1 | 4 | $something = sprintf("%4X", $something); | |||
40 | 1 | 7 | ok( Sip::Checksum::verify_cksum($testdata.$something), "Checksum: $something is valid."); | |||
41 | ||||||
42 | 1 | 413 | my $invalidTest = Sip::Checksum::verify_cksum("1234567"); | |||
43 | 1 | 7 | is($invalidTest, 0, "Checksum: 1234567 is invalid as expected"); |