Back to home page

Enduro/X

 
 

    


0001 /**
0002  * Perform Bconcat API tests
0003  * @file test_bconcat.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 /**
0045  * Preparation before the test
0046  */
0047 Ensure(bconcat_basic_setup1)
0048 {
0049     /* shared load */
0050     load_field_table(); 
0051 }
0052 
0053 void load_concat_test_data(UBFH *p_ub)
0054 {
0055     short s = 88;
0056     long l = -1021;
0057     char c = 'c';
0058     float f = 17.31;
0059     double d = 12312.1111;
0060     char carr[] = "CARRAY1 TEST STRING DATA";
0061     BFLDLEN len = strlen(carr);
0062     
0063     /* Section 1: */
0064     assert_equal(Bchg(p_ub, T_SHORT_FLD, 0, (char *)&s, 0), EXSUCCEED);
0065     assert_equal(Bchg(p_ub, T_LONG_FLD, 0, (char *)&l, 0), EXSUCCEED);
0066     assert_equal(Bchg(p_ub, T_CHAR_FLD, 0, (char *)&c, 0), EXSUCCEED);
0067     assert_equal(Bchg(p_ub, T_FLOAT_FLD, 0, (char *)&f, 0), EXSUCCEED);
0068     assert_equal(Bchg(p_ub, T_DOUBLE_FLD, 0, (char *)&d, 0), EXSUCCEED);
0069     assert_equal(Bchg(p_ub, T_STRING_FLD, 0, (char *)"TEST STR VAL", 0), EXSUCCEED);
0070     assert_equal(Bchg(p_ub, T_CARRAY_FLD, 0, (char *)carr, len), EXSUCCEED);
0071 
0072     gen_load_view(p_ub, 0, 1, 0);
0073     gen_load_ptr(p_ub, 0, 1, 0);
0074     gen_load_ubf(p_ub, 0, 1, 0);
0075 
0076     /* Make second copy of field data (another for not equal test)*/
0077     s = 8;
0078     l = -21;
0079     c = '.';
0080     f = 1.31;
0081     d = 1231.1111;
0082     carr[0] = 'Y';
0083     len = strlen(carr);
0084     /* Section 2: */
0085     
0086     assert_equal(Bchg(p_ub, T_SHORT_FLD, 1, (char *)&s, 0), EXSUCCEED);
0087     assert_equal(Bchg(p_ub, T_LONG_FLD, 1, (char *)&l, 0), EXSUCCEED);
0088     assert_equal(Bchg(p_ub, T_CHAR_FLD, 1, (char *)&c, 0), EXSUCCEED);
0089     assert_equal(Bchg(p_ub, T_FLOAT_FLD, 1, (char *)&f, 0), EXSUCCEED);
0090     assert_equal(Bchg(p_ub, T_DOUBLE_FLD, 1, (char *)&d, 0), EXSUCCEED);
0091     assert_equal(Bchg(p_ub, T_STRING_FLD, 1, (char *)"TEST STRING ARRAY2", 0), EXSUCCEED);
0092     assert_equal(Bchg(p_ub, T_CARRAY_FLD, 1, (char *)carr, len), EXSUCCEED);
0093     
0094     gen_load_view(p_ub, 1, 2, 0);
0095     gen_load_ptr(p_ub, 1, 2, 0);
0096     gen_load_ubf(p_ub, 1, 2, 0);
0097 }
0098 
0099 void test_concat_data_1(UBFH *p_ub)
0100 {
0101     short s;
0102     long l;
0103     char c;
0104     float f;
0105     double d;
0106     char buf[100];
0107     BFLDLEN len;
0108     char carr[] = "CARRAY1 TEST STRING DATA";
0109     
0110     /* Matches Section 1: */
0111     /* OCC 0 */
0112     assert_equal(Bget(p_ub, T_SHORT_FLD, 0, (char *)&s, 0), EXSUCCEED);
0113     assert_equal(s, 88);
0114     assert_equal(Bget(p_ub, T_LONG_FLD, 0, (char *)&l, 0), EXSUCCEED);
0115     assert_equal(l, -1021);
0116     assert_equal(Bget(p_ub, T_CHAR_FLD, 0, (char *)&c, 0), EXSUCCEED);
0117     assert_equal(c, 'c');
0118     assert_equal(Bget(p_ub, T_FLOAT_FLD, 0, (char *)&f, 0), EXSUCCEED);
0119     assert_double_equal(f, 17.31);
0120     assert_equal(Bget(p_ub, T_DOUBLE_FLD, 0, (char *)&d, 0), EXSUCCEED);
0121     assert_double_equal(d, 12312.1111);
0122     assert_equal(Bget(p_ub, T_STRING_FLD, 0, (char *)buf, 0), EXSUCCEED);
0123     assert_string_equal(buf, "TEST STR VAL");
0124 
0125     len = sizeof(buf);
0126     assert_equal(Bget(p_ub, T_CARRAY_FLD, 0, (char *)buf, &len), EXSUCCEED);
0127     assert_equal(strncmp(buf, carr, strlen(carr)), 0);
0128     
0129     gen_test_view(p_ub, 0, 1, 0);
0130     gen_test_ubf(p_ub, 0, 1, 0);
0131     gen_test_ptr(p_ub, 0, 1, 0);
0132     
0133     /* Matches Section 2: */
0134     /* OCC 1 */
0135     assert_equal(Bget(p_ub, T_SHORT_FLD, 1, (char *)&s, 0), EXSUCCEED);
0136     assert_equal(s, 8);
0137     assert_equal(Bget(p_ub, T_LONG_FLD, 1, (char *)&l, 0), EXSUCCEED);
0138     assert_equal(l, -21);
0139     assert_equal(Bget(p_ub, T_CHAR_FLD, 1, (char *)&c, 0), EXSUCCEED);
0140     assert_equal(c, '.');
0141     assert_equal(Bget(p_ub, T_FLOAT_FLD, 1, (char *)&f, 0), EXSUCCEED);
0142     assert_double_equal(f, 1.31);
0143     assert_equal(Bget(p_ub, T_DOUBLE_FLD, 1, (char *)&d, 0), EXSUCCEED);
0144     assert_double_equal(d, 1231.1111);
0145     assert_equal(Bget(p_ub, T_STRING_FLD, 1, (char *)buf, 0), EXSUCCEED);
0146     assert_string_equal(buf, "TEST STRING ARRAY2");
0147 
0148     len = sizeof(buf);
0149     carr[0] = 'Y';
0150     assert_equal(Bget(p_ub, T_CARRAY_FLD, 1, (char *)buf, &len), EXSUCCEED);
0151     assert_equal(strncmp(buf, carr, strlen(carr)), 0);
0152     
0153     gen_test_ubf(p_ub, 1, 2, 0);
0154     gen_test_ptr(p_ub, 1, 2, 0);
0155     gen_test_view(p_ub, 1, 2, 0);
0156    
0157 }
0158 
0159 /**
0160  * Load alternate data, which after
0161  * @param p_ub
0162  */
0163 void load_concat_test_data_2(UBFH *p_ub)
0164 {
0165     short s = 881;
0166     long l = -10211;
0167     char c = '1';
0168     float f = 117.31;
0169     double d = 112312.1111;
0170     char carr[] = "CARRAY1 TEST STRING DATA1 --- SOME --- LONG - STUFF";
0171     BFLDLEN len = strlen(carr);
0172 
0173     /* Section 3: */
0174     assert_equal(Bchg(p_ub, T_SHORT_FLD, 0, (char *)&s, 0), EXSUCCEED);
0175     assert_equal(Bchg(p_ub, T_LONG_FLD, 0, (char *)&l, 0), EXSUCCEED);
0176     assert_equal(Bchg(p_ub, T_CHAR_FLD, 0, (char *)&c, 0), EXSUCCEED);
0177     assert_equal(Bchg(p_ub, T_FLOAT_FLD, 0, (char *)&f, 0), EXSUCCEED);
0178     assert_equal(Bchg(p_ub, T_DOUBLE_FLD, 0, (char *)&d, 0), EXSUCCEED);
0179     assert_equal(Bchg(p_ub, T_STRING_FLD, 0, (char *)"TEST STR VAL1M THIS IS LOGN STRING", 0), EXSUCCEED);
0180     assert_equal(Bchg(p_ub, T_CARRAY_FLD, 0, (char *)carr, len), EXSUCCEED);
0181 
0182     gen_load_ubf(p_ub, 0, 3, 0);
0183     gen_load_view(p_ub, 0, 3, 0);
0184     gen_load_ptr(p_ub, 0, 3, 0);
0185     
0186     /* Make second copy of field data (another for not equal test)*/
0187     s = 81;
0188     l = -211;
0189     c = '.';
0190     f = 11.31;
0191     d = 11231.1111;
0192     carr[0] = '2';
0193     len = strlen(carr);
0194 
0195     /* Section 4: */
0196     assert_equal(Bchg(p_ub, T_SHORT_FLD, 1, (char *)&s, 0), EXSUCCEED);
0197     assert_equal(Bchg(p_ub, T_LONG_FLD, 1, (char *)&l, 0), EXSUCCEED);
0198     assert_equal(Bchg(p_ub, T_CHAR_FLD, 1, (char *)&c, 0), EXSUCCEED);
0199     assert_equal(Bchg(p_ub, T_FLOAT_FLD, 1, (char *)&f, 0), EXSUCCEED);
0200     assert_equal(Bchg(p_ub, T_DOUBLE_FLD, 1, (char *)&d, 0), EXSUCCEED);
0201     assert_equal(Bchg(p_ub, T_STRING_FLD, 1, (char *)"3EST STRING ARRAY2 THIS IS EVEN MORE LONGER", 0), EXSUCCEED);
0202     assert_equal(Bchg(p_ub, T_CARRAY_FLD, 1, (char *)carr, len), EXSUCCEED);
0203     gen_load_ptr(p_ub, 1, 4, 0);
0204     gen_load_ubf(p_ub, 1, 4, 0);
0205     gen_load_view(p_ub, 1, 4, 0);
0206     
0207     /* This part we will keep the same */
0208     s = 2121;
0209     l = 2121;
0210     c = 'c';
0211     f = 1227;
0212     d = 1232.1;
0213     carr[0] = 'G';
0214     
0215     /* Section 5: */
0216     
0217     assert_equal(Bchg(p_ub, T_SHORT_2_FLD, 2, (char *)&s, 0), EXSUCCEED);
0218     assert_equal(Bchg(p_ub, T_LONG_2_FLD, 2, (char *)&l, 0), EXSUCCEED);
0219     assert_equal(Bchg(p_ub, T_CHAR_2_FLD, 2, (char *)&c, 0), EXSUCCEED);
0220     assert_equal(Bchg(p_ub, T_FLOAT_2_FLD, 2, (char *)&f, 0), EXSUCCEED);
0221     assert_equal(Bchg(p_ub, T_DOUBLE_2_FLD, 2, (char *)&d, 0), EXSUCCEED);
0222     assert_equal(Bchg(p_ub, T_STRING_2_FLD, 2, (char *)"XTEST STR VAL", 0), EXSUCCEED);
0223     assert_equal(Bchg(p_ub, T_CARRAY_2_FLD, 2, (char *)carr, len), EXSUCCEED);
0224     gen_load_view(p_ub, 2, 5, 1);
0225     gen_load_ptr(p_ub, 2, 5, 1);
0226     gen_load_ubf(p_ub, 2, 5, 1);
0227 }
0228 
0229 void test_concat_data_2(UBFH *p_ub)
0230 {
0231     short s;
0232     long l;
0233     char c;
0234     float f;
0235     double d;
0236     char buf[100];
0237     BFLDLEN len;
0238     char carr[] = "CARRAY1 TEST STRING DATA1 --- SOME --- LONG - STUFF";
0239 
0240     /* Matches Section 3: */
0241     
0242     /* OCC 0 */
0243     assert_equal(Bget(p_ub, T_SHORT_FLD, 2, (char *)&s, 0), EXSUCCEED);
0244     assert_equal(s, 881);
0245     assert_equal(Bget(p_ub, T_LONG_FLD, 2, (char *)&l, 0), EXSUCCEED);
0246     assert_equal(l, -10211);
0247     assert_equal(Bget(p_ub, T_CHAR_FLD, 2, (char *)&c, 0), EXSUCCEED);
0248     assert_equal(c, '1');
0249     assert_equal(Bget(p_ub, T_FLOAT_FLD, 2, (char *)&f, 0), EXSUCCEED);
0250     assert_double_equal(f, 117.31);
0251     assert_equal(Bget(p_ub, T_DOUBLE_FLD, 2, (char *)&d, 0), EXSUCCEED);
0252     assert_double_equal(d, 112312.1111);
0253     assert_equal(Bget(p_ub, T_STRING_FLD, 2, (char *)buf, 0), EXSUCCEED);
0254     assert_string_equal(buf, "TEST STR VAL1M THIS IS LOGN STRING");
0255 
0256     len = sizeof(buf);
0257     assert_equal(Bget(p_ub, T_CARRAY_FLD, 2, (char *)buf, &len), EXSUCCEED);
0258     assert_equal(strncmp(buf, carr, strlen(carr)), 0);
0259     gen_test_ubf(p_ub, 2, 3, 0);
0260     gen_test_view(p_ub, 2, 3, 0);
0261     gen_test_ptr(p_ub, 2, 3, 0);
0262     
0263     /* Matches Section 4: */
0264     
0265     /* OCC 1 */
0266     assert_equal(Bget(p_ub, T_SHORT_FLD, 3, (char *)&s, 0), EXSUCCEED);
0267     assert_equal(s, 81);
0268     assert_equal(Bget(p_ub, T_LONG_FLD, 3, (char *)&l, 0), EXSUCCEED);
0269     assert_equal(l, -211);
0270     assert_equal(Bget(p_ub, T_CHAR_FLD, 3, (char *)&c, 0), EXSUCCEED);
0271     assert_equal(c, '.');
0272     assert_equal(Bget(p_ub, T_FLOAT_FLD, 3, (char *)&f, 0), EXSUCCEED);
0273     assert_double_equal(f, 11.31);
0274     assert_equal(Bget(p_ub, T_DOUBLE_FLD, 3, (char *)&d, 0), EXSUCCEED);
0275     assert_double_equal(d, 11231.1111);
0276     assert_equal(Bget(p_ub, T_STRING_FLD, 3, (char *)buf, 0), EXSUCCEED);
0277     assert_string_equal(buf, "3EST STRING ARRAY2 THIS IS EVEN MORE LONGER");
0278 
0279     len = sizeof(buf);
0280     carr[0] = '2';
0281     assert_equal(Bget(p_ub, T_CARRAY_FLD, 3, (char *)buf, &len), EXSUCCEED);
0282     assert_equal(strncmp(buf, carr, strlen(carr)), 0);
0283     gen_test_ubf(p_ub, 3, 4, 0);
0284     gen_test_view(p_ub, 3, 4, 0);
0285     gen_test_ptr(p_ub, 3, 4, 0);
0286 
0287     /* Matches Section 5: */
0288     /* Test FLD2 */
0289     assert_equal(Bget(p_ub, T_SHORT_2_FLD, 2, (char *)&s, 0), EXSUCCEED);
0290     assert_equal(s, 2121);
0291     assert_equal(Bget(p_ub, T_LONG_2_FLD, 2, (char *)&l, 0), EXSUCCEED);
0292     assert_equal(l, 2121);
0293     assert_equal(Bget(p_ub, T_CHAR_2_FLD, 2, (char *)&c, 0), EXSUCCEED);
0294     assert_equal(c, 'c');
0295     assert_equal(Bget(p_ub, T_FLOAT_2_FLD, 2, (char *)&f, 0), EXSUCCEED);
0296     assert_double_equal(f, 1227);
0297     assert_equal(Bget(p_ub, T_DOUBLE_2_FLD, 2, (char *)&d, 0), EXSUCCEED);
0298     assert_double_equal(d, 1232.1);
0299     assert_equal(Bget(p_ub, T_STRING_2_FLD, 2, (char *)buf, 0), EXSUCCEED);
0300     assert_string_equal(buf, "XTEST STR VAL");
0301 
0302     len = sizeof(buf);
0303     carr[0] = 'G';
0304     assert_equal(Bget(p_ub, T_CARRAY_2_FLD, 2, (char *)buf, &len), EXSUCCEED);
0305     assert_equal(strncmp(buf, carr, strlen(carr)), 0);
0306     
0307     gen_test_ubf(p_ub, 2, 5, 1);
0308     gen_test_view(p_ub, 2, 5, 1);
0309     gen_test_ptr(p_ub, 2, 5, 1);
0310     
0311 }
0312 
0313 
0314 /**
0315  * This simply reads all field and adds them to another buffer, then do compare
0316  */
0317 Ensure(test_fconcat)
0318 {
0319     char fb[9000];
0320     UBFH *p_ub = (UBFH *)fb;
0321 
0322     char fb2[9000];
0323     UBFH *p_ub2 = (UBFH *)fb2;
0324 
0325     assert_equal(Binit(p_ub, sizeof(fb)), EXSUCCEED);
0326     assert_equal(Binit(p_ub2, sizeof(fb2)), EXSUCCEED);
0327 
0328     load_concat_test_data(p_ub);
0329     /* Do the full copy - output should be the same */
0330     assert_equal(Bconcat(p_ub2, p_ub), EXSUCCEED);
0331     assert_equal(Bcmp(p_ub2, p_ub), 0);
0332 
0333     /* Do the update over again - should be the same */
0334     assert_equal(Bcmp(p_ub2, p_ub), 0);
0335     test_concat_data_1(p_ub2);
0336 
0337     /* -------------------------------------------------------- */
0338     /* test real append */
0339     assert_equal(Binit(p_ub2, sizeof(fb2)), EXSUCCEED);
0340     assert_equal(Binit(p_ub, sizeof(fb)), EXSUCCEED);
0341 
0342     load_concat_test_data(p_ub);
0343     load_concat_test_data_2(p_ub2);
0344     
0345     Bfprint(p_ub, stderr);
0346     
0347     Bfprint(p_ub2, stderr);
0348     
0349     assert_equal(Bconcat(p_ub, p_ub2), EXSUCCEED);
0350 
0351     /* Both tests should be passed. */
0352     test_concat_data_1(p_ub);
0353     test_concat_data_2(p_ub);
0354 
0355 }
0356 
0357 TestSuite *ubf_fconcat_tests(void)
0358 {
0359     TestSuite *suite = create_test_suite();
0360 
0361     set_setup(suite, bconcat_basic_setup1);
0362     
0363     add_test(suite, test_fconcat);
0364 
0365     return suite;
0366 }
0367 
0368 /* vim: set ts=4 sw=4 et smartindent: */