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, 9216);
0061 long rsplen;
0062 int ret=EXSUCCEED;
0063 TPTRANID t;
0064 char cnvstr[TPCONVMAXSTR];
0065 char cnvbin[TPCONVMAXSTR];
0066
0067 if (EXSUCCEED!=tpopen())
0068 {
0069 NDRX_LOG(log_error, "TESTERROR: tpopen() fail: %d:[%s]",
0070 tperrno, tpstrerror(tperrno));
0071 EXFAIL_OUT(ret);
0072 }
0073
0074
0075 NDRX_LOG(log_debug, "Testing tpconvert()");
0076
0077
0078 if (EXSUCCEED!=tpbegin(5, 0))
0079 {
0080 NDRX_LOG(log_error, "TESTERROR: tpbegin() fail: %d:[%s]",
0081 tperrno, tpstrerror(tperrno));
0082 EXFAIL_OUT(ret);
0083 }
0084
0085
0086
0087
0088
0089
0090
0091
0092 if (EXSUCCEED!=tpcall("TESTCLTID", NULL, 0L, (char **)&p_ub, &rsplen, TPNOTRAN))
0093 {
0094 NDRX_LOG(log_error, "TESTERROR: Failed to call TESTCLTID: %s - "
0095 "client id convert failed!", tpstrerror(tperrno));
0096 EXFAIL_OUT(ret);
0097 }
0098
0099
0100
0101
0102
0103
0104
0105 if (EXSUCCEED!=tpsuspend(&t, 0L))
0106 {
0107 NDRX_LOG(log_error, "TESTERROR: Failed to suspend transaction: %s!",
0108 tpstrerror(tperrno));
0109 EXFAIL_OUT(ret);
0110 }
0111
0112 cnvstr[0] = EXEOS;
0113 cnvbin[0] = EXEOS;
0114
0115 if (EXSUCCEED!=tpconvert(cnvstr, (char *)&t, TPCONVTRANID | TPTOSTRING))
0116 {
0117 NDRX_LOG(log_error, "TESTERROR: Failed to tpconvert() "
0118 "TPCONVTRANID | TPTOSTRING: %s!", tpstrerror(tperrno));
0119 EXFAIL_OUT(ret);
0120 }
0121
0122
0123 NDRX_LOG(log_debug, "Convert TPCONVTRANID from string to bin: [%s]",
0124 cnvstr);
0125
0126 if (EXSUCCEED!=tpconvert(cnvstr, cnvbin, TPCONVTRANID))
0127 {
0128 NDRX_LOG(log_error, "TESTERROR: Failed to tpconvert() "
0129 "TPCONVTRANID from string: %s!",
0130 tpstrerror(tperrno));
0131 EXFAIL_OUT(ret);
0132 }
0133
0134
0135 if (EXSUCCEED!=tpresume((TPTRANID *)cnvbin, 0L))
0136 {
0137 NDRX_LOG(log_error, "TESTERROR: Failed to resume transaction: %s!",
0138 tpstrerror(tperrno));
0139 EXFAIL_OUT(ret);
0140 }
0141
0142
0143
0144
0145
0146
0147
0148
0149
0150 cnvstr[0] = EXEOS;
0151 cnvbin[0] = EXEOS;
0152
0153
0154 if (EXSUCCEED!=tpconvert(t.tmxid, cnvbin, TPCONVXID))
0155 {
0156 NDRX_LOG(log_error, "TESTERROR: Failed to tpconvert() "
0157 "TPCONVXID from string: %s!",
0158 tpstrerror(tperrno));
0159 EXFAIL_OUT(ret);
0160 }
0161
0162
0163 if (0==strcmp(t.tmxid, cnvbin))
0164 {
0165 NDRX_LOG(log_error, "TESTERROR: Failed to tpconvert() TPCONVXID "
0166 "binary equal string [%s]!!!", cnvbin);
0167 EXFAIL_OUT(ret);
0168 }
0169
0170 if (EXSUCCEED!=tpconvert(cnvstr, cnvbin, TPCONVXID | TPTOSTRING))
0171 {
0172 NDRX_LOG(log_error, "TESTERROR: Failed to tpconvert() TPCONVXID | "
0173 "TPTOSTRING failed: %s!", tpstrerror(tperrno));
0174 EXFAIL_OUT(ret);
0175 }
0176
0177 if (0!=strcmp(t.tmxid, cnvstr))
0178 {
0179 NDRX_LOG(log_error, "TESTERROR: TPCONVXID strings must match!!! "
0180 "tmxid: [%s] vs cnvstr [%s]", t.tmxid, cnvstr);
0181 EXFAIL_OUT(ret);
0182 }
0183
0184 if (EXSUCCEED!=tpcommit(0))
0185 {
0186 NDRX_LOG(log_error, "TESTERROR: tpcommit()==%d fail: %d:[%s]",
0187 ret, tperrno, tpstrerror(tperrno));
0188 ret=EXFAIL;
0189 goto out;
0190 }
0191
0192
0193 NDRX_LOG(log_debug, "Done...");
0194
0195
0196 if (EXSUCCEED!=tpclose())
0197 {
0198 NDRX_LOG(log_error, "TESTERROR: tpclose() fail: %d:[%s]",
0199 tperrno, tpstrerror(tperrno));
0200 ret=EXFAIL;
0201 goto out;
0202 }
0203
0204 out:
0205 if (EXSUCCEED!=ret)
0206 {
0207
0208 if (EXSUCCEED!=tpabort(0))
0209 {
0210 NDRX_LOG(log_error, "TESTERROR: tpabort() fail: %d:[%s]",
0211 tperrno, tpstrerror(tperrno));
0212 }
0213 tpclose();
0214 }
0215
0216 tpterm();
0217
0218 NDRX_LOG(log_error, "Exiting with %d", ret);
0219
0220 return ret;
0221 }
0222