shlist

share and manage lists between multiple people
Log | Files | Refs

header.t (1179B)


      1 use strict;
      2 use Test;
      3 use SL::Test;
      4 
      5 BEGIN { plan tests => 6 }
      6 
      7 # Need a new connection every time because server disconnects on header errors.
      8 my $s = SL::Test::Server->new();
      9 
     10 # Invalid message number
     11 my $client = SL::Test::Client->new(1);
     12 $client->send_all(pack('nnn', 0, 47837, 0), 6);
     13 ok($s->readline(), '/error: unknown message type 47837/');
     14 
     15 # Bad protocol version
     16 $client = SL::Test::Client->new(1);
     17 $client->send_all(pack('nnn', 101, 0, 0), 6);
     18 ok($s->readline(), '/error: unsupported protocol version 101/');
     19 
     20 # Payload length that's too long
     21 $client = SL::Test::Client->new(1);
     22 $client->send_all(pack('nnn', 0, 0, 25143), 6);
     23 ok($s->readline(), '/error: 25143 byte payload invalid/');
     24 
     25 # Advertised payload length longer than actual data length
     26 $client = SL::Test::Client->new(1);
     27 $client->send_all(pack('nnnZ*', 0, 0, 5, 'ab'), 9);
     28 
     29 # Truncated header
     30 $client = SL::Test::Client->new(1);
     31 $client->send_all(pack('nn', 101, 69), 4);
     32 ok($s->readline(), '/disconnected!/');
     33 
     34 # Zero bytes payload
     35 $client = SL::Test::Client->new(1);
     36 $client->send_all(pack('nnn', 0, 0, 0), 6);
     37 ok($s->readline(), '/disconnected!/');
     38 ok($s->readline(), '/error: 0 byte payload invalid/');