Back to home page

Enduro/X

 
 

    


0001 /* 
0002 ** Typed VIEW tests
0003 **
0004 ** @file atmisv40.c
0005 ** 
0006 ** -----------------------------------------------------------------------------
0007 ** Enduro/X Middleware Platform for Distributed Transaction Processing
0008 ** Copyright (C) 2015, Mavimax, Ltd. All Rights Reserved.
0009 ** This software is released under one of the following licenses:
0010 ** GPL or Mavimax's license for commercial use.
0011 ** -----------------------------------------------------------------------------
0012 ** GPL license:
0013 ** 
0014 ** This program is free software; you can redistribute it and/or modify it under
0015 ** the terms of the GNU General Public License as published by the Free Software
0016 ** Foundation; either version 2 of the License, or (at your option) any later
0017 ** version.
0018 **
0019 ** This program is distributed in the hope that it will be useful, but WITHOUT ANY
0020 ** WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
0021 ** PARTICULAR PURPOSE. See the GNU General Public License for more details.
0022 **
0023 ** You should have received a copy of the GNU General Public License along with
0024 ** this program; if not, write to the Free Software Foundation, Inc., 59 Temple
0025 ** Place, Suite 330, Boston, MA 02111-1307 USA
0026 **
0027 ** -----------------------------------------------------------------------------
0028 ** A commercial use license is available from Mavimax, Ltd
0029 ** contact@mavimax.com
0030 ** -----------------------------------------------------------------------------
0031 */
0032 
0033 #include <stdio.h>
0034 #include <stdlib.h>
0035 #include <ndebug.h>
0036 #include <atmi.h>
0037 #include <ndrstandard.h>
0038 #include <ubf.h>
0039 #include <test.fd.h>
0040 #include <string.h>
0041 #include "test040.h"
0042 
0043 long M_subs_to_unsibscribe = -1;
0044 
0045 /**
0046  * Receive some string & reply back with string, ok?
0047  */
0048 void TEST40_VIEW(TPSVCINFO *p_svc)
0049 {
0050     int ret = EXSUCCEED;
0051     char *buf = p_svc->data;
0052     char type[16+1]={EXEOS};
0053     char subtype[XATMI_SUBTYPE_LEN]={EXEOS};
0054     
0055     NDRX_LOG(log_debug, "Into: %s", __func__);
0056     
0057     if (EXFAIL==tptypes(buf, type, subtype))
0058     {
0059         NDRX_LOG(log_error, "TESTERROR: TEST40_VIEW cannot "
0060                 "determine buffer type");
0061         EXFAIL_OUT(ret);
0062     }
0063     
0064     if (0!=strcmp(type, "VIEW"))
0065     {
0066         NDRX_LOG(log_error, "TESTERROR: Buffer not VIEW!");
0067         EXFAIL_OUT(ret);
0068     }
0069     
0070     NDRX_LOG(log_debug, "%s VIEW ok", __func__);
0071     
0072     if (0!=strcmp(subtype, "MYVIEW1"))
0073     {
0074         NDRX_LOG(log_error, "TESTERROR: sub-type not MYVIEW1, but [%s]", 
0075                 subtype);
0076         EXFAIL_OUT(ret);
0077     }
0078     
0079     NDRX_LOG(log_debug, "%s MYVIEW1 ok", __func__);
0080         
0081     NDRX_LOG(log_debug, "%s About to compare data block..", __func__);
0082     
0083     NDRX_LOG(log_error, "v1 OK, now BUF")
0084     if (EXSUCCEED!=validate_MYVIEW1((struct MYVIEW1 *)buf))
0085     {
0086         NDRX_LOG(log_error, "Invalid data recovered from FB!");
0087         EXFAIL_OUT(ret);
0088     }
0089     NDRX_LOG(log_error, "BUF OK")
0090     
0091     /* Return different block back */
0092     if (NULL==(buf = tpalloc("VIEW", "MYVIEW3", sizeof(struct MYVIEW3))))
0093     {
0094         NDRX_LOG(log_error, "Failed VIEW buffer: %s", tpstrerror(tperrno));
0095         EXFAIL_OUT(ret);
0096     }
0097     
0098     /* Setup the values */
0099     init_MYVIEW3((struct MYVIEW3 *)buf);
0100     
0101     
0102 out:
0103     
0104     tpreturn(EXSUCCEED==ret?TPSUCCESS:TPFAIL, 0, buf, 0L, 0L);
0105 }
0106 
0107 /**
0108  * Test View to JSON convert
0109  * @param p_svc
0110  */
0111 void TEST40_V2JSON(TPSVCINFO *p_svc)
0112 {
0113     int ret = EXSUCCEED;
0114     char *buf = p_svc->data;
0115     char type[16+1]={EXEOS};
0116     char subtype[XATMI_SUBTYPE_LEN]={EXEOS};
0117     char *input = "{\"MYVIEW3\":{\"tshort1\":1,\"tshort2\":2,\"tshort3\":3}}";
0118     char *output = "{\"MYVIEW3\":{\"tshort1\":4,\"tshort2\":5,\"tshort3\":6}}";
0119     
0120     NDRX_LOG(log_debug, "Into: %s", __func__);
0121     
0122     if (EXFAIL==tptypes(buf, type, subtype))
0123     {
0124         NDRX_LOG(log_error, "TESTERROR: TEST40_VIEW cannot "
0125                 "determine buffer type");
0126         EXFAIL_OUT(ret);
0127     }
0128     
0129     if (0!=strcmp(type, "JSON"))
0130     {
0131         NDRX_LOG(log_error, "TESTERROR: Buffer not JSON!");
0132         EXFAIL_OUT(ret);
0133     }
0134     
0135     NDRX_LOG(log_debug, "%s JSON received ok: [%s]", __func__, buf);
0136     
0137     /* compare.. */
0138     if (0!=strcmp(input, buf))
0139     {
0140         NDRX_LOG(log_error, "TESTERROR: Input of V2J not matched, expected: "
0141                 "[%s] got [%s]", input, buf);
0142         EXFAIL_OUT(ret);
0143     }
0144     
0145     /* size not changed... */
0146     strcpy(buf, output);
0147     
0148 out:
0149     
0150     tpreturn(EXSUCCEED==ret?TPSUCCESS:TPFAIL, 0, buf, 0L, 0L);
0151 }
0152 
0153 
0154 /**
0155  * Process view recieved from json buffer
0156  */
0157 void TEST40_JSON2V(TPSVCINFO *p_svc)
0158 {
0159     int ret = EXSUCCEED;
0160     char *buf = p_svc->data;
0161     char type[16+1]={EXEOS};
0162     char subtype[XATMI_SUBTYPE_LEN]={EXEOS};
0163     struct MYVIEW3 *v3 = (struct MYVIEW3 *)buf;
0164     
0165     NDRX_LOG(log_debug, "Into: %s", __func__);
0166     
0167     if (EXFAIL==tptypes(buf, type, subtype))
0168     {
0169         NDRX_LOG(log_error, "TESTERROR: TEST40_VIEW cannot "
0170                 "determine buffer type");
0171         EXFAIL_OUT(ret);
0172     }
0173     
0174     if (0!=strcmp(type, "VIEW"))
0175     {
0176         NDRX_LOG(log_error, "TESTERROR: Buffer not VIEW!");
0177         EXFAIL_OUT(ret);
0178     }
0179     
0180     NDRX_LOG(log_debug, "%s VIEW ok", __func__);
0181     
0182     if (0!=strcmp(subtype, "MYVIEW3"))
0183     {
0184         NDRX_LOG(log_error, "TESTERROR: sub-type not MYVIEW3, but [%s]", 
0185                 subtype);
0186         EXFAIL_OUT(ret);
0187     }
0188          
0189     NDRX_LOG(log_debug, "%s About to compare data block..", __func__);
0190 
0191     if (6!=v3->tshort1)
0192     {
0193         NDRX_LOG(log_error, "TESTERROR: tshort1 must be 6 but must be %hd",
0194                 v3->tshort1);
0195         EXFAIL_OUT(ret);
0196     }
0197     
0198     if (7!=v3->tshort2)
0199     {
0200         NDRX_LOG(log_error, "TESTERROR: tshort2 must be 7 but must be %hd",
0201                 v3->tshort2);
0202         EXFAIL_OUT(ret);
0203     }
0204     
0205     if (8!=v3->tshort3)
0206     {
0207         NDRX_LOG(log_error, "TESTERROR: tshort3 must be 8 but must be %hd",
0208                 v3->tshort3);
0209         EXFAIL_OUT(ret);
0210     }
0211     
0212     v3->tshort1 = 9;
0213     v3->tshort2 = 1;
0214     v3->tshort3 = 2;
0215 
0216 out:
0217     
0218     tpreturn(EXSUCCEED==ret?TPSUCCESS:TPFAIL, 0, buf, 0L, 0L);
0219 }
0220 
0221 
0222 
0223 /**
0224  * Do initialisation
0225  */
0226 int NDRX_INTEGRA(tpsvrinit)(int argc, char **argv)
0227 {
0228     int ret=EXSUCCEED;
0229     
0230     NDRX_LOG(log_debug, "tpsvrinit called");
0231 
0232 
0233     if (EXSUCCEED!=tpadvertise("TEST40_VIEW", TEST40_VIEW))
0234     {
0235         NDRX_LOG(log_error, "Failed to initialise TEST40_VIEW!");
0236         EXFAIL_OUT(ret);
0237     }
0238     
0239     if (EXSUCCEED!=tpadvertise("TEST40_V2JSON", TEST40_V2JSON))
0240     {
0241         NDRX_LOG(log_error, "Failed to initialise TEST40_V2JSON!");
0242         EXFAIL_OUT(ret);
0243     }
0244     
0245     if (EXSUCCEED!=tpadvertise("TEST40_JSON2V", TEST40_JSON2V))
0246     {
0247         NDRX_LOG(log_error, "Failed to initialise TEST40_JSON2V!");
0248         EXFAIL_OUT(ret);
0249     }
0250 
0251 out:
0252     return ret;
0253 }
0254 
0255 /**
0256  * Do de-initialisation
0257  */
0258 void NDRX_INTEGRA(tpsvrdone)(void)
0259 {
0260     NDRX_LOG(log_debug, "tpsvrdone called");
0261 }
0262