From 7876d4fa8dcc67ec54448edb7c4cd9d454dcf52a Mon Sep 17 00:00:00 2001 From: Duncan Tyler Date: Thu, 8 Dec 2011 14:38:28 +1300 Subject: [PATCH] Added unit tests for Sip Checksum.pm http://bugs.koha-community.org/show_bug.cgi?id=5327 Signed-off-by: Katrin Fischer Test passes. Signed-off-by: Paul Poulain --- t/SIP_Sip.t | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/t/SIP_Sip.t b/t/SIP_Sip.t index 879c9835d4..d837609b34 100755 --- a/t/SIP_Sip.t +++ b/t/SIP_Sip.t @@ -6,7 +6,7 @@ use strict; use warnings; -use Test::More tests => 4; +use Test::More tests => 8; BEGIN { use FindBin; @@ -25,3 +25,19 @@ like( $date_time, qr/^\d{8} \d{6}$/, 'Timestamp format secs'); $date_time = Sip::timestamp('2011-01-12'); ok( $date_time eq '20110112 235900', 'Timestamp iso date string'); +my $myChecksum = Sip::Checksum::checksum("12345"); +my $checker = 65281; +my $stringChecksum = Sip::Checksum::checksum("teststring"); +my $stringChecker = 64425; + +is( $myChecksum, $checker, "Checksum: $myChecksum matches expected output"); +is( $stringChecksum, $stringChecker, "Checksum: $stringChecksum matches expected output"); + +my $testdata = "abcdAZ"; +my $something = Sip::Checksum::checksum($testdata); + +$something = sprintf("%4X", $something); +ok( Sip::Checksum::verify_cksum($testdata.$something), "Checksum: $something is valid."); + +my $invalidTest = Sip::Checksum::verify_cksum("1234567"); +is($invalidTest, 0, "Checksum: 1234567 is invalid as expected"); -- 2.39.5