1BEGIN {
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
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
30my $msq =
31    new IPC::Msg(IPC_PRIVATE, S_IRWXU | S_IRWXG | S_IRWXO)
32    || die "msgget: ",$!+0," $!\n";
33	
34print "ok 1\n";
35
36#Putting a message on the queue
37$msgtype = 1;
38$msg = "hello";
39print $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 ";
43print "ok 3\n";
44
45print "not " unless $ds && $ds->qnum() == 1;
46print "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 ";
51print "ok 5\n";
52
53print "not " unless $rmsgtype == $msgtype && $rmsg eq $msg;
54print "ok 6\n";
55
56$ds = $msq->stat() or print "not ";
57print "ok 7\n";
58
59print "not " unless $ds && $ds->qnum() == 0;
60print "ok 8\n";
61
62END {
63	(defined $msq && $msq->remove) || print "not ";
64	print "ok 9\n";
65}
66