Back to home page

Enduro/X

 
 

    


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