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 "test47.h"
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064 int check_balance(char *accnum, long *balance)
0065 {
0066 int ret=EXSUCCEED;
0067 UBFH *p_ub = (UBFH *)tpalloc("UBF", NULL, 56000);
0068 long rsplen;
0069
0070 if (EXFAIL==CBchg(p_ub, T_STRING_FLD, 0, accnum, 0, BFLD_STRING))
0071 {
0072 NDRX_LOG(log_debug, "Failed to set T_STRING_FLD[0]: %s", Bstrerror(Berror));
0073 ret=EXFAIL;
0074 goto out;
0075 }
0076
0077 if (EXFAIL == tpcall("BALANCE", (char *)p_ub, 0L, (char **)&p_ub, &rsplen,TPNOABORT))
0078 {
0079 NDRX_LOG(log_error, "BALANCE failed: %s", tpstrerror(tperrno));
0080 ret=EXFAIL;
0081 goto out;
0082 }
0083
0084 if (EXFAIL==Bget(p_ub, T_LONG_FLD, 0, (char *)balance, 0))
0085 {
0086 NDRX_LOG(log_debug, "Failed to set T_LONG_FLD[0]: %s", Bstrerror(Berror));
0087 ret=EXFAIL;
0088 goto out;
0089 }
0090
0091 out:
0092 if (NULL!=p_ub)
0093 {
0094 tpfree((char *)p_ub);
0095 }
0096
0097 return ret;
0098 }
0099
0100
0101
0102
0103 int main(int argc, char** argv)
0104 {
0105 UBFH *p_ub = (UBFH *)tpalloc("UBF", NULL, 56000);
0106 long rsplen;
0107 long l;
0108 char *rsp=NULL;
0109 char tmp[51];
0110 long bal;
0111 int ret=EXSUCCEED;
0112 int upper1=100, upper2=300;
0113 char *p;
0114 ndrx_stopwatch_t w_loop;
0115 ndrx_stopwatch_t w_rsp;
0116 long max_rsp=-1;
0117
0118 if (NULL!=(p=getenv(CONF_NDRX_XA_FLAGS)) && NULL!=strstr(p, "BTIGHT"))
0119 {
0120 upper1=5;
0121 upper2=205;
0122 }
0123
0124 if (EXSUCCEED!=tpinit(NULL))
0125 {
0126 NDRX_LOG(log_debug, "Failed to init!: %s", tpstrerror(tperrno));
0127 EXFAIL_OUT(ret);
0128 }
0129
0130
0131 if (EXSUCCEED!=tpopen())
0132 {
0133 NDRX_LOG(log_debug, "Failed to tpopen!: %s", tpstrerror(tperrno));
0134 EXFAIL_OUT(ret);
0135 }
0136
0137 ndrx_stopwatch_reset(&w_loop);
0138 ndrx_stopwatch_reset(&w_rsp);
0139
0140
0141 while (1)
0142 {
0143 again:
0144
0145 if (ndrx_stopwatch_get_delta_sec(&w_loop) >= 800)
0146 {
0147 break;
0148 }
0149
0150 if ((l=ndrx_stopwatch_get_delta_sec(&w_rsp)) > MAX_RSP)
0151 {
0152 NDRX_LOG(log_error, "TESTERROR: Expected OK response in %d sec got %ld", MAX_RSP, l);
0153 EXFAIL_OUT(ret);
0154 }
0155
0156
0157 while (EXFAIL == tpcall("ACCCLEAN", NULL, 0L, &rsp, &rsplen,0))
0158 {
0159 NDRX_LOG(log_error, "ACCCLEAN failed: %s", tpstrerror(tperrno));
0160 sleep(1);
0161
0162
0163 if ((l=ndrx_stopwatch_get_delta_sec(&w_rsp)) > MAX_RSP)
0164 {
0165 NDRX_LOG(log_error, "TESTERROR: Expected OK response in %d sec got %ld (2)",
0166 MAX_RSP, l);
0167 EXFAIL_OUT(ret);
0168 }
0169 }
0170
0171 while (EXSUCCEED != tpbegin(MAX_RSP, 0))
0172 {
0173 NDRX_LOG(log_error, "tpbegin failed: %s", tpstrerror(tperrno));
0174 sleep(1);
0175 }
0176
0177
0178 for (l=200; l<upper2; l++)
0179 {
0180 snprintf(tmp, sizeof(tmp), "ACC%03ld", l);
0181
0182 if (EXFAIL==CBchg(p_ub, T_STRING_FLD, 0, tmp, 0, BFLD_STRING))
0183 {
0184 NDRX_LOG(log_debug, "Failed to set T_STRING_FLD[0]: %s", Bstrerror(Berror));
0185 ret=EXFAIL;
0186 goto out;
0187 }
0188
0189 if (EXFAIL==CBchg(p_ub, T_LONG_FLD, 0, (char *)&l, 0, BFLD_LONG))
0190 {
0191 NDRX_LOG(log_debug, "Failed to set T_LONG_FLD[0]: %s", Bstrerror(Berror));
0192 ret=EXFAIL;
0193 goto out;
0194 }
0195
0196
0197
0198
0199 if (EXFAIL == tpcall("ACCOPEN", (char *)p_ub, 0L, (char **)&p_ub, &rsplen,0))
0200 {
0201 NDRX_LOG(log_error, "ACCOPEN failed: %s", tpstrerror(tperrno));
0202
0203 if (EXSUCCEED!=tpabort(0))
0204 {
0205 NDRX_LOG(log_error, "tpabort failed: %s", tpstrerror(tperrno));
0206 }
0207
0208 goto again;
0209 }
0210
0211 ndrx_stopwatch_reset(&w_rsp);
0212 }
0213
0214
0215 if (EXSUCCEED != tpcommit(0))
0216 {
0217 NDRX_LOG(log_error, "tpcommit failed: %s", tpstrerror(tperrno));
0218 tpabort(0);
0219 }
0220 }
0221
0222
0223 out:
0224
0225
0226 if ((l=ndrx_stopwatch_get_delta_sec(&w_rsp)) > MAX_RSP)
0227 {
0228 NDRX_LOG(log_error, "TESTERROR: Expected OK response in %d sec got %ld", MAX_RSP, l);
0229 ret=EXFAIL;
0230 }
0231
0232 if (EXSUCCEED!=ret)
0233 {
0234
0235 tpabort(0);
0236 }
0237
0238 if (NULL!=p_ub)
0239 {
0240 tpfree((char *)p_ub);
0241 }
0242
0243 tpclose();
0244 tpterm();
0245
0246
0247 if (EXSUCCEED!=ret)
0248 {
0249 NDRX_LOG(log_error, "TESTERROR: Exit with %d", ret);
0250 }
0251
0252 fprintf(stderr, "Exit with %d\n", ret);
0253
0254 return ret;
0255 }
0256