2 * Copyright (c) 2016, JANET(UK)
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of JANET(UK) nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
25 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
29 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
31 * OF THE POSSIBILITY OF SUCH DAMAGE.
41 static void notify_cb(TR_MQ *mq, void *arg)
45 printf("MQ %s no longer empty.\n", s);
59 mq->notify_cb=notify_cb;
60 mq->notify_cb_arg=mq_name;
62 msg1= tr_mq_msg_new(NULL, "Message 1");
63 assert(asprintf((char **)&(msg1->p), "First message.\n")!=-1);
66 assert(mq->head==msg1);
67 assert(mq->tail==msg1);
68 assert(msg1->next==NULL);
70 msg2= tr_mq_msg_new(NULL, "Message 2");
71 assert(asprintf((char **)&(msg2->p), "Second message.\n")!=-1);
74 assert(mq->head==msg1);
75 assert(msg1->next==msg2);
76 assert(mq->tail==msg2);
77 assert(msg2->next==NULL);
79 msg=tr_mq_pop(mq, NULL);
81 assert(mq->head==msg2);
82 assert(mq->tail==msg2);
83 assert(msg2->next==NULL);
84 if ((msg!=NULL) && (msg->p!=NULL)) {
85 printf("%s", (char *)msg->p);
88 printf("no message to pop\n");
90 msg3= tr_mq_msg_new(NULL, "Message 3");
91 assert(asprintf((char **)&(msg3->p), "%s", "Third message.\n")!=-1);
94 assert(mq->head==msg2);
95 assert(mq->tail==msg3);
96 assert(msg2->next==msg3);
97 assert(msg3->next==NULL);
99 msg=tr_mq_pop(mq, NULL);
101 assert(mq->head==msg3);
102 assert(mq->tail==msg3);
103 assert(msg3->next==NULL);
104 if ((msg!=NULL) && (msg->p!=NULL)) {
105 printf("%s",(char *)msg->p);
108 printf("no message to pop\n");
110 msg=tr_mq_pop(mq, NULL);
112 assert(mq->head==NULL);
113 assert(mq->tail==NULL);
114 if ((msg!=NULL) && (msg->p!=NULL)) {
115 printf("%s",(char *)msg->p);
118 printf("no message to pop\n");
120 msg=tr_mq_pop(mq, NULL);
122 assert(mq->head==NULL);
123 assert(mq->tail==NULL);
124 if ((msg!=NULL) && (msg->p!=NULL)) {
125 printf("%s",(char *)msg->p);
128 printf("no message to pop\n");
130 msg4= tr_mq_msg_new(NULL, "Message 4");
131 assert(asprintf((char **)&(msg4->p), "%s", "Fourth message.\n")!=-1);
134 assert(mq->head==msg4);
135 assert(mq->tail==msg4);
136 assert(msg4->next==NULL);
138 msg=tr_mq_pop(mq, NULL);
140 assert(mq->head==NULL);
141 assert(mq->tail==NULL);
142 if ((msg!=NULL) && (msg->p!=NULL)) {
143 printf("%s",(char *)msg->p);
146 printf("no message to pop\n");
148 msg=tr_mq_pop(mq, NULL);
150 assert(mq->head==NULL);
151 assert(mq->tail==NULL);
152 if ((msg!=NULL) && (msg->p!=NULL)) {
153 printf("%s",(char *)msg->p);
156 printf("no message to pop\n");