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 <atmi_int.h>
0042 #include <ubf.h>
0043 #include <ndebug.h>
0044 #include <test.fd.h>
0045 #include <ndrstandard.h>
0046 #include <nstopwatch.h>
0047 #include <fcntl.h>
0048 #include <unistd.h>
0049 #include <nstdutil.h>
0050 #include <ubfutil.h>
0051 #include "test56.h"
0052 #include <exbase64.h>
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065 expublic int test_impexp_ubf(void)
0066 {
0067 int ret = EXSUCCEED;
0068 int i;
0069 long rsplen,olen;
0070 char *obuf;
0071 char json_ubf_in_b64[CARR_BUFFSIZE_B64+1];
0072 char json_ubf_out_b64[CARR_BUFFSIZE_B64+1];
0073 size_t len_b64;
0074 char *json_ubf_in =
0075 "{"
0076 "\"buftype\":\"UBF\","
0077 "\"version\":1,"
0078 "\"data\":"
0079 "{"
0080 "\"T_SHORT_FLD\":1765,"
0081 "\"T_LONG_FLD\":[3333111,2],"
0082 "\"T_CHAR_FLD\":\"A\","
0083 "\"T_FLOAT_FLD\":1,"
0084 "\"T_DOUBLE_FLD\":[1111.220000,333,444],"
0085 "\"T_STRING_FLD\":\"HELLO WORLD\","
0086 "\"T_CARRAY_FLD\":\"AAECA0hFTExPIEJJTkFSWQQFAA==\""
0087 "}"
0088 "}";
0089 char json_ubf_out[1024];
0090 char *istrtemp=NULL;
0091 size_t bufsz;
0092 long blen;
0093
0094 NDRX_LOG(log_info, "JSON UBF IN: [%s]", json_ubf_in);
0095
0096 if (NULL == (obuf = tpalloc("UBF", NULL, NDRX_MSGSIZEMAX)))
0097 {
0098 NDRX_LOG(log_error, "Failed to allocate UBFH %ld bytes: %s",
0099 NDRX_MSGSIZEMAX, tpstrerror(tperrno));
0100 EXFAIL_OUT(ret);
0101 }
0102
0103 for (i=0; i<10000; i++)
0104 {
0105 rsplen=0L;
0106 if ( EXFAIL == tpimport(json_ubf_in,
0107 (long)strlen(json_ubf_in),
0108 (char **)&obuf,
0109 &rsplen,
0110 0L) )
0111 {
0112 NDRX_LOG(log_error, "TESTERROR: Failed to import JSON UBF!!!!");
0113 EXFAIL_OUT(ret);
0114 }
0115 ndrx_debug_dump_UBF(log_debug, "JSON UBF imported. Return obuf", (UBFH *)obuf);
0116
0117 if (EXFAIL==(blen=tptypes(obuf, NULL, NULL)))
0118 {
0119 NDRX_LOG(log_error, "TESTERROR: tptypes failed: %s", tpstrerror(tperrno));
0120 EXFAIL_OUT(ret);
0121 }
0122
0123 if (rsplen!=blen)
0124 {
0125 NDRX_LOG(log_error, "TESTERROR: buffer imported len=%ld tptypes=%ld",
0126 rsplen, blen);
0127 EXFAIL_OUT(ret);
0128 }
0129
0130 memset(json_ubf_out, 0, sizeof(json_ubf_out));
0131 olen = sizeof(json_ubf_out);
0132 if ( EXFAIL == tpexport(obuf,
0133 (long)strlen(obuf),
0134 json_ubf_out,
0135 &olen,
0136 0L) )
0137 {
0138 NDRX_LOG(log_error, "TESTERROR: Failed to export JSON UBF!!!!");
0139 EXFAIL_OUT(ret);
0140 }
0141 NDRX_LOG(log_debug,
0142 "JSON UBF exported. Return json_ubf_out=[%s] olen=[%ld]",
0143 json_ubf_out, olen);
0144
0145 if (0!=strcmp(json_ubf_in, json_ubf_out))
0146 {
0147 NDRX_LOG(log_error,
0148 "TESTERROR: Exported UBF not equal to incoming string ");
0149 EXFAIL_OUT(ret);
0150 }
0151 }
0152
0153
0154 NDRX_LOG(log_debug, "convert to b64");
0155
0156 len_b64 = sizeof(json_ubf_in_b64);
0157 if (NULL==ndrx_base64_encode((unsigned char *)json_ubf_in, strlen(json_ubf_in),
0158 &len_b64, json_ubf_in_b64))
0159 {
0160 NDRX_LOG(log_error, "Failed to convert to b64!");
0161 EXFAIL_OUT(ret);
0162 }
0163
0164 for (i=0; i<10000; i++)
0165 {
0166 rsplen=0L;
0167 if ( EXFAIL == tpimport(json_ubf_in_b64,
0168 (long)strlen(json_ubf_in_b64),
0169 (char **)&obuf,
0170 &rsplen,
0171 TPEX_STRING) )
0172 {
0173 NDRX_LOG(log_error, "TESTERROR: Failed to import JSON UBF!!!!");
0174 EXFAIL_OUT(ret);
0175 }
0176 ndrx_debug_dump_UBF(log_debug, "JSON UBF imported. Return obuf", (UBFH *)obuf);
0177
0178
0179
0180 memset(json_ubf_out_b64, 0, sizeof(json_ubf_out_b64));
0181 olen = sizeof(json_ubf_out_b64);
0182 if ( EXFAIL == tpexport(obuf,
0183 (long)strlen(obuf),
0184 json_ubf_out_b64,
0185 &olen,
0186 TPEX_STRING) )
0187 {
0188 NDRX_LOG(log_error, "TESTERROR: Failed to export JSON UBF!!!!");
0189 EXFAIL_OUT(ret);
0190 }
0191 NDRX_LOG(log_debug,
0192 "JSON UBF exported. Return json_ubf_out=[%s] olen=[%ld]",
0193 json_ubf_out_b64, olen);
0194
0195
0196 bufsz = strlen(json_ubf_out_b64);
0197 if (NULL==(istrtemp = NDRX_MALLOC(bufsz)))
0198 {
0199 NDRX_LOG(log_error, "Failed to allocate %ld bytes", strlen(json_ubf_out_b64));
0200 EXFAIL_OUT(ret);
0201 }
0202
0203 if (NULL==ndrx_base64_decode(json_ubf_out_b64, strlen(json_ubf_out_b64), &bufsz, istrtemp))
0204 {
0205 NDRX_LOG(log_error, "Failed to decode CARRAY");
0206 EXFAIL_OUT(ret);
0207 }
0208 istrtemp[bufsz]=0;
0209
0210 if (0!=strcmp(json_ubf_in, istrtemp))
0211 {
0212 NDRX_LOG(log_error,
0213 "TESTERROR: Exported UBF not equal to incoming string ");
0214 EXFAIL_OUT(ret);
0215 }
0216 if (NULL!=istrtemp)
0217 {
0218 NDRX_FREE(istrtemp);
0219 istrtemp=NULL;
0220 }
0221 }
0222
0223 out:
0224
0225 if (NULL!=istrtemp)
0226 {
0227 NDRX_FREE(istrtemp);
0228 istrtemp=NULL;
0229 }
0230
0231 return ret;
0232 }
0233