# Before 'make install' is performed this script should be runnable with # 'make test'. After 'make install' it should work as 'perl Net-SNTP-Client.t' ######################### # change 'tests => 1' to 'tests => last_test_to_print'; use strict; use warnings; use lib '/home/username/Desktop/Net-SNTP-Client-0.01/lib/'; # note here use Test::More tests => 15; use Test::Deep; my %hashInputModuleHostnameTest = ( -hostname => undef ); my %hashInputModuleTest = ( -hostname => "0.pool.ntp.org", -port => 123 ); my %hashInputModuleTestExtraKeysInserted = ( -hostname => "0.pool.ntp.org", -port => 123, -RFC4330 => 1, -clearScreen => 1, -extraKey => "Test" ); my %hashInputModuleTestNoHostName = ( -port => 123, -RFC4330 => 1, -clearScreen => 1 ); my %hashInputModuleTestNegativePortNumber = ( -hostname => "0.pool.ntp.org", -port => -123, -RFC4330 => 1, -clearScreen => 1 ); my %hashInputModuleTestOutOfRangePortNumber = ( -hostname => "0.pool.ntp.org", -port => 65536, -RFC4330 => 1, -clearScreen => 1 ); my %hashInputModuleTestNotCorrectNtpPortNumber = ( -hostname => "0.pool.ntp.org", -port => 12345, -RFC4330 => 1, -clearScreen => 1 ); my @hashInputModuleTestOriginalKeys = ( "-hostname" , "-port", "-RFC4330", "-clearScreen" ); my $hashRefExpected = { 'Net-SNTP-Client.t' => { 'VN' => 4, 'Originate Timestamp' => '00', 'Root Delay' => '0', 'Stratum' => '0', 'Receive Timestamp' => ignore(), 'Transmit Timestamp' => ignore(), 'Reference Timestamp' => '00', 'Precision' => '0', 'LI' => 0, 'Root Dispersion' => '0', 'Poll' => '0', 'Reference Identifier' => '0', 'Mode' => 3 }, 'RFC4330' => { 'Round Trip Delay' => ignore(), 'Clock Offset' => ignore() }, '0.pool.ntp.org' => { 'LI' => ignore(), 'Transmit Timestamp' => ignore(), 'Receive Timestamp' => ignore(), 'Reference Timestamp' => ignore(), 'Precision' => ignore(), 'Root Delay' => ignore(), 'Stratum' => ignore(), 'VN' => 4, 'Originate Timestamp' => ignore(), 'Mode' => 4, 'Poll' => ignore(), 'Reference Identifier' => ignore(), 'Root Dispersion' => ignore() } }; BEGIN { use_ok('Net::SNTP::Client', qw(getSNTPTime) ) }; ok( getSNTPTime( %hashInputModuleTest ), 'Module Hash Input Works' ); ok( !defined( $hashInputModuleHostnameTest{-hostname} ), 'Hostname Must be Defined' ); ok( defined( $hashInputModuleTest{-port} ) && $hashInputModuleTest{-port} =~ /\A (\d+) \z/xms , 'Port Has to be Defined and Integer' ); ok( my ( $error , $hashRefOutput ) = getSNTPTime( %hashInputModuleTest ), 'Got Hash Output' ); my @expectedHashKeys = ( 'Net-SNTP-Client.t', 'RFC4330', '0.pool.ntp.org' ); my @gotHashRefKeys = keys $hashRefOutput; ok( eq_set(\@gotHashRefKeys, \@expectedHashKeys), 'Module Hash Keys are Identical' ); #is_deeply( [sort @gotHashRefKeys], [sort @expectedHashKeys], 'Module Hash Keys are Identical' ); cmp_deeply( $hashRefOutput, $hashRefExpected, 'Exptected Output From the Module Received' ); ok( my ( $errorForExtraHashKey , $hashRefOutputForExtraHashKey ) = getSNTPTime( %hashInputModuleTestExtraKeysInserted ), 'Faulty Test Extra Key' ); ok( $errorForExtraHashKey eq 'Not defined key(s)', 'Correct Output Error Extra Hash Key' ); ok( my ( $errorNoHostname , $hashRefOutputNoHostName ) = getSNTPTime( %hashInputModuleTestNoHostName ), 'Faulty Test no Hostname' ); ok( $errorNoHostname eq 'Not defined Hostname', 'Correct Output Error No Hostname' ); ok( my ( $errorNegativePortNumber , $hashRefOutputNegativePortNumber ) = getSNTPTime( %hashInputModuleTestNegativePortNumber ), 'Faulty Test Negative Port Number' ); ok( $errorNegativePortNumber eq 'Not correct port number', 'Correct Output Error for Negative Port Number' ); ok( my ( $errorOutOfRangePortNumber , $hashRefOutputOutOfRangePortNumber ) = getSNTPTime( %hashInputModuleTestOutOfRangePortNumber ), 'Faulty Test Out of Range Port Number' ); ok( $errorOutOfRangePortNumber eq 'Not correct port number', 'Correct Output Error Out of Range Port Number' ); use Data::Dumper; #print Dumper $hashRefOutputNegativePortNumber; #print "Error: " . $errorNegativePortNumber . "\n"; ######################### # Insert your test code below, the Test::More module is use()ed here so read # its man page ( perldoc Test::More ) for help writing this test script.