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 #include <unistd.h>
0040
0041 #include <atmi.h>
0042 #include <ubf.h>
0043 #include <ndebug.h>
0044 #include <test.fd.h>
0045 #include <ndrstandard.h>
0046 #include <nstopwatch.h>
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058 int main(int argc, char** argv) {
0059
0060 UBFH *p_ub = (UBFH *)tpalloc("UBF", NULL, 9218);
0061 long rsplen;
0062 int i;
0063 int ret=EXSUCCEED;
0064 int cd_got;
0065 int cd[3];
0066 int got_send_block;
0067 char bigmsg[8000];
0068
0069 Badd(p_ub, T_STRING_FLD, "THIS IS TEST FIELD 1", 0);
0070 Badd(p_ub, T_STRING_FLD, "THIS IS TEST FIELD 2", 0);
0071 Badd(p_ub, T_STRING_FLD, "THIS IS TEST FIELD 3", 0);
0072
0073 cd[0] = tpacall("TESTSV", (char *)p_ub, 0L, 0L);
0074 if (cd[0] <= 0)
0075 {
0076 NDRX_LOG(log_error, "TESTERROR first tpacall got %d: %s",
0077 cd[0], tpstrerror(tperrno));
0078 EXFAIL_OUT(ret);
0079 }
0080
0081 cd[1] = tpacall("TESTSV", (char *)p_ub, 0L, 0L);
0082 if (cd[1] <= 0)
0083 {
0084 NDRX_LOG(log_error, "TESTERROR second tpacall got %d: %s",
0085 cd[1], tpstrerror(tperrno));
0086 EXFAIL_OUT(ret);
0087 }
0088
0089 cd[2] = tpacall("TESTSV", (char *)p_ub, 0L, 0L);
0090 if (cd[2] <= 0)
0091 {
0092 NDRX_LOG(log_error, "TESTERROR third tpacall got %d: %s",
0093 cd[2], tpstrerror(tperrno));
0094 EXFAIL_OUT(ret);
0095 }
0096
0097
0098 sleep(10);
0099
0100 for (i = 0; i<3; i++)
0101 {
0102 cd_got = cd[i];
0103 if (EXSUCCEED==(ret = tpgetrply(&cd_got, (char **)&p_ub, &rsplen, TPNOBLOCK)))
0104 {
0105 NDRX_LOG(log_error, "TESTERROR The call was ok to server "
0106 "- must be tout!");
0107 ret=EXFAIL;
0108 goto out;
0109 }
0110
0111 ret = EXSUCCEED;
0112 if (cd_got != cd[i])
0113 {
0114 NDRX_LOG(log_error, "TESTERROR cd %d <> go_cd %d", cd, cd_got);
0115 ret=EXFAIL;
0116 goto out;
0117 }
0118
0119 if (tperrno!=TPETIME)
0120 {
0121 NDRX_LOG(log_error, "Te error should be time-out!");
0122 ret=EXFAIL;
0123 goto out;
0124 }
0125 }
0126
0127
0128 cd[0] = tpacall("ECHO", (char *)p_ub, 0L, 0L);
0129 sleep(1);
0130 if (EXSUCCEED==(ret = tpgetrply(&cd_got, (char **)&p_ub, &rsplen, TPNOBLOCK | TPGETANY)))
0131 {
0132 NDRX_LOG(log_error, "TESTERROR Must be TPEBLOCK");
0133 ret=EXFAIL;
0134 goto out;
0135 }
0136
0137 if (tperrno!=TPEBLOCK)
0138 {
0139 NDRX_LOG(log_error, "TESTERROR! got tperror=%d %s expected TPENOBLOCK %d",
0140 tperrno, tpstrerror(tperrno), TPEBLOCK);
0141 ret=EXFAIL;
0142 goto out;
0143 }
0144
0145 sleep(10);
0146 if (EXSUCCEED!=(ret = tpgetrply(&cd_got, (char **)&p_ub, &rsplen, TPNOBLOCK | TPGETANY)))
0147 {
0148 NDRX_LOG(log_error, "TESTERROR Normal reply fails!!!");
0149 ret=EXFAIL;
0150 goto out;
0151 }
0152
0153 if (cd_got!=cd[0])
0154 {
0155 NDRX_LOG(log_error, "TESTERROR Got invalid response! "
0156 "cd[0] = %d got_cd = %d", cd[0], cd_got);
0157 ret=EXFAIL;
0158 goto out;
0159 }
0160
0161
0162 if (EXSUCCEED==(ret = tpgetrply(&cd_got, (char **)&p_ub, &rsplen, TPNOBLOCK)))
0163 {
0164 NDRX_LOG(log_error, "TESTERROR Queue must be empty!");
0165 ret=EXFAIL;
0166 goto out;
0167 }
0168
0169 NDRX_LOG(log_debug, "got tperror=%d %s", tperrno, tpstrerror(tperrno));
0170
0171 if (tperrno!=TPEBADDESC)
0172 {
0173 NDRX_LOG(log_error, "TESTERROR! got tperror=%d %s expected TPEBADDESC %d",
0174 tperrno, tpstrerror(tperrno), TPEBADDESC);
0175 ret=EXFAIL;
0176 goto out;
0177 }
0178 ret=EXSUCCEED;
0179
0180
0181
0182 if (EXSUCCEED!=Bchg(p_ub, T_CARRAY_FLD, 0, bigmsg, sizeof(bigmsg)))
0183 {
0184 NDRX_LOG(log_error, "TESTERROR! Failed to add bigmsg: %s",
0185 Bstrerror(Berror));
0186 EXFAIL_OUT(ret);
0187 }
0188
0189 got_send_block = EXFALSE;
0190 while (1)
0191 {
0192 if (EXFAIL==tpacall("BLOCKY", (char *)p_ub, 0L, TPNOBLOCK))
0193 {
0194 if (tperrno!=TPEBLOCK)
0195 {
0196 NDRX_LOG(log_error, "TESTERROR! got tperror=%d %s expected TPENOBLOCK %d",
0197 tperrno, tpstrerror(tperrno), TPEBLOCK);
0198 ret=EXFAIL;
0199 goto out;
0200 }
0201 else
0202 {
0203 got_send_block = EXTRUE;
0204 break;
0205 }
0206 }
0207 }
0208
0209 if (!got_send_block)
0210 {
0211 NDRX_LOG(log_error, "TESTERROR: expected TPEBLOCK condition in previous run!");
0212 ret=EXFAIL;
0213 goto out;
0214 }
0215
0216 out:
0217
0218 if (NULL!=p_ub)
0219 {
0220 tpfree((char *)p_ub);
0221 }
0222
0223 tpterm();
0224 NDRX_LOG(log_error, "RESULT: %d", ret);
0225 return ret;
0226 }
0227
0228