1/*
2 * Copyright (c) 2003, Intel Corporation. All rights reserved.
3 * Created by:  crystal.xiong REMOVE-THIS AT intel DOT com
4 * This file is licensed under the GPL license.  For the full content
5 * of this license, see the COPYING file at the top level of this
6 * source tree.
7 */
8
9/*
10 * mq_receive() test plan:
11 * mq_receive() will fail with EBADF, if mqdes is not a valid message
12 * message queue descriptor.
13 */
14
15#include <stdio.h>
16#include <errno.h>
17#include <mqueue.h>
18#include <fcntl.h>
19#include <sys/stat.h>
20#include <sys/types.h>
21#include <unistd.h>
22#include <string.h>
23#include <stdlib.h>
24#include "posixtest.h"
25
26#define TEST "11-1"
27#define FUNCTION "mq_receive"
28#define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": "
29
30#define NAMESIZE 50
31#define BUFFER 40
32
33int main()
34{
35	char mqname[NAMESIZE];
36	mqd_t mqdes;
37        char msgrv[BUFFER];
38	struct mq_attr attr;
39	int unresolved = 0, failure = 0;
40
41	sprintf(mqname, "/" FUNCTION "_" TEST "_%d", getpid());
42
43	attr.mq_msgsize = BUFFER;
44	attr.mq_maxmsg = BUFFER;
45	mqdes = mq_open(mqname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &attr);
46	if (mqdes == (mqd_t)-1) {
47		perror(ERROR_PREFIX "mq_open()");
48		unresolved = 1;
49	}
50	mqdes = mqdes + 1;
51       	if (mq_receive(mqdes, msgrv, BUFFER, NULL) == -1) {
52		if (EBADF != errno) {
53			printf("errno != EBADF \n");
54			failure = 1;
55		}
56	}
57	else {
58		printf("mq_receive() succeed unexpectly \n");
59		failure = 1;
60	}
61	if (mq_close(mqdes - 1) != 0) {
62                perror(ERROR_PREFIX "mq_close()");
63                unresolved=1;
64        }
65        if (mq_unlink(mqname) != 0) {
66                perror(ERROR_PREFIX "mq_unlink()");
67                unresolved=1;
68        }
69        if (failure==1) {
70                printf("Test FAILED\n");
71                return PTS_FAIL;
72        }
73        if (unresolved==1) {
74                printf("Test UNRESOLVED\n");
75                return PTS_UNRESOLVED;
76	}
77	printf("Test PASSED\n");
78        return PTS_PASS;
79}
80
81