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
0035 #include <stdio.h>
0036 #include <stdlib.h>
0037 #include <ndebug.h>
0038 #include <atmi.h>
0039 #include <ndrstandard.h>
0040 #include <ubf.h>
0041 #include <test.fd.h>
0042 #include <string.h>
0043 #include "test026.h"
0044
0045
0046
0047
0048 void TEST26_UBF2JSON(TPSVCINFO *p_svc)
0049 {
0050 int ret = EXSUCCEED;
0051 char *buf = p_svc->data;
0052 char type[16+1]={EXEOS};
0053
0054 if (EXFAIL==tptypes(buf, type, NULL))
0055 {
0056 NDRX_LOG(log_error, "TESTERROR: TEST26_UBF2JSON cannot "
0057 "determine buffer type");
0058 EXFAIL_OUT(ret);
0059 }
0060
0061 if (0!=strcmp(type, "JSON"))
0062 {
0063 NDRX_LOG(log_error, "TESTERROR: Buffer not JSON, but [%s]!", type);
0064 EXFAIL_OUT(ret);
0065 }
0066
0067 if (0!=strcmp(buf, "{\"T_STRING_FLD\":\"HELLO FROM UBF\",\"T_PTR_FLD\":{\"buftype\":\"UBF\",\"version\":1,\"data\":{\"T_STRING_FLD\":\"HELLO FROM INNER\"}}}"))
0068 {
0069 NDRX_LOG(log_error, "TESTERROR: Invalid request!");
0070 EXFAIL_OUT(ret);
0071 }
0072
0073 if (NULL== (buf = tprealloc(buf, 1024)))
0074 {
0075 NDRX_LOG(log_error, "TESTERROR: realloc fail!");
0076 EXFAIL_OUT(ret);
0077 }
0078
0079 strcpy(buf, "{\"T_STRING_FLD\":[\"HELLO FROM UBF\", \"HELLO FROM JSON!\"], "
0080 "\"T_LONG_FLD\":1001,"
0081 "\"T_PTR_FLD\":{\"buftype\":\"UBF\",\"version\":1,\"data\":{\"T_STRING_FLD\":\"HELLO FROM INNER\"}}}");
0082
0083 NDRX_LOG(log_debug, "Sending buffer: [%s]", buf);
0084
0085 out:
0086
0087 tpreturn(EXSUCCEED==ret?TPSUCCESS:TPFAIL, 0, buf, 0L, 0L);
0088
0089 }
0090
0091
0092
0093
0094 void TEST26_JSON2UBF(TPSVCINFO *p_svc)
0095 {
0096 int ret = EXSUCCEED;
0097 UBFH *buf = (UBFH *)p_svc->data;
0098 char tmp[1024];
0099 char type[16+1]={EXEOS};
0100
0101 if (EXFAIL==tptypes((char *)buf, type, NULL))
0102 {
0103 NDRX_LOG(log_error, "TESTERROR: TEST26_JSON2UBF cannot "
0104 "determine buffer type");
0105 EXFAIL_OUT(ret);
0106 }
0107
0108 if (0!=strcmp(type, "UBF"))
0109 {
0110 NDRX_LOG(log_error, "TESTERROR: Buffer not UBF buf: %s!", type);
0111 EXFAIL_OUT(ret);
0112 }
0113
0114 if (EXSUCCEED!=Bget(buf, T_STRING_FLD, 0, tmp, 0L))
0115 {
0116 NDRX_LOG(log_error, "TESTERROR: T_STRING_FLD[0] not set!");
0117 EXFAIL_OUT(ret);
0118 }
0119
0120 if (0!=strcmp(tmp, "HELLO UBF FROM JSON 1!"))
0121 {
0122 NDRX_LOG(log_error, "TESTERROR: Invalid request value [%s] in T_STRING_FLD[0]",
0123 tmp);
0124 EXFAIL_OUT(ret);
0125 }
0126
0127 if (EXSUCCEED!=Bget(buf, T_STRING_FLD, 1, tmp, 0L))
0128 {
0129 NDRX_LOG(log_error, "TESTERROR: T_STRING_FLD[1] not set!");
0130 EXFAIL_OUT(ret);
0131 }
0132
0133 if (0!=strcmp(tmp, "HELLO UBF FROM JSON 2!"))
0134 {
0135 NDRX_LOG(log_error, "TESTERROR: Invalid request value [%s] in T_STRING_FLD[1]",
0136 tmp);
0137 EXFAIL_OUT(ret);
0138 }
0139
0140 if (EXSUCCEED!=Bchg(buf, T_STRING_FLD, 2, "HELLO FROM UBF!", 0L))
0141 {
0142 NDRX_LOG(log_error, "TESTERROR: Failed to set T_LONG_FLD!: %s", Bstrerror(Berror));
0143 EXFAIL_OUT(ret);
0144 }
0145
0146 out:
0147
0148 tpreturn(EXSUCCEED==ret?TPSUCCESS:TPFAIL, 0, (char *)buf, 0L, 0L);
0149
0150 }
0151
0152
0153
0154
0155 int NDRX_INTEGRA(tpsvrinit)(int argc, char **argv)
0156 {
0157 int ret=EXSUCCEED;
0158
0159 NDRX_LOG(log_debug, "tpsvrinit called");
0160
0161 if (EXSUCCEED!=tpadvertise("TEST26_UBF2JSON", TEST26_UBF2JSON))
0162 {
0163 NDRX_LOG(log_error, "Failed to initialize TEST26_UBF2JSON!");
0164 ret=EXFAIL;
0165 }
0166
0167 if (EXSUCCEED!=tpadvertise("TEST26_JSON2UBF", TEST26_JSON2UBF))
0168 {
0169 NDRX_LOG(log_error, "Failed to initialize TEST26_JSON2UBF!");
0170 ret=EXFAIL;
0171 }
0172
0173 out:
0174 return ret;
0175 }
0176
0177
0178
0179
0180 void NDRX_INTEGRA(tpsvrdone)(void)
0181 {
0182 NDRX_LOG(log_debug, "tpsvrdone called");
0183 }
0184
0185