1 ################################################################################
5 # $Date: 2008/11/28 18:08:11 +0100 $
7 ################################################################################
9 # Version 2.x, Copyright (C) 2007, Marcus Holland-Moritz <mhx@cpan.org>.
10 # Version 1.x, Copyright (C) 1999, Graham Barr <gbarr@pobox.com>.
12 # This program is free software; you can redistribute it and/or
13 # modify it under the same terms as Perl itself.
15 ################################################################################
18 if ($ENV{'PERL_CORE'}) {
20 @INC = '../lib' if -d '../lib' && -d '../ext';
23 require Test::More; import Test::More;
24 require Config; import Config;
26 if ($ENV{'PERL_CORE'} && $Config{'extensions'} !~ m[\bIPC/SysV\b]) {
27 plan(skip_all => 'IPC::SysV was not built');
31 if ($Config{'d_sem'} ne 'define') {
32 plan(skip_all => '$Config{d_sem} undefined');
33 } elsif ($Config{'d_msg'} ne 'define') {
34 plan(skip_all => '$Config{d_msg} undefined');
37 use IPC::SysV qw(IPC_PRIVATE IPC_RMID IPC_NOWAIT IPC_STAT S_IRWXU S_IRWXG S_IRWXO);
41 #Creating a message queue
45 if (exists $SIG{SYS}) {
46 local $SIG{SYS} = sub { plan(skip_all => "SIGSYS caught") };
50 }->(sub { new IPC::Msg(IPC_PRIVATE, S_IRWXU | S_IRWXG | S_IRWXO) });
52 unless (defined $msq) {
53 my $info = "IPC::Msg->new failed: $!";
54 if ($! == &IPC::SysV::ENOSPC || $! == &IPC::SysV::ENOSYS ||
55 $! == &IPC::SysV::ENOMEM || $! == &IPC::SysV::EACCES) {
56 plan(skip_all => $info);
65 pass('create message queue');
67 #Putting a message on the queue
68 my $test_name = 'enqueue message';
72 if ($msq->snd($msgtype,$msg,IPC_NOWAIT)) {
80 #Check if there are messages on the queue
85 is($ds->qnum, 1, 'qnum');
91 #Retrieving a message from the queue
93 my $rmsgtype = 0; # Give me any type
94 $rmsgtype = $msq->rcv($rmsg,256,$rmsgtype,IPC_NOWAIT);
95 is($rmsgtype, $msgtype, 'rmsgtype');
96 is($rmsg, $msg, 'rmsg');
102 is($ds->qnum, 0, 'qnum');
109 ok($msq->remove, 'remove message') if defined $msq;