[perl #23216] ext/IPC/SysV/t/sem.t don't remove semaphore on NetBSD sparc
[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 my $msq =
31     new IPC::Msg(IPC_PRIVATE, S_IRWXU | S_IRWXG | S_IRWXO)
32     || die "msgget: ",$!+0," $!\n";
33         
34 print "ok 1\n";
35
36 #Putting a message on the queue
37 $msgtype = 1;
38 $msg = "hello";
39 print $msq->snd($msgtype,$msg,IPC_NOWAIT) ? "ok 2\n" : "not ok 2 # $!\n";
40
41 #Check if there are messages on the queue
42 $ds = $msq->stat() or print "not ";
43 print "ok 3\n";
44
45 print "not " unless $ds && $ds->qnum() == 1;
46 print "ok 4\n";
47
48 #Retreiving a message from the queue
49 $rmsgtype = 0; # Give me any type
50 $rmsgtype = $msq->rcv($rmsg,256,$rmsgtype,IPC_NOWAIT) || print "not ";
51 print "ok 5\n";
52
53 print "not " unless $rmsgtype == $msgtype && $rmsg eq $msg;
54 print "ok 6\n";
55
56 $ds = $msq->stat() or print "not ";
57 print "ok 7\n";
58
59 print "not " unless $ds && $ds->qnum() == 0;
60 print "ok 8\n";
61
62 END {
63         (defined $msq && $msq->remove) || print "not ";
64         print "ok 9\n";
65 }