0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034 #include <string.h>
0035 #include <stdio.h>
0036 #include <stdlib.h>
0037 #include <memory.h>
0038 #include <math.h>
0039
0040 #include <atmi.h>
0041 #include <ubf.h>
0042 #include <ndebug.h>
0043 #include <test.fd.h>
0044 #include <ndrstandard.h>
0045 #include <nstopwatch.h>
0046 #include <fcntl.h>
0047 #include <unistd.h>
0048 #include <nstdutil.h>
0049 #include "test104.h"
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061 int main(int argc, char** argv)
0062 {
0063 UBFH *p_ub = (UBFH *)tpalloc("UBF", NULL, 56000);
0064 long rsplen;
0065 int i;
0066 int ret=EXSUCCEED;
0067 TPQCTL qctl;
0068 short num;
0069 long len;
0070
0071 if (argc < 3)
0072 {
0073 fprintf(stderr, "Usage: %s {enq <msg_no> | deq <msg_tot> }\n", argv[0]);
0074 exit(EXFAIL);
0075 }
0076 num = atoi(argv[2]);
0077
0078 if (0==strcmp(argv[1], "enq"))
0079 {
0080 if (EXSUCCEED!=Bchg(p_ub, T_SHORT_FLD, 0, (char *)&num, 0L))
0081 {
0082 fprintf(stderr, "Failed to set T_SHORT_FLD\n");
0083 EXFAIL_OUT(ret);
0084 }
0085
0086
0087 memset(&qctl, 0, sizeof(qctl));
0088
0089 if (EXSUCCEED!=tpenqueue("TESTSP", "Q1", &qctl, (char *)p_ub, 0, 0))
0090 {
0091 NDRX_LOG(log_error, "TESTERROR: tpenqueue() to `Q1' failed %s diag: %d:%s",
0092 tpstrerror(tperrno), qctl.diagnostic, qctl.diagmsg);
0093 EXFAIL_OUT(ret);
0094 EXFAIL_OUT(ret);
0095 }
0096 }
0097 else if (0==strcmp(argv[1], "deq"))
0098 {
0099
0100 short messages[num];
0101 short val;
0102 char q[2][16] = {"Q1", "Q2"};
0103 int j;
0104 memset(messages, 0, sizeof(messages));
0105
0106 for (j=0; j<2; j++)
0107 {
0108
0109 memset(&qctl, 0, sizeof(qctl));
0110 while (EXSUCCEED==tpdequeue("TESTSP", q[j], &qctl, (char **)&p_ub, &len, 0))
0111 {
0112 if (EXSUCCEED!=Bget(p_ub, T_SHORT_FLD, 0, (char *)&val, NULL))
0113 {
0114 NDRX_LOG(log_error, "TESTERROR: Failed to get T_SHORT_FLD: %s", Bstrerror(Berror));
0115 EXFAIL_OUT(ret);
0116 }
0117
0118 if (val<0 || val>=num)
0119 {
0120 NDRX_LOG(log_error, "TESTERROR: Message %d out of range in Q [%s]", val, q[j]);
0121 EXFAIL_OUT(ret);
0122 }
0123
0124 if (messages[val]!=0)
0125 {
0126 NDRX_LOG(log_error, "TESTERROR: Duplicate message %d in Q [%s]", val, q[j]);
0127 EXFAIL_OUT(ret);
0128 }
0129 NDRX_LOG(log_error, "GOT j=%d, val=%hd", j, val);
0130 messages[val] = 1;
0131 memset(&qctl, 0, sizeof(qctl));
0132 }
0133
0134 if (TPEDIAGNOSTIC!=tperrno)
0135 {
0136 NDRX_LOG(log_error, "TESTRROR: Expected TPEDIAGNOSTIC, got %s", tpstrerror(tperrno));
0137 EXFAIL_OUT(ret);
0138 }
0139
0140 NDRX_LOG(log_error, "tpdequeue(%s) failed %s diag: %d:%s", q[j],
0141 tpstrerror(tperrno), qctl.diagnostic, qctl.diagmsg);
0142 }
0143
0144 for (j=0; j<num; j++)
0145 {
0146 if (messages[j]!=1)
0147 {
0148 NDRX_LOG(log_error, "TESTERROR: Message %d not found in Q", j);
0149 EXFAIL_OUT(ret);
0150 }
0151 }
0152 }
0153 else
0154 {
0155 NDRX_LOG(log_error, "Unknown command %s", argv[1]);
0156 exit(EXFAIL);
0157 }
0158
0159 out:
0160 tpterm();
0161 fprintf(stderr, "Exit with %d\n", ret);
0162
0163 return ret;
0164 }
0165
0166