Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief Basic test client
0003  *
0004  * @file atmiclt005.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 
0039 #include <atmi.h>
0040 #include <ubf.h>
0041 #include <ndebug.h>
0042 #include <test.fd.h>
0043 #include <ndrstandard.h>
0044 /*---------------------------Externs------------------------------------*/
0045 /*---------------------------Macros-------------------------------------*/
0046 /*---------------------------Enums--------------------------------------*/
0047 /*---------------------------Typedefs-----------------------------------*/
0048 /*---------------------------Globals------------------------------------*/
0049 /*---------------------------Statics------------------------------------*/
0050 /*---------------------------Prototypes---------------------------------*/
0051 
0052 /**
0053  * This basically tests the normal case when all have been finished OK!
0054  * @return
0055  */
0056 int test_normal_case(void)
0057 {
0058     UBFH *p_ub = (UBFH *)tpalloc("UBF", NULL, 1024);
0059     int ret=EXSUCCEED;
0060     int cd;
0061     long revent;
0062     int recv_continue = 1;
0063     int tp_errno;
0064     int rcv_count = 0;
0065     if (EXFAIL == (cd = tpconnect("CONVSV",
0066                                     NULL,
0067                                     0,
0068                                     TPNOTRAN | /* untl XA   */
0069                                     TPSENDONLY)))
0070     {
0071         NDRX_LOG(log_error, "TESTERROR: connect error %d", tperrno );
0072         ret = EXFAIL;
0073         goto out;
0074     }
0075     NDRX_LOG(log_debug, "Connected OK, cd = %d", cd );
0076 
0077     /* Now send configuration paramters */
0078 
0079     if (EXFAIL==Bchg(p_ub, T_STRING_2_FLD, 0, "TERMINAL_T", 0L))
0080     {
0081         NDRX_LOG(log_error, "TESTERROR: failed to set T_STRING_2_FLD: %d",
0082                                         Berror );
0083         ret = EXFAIL;
0084         goto out;
0085     }
0086 
0087     /* Send the configuration stuff to the server */
0088     if (EXFAIL == tpsend(cd, (char *)p_ub, 0L, TPRECVONLY, &revent))
0089     {
0090         tp_errno = tperrno;
0091         if (TPEEVENT == tp_errno)
0092         {
0093             NDRX_LOG(log_error,
0094                              "TESTERROR: Unexpected conv event %lx", revent );
0095         }
0096         else
0097         {
0098                 NDRX_LOG(log_error, "send error %d", tp_errno );
0099         }
0100         ret = EXFAIL;
0101         goto out;
0102     }
0103 
0104     while (recv_continue)
0105     {
0106         recv_continue=0;
0107         if (EXFAIL == tprecv(cd,
0108                             (char **)&p_ub,
0109                             0L,
0110                             0L,
0111                             &revent))
0112         {
0113             ret = EXFAIL;
0114             tp_errno = tperrno;
0115             if (TPEEVENT == tp_errno)
0116             {
0117                     if (TPEV_SENDONLY == revent)
0118                     {
0119                         if (EXFAIL == tpsend(cd, NULL,
0120                                          0L, TPRECVONLY, &revent))
0121                         {
0122                             NDRX_LOG(log_error,
0123                                      "TESTERROR: Send failed %d", tperrno);
0124                             ret=EXFAIL;
0125                             goto out;
0126                         }
0127                         else
0128                         {
0129                             recv_continue=1;
0130                             ret = EXSUCCEED;
0131                         }
0132                     }
0133                     else if (TPEV_SVCSUCC == revent)
0134                             ret = EXSUCCEED;
0135                     else
0136                     {
0137                         NDRX_LOG(log_error,
0138                                  "TESTERROR: Unexpected conv event %lx", revent );
0139                         ret=EXFAIL;
0140                         goto out;
0141                     }
0142             }
0143             else
0144             {
0145                 NDRX_LOG(log_error, "TESTERROR: recv error %d", tp_errno  );
0146                 ret = EXFAIL;
0147                 goto out;
0148             }
0149         }
0150         else
0151         {
0152             Bfprint(p_ub, stderr);
0153             rcv_count++;
0154             recv_continue=1;
0155         }
0156     }
0157 
0158     if (100!=rcv_count)
0159     {
0160         NDRX_LOG(log_error, "TESTERROR: Did not receive 100x config details, but %d!!!", rcv_count);
0161         ret=EXFAIL;
0162         goto out;
0163     }
0164 
0165 out:
0166     return ret;
0167 }
0168 
0169 /**
0170  * TODO: Test the case when client aborts!
0171  * We will see how the actually server acts in this case??!?!
0172  */
0173 int test_clt_abort_case(void)
0174 {
0175     int ret=EXSUCCEED;
0176     
0177 out:
0178     return ret;
0179 }
0180 /*
0181  * Do the test call to the server
0182  */
0183 int main(int argc, char** argv) {
0184     int ret=EXSUCCEED;
0185 
0186     if (EXFAIL==test_normal_case())
0187     {
0188         ret=EXFAIL;
0189         goto out;
0190     }
0191     
0192 out:
0193     tpterm();
0194     return ret;
0195 }
0196 
0197 /* vim: set ts=4 sw=4 et smartindent: */