Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief Test the tpconvert() function
0003  *
0004  * @file atmiclt21-tpconvert.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 #include <unistd.h>
0040 
0041 #include <atmi.h>
0042 #include <ubf.h>
0043 #include <ndebug.h>
0044 #include <test.fd.h>
0045 #include <ndrstandard.h>
0046 #include <nstopwatch.h>
0047 /*---------------------------Externs------------------------------------*/
0048 /*---------------------------Macros-------------------------------------*/
0049 /*---------------------------Enums--------------------------------------*/
0050 /*---------------------------Typedefs-----------------------------------*/
0051 /*---------------------------Globals------------------------------------*/
0052 /*---------------------------Statics------------------------------------*/
0053 /*---------------------------Prototypes---------------------------------*/
0054 
0055 /*
0056  * Do the test call to the server
0057  */
0058 int main(int argc, char** argv) {
0059 
0060     UBFH *p_ub = (UBFH *)tpalloc("UBF", NULL, 9216);
0061     long rsplen;
0062     int ret=EXSUCCEED;
0063     TPTRANID t;
0064     char cnvstr[TPCONVMAXSTR];
0065     char cnvbin[TPCONVMAXSTR];
0066     
0067     if (EXSUCCEED!=tpopen())
0068     {
0069         NDRX_LOG(log_error, "TESTERROR: tpopen() fail: %d:[%s]", 
0070                                             tperrno, tpstrerror(tperrno));
0071         EXFAIL_OUT(ret);
0072     }
0073     
0074     /***************************************************************************/
0075     NDRX_LOG(log_debug, "Testing tpconvert()");
0076     /***************************************************************************/
0077 
0078     if (EXSUCCEED!=tpbegin(5, 0))
0079     {
0080         NDRX_LOG(log_error, "TESTERROR: tpbegin() fail: %d:[%s]", 
0081                                             tperrno, tpstrerror(tperrno));
0082         EXFAIL_OUT(ret);
0083     }
0084     
0085     /*
0086      * Call service
0087      * - Service shall read the TPSVCINFO.cltid
0088      * - convert to string, must be equal to TPSVCINFO.cltid
0089      * - convert to binary, must be equal to TPSVCINFO.cltid
0090      * ... because we have always in string format
0091      */
0092     if (EXSUCCEED!=tpcall("TESTCLTID", NULL, 0L, (char **)&p_ub, &rsplen, TPNOTRAN))
0093     {
0094         NDRX_LOG(log_error, "TESTERROR: Failed to call TESTCLTID: %s - "
0095                 "client id convert failed!", tpstrerror(tperrno));
0096         EXFAIL_OUT(ret);
0097     }
0098     
0099     /* Testing of TID:
0100      * - suspend transaction
0101      * - convert transaction id to string, perform strpcy()
0102      * - convert id from string to bin
0103      * - resume transaction with convert bin tid
0104      */
0105     if (EXSUCCEED!=tpsuspend(&t, 0L))
0106     {
0107         NDRX_LOG(log_error, "TESTERROR: Failed to suspend transaction: %s!",
0108                 tpstrerror(tperrno));
0109         EXFAIL_OUT(ret);
0110     }
0111     
0112     cnvstr[0] = EXEOS;
0113     cnvbin[0] = EXEOS;
0114     
0115     if (EXSUCCEED!=tpconvert(cnvstr, (char *)&t, TPCONVTRANID | TPTOSTRING))
0116     {
0117         NDRX_LOG(log_error, "TESTERROR: Failed to tpconvert() "
0118                 "TPCONVTRANID | TPTOSTRING: %s!", tpstrerror(tperrno));
0119         EXFAIL_OUT(ret);
0120     }
0121     
0122     /* convert back to bin */
0123     NDRX_LOG(log_debug, "Convert TPCONVTRANID from string to bin: [%s]",
0124             cnvstr);
0125     
0126     if (EXSUCCEED!=tpconvert(cnvstr, cnvbin, TPCONVTRANID))
0127     {
0128         NDRX_LOG(log_error, "TESTERROR: Failed to tpconvert() "
0129                 "TPCONVTRANID from string: %s!",
0130                 tpstrerror(tperrno));
0131         EXFAIL_OUT(ret);
0132     }
0133     
0134     /* resume transaction with convert bin */
0135     if (EXSUCCEED!=tpresume((TPTRANID *)cnvbin, 0L))
0136     {
0137         NDRX_LOG(log_error, "TESTERROR: Failed to resume transaction: %s!",
0138                 tpstrerror(tperrno));
0139         EXFAIL_OUT(ret);
0140     }
0141     
0142     /*
0143      * Testing on XID:
0144      * - get value from TPTRANID. This is string value, convert to BIN
0145      * - BIN must not be equal to string
0146      * - convert BIN to back to string
0147      * - compare with TPTRANID, must be equal 
0148      */
0149     
0150     cnvstr[0] = EXEOS;
0151     cnvbin[0] = EXEOS;        
0152     
0153     /* t.tmxid is string,  convert to binary */
0154     if (EXSUCCEED!=tpconvert(t.tmxid, cnvbin, TPCONVXID))
0155     {
0156         NDRX_LOG(log_error, "TESTERROR: Failed to tpconvert() "
0157                 "TPCONVXID from string: %s!",
0158                 tpstrerror(tperrno));
0159         EXFAIL_OUT(ret);
0160     }
0161     
0162     /* thy must not match */
0163     if (0==strcmp(t.tmxid, cnvbin))
0164     {
0165         NDRX_LOG(log_error, "TESTERROR: Failed to tpconvert() TPCONVXID "
0166                 "binary equal string [%s]!!!", cnvbin);
0167         EXFAIL_OUT(ret);
0168     }
0169     
0170     if (EXSUCCEED!=tpconvert(cnvstr, cnvbin, TPCONVXID | TPTOSTRING))
0171     {
0172         NDRX_LOG(log_error, "TESTERROR: Failed to tpconvert() TPCONVXID | "
0173                 "TPTOSTRING failed: %s!", tpstrerror(tperrno));
0174         EXFAIL_OUT(ret);
0175     }
0176     
0177     if (0!=strcmp(t.tmxid, cnvstr))
0178     {
0179         NDRX_LOG(log_error, "TESTERROR: TPCONVXID strings must match!!! "
0180                 "tmxid: [%s] vs cnvstr [%s]", t.tmxid, cnvstr);
0181         EXFAIL_OUT(ret);
0182     }
0183     
0184     if (EXSUCCEED!=tpcommit(0))
0185     {
0186         NDRX_LOG(log_error, "TESTERROR: tpcommit()==%d fail: %d:[%s]", 
0187                                             ret, tperrno, tpstrerror(tperrno));
0188         ret=EXFAIL;
0189         goto out;
0190     }
0191    
0192     /***************************************************************************/
0193     NDRX_LOG(log_debug, "Done...");
0194     /***************************************************************************/
0195     
0196     if (EXSUCCEED!=tpclose())
0197     {
0198         NDRX_LOG(log_error, "TESTERROR: tpclose() fail: %d:[%s]", 
0199                                             tperrno, tpstrerror(tperrno));
0200         ret=EXFAIL;
0201         goto out;
0202     }
0203     
0204 out:
0205     if (EXSUCCEED!=ret)
0206     {
0207         /* atleast try... */
0208         if (EXSUCCEED!=tpabort(0))
0209         {
0210             NDRX_LOG(log_error, "TESTERROR: tpabort() fail: %d:[%s]", 
0211                                                 tperrno, tpstrerror(tperrno));
0212         }
0213         tpclose();
0214     }
0215 
0216     tpterm();
0217     
0218     NDRX_LOG(log_error, "Exiting with %d", ret);
0219             
0220     return ret;
0221 }
0222 /* vim: set ts=4 sw=4 et smartindent: */