| 1 | # Before `make install' is performed this script should be runnable with |
| 2 | # `make test'. After `make install' it should work as `perl 1.t' |
| 3 | |
| 4 | ######################### |
| 5 | |
| 6 | # change 'tests => 1' to 'tests => last_test_to_print'; |
| 7 | |
| 8 | use Test::More; |
| 9 | BEGIN { plan tests => 24 }; |
| 10 | use Socket; |
| 11 | use Socket::MsgHdr; |
| 12 | ok(1); # If we made it this far, we are ok. |
| 13 | |
| 14 | for my $g (*recvmsg, *sendmsg) { |
| 15 | ok(defined *{$g}{CODE}, "basic exports"); |
| 16 | } |
| 17 | |
| 18 | for my $m (qw|recvmsg sendmsg|) { |
| 19 | ok(IO::Socket->can($m), "IO::Socket->can($m)"); |
| 20 | } |
| 21 | |
| 22 | for my $m (qw|new name namelen buf buflen control controllen flags cmsghdr|) { |
| 23 | ok(Socket::MsgHdr->can($m), "Socket::MsgHdr->can($m)"); |
| 24 | } |
| 25 | |
| 26 | # len/int accessors |
| 27 | for $m (qw|namelen buflen controllen flags|) { |
| 28 | my $val = int(rand(1024)+1); |
| 29 | my $hdr = new Socket::MsgHdr ($m => $val); |
| 30 | ok($val == $hdr->$m(), "$m method/ctor ok"); |
| 31 | } |
| 32 | |
| 33 | # other accessors |
| 34 | for $m (qw|name buf control|) { |
| 35 | my $val = "foo" x int(rand(256)+1); |
| 36 | my $hdr = new Socket::MsgHdr ($m => $val); |
| 37 | my $mlen = $m. "len"; |
| 38 | ok($val eq $hdr->$m() && length($hdr->$m)==$hdr->$mlen, "$m method/ctor ok"); |
| 39 | } |
| 40 | |
| 41 | my $hdr = Socket::MsgHdr->new(); |
| 42 | ok(!$hdr->controllen && !length($hdr->control), |
| 43 | "empty initial cmsghdr sets control"); |
| 44 | my @l = (5, 10, "fifteen", 20, 25, "thirty"); |
| 45 | $hdr->cmsghdr(@l); |
| 46 | ok($hdr->controllen && (length($hdr->control) == $hdr->controllen), |
| 47 | "cmsghdr sets control"); |
| 48 | ok(eq_array(\@l, [$hdr->cmsghdr]), "cmsghdr fetches properly"); |
| 49 | |
| 50 | |
| 51 | ######################### |
| 52 | |
| 53 | # Insert your test code below, the Test::More module is use()ed here so read |
| 54 | # its man page ( perldoc Test::More ) for help writing this test script. |
| 55 |