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 "test64.h"
0050 #include <extest.h>
0051 #include <tpadm.h>
0052 #include <typed_buf.h>
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073 exprivate int tester(char *svc, char *input_type, char *input_sub,
0074 char *output_type, char *output_sub, long flags, int tpcallerr, int validate)
0075 {
0076 char *data = NULL;
0077 long len = 0;
0078 int tpcallerrgot = 0;
0079 int ret = EXSUCCEED;
0080 char btype[16]="";
0081 char stype[16]="";
0082
0083 NDRX_LOG(log_debug, "svc: [%s] input_type: [%s] input_sub: [%s] output_type: "
0084 "[%s] output_sub: [%s] flags: %ld tpcallerr: %d validate: %d",
0085 svc, input_type, input_sub, output_type, output_sub, flags,
0086 tpcallerr, validate);
0087
0088 if (0!=strcmp("NULL", input_type) &&
0089 NULL==(data = tpalloc(input_type, input_sub, 1024)))
0090 {
0091 NDRX_LOG(log_error, "Failed to alloc buffer!");
0092 EXFAIL_OUT(ret);
0093 }
0094
0095 if (0==strcmp(input_type, "STRING"))
0096 {
0097 strcpy(data, "HELLO CLIENT");
0098 }
0099 else if (0==strcmp(input_type, "JSON"))
0100 {
0101 strcpy(data, "[]");
0102 }
0103 else if (0==strcmp(input_type, "CARRAY"))
0104 {
0105 strcpy(data, "HELLO CARRAY CLIENT");
0106 len = strlen(data);
0107 }
0108 else if (0==strcmp(input_type, "VIEW"))
0109 {
0110 struct UBTESTVIEW1 *vv = (struct UBTESTVIEW1 *)data;
0111 strcpy(vv->tstring3[2], "HELLO VIEW");
0112 }
0113 else if (0==strcmp(input_type, "UBF"))
0114 {
0115 if (EXSUCCEED!=Bchg((UBFH *)data, T_STRING_9_FLD, 4, "HELLO UBF CLIENT", 0L))
0116 {
0117 NDRX_LOG(log_error, "Failed to add T_STRING_9_FLD[4]: %s",
0118 Bstrerror(Berror));
0119 EXFAIL_OUT(ret);
0120 }
0121 }
0122 else if (0==strcmp(input_type, "NULL"))
0123 {
0124
0125 }
0126 else
0127 {
0128 NDRX_LOG(log_error, "Unsupported buffer type [%s]", input_type);
0129 EXFAIL_OUT(ret);
0130 }
0131
0132
0133
0134 if (EXSUCCEED!=tpcall(svc, data, len, &data, &len, flags))
0135 {
0136 NDRX_LOG(log_error, "Failed to call %s: %s", svc, tpstrerror(tperrno));
0137
0138
0139 tpcallerrgot = tperrno;
0140 }
0141
0142 if (tpcallerr!=tpcallerrgot)
0143 {
0144 NDRX_LOG(log_error, "TESTERROR! Expected %d error, but got: %d",
0145 tpcallerr, tpcallerrgot);
0146 EXFAIL_OUT(ret);
0147 }
0148
0149
0150
0151
0152
0153 NDRX_LOG(log_debug, "Response ptr: %p", data);
0154
0155 if (EXFAIL==tptypes(data, btype, stype))
0156 {
0157 NDRX_LOG(log_error, "TESTERROR! Failed to read buffer %p type: %s",
0158 data, tpstrerror(tperrno));
0159 EXFAIL_OUT(ret);
0160 }
0161
0162 if (0!=strcmp(output_type, btype))
0163 {
0164 NDRX_LOG(log_error, "TESTERROR! Expected response type [%s] but got [%s]",
0165 output_type, btype);
0166 EXFAIL_OUT(ret);
0167 }
0168
0169 if (0!=strcmp(output_sub, stype))
0170 {
0171 NDRX_LOG(log_error, "TESTERROR! Expected response sub-type [%s] but got [%s]",
0172 output_sub, stype);
0173 EXFAIL_OUT(ret);
0174 }
0175
0176 if (!validate)
0177 {
0178 NDRX_LOG(log_debug, "No validate");
0179 goto out;
0180 }
0181
0182
0183
0184 if (0==strcmp(output_type, "STRING"))
0185 {
0186 if (0!=strcmp(data, "WORLD"))
0187 {
0188 NDRX_LOG(log_error, "Test error, expected: [WORLD] got [%s]",
0189 data);
0190 EXFAIL_OUT(ret);
0191 }
0192 }
0193 else if (0==strcmp(output_type, "JSON"))
0194 {
0195 if (0!=strcmp(data, "{}"))
0196 {
0197 NDRX_LOG(log_error, "Test error, expected: [{}] got [%s]",
0198 data);
0199 EXFAIL_OUT(ret);
0200 }
0201 }
0202 else if (0==strcmp(output_type, "CARRAY"))
0203 {
0204 if (0!=strncmp(data, "SPACE", 5))
0205 {
0206 NDRX_LOG(log_error, "Test error, expected: [SPACE] got [%c%c%c%c%c]",
0207 data[0],data[1],data[2],data[3],data[4]);
0208 EXFAIL_OUT(ret);
0209 }
0210 }
0211 else if (0==strcmp(output_type, "VIEW"))
0212 {
0213 struct UBTESTVIEW2 *v = (struct UBTESTVIEW2 *)data;
0214
0215 if (0!=strcmp(v->tstring1, "TEST 55"))
0216 {
0217 NDRX_LOG(log_error, "Test error, expected: [TEST 55] got [%s]",
0218 v->tstring1);
0219 EXFAIL_OUT(ret);
0220 }
0221
0222 }
0223 else if (0==strcmp(output_type, "UBF"))
0224 {
0225 char tmp[128];
0226
0227 if (EXSUCCEED!=Bget((UBFH *)data, T_STRING_FLD, 1, tmp, 0L))
0228 {
0229 NDRX_LOG(log_error, "TESTERROR ! Failed to get data!");
0230 EXFAIL_OUT(ret);
0231 }
0232
0233 if (0!=strcmp(tmp, "HELLO WORLD"))
0234 {
0235 NDRX_LOG(log_error, "TESTERROR, expected: [HELLO WORLD] got [%s]",
0236 tmp);
0237 EXFAIL_OUT(ret);
0238 }
0239 }
0240 else if (0==strcmp(output_type, "NULL"))
0241 {
0242
0243 }
0244 else
0245 {
0246 NDRX_LOG(log_error, "Unsupported buffer type [%s]", input_type);
0247 EXFAIL_OUT(ret);
0248 }
0249
0250 out:
0251
0252 if (data!=NULL)
0253 {
0254 tpfree(data);
0255 }
0256
0257 return ret;
0258 }
0259
0260
0261
0262
0263 int main(int argc, char** argv)
0264 {
0265 int i;
0266 int ret=EXSUCCEED;
0267 char *bufs[] = {"NULL", "JSON", "STRING", "CARRAY", "VIEW", "UBF", ""};
0268 char **p;
0269 char subtyp[16];
0270 char osubtyp[16];
0271 char svcnm[XATMI_SERVICE_NAME_LENGTH+1];
0272 ndrx_growlist_t list;
0273 if (argc < 2)
0274 {
0275 NDRX_LOG(log_error, "Usage: %s NULL|JSON|STRING|"
0276 "CARRAY|VIEW|UBF", argv[0]);
0277 EXFAIL_OUT(ret);
0278 }
0279
0280
0281
0282
0283 snprintf(svcnm, sizeof(svcnm), "%sRSP", argv[1]);
0284
0285 if (0==strcmp(argv[1], "VIEW"))
0286 {
0287 NDRX_STRCPY_SAFE(osubtyp, "UBTESTVIEW2");
0288 }
0289 else
0290 {
0291 osubtyp[0]=EXEOS;
0292 }
0293
0294 for (i=0; i<1000; i++)
0295 {
0296 p = bufs;
0297
0298 while (*p[0]!=EXEOS)
0299 {
0300 int ret_err = 0;
0301 if (0==strcmp(*p, "VIEW"))
0302 {
0303 NDRX_STRCPY_SAFE(subtyp, "UBTESTVIEW1");
0304 }
0305 else
0306 {
0307 NDRX_STRCPY_SAFE(subtyp, "");
0308 }
0309
0310
0311 if (EXSUCCEED!=tester(svcnm, *p, subtyp, argv[1], osubtyp, 0L, 0, EXTRUE))
0312 {
0313 NDRX_LOG(log_error, "1 fail");
0314 EXFAIL_OUT(ret);
0315 }
0316
0317
0318 if (0!=strcmp(argv[1], *p) ||
0319
0320 0==strcmp(*p, "VIEW")
0321 )
0322 {
0323 ret_err = TPEOTYPE;
0324 }
0325
0326 if (EXSUCCEED!=tester(svcnm, *p, subtyp, *p, subtyp, TPNOCHANGE,
0327 ret_err, EXFALSE))
0328 {
0329 NDRX_LOG(log_error, "2 fail");
0330 EXFAIL_OUT(ret);
0331 }
0332
0333 p++;
0334 }
0335 }
0336
0337 out:
0338
0339
0340
0341
0342
0343 if (EXSUCCEED==ndrx_buffer_list(&list))
0344 {
0345 NDRX_LOG(log_debug, "buffers left: %d", list.maxindexused);
0346
0347 if (list.maxindexused > -1)
0348 {
0349 NDRX_LOG(log_error, "TESTERROR! Buffers in system: %d",
0350 list.maxindexused+1);
0351 ret=EXFAIL;
0352 }
0353 }
0354 else
0355 {
0356 ret=EXFAIL;
0357 }
0358
0359 tpterm();
0360 fprintf(stderr, "Exit with %d\n", ret);
0361
0362 return ret;
0363 }
0364
0365