Bug 14778: Make Barcodes_ValueBuilder.t db dependent
[koha.git] / t / SIP_Sip.t
1 #!/usr/bin/perl
2
3 # This file is part of Koha.
4 #
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18 use Modern::Perl;
19
20 use Test::More tests => 9;
21 use Test::Warn;
22
23 BEGIN {
24         use_ok('C4::SIP::Sip');
25 }
26
27 my $date_time = C4::SIP::Sip::timestamp();
28 like( $date_time, qr/^\d{8}    \d{6}$/, 'Timestamp format no param');
29
30 my $t = time();
31
32 $date_time = C4::SIP::Sip::timestamp($t);
33 like( $date_time, qr/^\d{8}    \d{6}$/, 'Timestamp format secs');
34
35 $date_time = C4::SIP::Sip::timestamp('2011-01-12');
36 ok( $date_time eq '20110112    235900', 'Timestamp iso date string');
37
38 my $myChecksum = C4::SIP::Sip::Checksum::checksum("12345");
39 my $checker = 65281;
40 my $stringChecksum = C4::SIP::Sip::Checksum::checksum("teststring");
41 my $stringChecker = 64425;
42
43 is( $myChecksum, $checker, "Checksum: $myChecksum matches expected output");
44 is( $stringChecksum, $stringChecker, "Checksum: $stringChecksum matches expected output");
45
46 my $testdata = "abcdAZ";
47 my $something = C4::SIP::Sip::Checksum::checksum($testdata);
48
49 $something =  sprintf("%4X", $something);
50 ok( C4::SIP::Sip::Checksum::verify_cksum($testdata.$something), "Checksum: $something is valid.");
51
52 my $invalidTest;
53 warning_is { $invalidTest = C4::SIP::Sip::Checksum::verify_cksum("1234567") }
54             'verify_cksum: no sum detected',
55             'verify_cksum prints the expected warning for an invalid checksum';
56 is($invalidTest, 0, "Checksum: 1234567 is invalid as expected");
57
58 1;