Back to home page

Enduro/X

 
 

    


0001 /**
0002  *
0003  * @file test_macro.c
0004  */
0005 /* -----------------------------------------------------------------------------
0006  * Enduro/X Middleware Platform for Distributed Transaction Processing
0007  * Copyright (C) 2009-2016, ATR Baltic, Ltd. All Rights Reserved.
0008  * Copyright (C) 2017-2023, Mavimax, Ltd. All Rights Reserved.
0009  * This software is released under one of the following licenses:
0010  * AGPL (with Java and Go exceptions) or Mavimax's license for commercial use.
0011  * See LICENSE file for full text.
0012  * -----------------------------------------------------------------------------
0013  * AGPL license:
0014  *
0015  * This program is free software; you can redistribute it and/or modify it under
0016  * the terms of the GNU Affero General Public License, version 3 as published
0017  * by the Free Software Foundation;
0018  *
0019  * This program is distributed in the hope that it will be useful, but WITHOUT ANY
0020  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
0021  * PARTICULAR PURPOSE. See the GNU Affero General Public License, version 3
0022  * for more details.
0023  *
0024  * You should have received a copy of the GNU Affero General Public License along 
0025  * with this program; if not, write to the Free Software Foundation, Inc.,
0026  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
0027  *
0028  * -----------------------------------------------------------------------------
0029  * A commercial use license is available from Mavimax, Ltd
0030  * contact@mavimax.com
0031  * -----------------------------------------------------------------------------
0032  */
0033 
0034 #include <stdio.h>
0035 #include <stdlib.h>
0036 #include <cgreen/cgreen.h>
0037 #include <ubf.h>
0038 #include <ndrstandard.h>
0039 #include <string.h>
0040 #include "test.fd.h"
0041 #include "ubfunit1.h"
0042 
0043 /**
0044  * Performs basic macro function testing.
0045  */
0046 Ensure(test_macros)
0047 {
0048     char fb[1024];
0049     UBFH *p_ub = (UBFH *)fb;
0050     char test_buf[64];
0051     char *p;
0052     assert_equal(Binit(p_ub, sizeof(fb)), EXSUCCEED);
0053 
0054     assert_equal(Badds (p_ub, T_SHORT_FLD, "321"), EXSUCCEED);
0055     assert_equal(Bchgs (p_ub, T_LONG_FLD, 10, "88889"), EXSUCCEED);
0056     assert_equal(Bchgs (p_ub, T_CARRAY_FLD, 5, "THIS IS TEST VALUE"), EXSUCCEED);
0057     
0058     assert_equal(Bgets (p_ub, T_LONG_FLD, 10, test_buf), EXSUCCEED);
0059     assert_string_equal(test_buf, "88889");
0060     assert_equal(Bgets (p_ub, T_SHORT_FLD, 0, test_buf), EXSUCCEED);
0061     assert_string_equal(test_buf, "321");
0062 
0063     /* Get with allocate */
0064     assert_string_equal((p=Bgetsa (p_ub, T_CARRAY_FLD, 5, 0)), "THIS IS TEST VALUE");
0065     assert_not_equal(p, NULL);
0066     free(p);
0067     
0068     assert_string_equal(Bfinds (p_ub, T_CARRAY_FLD, 5), "THIS IS TEST VALUE");
0069     
0070 }
0071 
0072 TestSuite *ubf_macro_tests(void)
0073 {
0074     TestSuite *suite = create_test_suite();
0075 
0076     add_test(suite, test_macros);
0077     
0078     return suite;
0079 }
0080 /* vim: set ts=4 sw=4 et smartindent: */