Back to home page

Enduro/X

 
 

    


0001 /**
0002  *
0003  * @file test_bnum.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 void load_test_data(UBFH *p_ub)
0045 {
0046     short s = 88;
0047     long l = -1021;
0048     char c = 'c';
0049     float f = 17.31;
0050     double d = 12312.1111;
0051     char carr[] = "CARRAY1 TEST STRING DATA";
0052     BFLDLEN len = strlen(carr);
0053 
0054     assert_equal(Bchg(p_ub, T_SHORT_FLD, 0, (char *)&s, 0), EXSUCCEED);
0055     assert_equal(Bchg(p_ub, T_LONG_FLD, 0, (char *)&l, 0), EXSUCCEED);
0056     assert_equal(Bchg(p_ub, T_CHAR_FLD, 0, (char *)&c, 0), EXSUCCEED);
0057     assert_equal(Bchg(p_ub, T_FLOAT_FLD, 0, (char *)&f, 0), EXSUCCEED);
0058     assert_equal(Bchg(p_ub, T_DOUBLE_FLD, 0, (char *)&d, 0), EXSUCCEED);
0059     assert_equal(Bchg(p_ub, T_STRING_FLD, 0, (char *)"TEST STR VAL", 0), EXSUCCEED);
0060     assert_equal(Bchg(p_ub, T_CARRAY_FLD, 0, (char *)carr, len), EXSUCCEED);
0061     
0062     gen_load_ubf(p_ub, 0, 1, 0);
0063     gen_load_view(p_ub, 0, 1, 0);
0064     gen_load_ptr(p_ub, 0, 1, 0);
0065 
0066 
0067     /* Make second copy of field data (another for not equal test)*/
0068     s = 88;
0069     l = -1021;
0070     c = '.';
0071     f = 17.31;
0072     d = 12312.1111;
0073     carr[0] = 'Y';
0074     len = strlen(carr);
0075 
0076     assert_equal(Bchg(p_ub, T_SHORT_FLD, 1, (char *)&s, 0), EXSUCCEED);
0077     assert_equal(Bchg(p_ub, T_LONG_FLD, 1, (char *)&l, 0), EXSUCCEED);
0078     assert_equal(Bchg(p_ub, T_CHAR_FLD, 1, (char *)&c, 0), EXSUCCEED);
0079     assert_equal(Bchg(p_ub, T_FLOAT_FLD, 1, (char *)&f, 0), EXSUCCEED);
0080     assert_equal(Bchg(p_ub, T_DOUBLE_FLD, 1, (char *)&d, 0), EXSUCCEED);
0081     assert_equal(Bchg(p_ub, T_STRING_FLD, 1, (char *)"TEST STRING ARRAY2", 0), EXSUCCEED);
0082     assert_equal(Bchg(p_ub, T_CARRAY_FLD, 1, (char *)carr, len), EXSUCCEED);
0083     
0084     gen_load_ubf(p_ub, 1, 2, 0);
0085     gen_load_view(p_ub, 1, 2, 0);
0086     gen_load_ptr(p_ub, 1, 2, 0);
0087 
0088     s = 212;
0089     l = 212;
0090     c = 'b';
0091     f = 12127;
0092     d = 1231232.1;
0093     carr[0] = 'X';
0094     assert_equal(Bchg(p_ub, T_SHORT_2_FLD, 0, (char *)&s, 0), EXSUCCEED);
0095     assert_equal(Bchg(p_ub, T_LONG_2_FLD, 0, (char *)&l, 0), EXSUCCEED);
0096     assert_equal(Bchg(p_ub, T_CHAR_2_FLD, 0, (char *)&c, 0), EXSUCCEED);
0097     assert_equal(Bchg(p_ub, T_FLOAT_2_FLD, 0, (char *)&f, 0), EXSUCCEED);
0098     assert_equal(Bchg(p_ub, T_DOUBLE_2_FLD, 0, (char *)&d, 0), EXSUCCEED);
0099     assert_equal(Bchg(p_ub, T_STRING_2_FLD, 0, (char *)"XTEST STR VAL", 0), EXSUCCEED);
0100     assert_equal(Bchg(p_ub, T_CARRAY_2_FLD, 0, (char *)carr, len), EXSUCCEED);
0101     
0102     gen_load_ubf(p_ub, 0, 3, 1);
0103     gen_load_view(p_ub, 0, 3, 1);
0104     gen_load_ptr(p_ub, 0, 3, 1);
0105 }
0106 
0107 /**
0108  * This simply reads all fields and adds them to another buffer, then do compare
0109  */
0110 Ensure(test_bnum_simple)
0111 {
0112     char fb[1400];
0113     UBFH *p_ub = (UBFH *)fb;
0114     int fldcount;
0115 
0116     assert_equal(Binit(p_ub, sizeof(fb)), EXSUCCEED);
0117     load_test_data(p_ub);
0118 
0119     fldcount=Bnum(p_ub);
0120     assert_equal(fldcount, 30);
0121 }
0122 
0123 TestSuite *ubf_bnum_tests(void)
0124 {
0125     TestSuite *suite = create_test_suite();
0126 
0127     add_test(suite, test_bnum_simple);
0128 
0129     return suite;
0130 }
0131 
0132 /* vim: set ts=4 sw=4 et smartindent: */