Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief Test tpsprio, tpgprio - client
0003  *
0004  * @file atmiclt85.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 "test85.h"
0050 #include <exassert.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 
0065     UBFH *p_ub = (UBFH *)tpalloc("UBF", NULL, 56000);
0066     long rsplen;
0067     int i;
0068     int ret=EXSUCCEED;
0069     
0070     if (EXFAIL==CBchg(p_ub, T_STRING_FLD, 0, VALUE_EXPECTED, 0, BFLD_STRING))
0071     {
0072         NDRX_LOG(log_debug, "Failed to set T_STRING_FLD[0]: %s", Bstrerror(Berror));
0073         ret=EXFAIL;
0074         goto out;
0075     }
0076     
0077     /* 
0078      * Check Absolute
0079      */
0080     if (EXSUCCEED==tpsprio(0, TPABSOLUTE))
0081     {
0082         NDRX_LOG(log_error, "TESTERROR: 0 prio ABS shall fail");
0083         ret=EXFAIL;
0084         goto out;
0085     }
0086     NDRX_ASSERT_VAL_OUT(tperrno==TPEINVAL, "INvalid error, expected TPEINVAL got %d", tperrno);
0087     
0088     if (EXSUCCEED==tpsprio(101, TPABSOLUTE))
0089     {
0090         NDRX_LOG(log_error, "TESTERROR: 101 prio ABS shall fail");
0091         ret=EXFAIL;
0092         goto out;
0093     }
0094     NDRX_ASSERT_VAL_OUT(tperrno==TPEINVAL, "Invalid error, expected TPEINVAL got %d", tperrno);
0095     
0096     
0097     if (EXSUCCEED!=tpsprio(60, TPABSOLUTE))
0098     {
0099         NDRX_LOG(log_error, "TESTERROR: failed to set tpsprio()");
0100         ret=EXFAIL;
0101         goto out;
0102     }
0103     
0104     if (EXFAIL == tpcall("TESTSV", (char *)p_ub, 0L, (char **)&p_ub, &rsplen,0))
0105     {
0106         NDRX_LOG(log_error, "TESTSV failed: %s", tpstrerror(tperrno));
0107         ret=EXFAIL;
0108         goto out;
0109     }
0110     
0111     if (60!=(ret=tpgprio()))
0112     {
0113         NDRX_LOG(log_error, "TESTERROR: failed to verify tpgprio() got %d", ret);
0114         ret=EXFAIL;
0115         goto out;
0116     }
0117     
0118     ret=EXSUCCEED;
0119     
0120     if (EXFAIL == tpcall("TESTSV", (char *)p_ub, 0L, (char **)&p_ub, &rsplen,0))
0121     {
0122         NDRX_LOG(log_error, "TESTSV failed: %s", tpstrerror(tperrno));
0123         ret=EXFAIL;
0124         goto out;
0125     }
0126     
0127     if (50!=(ret=tpgprio()))
0128     {
0129         NDRX_LOG(log_error, "TESTERROR: failed to verify tpgprio() got %d", ret);
0130         ret=EXFAIL;
0131         goto out;
0132     }
0133     ret=EXSUCCEED;
0134     
0135     
0136     /* Check relative.. */
0137     if (EXSUCCEED==tpsprio(101, 0))
0138     {
0139         NDRX_LOG(log_error, "TESTERROR: 101 prio rel shall fail");
0140         ret=EXFAIL;
0141         goto out;
0142     }
0143     NDRX_ASSERT_VAL_OUT(tperrno==TPEINVAL, "INvalid error, expected TPEINVAL got %d", tperrno);
0144     
0145     if (EXSUCCEED==tpsprio(-101, 0))
0146     {
0147         NDRX_LOG(log_error, "TESTERROR: 101 prio rel shall fail");
0148         ret=EXFAIL;
0149         goto out;
0150     }
0151     NDRX_ASSERT_VAL_OUT(tperrno==TPEINVAL, "INvalid error, expected TPEINVAL got %d", tperrno);
0152     
0153     /* call relative -10 */
0154     if (EXSUCCEED!=tpsprio(-10, 0))
0155     {
0156         NDRX_LOG(log_error, "TESTERROR: failed to set tpsprio()");
0157         ret=EXFAIL;
0158         goto out;
0159     }
0160     
0161     if (EXFAIL == tpcall("TESTSV", (char *)p_ub, 0L, (char **)&p_ub, &rsplen,0))
0162     {
0163         NDRX_LOG(log_error, "TESTSV failed: %s", tpstrerror(tperrno));
0164         ret=EXFAIL;
0165         goto out;
0166     }
0167     
0168     if (40!=(ret=tpgprio()))
0169     {
0170         NDRX_LOG(log_error, "TESTERROR: failed to verify tpgprio() got %d", ret);
0171         ret=EXFAIL;
0172         goto out;
0173     }
0174     
0175     ret=EXSUCCEED;
0176     
0177     /* call relative -99 */
0178     if (EXSUCCEED!=tpsprio(-99, 0))
0179     {
0180         NDRX_LOG(log_error, "TESTERROR: failed to set tpsprio()");
0181         ret=EXFAIL;
0182         goto out;
0183     }
0184     
0185     if (EXFAIL == tpcall("TESTSV", (char *)p_ub, 0L, (char **)&p_ub, &rsplen,0))
0186     {
0187         NDRX_LOG(log_error, "TESTSV failed: %s", tpstrerror(tperrno));
0188         ret=EXFAIL;
0189         goto out;
0190     }
0191     
0192     if (1!=(ret=tpgprio()))
0193     {
0194         NDRX_LOG(log_error, "TESTERROR: failed to verify tpgprio() got %d", ret);
0195         ret=EXFAIL;
0196         goto out;
0197     }
0198     
0199     ret=EXSUCCEED;
0200     
0201     
0202     /* call relative 99 */
0203     if (EXSUCCEED!=tpsprio(99, 0))
0204     {
0205         NDRX_LOG(log_error, "TESTERROR: failed to set tpsprio()");
0206         ret=EXFAIL;
0207         goto out;
0208     }
0209     
0210     if (EXFAIL == tpcall("TESTSV", (char *)p_ub, 0L, (char **)&p_ub, &rsplen,0))
0211     {
0212         NDRX_LOG(log_error, "TESTSV failed: %s", tpstrerror(tperrno));
0213         ret=EXFAIL;
0214         goto out;
0215     }
0216     
0217     if (100!=(ret=tpgprio()))
0218     {
0219         NDRX_LOG(log_error, "TESTERROR: failed to verify tpgprio() got %d", ret);
0220         ret=EXFAIL;
0221         goto out;
0222     }
0223     
0224     ret=EXSUCCEED;
0225     
0226     if (EXFAIL == tpcall("TESTSV", (char *)p_ub, 0L, (char **)&p_ub, &rsplen,0))
0227     {
0228         NDRX_LOG(log_error, "TESTSV failed: %s", tpstrerror(tperrno));
0229         ret=EXFAIL;
0230         goto out;
0231     }
0232     
0233     if (50!=(ret=tpgprio()))
0234     {
0235         NDRX_LOG(log_error, "TESTERROR: failed to verify tpgprio() got %d", ret);
0236         ret=EXFAIL;
0237         goto out;
0238     }
0239     
0240     ret=EXSUCCEED;
0241 
0242     
0243 out:
0244     tpterm();
0245     fprintf(stderr, "Exit with %d\n", ret);
0246 
0247     return ret;
0248 }
0249 
0250 /* vim: set ts=4 sw=4 et smartindent: */