Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief DDR functionality tests - client
0003  *
0004  * @file atmiclt84.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 "test84.h"
0050 #include <unistd.h>
0051 /*---------------------------Externs------------------------------------*/
0052 /*---------------------------Macros-------------------------------------*/
0053 /*---------------------------Enums--------------------------------------*/
0054 /*---------------------------Typedefs-----------------------------------*/
0055 /*---------------------------Globals------------------------------------*/
0056 /*---------------------------Statics------------------------------------*/
0057 /*---------------------------Prototypes---------------------------------*/
0058 
0059 /**
0060  * Do the test call to the server
0061  */
0062 int main(int argc, char** argv)
0063 {
0064     UBFH *p_ub = (UBFH *)tpalloc("UBF", NULL, 56000);
0065     long rsplen;
0066     int ret=EXSUCCEED;
0067     char svcnm_proc[1024]={EXEOS}; /* service name which shall process request */
0068     int e=0; /* error expected */
0069     int c;
0070     char svcnm[XATMI_SERVICE_NAME_LENGTH+1]={EXEOS};
0071     char tmp[1024];
0072     int do_conv=EXFALSE;
0073     int do_null=EXFALSE;
0074     
0075     /* We shall parse cli, so field with will either:
0076      * -l (long)
0077      * -s (string)
0078      * -c (carray value)
0079      * -S Service name
0080      * -d (double)
0081      * -e <error code expected>
0082      * -g <group value expected in return>
0083      */
0084     while ((c = getopt(argc, argv, "S:s:l:d:e:g:Cc:N")) != -1) {
0085         
0086         switch (c)
0087         {
0088             case 'N':
0089                 do_null=EXTRUE;
0090                 break;
0091             case 'C':
0092                 NDRX_LOG(log_debug, "Doing conv");
0093                 do_conv=EXTRUE;
0094                 break;
0095             case 'S':
0096                 NDRX_STRCPY_SAFE(svcnm, optarg);
0097                 break;
0098             case 'g':
0099                 NDRX_STRCPY_SAFE(svcnm_proc, optarg);
0100                 break;
0101             case 'e':
0102                 e = atoi(optarg);
0103                 break;
0104             case 'l':
0105                 if (EXFAIL==CBchg(p_ub, T_LONG_2_FLD, 0, optarg, 0, BFLD_STRING))
0106                 {
0107                     NDRX_LOG(log_debug, "Failed to set T_LONG_2_FLD[0]: %s", Bstrerror(Berror));
0108                     ret=EXFAIL;
0109                     goto out;
0110                 }
0111                 break;
0112             case 's':
0113                 if (EXFAIL==CBchg(p_ub, T_STRING_2_FLD, 0, optarg, 0, BFLD_STRING))
0114                 {
0115                     NDRX_LOG(log_debug, "Failed to set T_STRING_2_FLD[0]: %s", Bstrerror(Berror));
0116                     ret=EXFAIL;
0117                     goto out;
0118                 }
0119                 break;
0120             case 'c':
0121                 if (EXFAIL==CBchg(p_ub, T_CARRAY_2_FLD, 0, optarg, 0, BFLD_STRING))
0122                 {
0123                     /* load carray... */
0124                     NDRX_LOG(log_debug, "Failed to set T_CARRAY_2_FLD[0]: %s", Bstrerror(Berror));
0125                     ret=EXFAIL;
0126                     goto out;
0127                 }
0128                 break;
0129             case 'd':
0130                 if (EXFAIL==CBchg(p_ub, T_DOUBLE_2_FLD, 0, optarg, 0, BFLD_STRING))
0131                 {
0132                     NDRX_LOG(log_debug, "Failed to set T_DOUBLE_2_FLD[0]: %s", Bstrerror(Berror));
0133                     ret=EXFAIL;
0134                     goto out;
0135                 }
0136                 break;
0137             default: /* '?' */
0138                 fprintf(stderr, "Usage: %s -S <service_name> -e <errcode_expt> -g <proc_service> -l <long_val>|-s <string_val>|-d <double_val> [-N]\n",
0139                         argv[0]);
0140                 exit(EXIT_FAILURE);
0141         }
0142     }
0143     
0144     tplogprintubf(log_debug, "UBF buffer", p_ub);
0145 
0146     /* call the service */
0147     if (do_conv)
0148     {
0149         long ev;
0150         int cd;
0151         long rcvlen;
0152         /* try to connect */
0153         if (EXFAIL == (cd=tpconnect(svcnm, (char *)p_ub, 0L, TPRECVONLY)))
0154         {
0155             NDRX_LOG(log_error, "%s failed: %s", svcnm, tpstrerror(tperrno));
0156             /* check error code */
0157             if (tperrno!=e)
0158             {
0159                 NDRX_LOG(log_error, "TESTERROR: Expected error %d got %d", e, tperrno);
0160                 ret=EXFAIL;
0161             }
0162             goto out;
0163         }
0164         
0165         if (EXSUCCEED==tprecv(cd, (char **)&p_ub, &rcvlen, 0, &ev))
0166         {
0167             NDRX_LOG(log_error, "TESTERROR: Expected con error!");
0168             EXFAIL_OUT(ret);
0169         }
0170         else if (tperrno!=TPEEVENT)
0171         {
0172             NDRX_LOG(log_error, "%s failed: %s", svcnm, tpstrerror(tperrno));
0173             /* check error code */
0174             if (tperrno!=e)
0175             {
0176                 NDRX_LOG(log_error, "TESTERROR: Expected error %d got %d", e, tperrno);
0177                 EXFAIL_OUT(ret);
0178             }
0179         }
0180     }
0181     else if (EXFAIL == tpcall(svcnm, do_null?NULL:((char *)p_ub), 0L, (char **)&p_ub, &rsplen,0))
0182     {
0183         NDRX_LOG(log_error, "%s failed: %s", svcnm, tpstrerror(tperrno));
0184         
0185         /* check error code */
0186         if (tperrno!=e)
0187         {
0188             NDRX_LOG(log_error, "TESTERROR: Expected error %d got %d", e, tperrno);
0189             ret=EXFAIL;
0190         }
0191         goto out;
0192     }
0193     
0194     if (!do_null)
0195     {
0196         if (EXSUCCEED!=Bget(p_ub, T_STRING_FLD, 0, tmp, 0L))
0197         {
0198             NDRX_LOG(log_debug, "Failed to get T_STRING_FLD[0]: %s", Bstrerror(Berror));
0199             ret=EXFAIL;
0200             goto out;
0201         }
0202 
0203         if (0!=strcmp(tmp, svcnm_proc))
0204         {
0205             NDRX_LOG(log_error, "TESTERROR: Expected service [%s] to process request, but got [%s]",
0206                     svcnm_proc, tmp);
0207             EXFAIL_OUT(ret);
0208         }
0209     }
0210     
0211 out:
0212     tpterm();
0213     fprintf(stderr, "Exit with %d\n", ret);
0214 
0215     return ret;
0216 }
0217 
0218 /* vim: set ts=4 sw=4 et smartindent: */