Back to home page

Enduro/X

 
 

    


0001 /**
0002  *
0003  * @file test_bproj.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 #include "ndebug.h"
0043 #include <fdatatype.h>
0044 #include <time.h>
0045 #include <ubfutil.h>
0046 /**
0047  * Init the memory, so that valgrind does not barg on padding bytes
0048  * as un-initialized
0049  */
0050 void randomize_test_data(char *ptr, int size)
0051 {
0052     int i;
0053 
0054     for (i=0; i<size; i++)
0055     {
0056         ptr[i]=(char)(ndrx_rand() % 255);
0057     }
0058 }
0059 void test_proj_data_1(UBFH *p_ub)
0060 {
0061     short s;
0062     long l;
0063     char c;
0064     float f;
0065     double d;
0066     char buf[100];
0067     BFLDLEN len;
0068     char carr[] = "CARRAY1 TEST STRING DATA";
0069 
0070     /* OCC 0 */
0071     assert_equal(Bget(p_ub, T_SHORT_FLD, 0, (char *)&s, 0), EXSUCCEED);
0072     assert_equal(s, 88);
0073     assert_equal(Bget(p_ub, T_LONG_FLD, 0, (char *)&l, 0), EXSUCCEED);
0074     assert_equal(l, -1021);
0075     assert_equal(Bget(p_ub, T_CHAR_FLD, 0, (char *)&c, 0), EXSUCCEED);
0076     assert_equal(c, 'c');
0077     assert_equal(Bget(p_ub, T_FLOAT_FLD, 0, (char *)&f, 0), EXSUCCEED);
0078     assert_double_equal(f, 17.31);
0079     assert_equal(Bget(p_ub, T_DOUBLE_FLD, 0, (char *)&d, 0), EXSUCCEED);
0080     assert_double_equal(d, 12312.1111);
0081     assert_equal(Bget(p_ub, T_STRING_FLD, 0, (char *)buf, 0), EXSUCCEED);
0082     assert_string_equal(buf, "TEST STR VAL");
0083     
0084     len = sizeof(buf);
0085     assert_equal(Bget(p_ub, T_CARRAY_FLD, 0, (char *)buf, &len), EXSUCCEED);
0086     assert_equal(strncmp(buf, carr, strlen(carr)), 0);
0087     
0088     gen_load_ubf(p_ub, 0, 1, 0);
0089     gen_load_view(p_ub, 0, 1, 0);
0090     gen_load_ptr(p_ub, 0, 1, 0);
0091     
0092     
0093     /* OCC 1 */
0094     assert_equal(Bget(p_ub, T_SHORT_FLD, 1, (char *)&s, 0), EXSUCCEED);
0095     assert_equal(s, 8);
0096     assert_equal(Bget(p_ub, T_LONG_FLD, 1, (char *)&l, 0), EXSUCCEED);
0097     assert_equal(l, -21);
0098     assert_equal(Bget(p_ub, T_CHAR_FLD, 1, (char *)&c, 0), EXSUCCEED);
0099     assert_equal(c, '.');
0100     assert_equal(Bget(p_ub, T_FLOAT_FLD, 1, (char *)&f, 0), EXSUCCEED);
0101     assert_double_equal(f, 1.31);
0102     assert_equal(Bget(p_ub, T_DOUBLE_FLD, 1, (char *)&d, 0), EXSUCCEED);
0103     assert_double_equal(d, 1231.1111);
0104     assert_equal(Bget(p_ub, T_STRING_FLD, 1, (char *)buf, 0), EXSUCCEED);
0105     assert_string_equal(buf, "TEST STRING ARRAY2");
0106 
0107     len = sizeof(buf);
0108     carr[0] = 'Y';
0109     assert_equal(Bget(p_ub, T_CARRAY_FLD, 1, (char *)buf, &len), EXSUCCEED);
0110     assert_equal(strncmp(buf, carr, strlen(carr)), 0);
0111     
0112     gen_load_ubf(p_ub, 1, 2, 0);
0113     gen_load_view(p_ub, 1, 2, 0);
0114     gen_load_ptr(p_ub, 1, 2, 0);
0115 }
0116 
0117 void load_proj_test_data(UBFH *p_ub)
0118 {
0119     short s = 88;
0120     long l = -1021;
0121     char c = 'c';
0122     float f = 17.31;
0123     double d = 12312.1111;
0124     char carr[] = "CARRAY1 TEST STRING DATA";
0125     BFLDLEN len = strlen(carr);
0126 
0127     assert_equal(Bchg(p_ub, T_SHORT_FLD, 0, (char *)&s, 0), EXSUCCEED);
0128     assert_equal(Bchg(p_ub, T_LONG_FLD, 0, (char *)&l, 0), EXSUCCEED);
0129     assert_equal(Bchg(p_ub, T_CHAR_FLD, 0, (char *)&c, 0), EXSUCCEED);
0130     assert_equal(Bchg(p_ub, T_FLOAT_FLD, 0, (char *)&f, 0), EXSUCCEED);
0131     assert_equal(Bchg(p_ub, T_DOUBLE_FLD, 0, (char *)&d, 0), EXSUCCEED);
0132     assert_equal(Bchg(p_ub, T_STRING_FLD, 0, (char *)"TEST STR VAL", 0), EXSUCCEED);
0133     assert_equal(Bchg(p_ub, T_CARRAY_FLD, 0, (char *)carr, len), EXSUCCEED);
0134 
0135     gen_load_ubf(p_ub, 0, 3, 0);
0136     gen_load_view(p_ub, 0, 3, 0);
0137     gen_load_ptr(p_ub, 0, 3, 0);
0138     
0139     /* Make second copy of field data (another for not equal test)*/
0140     s = 8;
0141     l = -21;
0142     c = '.';
0143     f = 1.31;
0144     d = 1231.1111;
0145     carr[0] = 'Y';
0146     len = strlen(carr);
0147 
0148     assert_equal(Bchg(p_ub, T_SHORT_FLD, 1, (char *)&s, 0), EXSUCCEED);
0149     assert_equal(Bchg(p_ub, T_LONG_FLD, 1, (char *)&l, 0), EXSUCCEED);
0150     assert_equal(Bchg(p_ub, T_CHAR_FLD, 1, (char *)&c, 0), EXSUCCEED);
0151     assert_equal(Bchg(p_ub, T_FLOAT_FLD, 1, (char *)&f, 0), EXSUCCEED);
0152     assert_equal(Bchg(p_ub, T_DOUBLE_FLD, 1, (char *)&d, 0), EXSUCCEED);
0153     assert_equal(Bchg(p_ub, T_STRING_FLD, 1, (char *)"TEST STRING ARRAY2", 0), EXSUCCEED);
0154     assert_equal(Bchg(p_ub, T_CARRAY_FLD, 1, (char *)carr, len), EXSUCCEED);
0155     
0156     gen_load_ubf(p_ub, 1, 4, 0);
0157     gen_load_view(p_ub, 1, 4, 0);
0158     gen_load_ptr(p_ub, 1, 4, 0);
0159 
0160     s = 212;
0161     l = 212;
0162     c = 'b';
0163     f = 12127;
0164     d = 1231232.1;
0165     carr[0] = 'X';
0166     assert_equal(Bchg(p_ub, T_SHORT_2_FLD, 0, (char *)&s, 0), EXSUCCEED);
0167     assert_equal(Bchg(p_ub, T_LONG_2_FLD, 0, (char *)&l, 0), EXSUCCEED);
0168     assert_equal(Bchg(p_ub, T_CHAR_2_FLD, 0, (char *)&c, 0), EXSUCCEED);
0169     assert_equal(Bchg(p_ub, T_FLOAT_2_FLD, 0, (char *)&f, 0), EXSUCCEED);
0170     assert_equal(Bchg(p_ub, T_DOUBLE_2_FLD, 0, (char *)&d, 0), EXSUCCEED);
0171     assert_equal(Bchg(p_ub, T_STRING_2_FLD, 0, (char *)"XTEST STR VAL", 0), EXSUCCEED);
0172     assert_equal(Bchg(p_ub, T_CARRAY_2_FLD, 0, (char *)carr, len), EXSUCCEED);
0173     
0174     gen_load_ubf(p_ub, 0, 5, 1);
0175     gen_load_view(p_ub, 0, 5, 1);
0176     gen_load_ptr(p_ub, 0, 5, 1);
0177 }
0178 
0179 /**
0180  * This simply reads all field and adds them to another buffer, then do compare
0181  */
0182 Ensure(test_proj_simple)
0183 {
0184     char fb[1400];
0185     UBFH *p_ub = (UBFH *)fb;
0186     char data_buf[100];
0187     BFLDLEN  len;
0188 
0189     BFLDID proj[] = {
0190         T_SHORT_FLD,
0191         T_LONG_FLD,
0192         T_CHAR_FLD,
0193         T_FLOAT_FLD,
0194         T_DOUBLE_FLD,
0195         T_STRING_FLD,
0196         T_CARRAY_FLD,
0197         T_PTR_FLD,
0198         T_VIEW_FLD,
0199         T_UBF_FLD,
0200         BBADFLDID
0201     };
0202     /* Empty list - delete all */
0203     BFLDID proj_empty[] = {
0204         BBADFLDID
0205     };
0206 
0207     assert_equal(Binit(p_ub, sizeof(fb)), EXSUCCEED);
0208 
0209     load_proj_test_data(p_ub);
0210 
0211     /* Projection delete */
0212     assert_equal(Bproj(p_ub, proj), EXSUCCEED);
0213 
0214     assert_equal(Bpres(p_ub, T_SHORT_FLD, 0), EXTRUE);
0215     assert_equal(Bpres(p_ub, T_LONG_FLD, 0), EXTRUE);
0216     assert_equal(Bpres(p_ub, T_CHAR_FLD, 0), EXTRUE);
0217     assert_equal(Bpres(p_ub, T_FLOAT_FLD, 0), EXTRUE);
0218     assert_equal(Bpres(p_ub, T_DOUBLE_FLD, 0), EXTRUE);
0219     assert_equal(Bpres(p_ub, T_STRING_FLD, 0), EXTRUE);
0220     assert_equal(Bpres(p_ub, T_CARRAY_FLD, 0), EXTRUE);
0221     assert_equal(Bpres(p_ub, T_PTR_FLD, 0), EXTRUE);
0222     assert_equal(Bpres(p_ub, T_VIEW_FLD, 0), EXTRUE);
0223     assert_equal(Bpres(p_ub, T_UBF_FLD, 0), EXTRUE);
0224 
0225     assert_equal(Bpres(p_ub, T_SHORT_2_FLD, 0), EXFALSE);
0226     assert_equal(Bpres(p_ub, T_LONG_2_FLD, 0), EXFALSE);
0227     assert_equal(Bpres(p_ub, T_CHAR_2_FLD, 0), EXFALSE);
0228     assert_equal(Bpres(p_ub, T_FLOAT_2_FLD, 0), EXFALSE);
0229     assert_equal(Bpres(p_ub, T_DOUBLE_2_FLD, 0), EXFALSE);
0230     assert_equal(Bpres(p_ub, T_STRING_2_FLD, 0), EXFALSE);
0231     assert_equal(Bpres(p_ub, T_CARRAY_2_FLD, 0), EXFALSE);
0232     
0233     assert_equal(Bpres(p_ub, T_VIEW_2_FLD, 0), EXFALSE);
0234     assert_equal(Bpres(p_ub, T_UBF_2_FLD, 0), EXFALSE);
0235     assert_equal(Bpres(p_ub, T_PTR_2_FLD, 0), EXFALSE);
0236 
0237     test_proj_data_1(p_ub);
0238 
0239     /* Now test complete delete */
0240 
0241     assert_equal(Binit(p_ub, sizeof(fb)), EXSUCCEED);
0242     load_proj_test_data(p_ub);
0243     assert_equal(Bproj(p_ub, NULL), EXSUCCEED);
0244 
0245     assert_equal(Bpres(p_ub, T_SHORT_FLD, 0), EXFALSE);
0246     assert_equal(Bpres(p_ub, T_LONG_FLD, 0), EXFALSE);
0247     assert_equal(Bpres(p_ub, T_CHAR_FLD, 0), EXFALSE);
0248     assert_equal(Bpres(p_ub, T_FLOAT_FLD, 0), EXFALSE);
0249     assert_equal(Bpres(p_ub, T_DOUBLE_FLD, 0), EXFALSE);
0250     assert_equal(Bpres(p_ub, T_STRING_FLD, 0), EXFALSE);
0251     assert_equal(Bpres(p_ub, T_CARRAY_FLD, 0), EXFALSE);
0252     assert_equal(Bpres(p_ub, T_PTR_FLD, 0), EXFALSE);
0253     assert_equal(Bpres(p_ub, T_VIEW_FLD, 0), EXFALSE);
0254     assert_equal(Bpres(p_ub, T_UBF_FLD, 0), EXFALSE);
0255     
0256     assert_equal(Bpres(p_ub, T_SHORT_2_FLD, 0), EXFALSE);
0257     assert_equal(Bpres(p_ub, T_LONG_2_FLD, 0), EXFALSE);
0258     assert_equal(Bpres(p_ub, T_CHAR_2_FLD, 0), EXFALSE);
0259     assert_equal(Bpres(p_ub, T_FLOAT_2_FLD, 0), EXFALSE);
0260     assert_equal(Bpres(p_ub, T_DOUBLE_2_FLD, 0), EXFALSE);
0261     assert_equal(Bpres(p_ub, T_STRING_2_FLD, 0), EXFALSE);
0262     assert_equal(Bpres(p_ub, T_CARRAY_2_FLD, 0), EXFALSE);
0263     assert_equal(Bpres(p_ub, T_VIEW_2_FLD, 0), EXFALSE);
0264     assert_equal(Bpres(p_ub, T_UBF_2_FLD, 0), EXFALSE);
0265     assert_equal(Bpres(p_ub, T_PTR_2_FLD, 0), EXFALSE);
0266 
0267     /* Test the case when projection list is empty. */
0268     assert_equal(Binit(p_ub, sizeof(fb)), EXSUCCEED);
0269     load_proj_test_data(p_ub);
0270     assert_equal(Bproj(p_ub, proj_empty), EXSUCCEED);
0271     assert_equal(Bpres(p_ub, T_SHORT_FLD, 0), EXFALSE);
0272     assert_equal(Bpres(p_ub, T_LONG_FLD, 0), EXFALSE);
0273     assert_equal(Bpres(p_ub, T_CHAR_FLD, 0), EXFALSE);
0274     assert_equal(Bpres(p_ub, T_FLOAT_FLD, 0), EXFALSE);
0275     assert_equal(Bpres(p_ub, T_DOUBLE_FLD, 0), EXFALSE);
0276     assert_equal(Bpres(p_ub, T_STRING_FLD, 0), EXFALSE);
0277     assert_equal(Bpres(p_ub, T_CARRAY_FLD, 0), EXFALSE);
0278     assert_equal(Bpres(p_ub, T_PTR_FLD, 0), EXFALSE);
0279     assert_equal(Bpres(p_ub, T_VIEW_FLD, 0), EXFALSE);
0280     assert_equal(Bpres(p_ub, T_UBF_FLD, 0), EXFALSE);
0281 
0282     assert_equal(Bpres(p_ub, T_SHORT_2_FLD, 0), EXFALSE);
0283     assert_equal(Bpres(p_ub, T_LONG_2_FLD, 0), EXFALSE);
0284     assert_equal(Bpres(p_ub, T_CHAR_2_FLD, 0), EXFALSE);
0285     assert_equal(Bpres(p_ub, T_FLOAT_2_FLD, 0), EXFALSE);
0286     assert_equal(Bpres(p_ub, T_DOUBLE_2_FLD, 0), EXFALSE);
0287     assert_equal(Bpres(p_ub, T_STRING_2_FLD, 0), EXFALSE);
0288     assert_equal(Bpres(p_ub, T_CARRAY_2_FLD, 0), EXFALSE);
0289     assert_equal(Bpres(p_ub, T_VIEW_2_FLD, 0), EXFALSE);
0290     assert_equal(Bpres(p_ub, T_UBF_2_FLD, 0), EXFALSE);
0291     assert_equal(Bpres(p_ub, T_PTR_2_FLD, 0), EXFALSE);
0292 
0293 }
0294 
0295 /**
0296  * This test projcpy function
0297  */
0298 Ensure(test_projcpy)
0299 {
0300     char fb_src[2400];
0301     UBFH *p_ub_src = (UBFH *)fb_src;
0302     char fb_src2[2400];
0303     UBFH *p_ub_src2 = (UBFH *)fb_src2;
0304     
0305     char fb_dst[2400];
0306     UBFH *p_ub_dst = (UBFH *)fb_dst;
0307     
0308     UBF_header_t *hsrc = (UBF_header_t *)p_ub_src;
0309     UBF_header_t *hdst = (UBF_header_t *)p_ub_dst;
0310 
0311     BFLDID proj[] = {
0312         T_SHORT_FLD,
0313         T_LONG_FLD,
0314         T_CHAR_FLD,
0315         T_FLOAT_FLD,
0316         T_DOUBLE_FLD,
0317         T_STRING_FLD,
0318         T_CARRAY_FLD,
0319         T_PTR_FLD,
0320         T_VIEW_FLD,
0321         T_UBF_FLD,
0322         BBADFLDID
0323     };
0324     BFLDID proj_all[] = {
0325         T_SHORT_2_FLD,
0326         T_SHORT_2_FLD,
0327         T_LONG_2_FLD,
0328         T_CHAR_2_FLD,
0329         T_FLOAT_2_FLD,
0330         T_DOUBLE_2_FLD,
0331         T_STRING_2_FLD,
0332         T_CARRAY_2_FLD,
0333         T_PTR_2_FLD,
0334         T_VIEW_2_FLD,
0335         T_UBF_2_FLD,
0336         T_SHORT_FLD,
0337         T_LONG_FLD,
0338         T_CHAR_FLD,
0339         T_FLOAT_FLD,
0340         T_DOUBLE_FLD,
0341         T_STRING_FLD,
0342         T_CARRAY_FLD,
0343         T_PTR_FLD,
0344         T_VIEW_FLD,
0345         T_UBF_FLD,
0346         BBADFLDID
0347     };
0348 
0349     /* fill padded un-init memory: */
0350     memset(fb_src, 3, sizeof(fb_src));
0351     memset(fb_src2, 3, sizeof(fb_src2));
0352     memset(fb_dst, 3, sizeof(fb_dst));
0353 
0354     assert_equal(Binit(p_ub_src, sizeof(fb_src)), EXSUCCEED);
0355     assert_equal(Binit(p_ub_src2, sizeof(fb_src2)), EXSUCCEED);
0356     assert_equal(Binit(p_ub_dst, sizeof(fb_dst)), EXSUCCEED);
0357 
0358     load_proj_test_data(p_ub_src);
0359     /* Projcpy */
0360     assert_equal(Bprojcpy(p_ub_dst, p_ub_src, proj), EXSUCCEED);
0361     /* Projection */
0362     assert_equal(Bproj(p_ub_src, proj), EXSUCCEED);
0363     assert_equal(Bused(p_ub_src), Bused(p_ub_dst));
0364     /* Compare the buffer to one what we get from proj */
0365     assert_equal(memcmp(p_ub_dst, p_ub_src, Bused(p_ub_src)), EXSUCCEED);
0366     
0367     /* OK now test that all data have been copied! */
0368     load_proj_test_data(p_ub_src);
0369     assert_equal(Bprojcpy(p_ub_dst, p_ub_src, proj_all), EXSUCCEED);
0370     
0371     UBF_DUMP(log_debug, "Source buffer", p_ub_src, sizeof(fb_dst));
0372     
0373     UBF_LOG(log_debug, "hsrc dump short, 0: %ld", 0);
0374     UBF_LOG(log_debug, "hsrc dump long, 1: %ld", hsrc->cache_long_off);
0375     UBF_LOG(log_debug, "hsrc dump char, 2: %ld", hsrc->cache_char_off);
0376     UBF_LOG(log_debug, "hsrc dump float, 3: %ld", hsrc->cache_float_off);
0377     UBF_LOG(log_debug, "hsrc dump double, 4: %ld", hsrc->cache_double_off);
0378     UBF_LOG(log_debug, "hsrc dump string, 5: %ld", hsrc->cache_string_off);
0379     UBF_LOG(log_debug, "hsrc dump carray, 6: %ld", hsrc->cache_carray_off);
0380         
0381         
0382     assert_equal(memcmp(p_ub_dst, p_ub_src, Bused(p_ub_dst)), EXSUCCEED);
0383     UBF_DUMP(log_debug, "Dest buffer", p_ub_dst, sizeof(fb_dst));
0384     
0385         
0386     UBF_LOG(log_debug, "hdst dump short, 0: %ld", 0);
0387     UBF_LOG(log_debug, "hdst dump long, 1: %ld", hdst->cache_long_off);
0388     UBF_LOG(log_debug, "hdst dump char, 2: %ld", hdst->cache_char_off);
0389     UBF_LOG(log_debug, "hdst dump float, 3: %ld", hdst->cache_float_off);
0390     UBF_LOG(log_debug, "hdst dump double, 4: %ld", hdst->cache_double_off);
0391     UBF_LOG(log_debug, "hdst dump string, 5: %ld", hdst->cache_string_off);
0392     UBF_LOG(log_debug, "hdst dump carray, 6: %ld", hdst->cache_carray_off);
0393     
0394     UBF_LOG(log_debug, "hdst dump ptr, 6: %ld", hdst->cache_ptr_off);
0395     UBF_LOG(log_debug, "hdst dump ubf, 6: %ld", hdst->cache_ubf_off);
0396     UBF_LOG(log_debug, "hdst dump view, 6: %ld", hdst->cache_view_off);
0397     
0398     /* Now test the spacing. We will put big string in src buffer,
0399      * but dest buffer will be shorter, so we must get error, that we do not have
0400      * a space!
0401      */
0402     load_proj_test_data(p_ub_src2);
0403     assert_equal(Bchg(p_ub_src2, T_STRING_FLD, 0, BIG_TEST_STRING, 0), EXSUCCEED);
0404     
0405     assert_equal(Binit(p_ub_dst, 200), EXSUCCEED);
0406     
0407     assert_equal(Bprojcpy(p_ub_dst, p_ub_src2, proj_all), EXFAIL);
0408     assert_equal(Berror, BNOSPACE);
0409 
0410 }
0411 
0412 /**
0413  * Test Bdelall function
0414  */
0415 Ensure(test_Bdelall)
0416 {
0417     char fb[4096];
0418     char buf[64];
0419     UBFH *p_ub = (UBFH *)fb;
0420     int len;
0421     BFLDID bfldid;
0422     BFLDOCC occ;
0423     int flds = 0;
0424     
0425     assert_equal(Binit(p_ub, sizeof(fb)), EXSUCCEED);
0426     load_proj_test_data(p_ub);
0427     set_up_dummy_data(p_ub);
0428 
0429     assert_equal(Badd(p_ub, T_STRING_2_FLD, "TEST 2 data", 0), EXSUCCEED);
0430     /* Delete all string occurrences... */
0431     assert_equal(Bdelall(p_ub, T_STRING_2_FLD), EXSUCCEED);
0432     assert_equal(Bpres(p_ub, T_STRING_2_FLD, 0), EXFALSE);
0433     assert_equal(Bpres(p_ub, T_STRING_FLD, 0), EXTRUE);
0434     do_dummy_data_test(p_ub);
0435 
0436     /*----------------------------------------------------------*/
0437     /* Now do another test, as we are going to delete last element of the array */
0438     assert_equal(Binit(p_ub, sizeof(fb)), EXSUCCEED);
0439     load_proj_test_data(p_ub);
0440     assert_equal(Bdelall(p_ub, T_CARRAY_2_FLD), EXSUCCEED);
0441 
0442     /* validate the post previous field is present */
0443     len = sizeof(buf);
0444     assert_equal(Bget(p_ub, T_CARRAY_FLD, 1, (char *)buf, &len), EXSUCCEED);
0445     assert_equal(strncmp(buf, "YARRAY1 TEST STRING DATA", len), 0);
0446     /*----------------------------------------------------------*/
0447     /* Check if we delete nothing, then this is error condition */
0448     assert_equal(Bdelall(p_ub, T_CARRAY_2_FLD), EXFAIL);
0449     assert_equal(Berror, BNOTPRES);
0450     
0451     
0452     /* Bug #148 */
0453     
0454     assert_equal(Binit(p_ub, sizeof(fb)), EXSUCCEED);
0455     
0456     assert_equal(CBadd(p_ub, T_CHAR_FLD, "2", 0, BFLD_STRING), EXSUCCEED);
0457     assert_equal(CBadd(p_ub, T_STRING_FLD, "631419304311", 0, BFLD_STRING), EXSUCCEED);
0458     assert_equal(CBchg(p_ub, T_CHAR_FLD, 0, "Y", 0L, BFLD_STRING), EXSUCCEED);
0459     
0460     Bfprint(p_ub, stderr);
0461     
0462     assert_equal(Bdelall(p_ub, T_STRING_FLD), EXSUCCEED);
0463     
0464     NDRX_LOG(log_debug, "After T_STRING_FLD delete...");
0465     Bfprint(p_ub, stderr);
0466     
0467     assert_equal(CBchg(p_ub, T_CHAR_FLD, 0, "X", 0L, BFLD_STRING), EXSUCCEED);
0468     
0469     NDRX_LOG(log_debug, "After changed T_CHAR_FLD => occ: [%d]", 
0470             Boccur(p_ub, T_CHAR_FLD));
0471     
0472     Bfprint(p_ub, stderr);
0473     
0474     bfldid = BFIRSTFLDID;
0475     
0476     /* Only 1 field must be here! */
0477     while(1==Bnext(p_ub, &bfldid, &occ, NULL, NULL))
0478     {
0479         flds++;
0480     }
0481     
0482     assert_equal(flds, 1);
0483 }
0484 /**
0485  * Delete all items from 
0486  */
0487 Ensure(test_Bdelete)
0488 {
0489     char fb[2048];
0490     UBFH *p_ub = (UBFH *)fb;
0491     char fb2[2048];
0492     UBFH *p_ub2 = (UBFH *)fb2;
0493 
0494     BFLDID delete_fld2[] = {
0495         T_SHORT_2_FLD,
0496         T_SHORT_2_FLD,
0497         T_LONG_2_FLD,
0498         T_CHAR_2_FLD,
0499         T_FLOAT_2_FLD,
0500         T_DOUBLE_2_FLD,
0501         T_STRING_2_FLD,
0502         T_CARRAY_2_FLD,
0503         T_PTR_2_FLD,
0504         T_VIEW_2_FLD,
0505         T_UBF_2_FLD,
0506         BBADFLDID
0507     };
0508 
0509     BFLDID delete_all[] = {
0510         T_SHORT_FLD,
0511         T_LONG_FLD,
0512         T_CHAR_FLD,
0513         T_FLOAT_FLD,
0514         T_DOUBLE_FLD,
0515         T_STRING_FLD,
0516         T_CARRAY_FLD,
0517         T_PTR_FLD,
0518         T_VIEW_FLD,
0519         T_UBF_FLD,
0520         T_SHORT_2_FLD,
0521         T_SHORT_2_FLD,
0522         T_LONG_2_FLD,
0523         T_CHAR_2_FLD,
0524         T_FLOAT_2_FLD,
0525         T_DOUBLE_2_FLD,
0526         T_STRING_2_FLD,
0527         T_CARRAY_2_FLD,
0528         T_PTR_2_FLD,
0529         T_VIEW_2_FLD,
0530         T_UBF_2_FLD,
0531         BBADFLDID
0532     };
0533 
0534 
0535     assert_equal(Binit(p_ub, sizeof(fb)), EXSUCCEED);
0536     load_proj_test_data(p_ub);
0537     assert_equal(Bdelete(p_ub, delete_fld2), EXSUCCEED);
0538     test_proj_data_1(p_ub);
0539     /*----------------------------------------------------------*/
0540     /* Now check the error, that nothing have been deleted */
0541     assert_equal(Bdelete(p_ub, delete_fld2), EXFAIL);
0542     assert_equal(Berror, BNOTPRES);
0543     /*----------------------------------------------------------*/
0544     /* Ok now we are about to delete all items */
0545     assert_equal(Binit(p_ub2, sizeof(fb2)), EXSUCCEED);
0546     assert_equal(Bdelete(p_ub, delete_all), EXSUCCEED);
0547             
0548     assert_equal(memcmp(p_ub, p_ub2, Bused(p_ub)), EXSUCCEED);
0549     
0550     ndrx_debug_dump_UBF_hdr_ubflogger(log_debug, "p_ub", p_ub);
0551     
0552     ndrx_debug_dump_UBF(log_debug, "p_ub", p_ub);
0553     
0554     ndrx_debug_dump_UBF_hdr_ubflogger(log_debug, "p_ub2", p_ub2);
0555     
0556     ndrx_debug_dump_UBF(log_debug, "p_ub2", p_ub2);
0557     
0558     
0559 }
0560 
0561 TestSuite *ubf_fproj_tests(void)
0562 {
0563     TestSuite *suite = create_test_suite();
0564 
0565     add_test(suite, test_proj_simple);
0566     add_test(suite, test_projcpy);
0567     add_test(suite, test_Bdelall);
0568     add_test(suite, test_Bdelete);
0569     
0570     return suite;
0571 }
0572 
0573 /* vim: set ts=4 sw=4 et smartindent: */