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 "test040.h"
0044
0045 long M_subs_to_unsibscribe = -1;
0046
0047
0048
0049
0050 void TEST40_VIEW(TPSVCINFO *p_svc)
0051 {
0052 int ret = EXSUCCEED;
0053 char *buf = p_svc->data;
0054 char type[16+1]={EXEOS};
0055 char subtype[XATMI_SUBTYPE_LEN]={EXEOS};
0056
0057 NDRX_LOG(log_debug, "Into: %s", __func__);
0058
0059 if (EXFAIL==tptypes(buf, type, subtype))
0060 {
0061 NDRX_LOG(log_error, "TESTERROR: TEST40_VIEW cannot "
0062 "determine buffer type");
0063 EXFAIL_OUT(ret);
0064 }
0065
0066 if (0!=strcmp(type, "VIEW"))
0067 {
0068 NDRX_LOG(log_error, "TESTERROR: Buffer not VIEW!");
0069 EXFAIL_OUT(ret);
0070 }
0071
0072 NDRX_LOG(log_debug, "%s VIEW ok", __func__);
0073
0074 if (0!=strcmp(subtype, "MYVIEW1"))
0075 {
0076 NDRX_LOG(log_error, "TESTERROR: sub-type not MYVIEW1, but [%s]",
0077 subtype);
0078 EXFAIL_OUT(ret);
0079 }
0080
0081 NDRX_LOG(log_debug, "%s MYVIEW1 ok", __func__);
0082
0083 NDRX_LOG(log_debug, "%s About to compare data block..", __func__);
0084
0085 NDRX_LOG(log_error, "v1 OK, now BUF");
0086 if (EXSUCCEED!=validate_MYVIEW1((struct MYVIEW1 *)buf))
0087 {
0088 NDRX_LOG(log_error, "Invalid data recovered from FB!");
0089 EXFAIL_OUT(ret);
0090 }
0091 NDRX_LOG(log_error, "BUF OK");
0092
0093
0094 if (NULL==(buf = tpalloc("VIEW", "MYVIEW3", sizeof(struct MYVIEW3))))
0095 {
0096 NDRX_LOG(log_error, "Failed VIEW buffer: %s", tpstrerror(tperrno));
0097 EXFAIL_OUT(ret);
0098 }
0099
0100
0101 init_MYVIEW3((struct MYVIEW3 *)buf);
0102
0103
0104 out:
0105
0106 tpreturn(EXSUCCEED==ret?TPSUCCESS:TPFAIL, 0, buf, 0L, 0L);
0107 }
0108
0109
0110
0111
0112
0113 void TEST40_V2JSON(TPSVCINFO *p_svc)
0114 {
0115 int ret = EXSUCCEED;
0116 char *buf = p_svc->data;
0117 char type[16+1]={EXEOS};
0118 char subtype[XATMI_SUBTYPE_LEN]={EXEOS};
0119 char *input = "{\"MYVIEW3\":{\"tshort1\":1,\"tshort2\":2,\"tshort3\":3}}";
0120 char *output = "{\"MYVIEW3\":{\"tshort1\":4,\"tshort2\":5,\"tshort3\":6}}";
0121
0122 NDRX_LOG(log_debug, "Into: %s", __func__);
0123
0124 if (EXFAIL==tptypes(buf, type, subtype))
0125 {
0126 NDRX_LOG(log_error, "TESTERROR: TEST40_VIEW cannot "
0127 "determine buffer type");
0128 EXFAIL_OUT(ret);
0129 }
0130
0131 if (0!=strcmp(type, "JSON"))
0132 {
0133 NDRX_LOG(log_error, "TESTERROR: Buffer not JSON!");
0134 EXFAIL_OUT(ret);
0135 }
0136
0137 NDRX_LOG(log_debug, "%s JSON received ok: [%s]", __func__, buf);
0138
0139
0140 if (0!=strcmp(input, buf))
0141 {
0142 NDRX_LOG(log_error, "TESTERROR: Input of V2J not matched, expected: "
0143 "[%s] got [%s]", input, buf);
0144 EXFAIL_OUT(ret);
0145 }
0146
0147
0148 strcpy(buf, output);
0149
0150 out:
0151
0152 tpreturn(EXSUCCEED==ret?TPSUCCESS:TPFAIL, 0, buf, 0L, 0L);
0153 }
0154
0155
0156
0157
0158
0159 void TEST40_JSON2V(TPSVCINFO *p_svc)
0160 {
0161 int ret = EXSUCCEED;
0162 char *buf = p_svc->data;
0163 char type[16+1]={EXEOS};
0164 char subtype[XATMI_SUBTYPE_LEN]={EXEOS};
0165 struct MYVIEW3 *v3 = (struct MYVIEW3 *)buf;
0166
0167 NDRX_LOG(log_debug, "Into: %s", __func__);
0168
0169 if (EXFAIL==tptypes(buf, type, subtype))
0170 {
0171 NDRX_LOG(log_error, "TESTERROR: TEST40_VIEW cannot "
0172 "determine buffer type");
0173 EXFAIL_OUT(ret);
0174 }
0175
0176 if (0!=strcmp(type, "VIEW"))
0177 {
0178 NDRX_LOG(log_error, "TESTERROR: Buffer not VIEW!");
0179 EXFAIL_OUT(ret);
0180 }
0181
0182 NDRX_LOG(log_debug, "%s VIEW ok", __func__);
0183
0184 if (0!=strcmp(subtype, "MYVIEW3"))
0185 {
0186 NDRX_LOG(log_error, "TESTERROR: sub-type not MYVIEW3, but [%s]",
0187 subtype);
0188 EXFAIL_OUT(ret);
0189 }
0190
0191 NDRX_LOG(log_debug, "%s About to compare data block..", __func__);
0192
0193 if (6!=v3->tshort1)
0194 {
0195 NDRX_LOG(log_error, "TESTERROR: tshort1 must be 6 but must be %hd",
0196 v3->tshort1);
0197 EXFAIL_OUT(ret);
0198 }
0199
0200 if (7!=v3->tshort2)
0201 {
0202 NDRX_LOG(log_error, "TESTERROR: tshort2 must be 7 but must be %hd",
0203 v3->tshort2);
0204 EXFAIL_OUT(ret);
0205 }
0206
0207 if (8!=v3->tshort3)
0208 {
0209 NDRX_LOG(log_error, "TESTERROR: tshort3 must be 8 but must be %hd",
0210 v3->tshort3);
0211 EXFAIL_OUT(ret);
0212 }
0213
0214 v3->tshort1 = 9;
0215 v3->tshort2 = 1;
0216 v3->tshort3 = 2;
0217
0218 out:
0219
0220 tpreturn(EXSUCCEED==ret?TPSUCCESS:TPFAIL, 0, buf, 0L, 0L);
0221 }
0222
0223
0224
0225
0226
0227
0228 int NDRX_INTEGRA(tpsvrinit)(int argc, char **argv)
0229 {
0230 int ret=EXSUCCEED;
0231
0232 NDRX_LOG(log_debug, "tpsvrinit called");
0233
0234
0235 if (EXSUCCEED!=tpadvertise("TEST40_VIEW", TEST40_VIEW))
0236 {
0237 NDRX_LOG(log_error, "Failed to initialise TEST40_VIEW!");
0238 EXFAIL_OUT(ret);
0239 }
0240
0241 if (EXSUCCEED!=tpadvertise("TEST40_V2JSON", TEST40_V2JSON))
0242 {
0243 NDRX_LOG(log_error, "Failed to initialise TEST40_V2JSON!");
0244 EXFAIL_OUT(ret);
0245 }
0246
0247 if (EXSUCCEED!=tpadvertise("TEST40_JSON2V", TEST40_JSON2V))
0248 {
0249 NDRX_LOG(log_error, "Failed to initialise TEST40_JSON2V!");
0250 EXFAIL_OUT(ret);
0251 }
0252
0253 out:
0254 return ret;
0255 }
0256
0257
0258
0259
0260 void NDRX_INTEGRA(tpsvrdone)(void)
0261 {
0262 NDRX_LOG(log_debug, "tpsvrdone called");
0263 }
0264
0265