Re: [PATCH] Re: Oops - Can't calculate our powers
[p5sagit/p5-mst-13.2.git] / ext / IPC / SysV / t / msg.t
1 BEGIN {
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';
16     }
17     if ($reason) {
18         print "1..0 # Skip: $reason\n";
19         exit 0;
20     }
21 }
22
23 use IPC::SysV qw(IPC_PRIVATE IPC_RMID IPC_NOWAIT IPC_STAT S_IRWXU S_IRWXG S_IRWXO);
24
25 use IPC::Msg;
26 #Creating a message queue
27
28 print "1..9\n";
29
30 $msq = new IPC::Msg(IPC_PRIVATE, S_IRWXU | S_IRWXG | S_IRWXO)
31         || die "msgget: ",$!+0," $!\n";
32         
33 print "ok 1\n";
34
35 #Putting a message on the queue
36 $msgtype = 1;
37 $msg = "hello";
38 print $msq->snd($msgtype,$msg,IPC_NOWAIT) ? "ok 2\n" : "not ok 2 # $!\n";
39
40 #Check if there are messages on the queue
41 $ds = $msq->stat() or print "not ";
42 print "ok 3\n";
43
44 print "not " unless $ds && $ds->qnum() == 1;
45 print "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 ";
50 print "ok 5\n";
51
52 print "not " unless $rmsgtype == $msgtype && $rmsg eq $msg;
53 print "ok 6\n";
54
55 $ds = $msq->stat() or print "not ";
56 print "ok 7\n";
57
58 print "not " unless $ds && $ds->qnum() == 0;
59 print "ok 8\n";
60
61 $msq->remove || print "not ";
62 print "ok 9\n";