Re: [PATCH] Re: Oops - Can't calculate our powers
[p5sagit/p5-mst-13.2.git] / ext / IPC / SysV / t / msg.t
CommitLineData
72802890 1BEGIN {
6edcbe38 2 chdir 't' if -d 't';
3
4 @INC = '../lib';
5
6 require Config; import Config;
7
8 my $reason;
9
10 if ($Config{'extensions'} !~ /\bIPC\/SysV\b/) {
11 $reason = 'IPC::SysV was not built';
12 } elsif ($Config{'d_sem'} ne 'define') {
13 $reason = '$Config{d_sem} undefined';
14 } elsif ($Config{'d_msg'} ne 'define') {
15 $reason = '$Config{d_msg} undefined';
72802890 16 }
6edcbe38 17 if ($reason) {
18 print "1..0 # Skip: $reason\n";
19 exit 0;
72802890 20 }
21}
22
0ade1984 23use IPC::SysV qw(IPC_PRIVATE IPC_RMID IPC_NOWAIT IPC_STAT S_IRWXU S_IRWXG S_IRWXO);
24
25use IPC::Msg;
26#Creating a message queue
27
28print "1..9\n";
29
30$msq = new IPC::Msg(IPC_PRIVATE, S_IRWXU | S_IRWXG | S_IRWXO)
31 || die "msgget: ",$!+0," $!\n";
32
33print "ok 1\n";
34
35#Putting a message on the queue
36$msgtype = 1;
37$msg = "hello";
ddc3217d 38print $msq->snd($msgtype,$msg,IPC_NOWAIT) ? "ok 2\n" : "not ok 2 # $!\n";
0ade1984 39
40#Check if there are messages on the queue
41$ds = $msq->stat() or print "not ";
42print "ok 3\n";
43
44print "not " unless $ds && $ds->qnum() == 1;
45print "ok 4\n";
46
47#Retreiving a message from the queue
48$rmsgtype = 0; # Give me any type
49$rmsgtype = $msq->rcv($rmsg,256,$rmsgtype,IPC_NOWAIT) || print "not ";
50print "ok 5\n";
51
52print "not " unless $rmsgtype == $msgtype && $rmsg eq $msg;
53print "ok 6\n";
54
55$ds = $msq->stat() or print "not ";
56print "ok 7\n";
57
58print "not " unless $ds && $ds->qnum() == 0;
59print "ok 8\n";
60
61$msq->remove || print "not ";
62print "ok 9\n";