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 <ndebug.h>
0043 #include <ndrstandard.h>
0044 #include <nstopwatch.h>
0045 #include <fcntl.h>
0046 #include <unistd.h>
0047 #include <nstdutil.h>
0048 #include <ubfutil.h>
0049 #include <exbase64.h>
0050 #include "test56.h"
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063 int test_impexp_carray(void)
0064 {
0065 int ret = EXSUCCEED;
0066 int i;
0067 long rsplen,olen,ilen;
0068 char *obuf;
0069 char buf_bin[CARR_BUFFSIZE+1];
0070 char json_carray_in_b64[CARR_BUFFSIZE_B64+1];
0071 char json_carray_out_b64[CARR_BUFFSIZE_B64+1];
0072 size_t st_len, len_b64;
0073 char *json_carray_in =
0074 "{"
0075 "\"buftype\":\"CARRAY\","
0076 "\"version\":1,"
0077 "\"data\":\"SEVMTE8gV09STEQgQ0FSUkFZ\""
0078 "}";
0079 char json_carray_out[1024];
0080 char *istrtemp=NULL;
0081 size_t bufsz = 0;
0082
0083 NDRX_LOG(log_debug, "JSON CARRAY IN: [%s]", json_carray_in);
0084
0085 if (NULL==(obuf = tpalloc("CARRAY", NULL, 128)))
0086 {
0087 NDRX_LOG(log_error, "TESTERROR: failed to alloc CARRAY buffer!");
0088 EXFAIL_OUT(ret);
0089 }
0090
0091 for (i=0; i<10000; i++)
0092 {
0093 rsplen=0L;
0094 if ( EXFAIL == tpimport(json_carray_in,
0095 (long)strlen(json_carray_in),
0096 (char **)&obuf,
0097 &rsplen,
0098 0L) )
0099 {
0100 NDRX_LOG(log_error, "TESTERROR: Failed to import JSON CARRAY!!!!");
0101 EXFAIL_OUT(ret);
0102 }
0103
0104 NDRX_DUMP(log_debug, "Imported CARRAY", obuf, rsplen);
0105
0106 memset(json_carray_out, 0, sizeof(json_carray_out));
0107 olen = sizeof(json_carray_out);
0108 ilen = rsplen;
0109 if ( EXFAIL == tpexport(obuf,
0110 ilen,
0111 json_carray_out,
0112 &olen,
0113 0L) )
0114 {
0115 NDRX_LOG(log_error, "TESTERROR: Failed to export JSON CARRAY!!!!");
0116 EXFAIL_OUT(ret);
0117 }
0118
0119 NDRX_LOG(log_debug,
0120 "CARRAY exported. Return json_carray_out=[%s] olen=[%ld]",
0121 json_carray_out, olen);
0122
0123 if (0!=strcmp(json_carray_in, json_carray_out))
0124 {
0125
0126 NDRX_LOG(log_error,
0127 "TESTERROR: Exported JSON not equal to incoming carray");
0128 EXFAIL_OUT(ret);
0129 }
0130 }
0131
0132
0133 NDRX_LOG(log_debug, "convert to b64");
0134 len_b64 = sizeof(json_carray_in_b64);
0135 if (NULL==ndrx_base64_encode((unsigned char *)json_carray_in, strlen(json_carray_in),
0136 &len_b64, json_carray_in_b64))
0137 {
0138 NDRX_LOG(log_error, "Failed to convert to b64!");
0139 EXFAIL_OUT(ret);
0140 }
0141
0142 for (i=0; i<10000; i++)
0143 {
0144 rsplen=0L;
0145 if ( EXFAIL == tpimport(json_carray_in_b64,
0146 (long)len_b64,
0147 (char **)&obuf,
0148 &rsplen,
0149 TPEX_STRING) )
0150 {
0151 NDRX_LOG(log_error, "TESTERROR: Failed to import JSON CARRAY!!!!");
0152 EXFAIL_OUT(ret);
0153 }
0154
0155 NDRX_DUMP(log_debug, "Imported CARRAY [%s][%ld]", obuf, rsplen);
0156
0157 memset(json_carray_out_b64, 0, sizeof(json_carray_out_b64));
0158 olen = sizeof(json_carray_out_b64);
0159 ilen = rsplen;
0160 if ( EXFAIL == tpexport(obuf,
0161 ilen,
0162 json_carray_out_b64,
0163 &olen,
0164 TPEX_STRING) )
0165 {
0166 NDRX_LOG(log_error, "TESTERROR: Failed to export JSON CARRAY!!!!");
0167 EXFAIL_OUT(ret);
0168 }
0169
0170 NDRX_LOG(log_debug,
0171 "CARRAY exported. Return json_carray_out_b64=[%s] olen=[%ld]",
0172 json_carray_out_b64, olen);
0173
0174
0175 bufsz = strlen(json_carray_out_b64);
0176 if (NULL==(istrtemp = NDRX_MALLOC(bufsz)))
0177 {
0178 NDRX_LOG(log_error, "Failed to allocate %ld bytes", strlen(json_carray_out_b64));
0179 EXFAIL_OUT(ret);
0180 }
0181
0182 if (NULL==ndrx_base64_decode(json_carray_out_b64, strlen(json_carray_out_b64),
0183 &bufsz, istrtemp))
0184 {
0185 NDRX_LOG(log_error, "Failed to decode CARRAY");
0186 EXFAIL_OUT(ret);
0187 }
0188 istrtemp[bufsz]=0;
0189
0190 if (0!=strcmp(json_carray_in, istrtemp))
0191 {
0192 NDRX_LOG(log_error,
0193 "TESTERROR: \n"
0194 "json_carray_in=[%s]\n"
0195 " istrtemp=[%s]",
0196 json_carray_in, istrtemp);
0197 NDRX_LOG(log_error,
0198 "TESTERROR: Exported JSON not equal to incoming carray");
0199 EXFAIL_OUT(ret);
0200 }
0201 if (NULL!=istrtemp)
0202 {
0203 NDRX_FREE(istrtemp);
0204 istrtemp=NULL;
0205 }
0206 }
0207
0208 out:
0209
0210 if (NULL!=istrtemp)
0211 {
0212 NDRX_FREE(istrtemp);
0213 istrtemp=NULL;
0214 }
0215
0216 return ret;
0217 }
0218