Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief Test for Source buffer join functionality to Destination buffer (Bjoin)
0003  *
0004  * @file test_bjoin.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 
0035 #include <stdio.h>
0036 #include <stdlib.h>
0037 #include <cgreen/cgreen.h>
0038 #include <ubf.h>
0039 #include <ndrstandard.h>
0040 #include <string.h>
0041 #include "test.fd.h"
0042 #include "ubfunit1.h"
0043 #include "ndebug.h"
0044 #include <ubf_int.h>
0045 
0046 void load_test_data_bjoin_dst(UBFH *p_ub)
0047 {
0048     short s = 88;
0049     long l = -1021;
0050     char c = 'c';
0051     float f = 17.31;
0052     double d = 12312.1111;
0053     char carr[] = "CARRAY1 TEST STRING DATA";
0054     BFLDLEN len = strlen(carr);
0055 
0056     /* block 1 */
0057     assert_equal(Bchg(p_ub, T_SHORT_FLD, 0, (char *)&s, 0), EXSUCCEED);
0058     assert_equal(Bchg(p_ub, T_LONG_FLD, 0, (char *)&l, 0), EXSUCCEED);
0059     assert_equal(Bchg(p_ub, T_CHAR_FLD, 0, (char *)&c, 0), EXSUCCEED);
0060     assert_equal(Bchg(p_ub, T_FLOAT_FLD, 0, (char *)&f, 0), EXSUCCEED);
0061     assert_equal(Bchg(p_ub, T_DOUBLE_FLD, 0, (char *)&d, 0), EXSUCCEED);
0062     assert_equal(Bchg(p_ub, T_STRING_FLD, 0, (char *)"TEST STR VAL", 0), EXSUCCEED);
0063     assert_equal(Bchg(p_ub, T_CARRAY_FLD, 0, (char *)carr, len), EXSUCCEED);
0064     
0065     gen_load_ubf(p_ub, 0, 1, 0);
0066     gen_load_view(p_ub, 0, 1, 0);
0067     gen_load_ptr(p_ub, 0, 1, 0);
0068     
0069     /* block 2 */
0070     /* Make second copy of field data (another for not equal test)*/
0071     s = 88;
0072     l = -1021;
0073     c = '.';
0074     f = 17.31;
0075     d = 12312.1111;
0076     carr[0] = 'Y';
0077     len = strlen(carr);
0078 
0079     assert_equal(Bchg(p_ub, T_SHORT_FLD, 1, (char *)&s, 0), EXSUCCEED);
0080     assert_equal(Bchg(p_ub, T_CHAR_FLD, 1, (char *)&c, 0), EXSUCCEED);
0081     assert_equal(Bchg(p_ub, T_FLOAT_FLD, 1, (char *)&f, 0), EXSUCCEED);
0082     assert_equal(Bchg(p_ub, T_DOUBLE_FLD, 1, (char *)&d, 0), EXSUCCEED);
0083     assert_equal(Bchg(p_ub, T_STRING_FLD, 1, (char *)"TEST STRING 2", 0), EXSUCCEED);
0084     assert_equal(Bchg(p_ub, T_CARRAY_FLD, 1, (char *)carr, len), EXSUCCEED);
0085     
0086     gen_load_ubf(p_ub, 1, 2, 0);
0087     gen_load_view(p_ub, 1, 2, 0);
0088     gen_load_ptr(p_ub, 1, 2, 0);
0089     
0090 
0091     /* Make second copy of field data (another for not equal test)*/
0092     l = -2323;
0093     c = 'Q';
0094     f = 12.31;
0095     d = 6547.1111;
0096 
0097     assert_equal(Bchg(p_ub, T_CHAR_FLD, 2, (char *)&c, 0), EXSUCCEED);
0098     assert_equal(Bchg(p_ub, T_FLOAT_FLD, 2, (char *)&f, 0), EXSUCCEED);
0099     assert_equal(Bchg(p_ub, T_DOUBLE_FLD, 2, (char *)&d, 0), EXSUCCEED);
0100 }
0101 
0102 void load_test_data_bjoin_src(UBFH *p_ub)
0103 {
0104     short s = 222;
0105     long l = 23456789;
0106     char c = 'z';
0107     float f = 9.9;
0108     double d = 987654.9876;
0109 
0110     /* block 3 */
0111     assert_equal(Bchg(p_ub, T_SHORT_FLD, 0, (char *)&s, 0), EXSUCCEED);
0112     assert_equal(Bchg(p_ub, T_LONG_FLD, 0, (char *)&l, 0), EXSUCCEED);
0113     assert_equal(Bchg(p_ub, T_CHAR_FLD, 0, (char *)&c, 0), EXSUCCEED);
0114     assert_equal(Bchg(p_ub, T_FLOAT_FLD, 0, (char *)&f, 0), EXSUCCEED);
0115     assert_equal(Bchg(p_ub, T_DOUBLE_FLD, 0, (char *)&d, 0), EXSUCCEED);
0116     assert_equal(Bchg(p_ub, T_STRING_FLD, 0, (char *)"TEST STR VAL JOIN", 0), EXSUCCEED);
0117     
0118     gen_load_ubf(p_ub, 0, 3, 0);
0119     gen_load_view(p_ub, 0, 3, 0);
0120     gen_load_ptr(p_ub, 0, 3, 0);
0121     
0122 
0123     /* block 4 */
0124     /* Make second copy of field data (another for not equal test)*/
0125     s = 33;
0126     l = -2048;
0127     c = 'X';
0128     f = 8.8;
0129     d = 12312.1111;
0130 
0131     assert_equal(Bchg(p_ub, T_SHORT_FLD, 1, (char *)&s, 0), EXSUCCEED);
0132     assert_equal(Bchg(p_ub, T_LONG_FLD, 1, (char *)&l, 0), EXSUCCEED);
0133     assert_equal(Bchg(p_ub, T_CHAR_FLD, 1, (char *)&c, 0), EXSUCCEED);
0134     assert_equal(Bchg(p_ub, T_FLOAT_FLD, 1, (char *)&f, 0), EXSUCCEED);
0135     assert_equal(Bchg(p_ub, T_DOUBLE_FLD, 1, (char *)&d, 0), EXSUCCEED);
0136 
0137     gen_load_ubf(p_ub, 1, 4, 0);
0138     gen_load_view(p_ub, 1, 4, 0);
0139     gen_load_ptr(p_ub, 1, 4, 0);
0140     
0141     /* Make second copy of field data (another for not equal test)*/
0142     c = 'Q';
0143     f = 7.7;
0144 
0145     assert_equal(Bchg(p_ub, T_CHAR_FLD, 2, (char *)&c, 0), EXSUCCEED);
0146     assert_equal(Bchg(p_ub, T_FLOAT_FLD, 2, (char *)&f, 0), EXSUCCEED);
0147 
0148     /* Make second copy of field data (another for not equal test)*/
0149     c = 'Q';
0150     f = 6.6;
0151 
0152     assert_equal(Bchg(p_ub, T_CHAR_FLD, 3, (char *)&c, 0), EXSUCCEED);
0153     assert_equal(Bchg(p_ub, T_FLOAT_FLD, 3, (char *)&f, 0), EXSUCCEED);
0154 }
0155 
0156 Ensure(test_bjoin_simple)
0157 {
0158     char fb_src[1400];
0159     char fb_dst[1400];
0160     UBFH *p_ub_src = (UBFH *)fb_src;
0161     UBFH *p_ub_dst = (UBFH *)fb_dst;
0162     
0163     short s;
0164     long l;
0165     char c;
0166     float f;
0167     double d;
0168     char buf[100];
0169 
0170     Binit(p_ub_src, sizeof(fb_src));
0171     Binit(p_ub_dst, sizeof(fb_dst));
0172 
0173     load_test_data_bjoin_src(p_ub_src);
0174     load_test_data_bjoin_dst(p_ub_dst);
0175 
0176     significant_figures_for_assert_double_are(FLOAT_RESOLUTION);
0177 
0178     UBF_LOG(log_debug, "************* Bjoin START *****************");
0179     assert_equal(Bjoin(p_ub_dst, p_ub_src),EXSUCCEED);
0180     UBF_LOG(log_debug, "************* Bjoin END *****************");
0181 
0182     UBF_LOG(log_debug, "Field num in src buffer after Bjoin [%d]", Bnum(p_ub_src));
0183     UBF_LOG(log_debug, "Field num in dst buffer after Bjoin [%d]", Bnum(p_ub_dst));
0184 
0185     /* test block is from  block 3 */
0186     assert_equal(Bget(p_ub_dst, T_SHORT_FLD, 0, (char *)&s, 0), EXSUCCEED);
0187     assert_equal(s,222);
0188     assert_equal(Bget(p_ub_dst, T_LONG_FLD, 0, (char *)&l, 0), EXSUCCEED);
0189     assert_equal(l,23456789);
0190     assert_equal(Bget(p_ub_dst, T_CHAR_FLD, 0, (char *)&c, 0), EXSUCCEED);
0191     assert_equal(c,'z');
0192     assert_equal(Bget(p_ub_dst, T_FLOAT_FLD, 0, (char *)&f, 0), EXSUCCEED);
0193     assert_double_equal(f,9.9);
0194     assert_equal(Bget(p_ub_dst, T_DOUBLE_FLD, 0, (char *)&d, 0), EXSUCCEED);
0195     assert_double_equal(d,987654.9876);
0196     assert_equal(Bget(p_ub_dst, T_STRING_FLD, 0, (char *)buf, 0), EXSUCCEED);
0197     assert_string_equal(buf,"TEST STR VAL JOIN");
0198     assert_equal(Bpres(p_ub_dst, T_CARRAY_FLD, 0), EXFALSE);
0199     
0200     UBF_LOG(log_debug, "************* DST 0 TEST *****************");
0201     gen_test_ubf(p_ub_dst, 0, 3, 0);
0202     gen_test_view(p_ub_dst, 0, 3, 0);
0203     gen_test_ptr(p_ub_dst, 0, 3, 0);
0204     
0205 
0206     /* from block 4 */
0207     assert_equal(Bget(p_ub_dst, T_SHORT_FLD, 1, (char *)&s, 0), EXSUCCEED);
0208     assert_equal(s,33);
0209     assert_equal(Bpres(p_ub_dst, T_LONG_FLD, 1), EXFALSE);
0210     assert_equal(Bget(p_ub_dst, T_CHAR_FLD, 1, (char *)&c, 0), EXSUCCEED);
0211     assert_equal(c,'X');
0212     assert_equal(Bget(p_ub_dst, T_FLOAT_FLD, 1, (char *)&f, 0), EXSUCCEED);
0213     assert_double_equal(f,8.8);
0214     assert_equal(Bget(p_ub_dst, T_DOUBLE_FLD, 1, (char *)&d, 0), EXSUCCEED);
0215     assert_double_equal(d,12312.1111);
0216     assert_equal(Bpres(p_ub_dst, T_STRING_FLD, 1), EXFALSE);
0217     
0218     
0219     UBF_LOG(log_debug, "************* DST 1 TEST *****************");
0220     gen_test_ubf(p_ub_dst, 1, 4, 0);
0221     gen_test_view(p_ub_dst, 1, 4, 0);
0222     gen_test_ptr(p_ub_dst, 1, 4, 0);
0223     
0224     assert_equal(Bget(p_ub_dst, T_CHAR_FLD, 2, (char *)&c, 0), EXSUCCEED);
0225     assert_equal(c,'Q');
0226     assert_equal(Bget(p_ub_dst, T_FLOAT_FLD, 2, (char *)&f, 0), EXSUCCEED);
0227     assert_double_equal(f,7.7);
0228     assert_equal(Bpres(p_ub_dst, T_DOUBLE_FLD, 2), EXFALSE);
0229 
0230 }
0231 
0232 TestSuite *ubf_bjoin_tests(void)
0233 {
0234     TestSuite *suite = create_test_suite();
0235 
0236     add_test(suite, test_bjoin_simple);
0237 
0238     return suite;
0239 }
0240 
0241 /* vim: set ts=4 sw=4 et smartindent: */