Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief Test for Source buffer outer join functionality to Destination buffer (Bojoin)
0003  *
0004  * @file test_bojoin.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_bojoin_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 
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     
0061     gen_load_ubf(p_ub, 0, 1, 0);
0062     gen_load_view(p_ub, 0, 1, 0);
0063     gen_load_ptr(p_ub, 0, 1, 0);
0064     
0065     /* Make second copy of field data (another for not equal test)*/
0066     s = 88;
0067     l = -1021;
0068     c = '.';
0069     f = 17.31;
0070     d = 12312.1111;
0071 
0072     assert_equal(Bchg(p_ub, T_SHORT_FLD, 1, (char *)&s, 0), EXSUCCEED);
0073     assert_equal(Bchg(p_ub, T_CHAR_FLD, 1, (char *)&c, 0), EXSUCCEED);
0074     assert_equal(Bchg(p_ub, T_FLOAT_FLD, 1, (char *)&f, 0), EXSUCCEED);
0075     assert_equal(Bchg(p_ub, T_DOUBLE_FLD, 1, (char *)&d, 0), EXSUCCEED);
0076     assert_equal(Bchg(p_ub, T_STRING_FLD, 1, (char *)"TEST STRING 2", 0), EXSUCCEED);
0077     
0078     gen_load_ubf(p_ub, 1, 2, 0);
0079     gen_load_view(p_ub, 1, 2, 0);
0080     gen_load_ptr(p_ub, 1, 2, 0);
0081 
0082     /* Make second copy of field data (another for not equal test)*/
0083     l = -2323;
0084     c = 'Q';
0085     f = 12.31;
0086     d = 6547.1111;
0087 
0088     assert_equal(Bchg(p_ub, T_CHAR_FLD, 2, (char *)&c, 0), EXSUCCEED);
0089     assert_equal(Bchg(p_ub, T_FLOAT_FLD, 2, (char *)&f, 0), EXSUCCEED);
0090     assert_equal(Bchg(p_ub, T_DOUBLE_FLD, 2, (char *)&d, 0), EXSUCCEED);
0091 }
0092 
0093 void load_test_data_bojoin_src(UBFH *p_ub)
0094 {
0095     short s = 222;
0096     long l = 23456789;
0097     char c = 'z';
0098     float f = 9.9;
0099     double d = 987654.9876;
0100 
0101     assert_equal(Bchg(p_ub, T_SHORT_FLD, 0, (char *)&s, 0), EXSUCCEED);
0102     assert_equal(Bchg(p_ub, T_LONG_FLD, 0, (char *)&l, 0), EXSUCCEED);
0103     assert_equal(Bchg(p_ub, T_CHAR_FLD, 0, (char *)&c, 0), EXSUCCEED);
0104     assert_equal(Bchg(p_ub, T_FLOAT_FLD, 0, (char *)&f, 0), EXSUCCEED);
0105     assert_equal(Bchg(p_ub, T_DOUBLE_FLD, 0, (char *)&d, 0), EXSUCCEED);
0106     assert_equal(Bchg(p_ub, T_STRING_FLD, 0, (char *)"TEST STR VAL OUTER JOIN", 0), EXSUCCEED);
0107 
0108     gen_load_ubf(p_ub, 0, 3, 0);
0109     gen_load_view(p_ub, 0, 3, 0);
0110     gen_load_ptr(p_ub, 0, 3, 0);
0111     
0112     /* Make second copy of field data (another for not equal test)*/
0113     s = 33;
0114     l = -2048;
0115     c = 'X';
0116     f = 8.8;
0117     d = 12312.1111;
0118 
0119     assert_equal(Bchg(p_ub, T_SHORT_FLD, 1, (char *)&s, 0), EXSUCCEED);
0120     assert_equal(Bchg(p_ub, T_LONG_FLD, 1, (char *)&l, 0), EXSUCCEED);
0121     assert_equal(Bchg(p_ub, T_CHAR_FLD, 1, (char *)&c, 0), EXSUCCEED);
0122     assert_equal(Bchg(p_ub, T_FLOAT_FLD, 1, (char *)&f, 0), EXSUCCEED);
0123     assert_equal(Bchg(p_ub, T_DOUBLE_FLD, 1, (char *)&d, 0), EXSUCCEED);
0124 
0125     gen_load_ubf(p_ub, 1, 4, 0);
0126     gen_load_view(p_ub, 1, 4, 0);
0127     gen_load_ptr(p_ub, 1, 4, 0);
0128     
0129     /* Make second copy of field data (another for not equal test)*/
0130     c = 'Q';
0131     f = 7.7;
0132 
0133     assert_equal(Bchg(p_ub, T_CHAR_FLD, 2, (char *)&c, 0), EXSUCCEED);
0134     assert_equal(Bchg(p_ub, T_FLOAT_FLD, 2, (char *)&f, 0), EXSUCCEED);
0135 
0136     /* Make second copy of field data (another for not equal test)*/
0137     c = 'Q';
0138     f = 6.6;
0139 
0140     assert_equal(Bchg(p_ub, T_CHAR_FLD, 3, (char *)&c, 0), EXSUCCEED);
0141     assert_equal(Bchg(p_ub, T_FLOAT_FLD, 3, (char *)&f, 0), EXSUCCEED);
0142     
0143     gen_load_ubf(p_ub, 0, 5, 1);
0144     gen_load_view(p_ub, 0, 5, 1);
0145     gen_load_ptr(p_ub, 0, 5, 1);
0146  
0147 }
0148 
0149 Ensure(test_bojoin_simple)
0150 {
0151     char fb_src[1400];
0152     char fb_dst[1400];
0153     UBFH *p_ub_src = (UBFH *)fb_src;
0154     UBFH *p_ub_dst = (UBFH *)fb_dst;
0155     
0156     short s;
0157     long l;
0158     char c;
0159     float f;
0160     double d;
0161     char buf[100];
0162 
0163     Binit(p_ub_src, sizeof(fb_src));
0164     Binit(p_ub_dst, sizeof(fb_dst));
0165 
0166     load_test_data_bojoin_src(p_ub_src);
0167     load_test_data_bojoin_dst(p_ub_dst);
0168 
0169     significant_figures_for_assert_double_are(FLOAT_RESOLUTION);
0170 
0171     assert_equal(Bojoin(p_ub_dst, p_ub_src),EXSUCCEED);
0172 
0173     assert_equal(Bget(p_ub_dst, T_SHORT_FLD, 0, (char *)&s, 0), EXSUCCEED);
0174     assert_equal(s,222);
0175     assert_equal(Bget(p_ub_dst, T_LONG_FLD, 0, (char *)&l, 0), EXSUCCEED);
0176     assert_equal(l,23456789);
0177     assert_equal(Bget(p_ub_dst, T_CHAR_FLD, 0, (char *)&c, 0), EXSUCCEED);
0178     assert_equal(c,'z');
0179     assert_equal(Bget(p_ub_dst, T_FLOAT_FLD, 0, (char *)&f, 0), EXSUCCEED);
0180     assert_double_equal(f,9.9);
0181     assert_equal(Bget(p_ub_dst, T_DOUBLE_FLD, 0, (char *)&d, 0), EXSUCCEED);
0182     assert_double_equal(d,987654.9876);
0183     assert_equal(Bget(p_ub_dst, T_STRING_FLD, 0, (char *)buf, 0), EXSUCCEED);
0184     assert_string_equal(buf,"TEST STR VAL OUTER JOIN");
0185 
0186     assert_equal(Bget(p_ub_dst, T_SHORT_FLD, 1, (char *)&s, 0), EXSUCCEED);
0187     assert_equal(s,33);
0188     assert_equal(Bpres(p_ub_dst, T_LONG_FLD, 1), EXFALSE);
0189 
0190     assert_equal(Bget(p_ub_dst, T_CHAR_FLD, 1, (char *)&c, 0), EXSUCCEED);
0191     assert_equal(c,'X');
0192     assert_equal(Bget(p_ub_dst, T_FLOAT_FLD, 1, (char *)&f, 0), EXSUCCEED);
0193     assert_double_equal(f,8.8);
0194     assert_equal(Bget(p_ub_dst, T_DOUBLE_FLD, 1, (char *)&d, 0), EXSUCCEED);
0195     assert_double_equal(d,12312.1111);
0196     assert_equal(Bget(p_ub_dst, T_STRING_FLD, 1, (char *)buf,0), EXSUCCEED);
0197     assert_string_equal(buf,"TEST STRING 2");
0198 
0199     assert_equal(Bget(p_ub_dst, T_CHAR_FLD, 2, (char *)&c, 0), EXSUCCEED);
0200     assert_equal(c,'Q');
0201     assert_equal(Bget(p_ub_dst, T_FLOAT_FLD, 2, (char *)&f, 0), EXSUCCEED);
0202     assert_double_equal(f,7.7);
0203     assert_equal(Bpres(p_ub_dst, T_DOUBLE_FLD, 2), EXTRUE);
0204     
0205     /* test new types..: */
0206     gen_test_ubf(p_ub_dst, 0, 3, 0);
0207     gen_test_view(p_ub_dst, 0, 3, 0);
0208     gen_test_ptr(p_ub_dst, 0, 3, 0);
0209     
0210     gen_test_ubf(p_ub_dst, 1, 4, 0);
0211     gen_test_view(p_ub_dst, 1, 4, 0);
0212     gen_test_ptr(p_ub_dst, 1, 4, 0);
0213     
0214     /* test fields not pres: */
0215     assert_equal(Bpres(p_ub_dst, T_UBF_2_FLD, 2), EXFALSE);
0216     assert_equal(Bpres(p_ub_dst, T_VIEW_2_FLD, 2), EXFALSE);
0217     assert_equal(Bpres(p_ub_dst, T_PTR_2_FLD, 2), EXFALSE);
0218     
0219 }
0220 
0221 TestSuite *ubf_bojoin_tests(void)
0222 {
0223     TestSuite *suite = create_test_suite();
0224 
0225     add_test(suite, test_bojoin_simple);
0226 
0227     return suite;
0228 }
0229 
0230 /* vim: set ts=4 sw=4 et smartindent: */