1/*
2 * Copyright (c) 2003, Intel Corporation. All rights reserved.
3 * Created by:  julie.n.fleischer 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 * Basic test that mq_open() returns a valid message descriptor.
11 * Test by calling mq_open() and then verifying that that descriptor can
12 * be used to call mq_send().
13 */
14
15#include <stdio.h>
16#include <mqueue.h>
17#include <fcntl.h>
18#include <sys/stat.h>
19#include <sys/types.h>
20#include <unistd.h>
21#include <string.h>
22#include "posixtest.h"
23
24#define NAMESIZE 50
25#define MSGSTR "0123456789"
26
27int main()
28{
29        char qname[NAMESIZE];
30        const char *msgptr = MSGSTR;
31        mqd_t queue;
32	int failure=0;
33
34        sprintf(qname, "/mq_open_1-1_%d", getpid());
35
36        queue = mq_open(qname, O_CREAT |O_RDWR, S_IRUSR | S_IWUSR, NULL);
37        if (queue == (mqd_t)-1) {
38                perror("mq_open() did not return success");
39		printf("Test FAILED\n");
40                return PTS_FAIL;
41        }
42
43        if (mq_send(queue, msgptr, strlen(msgptr), 1) != 0) {
44                perror("mq_send() did not return success");
45		failure=1;
46        }
47
48	mq_close(queue);
49	mq_unlink(qname);
50
51	if (failure==1) {
52		printf("Test FAILED\n");
53		return PTS_FAIL;
54	}
55
56        printf("Test PASSED\n");
57        return PTS_PASS;
58}
59
60