Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief Test TPSVCINFO.len - client
0003  *
0004  * @file atmiclt99.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 #include <string.h>
0035 #include <stdio.h>
0036 #include <stdlib.h>
0037 #include <memory.h>
0038 #include <math.h>
0039 
0040 #include <atmi.h>
0041 #include <ubf.h>
0042 #include <ndebug.h>
0043 #include <test.fd.h>
0044 #include <ndrstandard.h>
0045 #include <nstopwatch.h>
0046 #include <fcntl.h>
0047 #include <unistd.h>
0048 #include <nstdutil.h>
0049 #include "test99.h"
0050 #include <test_view.h>
0051 #include <exassert.h>
0052 
0053 /*---------------------------Externs------------------------------------*/
0054 /*---------------------------Macros-------------------------------------*/
0055 /*---------------------------Enums--------------------------------------*/
0056 /*---------------------------Typedefs-----------------------------------*/
0057 typedef struct
0058 {
0059     char *ptr;
0060     long len;
0061 } test_buffer_t;
0062 /*---------------------------Globals------------------------------------*/
0063 /*---------------------------Statics------------------------------------*/
0064 /*---------------------------Prototypes---------------------------------*/
0065 
0066 /**
0067  * Do the test call to the server
0068  */
0069 int main(int argc, char** argv)
0070 {
0071 
0072     char *p_ub = tpalloc("UBF", NULL, 56000);
0073     char *str = tpalloc("STRING", NULL, 56000);
0074     char *carr = tpalloc("CARRAY", NULL, 56000);
0075     char *json = tpalloc("JSON", NULL, 56000);
0076     char *view = tpalloc("VIEW", "UBTESTVIEW1", sizeof(struct UBTESTVIEW1));
0077     char *ret_buf = NULL;
0078     long rsplen, revent;
0079     int cd, i;
0080     int ret=EXSUCCEED;
0081 
0082     NDRX_ASSERT_VAL_OUT(NULL!=p_ub, "p_ub failed to alloc");
0083     NDRX_ASSERT_VAL_OUT(NULL!=str, "str failed to alloc");
0084     NDRX_ASSERT_VAL_OUT(NULL!=json, "json failed to alloc");
0085     NDRX_ASSERT_VAL_OUT(NULL!=view, "view failed to alloc");
0086     
0087     test_buffer_t bufs[] = {{p_ub, 0}, {str, 0}, {carr, 5}, {json, 0}, {view, 0}, {NULL, 0}};
0088     char *p;
0089 
0090     strcpy(str, "hello");
0091     strcpy(carr, "world");
0092     strcpy(json, "{}");
0093 
0094     for (i=0; i<N_DIM(bufs); i++)
0095     {
0096         if (EXFAIL == tpcall("TESTSV", bufs[i].ptr, bufs[i].len, (char **)&ret_buf, &rsplen,0))
0097         {
0098             NDRX_LOG(log_error, "TESTSV failed (%d): %s", i, tpstrerror(tperrno));
0099             ret=EXFAIL;
0100             goto out;
0101         }
0102     }
0103 
0104     /* test conv: */
0105     for (i=0; i<N_DIM(bufs); i++)
0106     {
0107 
0108         if (EXFAIL==(cd = tpconnect("TESTSV", bufs[i].ptr, bufs[i].len, TPRECVONLY)))
0109         {
0110             NDRX_LOG(log_error, "TESTSV tpconnect failed (%d): %s", i, tpstrerror(tperrno));
0111             ret=EXFAIL;
0112             goto out;
0113         }
0114 
0115         revent=0;
0116         if (EXFAIL==tprecv(cd, (char **)&p_ub, &rsplen, 0, &revent))
0117         {
0118             if (TPEEVENT!=tperrno || TPEV_SVCSUCC!=revent)
0119             {
0120                 NDRX_LOG(log_error, "TESTSV tprecv failed (%d): %s %ld", i, tpstrerror(tperrno), revent);
0121                 ret=EXFAIL;
0122                 goto out;
0123             }
0124         }
0125     }
0126 
0127 out:
0128     tpterm();
0129     fprintf(stderr, "Exit with %d\n", ret);
0130 
0131     return ret;
0132 }
0133 
0134 /* vim: set ts=4 sw=4 et smartindent: */