Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief Enduro/X testing support library
0003  *
0004  * @file exassert.h
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 #ifndef EXASSERT_H
0035 #define EXASSERT_H
0036 
0037 #ifdef  __cplusplus
0038 extern "C" {
0039 #endif
0040 
0041 /*---------------------------Includes-----------------------------------*/
0042 #include <ndrstandard.h>
0043 
0044 #include "xatmi.h"
0045 /*---------------------------Externs------------------------------------*/
0046 /*---------------------------Macros-------------------------------------*/
0047     
0048 /**
0049  * Check the expression is true, if find out false
0050  * print the TP error to the log, ret=EXFAIL, goto out;
0051  * 
0052  * @param expr - test expression, expected true
0053  * @param msg - extra message for failure, format string
0054  * @param ... - params to format string
0055  */
0056 #define NDRX_ASSERT_TP_OUT(expr, msg, ...) \
0057     do {\
0058         if (!(expr)) {\
0059             char tmp_assert_buf_[PATH_MAX];\
0060             snprintf(tmp_assert_buf_, sizeof(tmp_assert_buf_), msg, ##__VA_ARGS__);\
0061             NDRX_LOG(log_always, "TESTERROR %s: expr [%s] is false: %s", tmp_assert_buf_, #expr, tpstrerror(tperrno));\
0062             EXFAIL_OUT(ret);\
0063         }\
0064     } while (0)
0065 
0066 /**
0067  * Check the expression is true, if find out false
0068  * print the UBF error to the log, ret=EXFAIL, goto out;
0069  * 
0070  * @param expr - test expression, expected true
0071  * @param msg - extra message for failure, format string
0072  * @param ... - params to format string
0073  */    
0074 #define NDRX_ASSERT_UBF_OUT(expr, msg, ...) \
0075     do {\
0076         if (!(expr)) {\
0077             char tmp_assert_buf_[PATH_MAX];\
0078             snprintf(tmp_assert_buf_, sizeof(tmp_assert_buf_), msg, ##__VA_ARGS__);\
0079             NDRX_LOG(log_always, "TESTERROR %s: expr [%s] is false: %s", tmp_assert_buf_, #expr, Bstrerror(Berror));\
0080             EXFAIL_OUT(ret);\
0081         }\
0082     } while (0)
0083     
0084 /**
0085  * Check the expression is true, if find out false
0086  * print the error
0087  * 
0088  * @param expr - test expression, expected true
0089  * @param msg - extra message for failure
0090  * @param ... - params to format string
0091  */    
0092 #define NDRX_ASSERT_VAL_OUT(expr, msg, ...) \
0093     do {\
0094         if (!(expr)) {\
0095             char tmp_assert_buf_[PATH_MAX];\
0096             snprintf(tmp_assert_buf_, sizeof(tmp_assert_buf_), msg, ##__VA_ARGS__);\
0097             NDRX_LOG(log_always, "TESTERROR %s: expr [%s] is false", tmp_assert_buf_, #expr);\
0098             EXFAIL_OUT(ret);\
0099         }\
0100     } while (0)
0101     
0102 /*---------------------------Enums--------------------------------------*/
0103 /*---------------------------Typedefs-----------------------------------*/
0104 /*---------------------------Globals------------------------------------*/
0105 /*---------------------------Statics------------------------------------*/
0106 /*---------------------------Prototypes---------------------------------*/
0107 #ifdef  __cplusplus
0108 }
0109 #endif
0110 
0111 #endif  /* EXASSERT_H */
0112 
0113 /* vim: set ts=4 sw=4 et smartindent: */