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-2023, Mavimax, Ltd. All Rights Reserved.
0010  * This software is released under one of the following licenses:
0011  * AGPL (with Java and Go exceptions) or Mavimax's license for commercial use.
0012  * See LICENSE file for full text.
0013  * -----------------------------------------------------------------------------
0014  * AGPL license:
0015  *
0016  * This program is free software; you can redistribute it and/or modify it under
0017  * the terms of the GNU Affero General Public License, version 3 as published
0018  * by the Free Software Foundation;
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 Affero General Public License, version 3
0023  * for more details.
0024  *
0025  * You should have received a copy of the GNU Affero General Public License along 
0026  * with this program; if not, write to the Free Software Foundation, Inc.,
0027  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
0028  *
0029  * -----------------------------------------------------------------------------
0030  * A commercial use license is available from Mavimax, Ltd
0031  * contact@mavimax.com
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  * Receive some string & reply back with string, ok?
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     /* Return different block back */
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     /* Setup the values */
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  * Test View to JSON convert
0111  * @param p_svc
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     /* compare.. */
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     /* size not changed... */
0148     strcpy(buf, output);
0149     
0150 out:
0151     
0152     tpreturn(EXSUCCEED==ret?TPSUCCESS:TPFAIL, 0, buf, 0L, 0L);
0153 }
0154 
0155 
0156 /**
0157  * Process view recieved from json buffer
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  * Do initialisation
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  * Do de-initialisation
0259  */
0260 void NDRX_INTEGRA(tpsvrdone)(void)
0261 {
0262     NDRX_LOG(log_debug, "tpsvrdone called");
0263 }
0264 
0265 /* vim: set ts=4 sw=4 et smartindent: */