Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief Test expression compiler & evaluator
0003  *
0004  * @file test_expr.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 <string.h>
0039 #include <sys/resource.h>
0040 
0041 #include <ubf.h>
0042 #include <ndrstandard.h>
0043 #include "test.fd.h"
0044 #include "ubfunit1.h"
0045 #include <ndebug.h>
0046 #include <ubf_int.h>
0047 
0048 
0049 void delete_fb_test_data(UBFH *p_ub)
0050 {
0051     
0052     assert_equal(Bdel(p_ub, T_SHORT_FLD, 0), EXSUCCEED);
0053     assert_equal(Bdel(p_ub, T_LONG_FLD, 0), EXSUCCEED);
0054     assert_equal(Bdel(p_ub, T_CHAR_FLD, 0), EXSUCCEED);
0055     assert_equal(Bdel(p_ub, T_FLOAT_FLD, 0), EXSUCCEED);
0056     assert_equal(Bdel(p_ub, T_DOUBLE_FLD, 0), EXSUCCEED);
0057     assert_equal(Bdel(p_ub, T_STRING_FLD, 0), EXSUCCEED);
0058     assert_equal(Bdel(p_ub, T_CARRAY_FLD, 0), EXSUCCEED);
0059 
0060 }
0061 
0062 void load_expr_test_data_1(UBFH *p_ub)
0063 {
0064     short s = 102;
0065     long l = 10212312;
0066     char c = 'a';
0067     float f = 127.001;
0068     double d = 12312312.1112;
0069     char carr[] = "CARRAY TEST";
0070     BFLDLEN len = strlen(carr);
0071 
0072     assert_equal(Bchg(p_ub, T_SHORT_FLD, 0, (char *)&s, 0), EXSUCCEED);
0073     assert_equal(Bchg(p_ub, T_LONG_FLD, 0, (char *)&l, 0), EXSUCCEED);
0074     assert_equal(Bchg(p_ub, T_CHAR_FLD, 0, (char *)&c, 0), EXSUCCEED);
0075     assert_equal(Bchg(p_ub, T_FLOAT_FLD, 0, (char *)&f, 0), EXSUCCEED);
0076     assert_equal(Bchg(p_ub, T_DOUBLE_FLD, 0, (char *)&d, 0), EXSUCCEED);
0077     assert_equal(Bchg(p_ub, T_STRING_FLD, 0, (char *)"TEST STR VAL", 0), EXSUCCEED);
0078     assert_equal(Bchg(p_ub, T_CARRAY_FLD, 0, (char *)carr, len), EXSUCCEED);
0079 
0080     /* Make second copy of field data (another for not equal test)*/
0081     s = 212;
0082     l = 212;
0083     c = 'b';
0084     f = 12127;
0085     d = 1231232.1;
0086     carr[0] = 'X';
0087     assert_equal(Bchg(p_ub, T_SHORT_2_FLD, 0, (char *)&s, 0), EXSUCCEED);
0088     assert_equal(Bchg(p_ub, T_LONG_2_FLD, 0, (char *)&l, 0), EXSUCCEED);
0089     assert_equal(Bchg(p_ub, T_CHAR_2_FLD, 0, (char *)&c, 0), EXSUCCEED);
0090     assert_equal(Bchg(p_ub, T_FLOAT_2_FLD, 0, (char *)&f, 0), EXSUCCEED);
0091     assert_equal(Bchg(p_ub, T_DOUBLE_2_FLD, 0, (char *)&d, 0), EXSUCCEED);
0092     assert_equal(Bchg(p_ub, T_STRING_2_FLD, 0, (char *)"XTEST STR VAL", 0), EXSUCCEED);
0093     assert_equal(Bchg(p_ub, T_CARRAY_2_FLD, 0, (char *)carr, len), EXSUCCEED);
0094 }
0095 
0096 void load_expr_test_data_2(UBFH *p_ub)
0097 {
0098     short s = -102;
0099     long l = -10212312;
0100     char c = 't';
0101     float f = -127.001;
0102     double d = -12312312.1112;
0103     char carr[] = "ZARRAY TEST";
0104     BFLDLEN len = strlen(carr);
0105 
0106     assert_equal(Bchg(p_ub, T_SHORT_FLD, 0, (char *)&s, 0), EXSUCCEED);
0107     assert_equal(Bchg(p_ub, T_LONG_FLD, 0, (char *)&l, 0), EXSUCCEED);
0108     assert_equal(Bchg(p_ub, T_CHAR_FLD, 0, (char *)&c, 0), EXSUCCEED);
0109     assert_equal(Bchg(p_ub, T_FLOAT_FLD, 0, (char *)&f, 0), EXSUCCEED);
0110     assert_equal(Bchg(p_ub, T_DOUBLE_FLD, 0, (char *)&d, 0), EXSUCCEED);
0111     assert_equal(Bchg(p_ub, T_STRING_FLD, 0, (char *)"TEST STR VAL", 0), EXSUCCEED);
0112     assert_equal(Bchg(p_ub, T_CARRAY_FLD, 0, (char *)carr, len), EXSUCCEED);
0113 
0114     /* Make second copy of field data (another for not equal test)*/
0115     s = -212;
0116     l = -212;
0117     c = 'c';
0118     f = -12127;
0119     d = -1231232.1;
0120     carr[0] = 'Z';
0121     assert_equal(Bchg(p_ub, T_SHORT_2_FLD, 0, (char *)&s, 0), EXSUCCEED);
0122     assert_equal(Bchg(p_ub, T_LONG_2_FLD, 0, (char *)&l, 0), EXSUCCEED);
0123     assert_equal(Bchg(p_ub, T_CHAR_2_FLD, 0, (char *)&c, 0), EXSUCCEED);
0124     assert_equal(Bchg(p_ub, T_FLOAT_2_FLD, 0, (char *)&f, 0), EXSUCCEED);
0125     assert_equal(Bchg(p_ub, T_DOUBLE_2_FLD, 0, (char *)&d, 0), EXSUCCEED);
0126     assert_equal(Bchg(p_ub, T_STRING_2_FLD, 0, (char *)"XTEST STR VAL", 0), EXSUCCEED);
0127     assert_equal(Bchg(p_ub, T_CARRAY_2_FLD, 0, (char *)carr, len), EXSUCCEED);
0128 }
0129 
0130 Ensure(test_expr_basic)
0131 {
0132     char buf[2048];
0133     UBFH *p_ub = (UBFH *)buf;
0134     char *tree = NULL;
0135     /*----------------------------------------------------------*/
0136     /* init */
0137     assert_equal(Binit(p_ub, sizeof(buf)), EXSUCCEED);
0138     /* Test OK */
0139     tree=Bboolco ("2+2*4==10 && 'abc' %% '.bc'");
0140     assert_not_equal(tree, NULL);
0141     assert_equal(Bboolev(NULL, tree), EXFAIL);
0142     Btreefree(tree);
0143     /*----------------------------------------------------------*/
0144     /* We have failure somehere! */
0145     tree=Bboolco ("100+1=='101' || 1==1 || 2==2 || 1 || #");
0146     B_error("Bboolco");
0147     assert_equal(tree, NULL);
0148     assert_equal(Berror, BSYNTAX);
0149     /* Print the error message */
0150     Btreefree(tree);
0151     /*----------------------------------------------------------*/
0152     {
0153     char buf[2048];
0154     strcpy(buf, getenv("FIELDTBLS"));
0155     unsetenv("FIELDTBLS");
0156     /* Field table not initialized - ERROR! */
0157     tree=Bboolco ("100+1=='101' || 1==1 || 2==2 || 1 || T_STRING_2_FLD %% '58.*'");
0158     /* Print the error message */
0159     B_error("Bboolco");
0160     assert_equal(tree, NULL);
0161     assert_equal(Berror, BFTOPEN);
0162     Btreefree(tree);
0163     setenv("FIELDTBLS", buf, 1);
0164     }
0165     /*----------------------------------------------------------*/
0166     /* Do some real test, load the environment vairables */
0167     load_field_table(); /* set field table environment variable */
0168     /* Insert data */
0169     assert_equal(CBadd(p_ub, T_STRING_2_FLD, "0123456789012345", 0, BFLD_STRING), EXSUCCEED);
0170     assert_equal(CBadd(p_ub, T_CHAR_FLD, "2", 0, BFLD_STRING), EXSUCCEED);
0171     tree=Bboolco ("T_STRING_2_FLD=='0123456789012345' && T_CHAR_FLD==2");
0172     assert_not_equal(tree, NULL);
0173     assert_equal(Bboolev(p_ub, tree), EXTRUE);
0174     Btreefree(tree);
0175     /*----------------------------------------------------------*/
0176     /* Reporduce the error when field is not found. In field tables */
0177     tree=Bboolco ("T_STRING_2_FLD=='0123456789012345' && T_CHAR_FLD==2 && B_AD_FIELDNAME");
0178     assert_equal(tree, NULL);
0179     B_error("Bboolco");
0180     assert_equal(Berror, BBADNAME);
0181     Btreefree(tree);
0182     /*----------------------------------------------------------*/
0183     /* Test that  '0' is not becoming as 1 in math ops */
0184     tree=Bboolco ("!'0'+1==2");
0185     assert_not_equal(tree, NULL);
0186     assert_equal(Bboolev(p_ub, tree), EXFALSE);
0187     Btreefree(tree);
0188     
0189     /*----------------------------------------------------------*/
0190     /* Test syntax error, Support #374 */
0191     /* tree=Bboolco ("T_STRING_2_FLD == 'hello x' !T_STRING_2_FLD"); */
0192     /* tree=Bboolco ("'hello x' !T_STRING_2_FLD"); */
0193     /* tree=Bboolco ("0 !T_STRING_2_FLD"); */
0194     tree=Bboolco ("!T_STRING_2_FLD 0");
0195     assert_equal(tree, NULL);
0196     assert_equal(Berror, BSYNTAX);
0197     Btreefree(tree);
0198 
0199 }
0200 
0201 /**
0202  * Tests basic logic operations:- &&, ||, ^, !
0203  */
0204 Ensure(test_expr_basic_logic)
0205 {
0206     char buf[1024];
0207     UBFH *p_ub = (UBFH *)buf;
0208     char *tree = NULL;
0209     double f;
0210     short s;
0211     double d_large=1223234232342324323423423423423423434342343454353453243245343453243452343453243243425343453425523423423423423234234234234234234234234234234234234234234234234243234234324343.65;
0212     float f_large=1223234232342324323423423423423423434342343454353453243245343453243452343453243243425343453425523423423423423234234234234234234234234234234234234234234234234243234234324343.65;
0213     assert_equal(Binit(p_ub, sizeof(buf)), EXSUCCEED);
0214     load_field_table(); /* set field table environment variable */
0215 
0216     /*----------------------------------------------------------*/
0217     /* Basic testing of OR */
0218         f = 127.001;
0219         assert_equal(Badd(p_ub, T_STRING_FLD, "TEST STR VAL", 0), EXSUCCEED);
0220         assert_equal(Badd(p_ub, T_DOUBLE_FLD, (char *)&f, 0), EXSUCCEED);
0221         /* In this case second expression should not be valuated. */
0222         tree=Bboolco ("T_DOUBLE_FLD==127.001 || T_STRING_FLD=='TEST STR VAL'");
0223         assert_not_equal(tree, NULL);
0224         assert_equal(Bboolev(p_ub, tree), EXTRUE);
0225 
0226         /* Now should be true because of second expression  */
0227         f = 127.002;
0228         assert_equal(Bchg(p_ub, T_STRING_FLD, 0, "TEST STR VAL", 0), EXSUCCEED);
0229         assert_equal(Bchg(p_ub, T_DOUBLE_FLD, 0, (char *)&f, 0), EXSUCCEED);
0230         assert_equal(Bboolev(p_ub, tree), EXTRUE);
0231         /* should be true */
0232         f = 127.001;
0233         assert_equal(Bchg(p_ub, T_STRING_FLD, 0, "XTEST STR VAL", 0), EXSUCCEED);
0234         assert_equal(Bchg(p_ub, T_DOUBLE_FLD, 0, (char *)&f, 0), EXSUCCEED);
0235         assert_equal(Bboolev(p_ub, tree), EXTRUE);
0236 
0237         /* Now it should not true */
0238         f = 127.002;
0239         assert_equal(Bchg(p_ub, T_STRING_FLD, 0, "XTEST STR VAL", 0), EXSUCCEED);
0240         assert_equal(Bchg(p_ub, T_DOUBLE_FLD, 0, (char *)&f, 0), EXSUCCEED);
0241         assert_equal(Bboolev(p_ub, tree), EXFALSE);
0242         Btreefree(tree);
0243     /*----------------------------------------------------------*/
0244     /* Basic AND testing */
0245         /* this should be true. */
0246         f = 127.001;
0247         assert_equal(Bchg(p_ub, T_STRING_FLD, 0, "TEST STR VAL", 0), EXSUCCEED);
0248         assert_equal(Bchg(p_ub, T_DOUBLE_FLD, 0, (char *)&f, 0), EXSUCCEED);
0249         tree=Bboolco ("T_DOUBLE_FLD==127.001 && T_STRING_FLD=='TEST STR VAL'");
0250         assert_not_equal(tree, NULL);
0251         assert_equal(Bboolev(p_ub, tree), EXTRUE);
0252         /* this should be false */
0253         f = 127.002;
0254         assert_equal(Bchg(p_ub, T_DOUBLE_FLD, 0, (char *)&f, 0), EXSUCCEED);
0255         assert_equal(Bboolev(p_ub, tree), EXFALSE);
0256         /* this also should be false */
0257         f = 127.001;
0258         assert_equal(Bchg(p_ub, T_DOUBLE_FLD, 0, (char *)&f, 0), EXSUCCEED);
0259         assert_equal(Bchg(p_ub, T_STRING_FLD, 0, "XTEST STR VAL", 0), EXSUCCEED);
0260         assert_equal(Bboolev(p_ub, tree), EXFALSE);
0261         /* Both false - false */
0262         f = 127.002;
0263         assert_equal(Bchg(p_ub, T_DOUBLE_FLD, 0, (char *)&f, 0), EXSUCCEED);
0264         assert_equal(Bchg(p_ub, T_STRING_FLD, 0, "XTEST STR VAL", 0), EXSUCCEED);
0265         assert_equal(Bboolev(p_ub, tree), EXFALSE);
0266         Btreefree(tree);
0267     /*----------------------------------------------------------*/
0268     /* Basic not (!) testing */
0269         s = 0; /* In this case if field is present, then value is true! */
0270         assert_equal(Bchg(p_ub, T_SHORT_FLD, 0, (char *)&f, 0), EXSUCCEED);
0271         tree=Bboolco ("T_DOUBLE_FLD || !1");
0272         assert_not_equal(tree, NULL);
0273         assert_equal(Bboolev(p_ub, tree), EXTRUE);
0274         /* should be true too */
0275         s = 1; /* In this case if field is present, then value is true! */
0276         assert_equal(Bchg(p_ub, T_SHORT_FLD, 0, (char *)&f, 0), EXSUCCEED);
0277         assert_equal(Bboolev(p_ub, tree), EXTRUE);
0278         Btreefree(tree);
0279         /*----------------------------------------------------------*/
0280         tree=Bboolco ("!1");
0281         assert_not_equal(tree, NULL);
0282         assert_equal(Bboolev(p_ub, tree), EXFALSE);
0283         Btreefree(tree);
0284         /*----------------------------------------------------------*/
0285         s = 0;
0286         assert_equal(Bchg(p_ub, T_SHORT_FLD, 0, (char *)&f, 0), EXSUCCEED);
0287         tree=Bboolco ("!T_SHORT_FLD || T_SHORT_FLD");
0288         assert_not_equal(tree, NULL);
0289         assert_equal(Bboolev(p_ub, tree), EXTRUE);
0290         Btreefree(tree);
0291         /*----------------------------------------------------------*/
0292         tree=Bboolco ("!T_SHORT_FLD || !T_SHORT_FLD");
0293         assert_not_equal(tree, NULL);
0294         assert_equal(Bboolev(p_ub, tree), EXFALSE);
0295         Btreefree(tree);
0296         
0297         /*----------------------------------------------------------*/
0298         /* Bug #325 */
0299         s = 1;
0300         /* assert_equal(Bchg(p_ub, T_SHORT_FLD, 0, (char *)&s, 0), EXSUCCEED); */
0301         assert_equal(CBchg(p_ub, T_CHAR_FLD, 0, "2", 0, BFLD_STRING), EXSUCCEED);
0302         assert_equal(Bdel(p_ub, T_SHORT_FLD, 0), EXSUCCEED);
0303         
0304         tree=Bboolco ("((T_CHAR_FLD== '1') || (T_CHAR_FLD == '2') || (T_CHAR_FLD=='3') || (T_CHAR_FLD=='4') || (T_CHAR_FLD=='Y')) && !(T_SHORT_FLD==1)");
0305         assert_not_equal(tree, NULL);
0306         assert_equal(Bboolev(p_ub, tree), EXTRUE);
0307         Btreefree(tree);
0308         
0309         tree=Bboolco ("((T_CHAR_FLD== '1') || (T_CHAR_FLD == '2') || (T_CHAR_FLD=='3') || (T_CHAR_FLD=='4') || (T_CHAR_FLD=='Y')) && !(1-2)");
0310         assert_not_equal(tree, NULL);
0311         assert_equal(Bboolev(p_ub, tree), EXFALSE);
0312         Btreefree(tree);
0313         
0314         tree=Bboolco ("(!(2-1)+1)==(!(4-3)+1)");
0315         assert_not_equal(tree, NULL);
0316         assert_equal(Bboolev(p_ub, tree), EXTRUE);
0317         Btreefree(tree);
0318         
0319         tree=Bboolco ("(4-4)");
0320         assert_not_equal(tree, NULL);
0321         assert_equal(Bboolev(p_ub, tree), EXFALSE);
0322         Btreefree(tree);
0323         
0324     /*----------------------------------------------------------*/
0325      /* Basic not XOR testing */
0326         tree=Bboolco ("1 ^ 1"); /* false */
0327         assert_not_equal(tree, NULL);
0328         assert_equal(Bboolev(p_ub, tree), EXFALSE);
0329         Btreefree(tree);
0330         /*----------------------------------------------------------*/
0331         tree=Bboolco ("0 ^ 1"); /* true */
0332         assert_not_equal(tree, NULL);
0333         assert_equal(Bboolev(p_ub, tree), EXTRUE);
0334         Btreefree(tree);
0335         /*----------------------------------------------------------*/
0336         tree=Bboolco ("1 ^ 0"); /* true */
0337         assert_not_equal(tree, NULL);
0338         assert_equal(Bboolev(p_ub, tree), EXTRUE);
0339         Btreefree(tree);
0340         /*----------------------------------------------------------*/
0341         tree=Bboolco ("0 ^ 0"); /* true */
0342         assert_not_equal(tree, NULL);
0343         assert_equal(Bboolev(p_ub, tree), EXFALSE);
0344         Btreefree(tree);       
0345     /*----------------------------------------------------------*/
0346      /* Test large float & double => was Overflow. */
0347         assert_equal(Bchg(p_ub, T_FLOAT_FLD, 0, (char *)&f_large, 0), EXSUCCEED);
0348         assert_equal(Bchg(p_ub, T_DOUBLE_FLD, 0, (char *)&d_large, 0), EXSUCCEED);
0349 
0350         tree=Bboolco ("T_FLOAT_FLD=='abc'"); /* false */
0351         assert_not_equal(tree, NULL);
0352         assert_equal(Bboolev(p_ub, tree), EXFALSE);
0353         Btreefree(tree);
0354 
0355         tree=Bboolco ("T_DOUBLE_FLD=='abc'"); /* false */
0356         assert_not_equal(tree, NULL);
0357         assert_equal(Bboolev(p_ub, tree), EXFALSE);
0358         Btreefree(tree);
0359 
0360 
0361 }
0362 /**
0363  * Tests ==, !=, %%, !%
0364  */
0365 Ensure(test_expr_basic_equality)
0366 {
0367     char buf[1024];
0368     UBFH *p_ub = (UBFH *)buf;
0369     char *tree = NULL;
0370     assert_equal(Binit(p_ub, sizeof(buf)), EXSUCCEED);
0371     load_field_table(); /* set field table environment variable */
0372 
0373     /*----------------------------------------------------------*/
0374     load_expr_test_data_1(p_ub);
0375     tree=Bboolco ("T_SHORT_FLD==102 && T_LONG_FLD==10212312 && T_CHAR_FLD=='a'&&"
0376                   "T_FLOAT_FLD-127.001<0.01 && T_FLOAT_2_FLD==12127 && "
0377                   "T_DOUBLE_FLD==12312312.1112 &&  "
0378                   "T_STRING_FLD=='TEST STR VAL' && T_CARRAY_FLD=='CARRAY TEST'");
0379     assert_not_equal(tree, NULL);
0380     assert_equal(Bboolev(p_ub, tree), EXTRUE);
0381     load_expr_test_data_2(p_ub);
0382     assert_equal(Bboolev(p_ub, tree), EXFALSE);
0383     Btreefree(tree); 
0384     /*----------------------------------------------------------*/
0385     load_expr_test_data_1(p_ub);
0386     tree=Bboolco ("T_SHORT_FLD!=102 || T_LONG_FLD!=10212312 || T_CHAR_FLD!='a'||"
0387                   "T_FLOAT_FLD-127.001>=0.01 || T_DOUBLE_FLD!=12312312.1112 || "
0388                   "T_DOUBLE_FLD!=12312312.1112 ||  "
0389                   "T_STRING_FLD!='TEST STR VAL' ||   T_CARRAY_FLD!='CARRAY TEST'");
0390     assert_not_equal(tree, NULL);
0391     assert_equal(Bboolev(p_ub, tree), EXFALSE);
0392     load_expr_test_data_2(p_ub);
0393     assert_equal(Bboolev(p_ub, tree), EXTRUE);
0394     Btreefree(tree);
0395     /*----------------------------------------------------------*/
0396         /* Actually here is error, that expression (T_FLOAT_FLD-127.001 %% '0\\.0.*')
0397          * is done against regex, so it will fail due to syntax error.
0398          */
0399         load_expr_test_data_1(p_ub);
0400         tree=Bboolco ("T_SHORT_FLD %% '1.2' && T_LONG_FLD %% '1021.312' && T_CHAR_FLD %% 'a'&&"
0401                       "T_FLOAT_FLD-127.001 %% '0\\.0.*' && T_DOUBLE_FLD %% '12312312.1112' &&  "
0402                       "T_STRING_FLD %% 'TEST STR ...' && T_CARRAY_FLD  %% 'CA..AY TEST'");
0403         assert_equal(tree, NULL);
0404         assert_equal(Berror, BSYNTAX);
0405 
0406         tree=Bboolco ("T_SHORT_FLD %% '1.2' && T_LONG_FLD %% '1021.312' && T_CHAR_FLD %% 'a'&&"
0407                       "T_FLOAT_FLD %% '127.*' && T_DOUBLE_FLD %% '12312312\\.111.*' &&  "
0408                       "T_STRING_FLD %% 'TEST STR ...' && T_CARRAY_FLD  %% 'CA..AY TEST'");
0409         assert_not_equal(tree, NULL);
0410         /* Above stuff should be true. */
0411         assert_equal(Bboolev(p_ub, tree), EXTRUE);
0412         load_expr_test_data_2(p_ub);
0413         /* should be false */
0414         assert_equal(Bboolev(p_ub, tree), EXFALSE);
0415         Btreefree(tree);
0416     /*----------------------------------------------------------*/
0417         /* Test error reporting when regular expression syntax is failed */
0418         load_expr_test_data_1(p_ub);
0419         tree=Bboolco ("T_SHORT_FLD %% '((((())))(()()\\9\12\1\\3\1((('");
0420         assert_not_equal(tree, NULL);
0421         assert_not_equal(Berror, BSYNTAX);
0422         
0423         assert_equal(Bboolev(p_ub, tree), EXFAIL);
0424         assert_equal(Berror, BSYNTAX);
0425         Btreefree(tree);
0426 
0427     /*----------------------------------------------------------*/
0428        
0429         tree=Bboolco ("T_SHORT_FLD !% '1.2' || T_LONG_FLD !% '1021.312' || T_CHAR_FLD !% 'a'||"
0430                       "T_FLOAT_FLD !% '127.*' || T_DOUBLE_FLD !% '12312312\\.111.*' ||  "
0431                       "T_STRING_FLD !% 'TEST STR ...' || T_CARRAY_FLD  !% 'CA..AY TEST'");
0432         assert_not_equal(tree, NULL);
0433         
0434         /* Above stuff should be false, because we have correct data */
0435         load_expr_test_data_1(p_ub);
0436         assert_equal(Bboolev(p_ub, tree), EXFALSE);
0437         load_expr_test_data_2(p_ub);
0438         /* should be TRUE, because we have bad data */
0439         assert_equal(Bboolev(p_ub, tree), EXTRUE);        
0440         
0441         Btreefree(tree);
0442     /*----------------------------------------------------------*/
0443        
0444         tree=Bboolco ("(T_STRING_9_FLD %% '79.*') || (T_STRING_10_FLD %% '79.*') || (T_STRING_FLD %% '79.*')");
0445         assert_not_equal(tree, NULL);
0446         
0447         /* Above stuff should be false, because we have correct data */
0448         load_expr_test_data_1(p_ub);
0449         assert_equal(Bboolev(p_ub, tree), EXFALSE);
0450         
0451         Btreefree(tree);
0452 
0453     /*----------------------------------------------------------*/
0454         /* test FB-to-FB equality */
0455 
0456         tree=Bboolco ("T_SHORT_FLD==T_SHORT_FLD && T_LONG_FLD==T_LONG_FLD && T_CHAR_FLD==T_CHAR_FLD&&"
0457                       "T_FLOAT_FLD==T_FLOAT_FLD && T_DOUBLE_FLD==T_DOUBLE_FLD &&  "
0458                       "T_STRING_FLD==T_STRING_FLD && T_CARRAY_FLD==T_CARRAY_FLD");
0459         assert_not_equal(tree, NULL);
0460         /* should be true with no matter of which data */
0461 
0462         load_expr_test_data_1(p_ub);
0463         assert_equal(Bboolev(p_ub, tree), EXTRUE);
0464         load_expr_test_data_2(p_ub);
0465         assert_equal(Bboolev(p_ub, tree), EXTRUE);
0466         Btreefree(tree);
0467     /*----------------------------------------------------------*/
0468         /* test Non existing field compare to 0, should be false */
0469         tree=Bboolco ("T_STRING_FLD=='0'");
0470         assert_not_equal(tree, NULL);
0471         /* should be true with no matter of which data */
0472         while (Bpres(p_ub, T_STRING_FLD, 0))
0473             Bdel(p_ub, T_STRING_FLD, 0);
0474         
0475         assert_equal(Bboolev(p_ub, tree), EXFALSE);
0476 
0477         Btreefree(tree);
0478     /*----------------------------------------------------------*/
0479 
0480 }
0481 
0482 /**
0483  * +, -, !, ~
0484  * Not sure about ~, but it should work simillary.
0485  */
0486 Ensure(test_expr_basic_unary)
0487 {
0488     char buf[1024];
0489     UBFH *p_ub = (UBFH *)buf;
0490     char *tree = NULL;
0491     assert_equal(Binit(p_ub, sizeof(buf)), EXSUCCEED);
0492     long test_long;
0493     load_field_table(); /* set field table environment variable */
0494 
0495     /*----------------------------------------------------------*/
0496         /* unary - operation test */
0497         load_expr_test_data_1(p_ub);
0498         tree=Bboolco ("-T_SHORT_FLD==0-102 && -T_LONG_FLD==0-10212312 && -T_CHAR_FLD==0 &&"
0499                   "-T_FLOAT_FLD<-126.001 && -T_DOUBLE_FLD==0-12312312.1112 &&  "
0500                   "-T_STRING_FLD==0 && -T_CARRAY_FLD==0 && -1==0-1 && -1.0==0-1");
0501         assert_not_equal(tree, NULL);
0502         assert_equal(Bboolev(p_ub, tree), EXTRUE);
0503         load_expr_test_data_2(p_ub);
0504         assert_equal(Bboolev(p_ub, tree), EXFALSE);
0505         Btreefree(tree);
0506     /*----------------------------------------------------------*/
0507         /* unary + operation test */
0508         load_expr_test_data_1(p_ub);
0509         tree=Bboolco ("+T_SHORT_FLD==+102 && +T_LONG_FLD==10212312 && +T_CHAR_FLD==0 &&"
0510                   "+T_FLOAT_FLD>=126.001 && T_FLOAT_2_FLD==12127 && +T_DOUBLE_FLD==+12312312.1112 &&  "
0511                   "+T_STRING_FLD==0 && +T_CARRAY_FLD==0");
0512         assert_not_equal(tree, NULL);
0513         assert_equal(Bboolev(p_ub, tree), EXTRUE);
0514         load_expr_test_data_2(p_ub);
0515         assert_equal(Bboolev(p_ub, tree), EXFALSE);
0516         Btreefree(tree);
0517     /*----------------------------------------------------------*/
0518         /* test ! on fields */
0519         load_expr_test_data_1(p_ub);
0520         /* Now delete all the stuff from FB? */
0521         delete_fb_test_data(p_ub);
0522         tree=Bboolco ("!T_SHORT_FLD && !T_LONG_FLD && !T_CHAR_FLD &&"
0523                   "!T_FLOAT_FLD && !T_DOUBLE_FLD &&  "
0524                   "!T_STRING_FLD && !T_CARRAY_FLD && !0 && !(!'0') && !0.0");
0525         assert_not_equal(tree, NULL);
0526         assert_equal(Bboolev(p_ub, tree), EXTRUE);
0527         /* now restore the data - should fail, because data available */
0528         load_expr_test_data_1(p_ub);
0529         assert_equal(Bboolev(p_ub, tree), EXFALSE);
0530         Btreefree(tree);
0531     /*----------------------------------------------------------*/
0532         /* test ! on fields */
0533         load_expr_test_data_1(p_ub);
0534         tree=Bboolco ("~T_SHORT_FLD==-2 && ~T_LONG_FLD==-2 && ~T_CHAR_FLD==-2 &&"
0535                   "~T_FLOAT_FLD==-2 && ~T_DOUBLE_FLD==-2 &&  "
0536                   "~T_STRING_FLD==-2 && ~T_CARRAY_FLD==-2 && ~0==-1 && ~'0'==-2 && ~0.0==-1");
0537         assert_not_equal(tree, NULL);
0538         assert_equal(Bboolev(p_ub, tree), EXTRUE);
0539         /* Test with 0 in LONG field - result should be the same. */
0540         test_long = 0;
0541         assert_equal(CBchg(p_ub, T_LONG_FLD, 0, (char *)&test_long, 0, BFLD_LONG), EXSUCCEED);
0542         assert_equal(Bboolev(p_ub, tree), EXTRUE);
0543         Btreefree(tree);
0544 }
0545 /**
0546  * Math operations with: +, -
0547  */
0548 Ensure(test_expr_basic_additive)
0549 {
0550     char buf[1024];
0551     UBFH *p_ub = (UBFH *)buf;
0552     char *tree = NULL;
0553     assert_equal(Binit(p_ub, sizeof(buf)), EXSUCCEED);
0554     double d = 2312.2;
0555     int big_test;
0556     load_field_table(); /* set field table environment variable */
0557     /*----------------------------------------------------------*/
0558         /* test + */
0559 
0560         /* T_SHORT_FLD = 102
0561          * T_LONG_FLD = 10212312
0562          * T_CHAR_FLD = 8
0563          * T_FLOAT_2_FLD = 12127
0564          * T_DOUBLE_FLD = 2312.2
0565          * T_STRING_FLD = 144
0566          * T_CARRAY_FLD= 244
0567          */
0568         tree=Bboolco ("100+100==200 && 100.51+100.49==201 && '123'+'123'==246 &&"
0569                       "T_SHORT_FLD+50==152 && T_SHORT_FLD+50==152.0 && "
0570                       "T_SHORT_FLD+50.1==152.1 && T_LONG_FLD+1==10212313 &&"
0571                       "T_LONG_FLD+1.1==10212313+0.1 && T_FLOAT_2_FLD+3==12130 &&"
0572                       "T_CHAR_FLD+1==9 && T_CHAR_FLD+0.1==8.1 && "
0573                       "T_CHAR_FLD+'1'==9 && T_CHAR_FLD+'0.1'==8+0.1 &&"
0574                       "T_CHAR_FLD+'1'=='5'+'4' &&"
0575                       "T_FLOAT_2_FLD+3.0==12130 && T_FLOAT_2_FLD+'3.0'==12130 && "
0576                       "T_FLOAT_2_FLD+'3'==12130 && T_FLOAT_2_FLD+'4'==12130.0+1 &&"
0577                       "T_DOUBLE_FLD+1==2313.2 && T_DOUBLE_FLD+'1'==2313.2 &&"
0578                       "T_DOUBLE_FLD+1.0=='2313.2'+0.1-0.1 &&"
0579                       "T_STRING_FLD+1==145 && T_STRING_FLD+0.1==144.1 && "
0580                       "T_STRING_FLD+'1'==145 && T_STRING_FLD+'0.1'==144+0.1 &&"
0581                       "T_STRING_FLD+'1'=='100'+'45' &&"
0582                       "T_CARRAY_FLD+1==245 && T_CARRAY_FLD+0.1==244.1 && "
0583                       "T_CARRAY_FLD+'1'==245 && T_CARRAY_FLD+'0.1'==244+0.1 &&"
0584                       "T_CARRAY_FLD+'1'=='200'+'45'");
0585         assert_not_equal(tree, NULL);
0586 #if UBF_BIG_TEST
0587         for (big_test=0; big_test<50; big_test++)
0588         {
0589 #endif
0590             load_expr_test_data_1(p_ub);
0591             /* Fix up double */
0592             assert_equal(Bchg(p_ub, T_DOUBLE_FLD, 0, (char *)&d, 0), EXSUCCEED);
0593             assert_equal(Bchg(p_ub, T_STRING_FLD, 0, (char *)"144", 0), EXSUCCEED);
0594             assert_equal(CBchg(p_ub, T_CARRAY_FLD, 0, (char *)"244", 3, BFLD_STRING), EXSUCCEED);
0595             assert_equal(CBchg(p_ub, T_CHAR_FLD, 0, (char *)"8", 3, BFLD_STRING), EXSUCCEED);
0596         
0597             assert_equal(Bboolev(p_ub, tree), EXTRUE);
0598             load_expr_test_data_2(p_ub);
0599             assert_equal(Bboolev(p_ub, tree), EXFALSE);
0600 #if UBF_BIG_TEST
0601         }
0602 #endif
0603         Btreefree(tree);
0604    /*----------------------------------------------------------*/
0605         /* test - */
0606         load_expr_test_data_1(p_ub);
0607         /* Fix up double */
0608         assert_equal(Bchg(p_ub, T_DOUBLE_FLD, 0, (char *)&d, 0), EXSUCCEED);
0609         assert_equal(Bchg(p_ub, T_STRING_FLD, 0, (char *)"144", 0), EXSUCCEED);
0610         assert_equal(CBchg(p_ub, T_CARRAY_FLD, 0, (char *)"-244", 3, BFLD_STRING), EXSUCCEED);
0611         assert_equal(CBchg(p_ub, T_CHAR_FLD, 0, (char *)"8", 3, BFLD_STRING), EXSUCCEED);
0612         
0613         /* T_SHORT_FLD = 102
0614          * T_LONG_FLD = 10212312
0615          * T_CHAR_FLD = 8
0616          * T_FLOAT_2_FLD = 12127
0617          * T_DOUBLE_FLD = 2312.2
0618          * T_STRING_FLD = 144
0619          * T_CARRAY_FLD= 244
0620          */
0621         tree=Bboolco ("100-100==0 && 100.51-100.49==0.02 && '123'-'126'==-3 && "
0622                       "50-T_SHORT_FLD==-52 && 50-T_SHORT_FLD==-52.0 && "
0623                       "T_SHORT_FLD-50.1==51.9 && 1-T_LONG_FLD==-10212311 &&"
0624                       "-T_LONG_FLD+1.1==-10212310.9 && T_LONG_FLD-1==10212311 &&"
0625                       "1-T_CHAR_FLD==-7 && T_CHAR_FLD-0.1==7.9 && "
0626                       "T_CHAR_FLD-'1'==7 && T_CHAR_FLD-'0.1'==8-0.1 &&"
0627                       "T_CHAR_FLD-'1'=='5'+'5'-3 && T_FLOAT_2_FLD-2==12125 &&"
0628                       "T_FLOAT_2_FLD-3.0==12124 && -T_FLOAT_2_FLD-'3.0'==-12130 && "
0629                       "T_FLOAT_2_FLD-'3'==12124 && T_FLOAT_2_FLD-'4'==12123+1-1 &&"
0630                       "T_DOUBLE_FLD-1==2311.2 && T_DOUBLE_FLD-'1'==2311.2 &&"
0631                       "T_DOUBLE_FLD-1.2=='2311'+0.1-0.1 &&"
0632                       "T_STRING_FLD-3==141 && 0.3-T_STRING_FLD==-143.7 && "
0633                       "T_STRING_FLD-'3'==141 && T_STRING_FLD-'0.3'==143.7 &&"
0634                       "T_STRING_FLD-'3'=='141'+4-'4' &&"
0635                       "T_CARRAY_FLD-5==-249 && T_CARRAY_FLD-0.5==-244.5 && "
0636                       "-T_CARRAY_FLD+'5'==+249 && T_CARRAY_FLD-'0.5'==-244-0.5 &&"
0637                       "T_CARRAY_FLD-'5'=='-244'-'5'");
0638         
0639         assert_equal(Bboolev(p_ub, tree), EXTRUE);
0640         load_expr_test_data_2(p_ub);
0641         assert_equal(Bboolev(p_ub, tree), EXFALSE);
0642         Btreefree(tree);
0643 }
0644 
0645 /**
0646  * Math operations with: *, /, %
0647  */
0648 Ensure(test_expr_basic_multiplicative)
0649 {
0650     char buf[1024];
0651     UBFH *p_ub = (UBFH *)buf;
0652     char *tree = NULL;
0653     assert_equal(Binit(p_ub, sizeof(buf)), EXSUCCEED);
0654     double d = 2312.2;
0655     int big_test;
0656     load_field_table(); /* set field table environment variable */
0657     /*----------------------------------------------------------*/
0658         /* test * */
0659         /* T_SHORT_FLD = 257
0660          * T_LONG_FLD = -8941
0661          * T_CHAR_FLD = 2
0662          * T_FLOAT_2_FLD = -0.2
0663          * T_DOUBLE_FLD = 887441
0664          * T_STRING_FLD = 448.33
0665          * T_CARRAY_FLD= 55412.11
0666          */
0667         assert_equal(CBchg(p_ub, T_SHORT_FLD, 0, (char *)"257", 3, BFLD_STRING), EXSUCCEED);
0668         assert_equal(CBchg(p_ub, T_LONG_FLD, 0, (char *)"-8941", 3, BFLD_STRING), EXSUCCEED);
0669         assert_equal(CBchg(p_ub, T_CHAR_FLD, 0, (char *)"2", 3, BFLD_STRING), EXSUCCEED);
0670         assert_equal(CBchg(p_ub, T_FLOAT_2_FLD, 0, (char *)"-0.2", 3, BFLD_STRING), EXSUCCEED);
0671         assert_equal(CBchg(p_ub, T_DOUBLE_FLD, 0, (char *)"887441", 3, BFLD_STRING), EXSUCCEED);
0672         assert_equal(CBchg(p_ub, T_STRING_FLD, 0, (char *)"448.33", 3, BFLD_STRING), EXSUCCEED);
0673         assert_equal(CBchg(p_ub, T_CARRAY_FLD, 0, (char *)"55412.11", 3, BFLD_STRING), EXSUCCEED);
0674 
0675         tree=Bboolco ("100*100==10000 && 100.51*1.49==149.7599 && '123'*'13'==1599 && -1*-1==1 &&"
0676                       "1285==T_SHORT_FLD*5 && 1310.7==T_SHORT_FLD*5.1 && "
0677                       "'1.1'*T_SHORT_FLD==282.7 && T_LONG_FLD*3==-26823 &&"
0678                       "-T_LONG_FLD*'1.1'==8941*1.1 && T_LONG_FLD*1.1==-8941*1.1 && "
0679                       "T_FLOAT_2_FLD*23==-4.6 &&"
0680                       "T_CHAR_FLD*2==4 && T_CHAR_FLD*0.3==0.6 && "
0681                       "T_CHAR_FLD*'4'==8 && T_CHAR_FLD*'0.3'==2*0.3 &&"
0682                       "T_CHAR_FLD*'3'==2+'4' &&"
0683                       "T_FLOAT_2_FLD*3.0==-0.6 && -T_FLOAT_2_FLD*'3.0'==0.6 && "
0684                       "T_FLOAT_2_FLD*'3'==-0.6 && T_FLOAT_2_FLD*'4'==-0.8 &&"
0685                       "T_DOUBLE_FLD*3==2662323 && T_DOUBLE_FLD*'2'==1774882 &&"
0686                       "T_DOUBLE_FLD*1.5=='1331161.5'+0 &&"
0687                       "T_STRING_FLD*3==1344.99 && T_STRING_FLD*0.3==134.499 && "
0688                       "T_STRING_FLD*'3'==1344.99 && T_STRING_FLD*'0.7'==313.831 &&"
0689                       "T_STRING_FLD*'3'==1344 + 0.99 &&"
0690                       "T_CARRAY_FLD*0.7==38788.477 && T_CARRAY_FLD*0.7==38788.477 && "
0691                       "T_CARRAY_FLD*'0.7'==38788.477 && 38788.477==T_CARRAY_FLD*'0.7' &&"
0692                       "T_CARRAY_FLD*'0.7'==('38788.477'/0.7)*0.7 &&"
0693                       "T_SHORT_FLD %% '257.*'");
0694         assert_not_equal(tree, NULL);
0695         assert_equal(Bboolev(p_ub, tree), EXTRUE);
0696         load_expr_test_data_2(p_ub);
0697         
0698         assert_equal(Bboolev(p_ub, tree), EXFALSE);
0699         Btreefree(tree);
0700     /*----------------------------------------------------------*/
0701         /* test / */
0702         assert_equal(CBchg(p_ub, T_SHORT_FLD, 0, (char *)"252", 3, BFLD_STRING), EXSUCCEED);
0703         assert_equal(CBchg(p_ub, T_LONG_FLD, 0, (char *)"-2980", 3, BFLD_STRING), EXSUCCEED);
0704         assert_equal(CBchg(p_ub, T_CHAR_FLD, 0, (char *)"2", 3, BFLD_STRING), EXSUCCEED);
0705         assert_equal(CBchg(p_ub, T_FLOAT_2_FLD, 0, (char *)"-0.2", 3, BFLD_STRING), EXSUCCEED);
0706         assert_equal(CBchg(p_ub, T_DOUBLE_FLD, 0, (char *)"42", 3, BFLD_STRING), EXSUCCEED);
0707         assert_equal(CBchg(p_ub, T_STRING_FLD, 0, (char *)"66", 3, BFLD_STRING), EXSUCCEED);
0708         assert_equal(CBchg(p_ub, T_CARRAY_FLD, 0, (char *)"80.4", 3, BFLD_STRING), EXSUCCEED);
0709 
0710         tree=Bboolco ("100/100==1 && 100.10/2==50.05 "
0711                       "&& '122'/'2'==61 "
0712                       "&& -3/-3==1"
0713                       "&& T_SHORT_FLD/2==252/2"
0714                       "&& 63==T_SHORT_FLD/4"
0715                       "&& '504'/T_SHORT_FLD==2.0 "
0716                       /* long -2980 */
0717                       "&& T_LONG_FLD/5==-2980/5"
0718                       "&& -T_LONG_FLD/-2980==-1"
0719                       "&& T_LONG_FLD/4.0==-745"
0720                       /* char: 2 */
0721                       "&& T_CHAR_FLD/2==1 "
0722                       "&& T_CHAR_FLD/2==1.0"
0723                       "&& T_CHAR_FLD/'1'=='2.0'-0"
0724                       "&& T_CHAR_FLD/'0.2'==10"
0725                       "&& T_CHAR_FLD/'2'==0+1"
0726                       /* float -0.2 */
0727                       "&& T_FLOAT_2_FLD/2.0==-0.1 "
0728                       "&& '4.0'/-T_FLOAT_2_FLD==20"
0729                       "&& '0.4'/T_FLOAT_2_FLD==-2 "
0730                       "&& T_FLOAT_2_FLD/'4'==-0.05"
0731                       /* double: 42 */
0732                       "&& T_DOUBLE_FLD/2==21 "
0733                       "&& T_DOUBLE_FLD/'1'==42"
0734                       "&& T_DOUBLE_FLD/1.5=='28'+0"
0735                       /* string: 66 */
0736                       "&& T_STRING_FLD/3==22 "
0737                       "&& 220==T_STRING_FLD/0.3"
0738                       "&& T_STRING_FLD/'3'==22.00"
0739                       "&& T_STRING_FLD/'0.5'==132"
0740                       "&& T_STRING_FLD/'3'==21.5 + 0.5"
0741                       /* carray: 80.4 */
0742                       "&& T_CARRAY_FLD/0.2==402"
0743                       "&& T_CARRAY_FLD/0.2==402.00"
0744                       "&& T_CARRAY_FLD/'2'==40.2"
0745                       "&& 16.08==T_CARRAY_FLD/'5'"
0746                       "&& T_CARRAY_FLD/'4'==20.1000"
0747                 );
0748         assert_not_equal(tree, NULL);
0749         assert_equal(Bboolev(p_ub, tree), EXTRUE);
0750         load_expr_test_data_2(p_ub);
0751         assert_equal(Bboolev(p_ub, tree), EXFALSE);
0752         Btreefree(tree);
0753 
0754         tree=Bboolco ("100/0==0");
0755         assert_not_equal(tree, NULL);
0756         assert_equal(Bboolev(p_ub, tree), EXTRUE);
0757         Btreefree(tree);
0758 
0759     /*----------------------------------------------------------*/
0760         /* test % */
0761         assert_equal(CBchg(p_ub, T_SHORT_FLD, 0, (char *)"252", 3, BFLD_STRING), EXSUCCEED);
0762         assert_equal(CBchg(p_ub, T_LONG_FLD, 0, (char *)"-2980", 3, BFLD_STRING), EXSUCCEED);
0763         assert_equal(CBchg(p_ub, T_CHAR_FLD, 0, (char *)"7", 3, BFLD_STRING), EXSUCCEED);
0764         assert_equal(CBchg(p_ub, T_FLOAT_2_FLD, 0, (char *)"14", 3, BFLD_STRING), EXSUCCEED);
0765         assert_equal(CBchg(p_ub, T_DOUBLE_FLD, 0, (char *)"42", 3, BFLD_STRING), EXSUCCEED);
0766         assert_equal(CBchg(p_ub, T_STRING_FLD, 0, (char *)"66", 3, BFLD_STRING), EXSUCCEED);
0767         assert_equal(CBchg(p_ub, T_CARRAY_FLD, 0, (char *)"80.4", 3, BFLD_STRING), EXSUCCEED);
0768 
0769         tree=Bboolco ("100 % 97==3"
0770                       "&& 10 % 3==1 "
0771                       "&& 2.9%'3.0'==2"
0772                       "&& '8' % '7'==1 "
0773                       "&& -2 %-3==-2"
0774                       "&& T_SHORT_FLD%200==52"
0775                       "&& 52.00==T_SHORT_FLD%200"
0776                       "&& '504'%T_SHORT_FLD==0"
0777                       /* long -2980 */
0778                       "&& T_LONG_FLD %  5 ==-2980%5"
0779                       "&& T_LONG_FLD % -3000 == -2980"
0780                       "&& T_LONG_FLD % 1== 0"
0781                       /* char: 2 */
0782                       "&& T_CHAR_FLD%2==1 "
0783                       "&& T_CHAR_FLD%5==2.0"
0784                       "&& T_CHAR_FLD%'5'=='2.0'-0"
0785                       "&& T_CHAR_FLD%'0.2'==7" /* special case from original system v8 */
0786                       "&& T_CHAR_FLD%'2'==0+1"
0787                       /* float -0.2 */
0788                       "&& T_FLOAT_2_FLD%2.0==0.0 "
0789                       "&& '4.0'%-T_FLOAT_2_FLD==4"
0790                       "&& '0.4'%T_FLOAT_2_FLD==0"
0791                       "&& T_FLOAT_2_FLD%'4'==2.00"
0792                       /* double: 42 */
0793                       "&& T_DOUBLE_FLD%5.5==2"
0794                       "&& T_DOUBLE_FLD%'1'==0"
0795                       "&& T_DOUBLE_FLD%1.5=='0'+0"
0796                       /* string: 66 */
0797                       "&& T_STRING_FLD%3==0"
0798                       "&& 66==T_STRING_FLD%0.3"
0799                       "&& T_STRING_FLD%'3'==0"
0800                       "&& T_STRING_FLD%'0.5'==66"
0801                       "&& T_STRING_FLD%'8'==2"
0802                       /* carray: 80.4 */
0803                       "&& T_CARRAY_FLD%8==0"
0804                       "&& T_CARRAY_FLD%4.2==0.00"
0805                       "&& T_CARRAY_FLD%'7'==3"
0806                       "&& 8.00==T_CARRAY_FLD%'12'"
0807                       "&& T_CARRAY_FLD%'100'==80"
0808                 );
0809         assert_not_equal(tree, NULL);
0810         assert_equal(Bboolev(p_ub, tree), EXTRUE);
0811         load_expr_test_data_2(p_ub);
0812         assert_equal(Bboolev(p_ub, tree), EXFALSE);
0813         Btreefree(tree);
0814 }
0815 
0816 /**
0817  * Basic floatev support test
0818  */
0819 Ensure(test_expr_basic_floatev)
0820 {
0821     char buf[1024];
0822     UBFH *p_ub = (UBFH *)buf;
0823     char *tree = NULL;
0824     assert_equal(Binit(p_ub, sizeof(buf)), EXSUCCEED);
0825     load_field_table(); /* set field table environment variable */
0826     /*----------------------------------------------------------*/
0827         /* test % */
0828         assert_equal(CBchg(p_ub, T_SHORT_FLD, 0, (char *)"252", 3, BFLD_STRING), EXSUCCEED);
0829         assert_equal(CBchg(p_ub, T_LONG_FLD, 0, (char *)"-2980", 3, BFLD_STRING), EXSUCCEED);
0830         assert_equal(CBchg(p_ub, T_CHAR_FLD, 0, (char *)"7", 3, BFLD_STRING), EXSUCCEED);
0831         assert_equal(CBchg(p_ub, T_FLOAT_2_FLD, 0, (char *)"14", 3, BFLD_STRING), EXSUCCEED);
0832         assert_equal(CBchg(p_ub, T_DOUBLE_FLD, 0, (char *)"42", 3, BFLD_STRING), EXSUCCEED);
0833         assert_equal(CBchg(p_ub, T_STRING_FLD, 0, (char *)"abc", 3, BFLD_STRING), EXSUCCEED);
0834         assert_equal(CBchg(p_ub, T_CARRAY_FLD, 0, (char *)"80.4", 3, BFLD_STRING), EXSUCCEED);
0835         /* Mod */
0836         tree=Bboolco ("100 % 97");
0837         assert_not_equal(tree, NULL);
0838         assert_equal(Bfloatev(p_ub, tree), 3.0);
0839         Btreefree(tree);
0840         /* Div */
0841         tree=Bboolco ("10/3");
0842         assert_not_equal(tree, NULL);
0843         assert_true(Bfloatev(p_ub, tree)>1.3);
0844         Btreefree(tree);
0845         /* Mul */
0846         tree=Bboolco ("10*3");
0847         assert_not_equal(tree, NULL);
0848         assert_equal(Bfloatev(p_ub, tree), 30);
0849         Btreefree(tree);
0850         /* + */
0851         tree=Bboolco ("0.9+19.1");
0852         assert_not_equal(tree, NULL);
0853         assert_equal(Bfloatev(p_ub, tree), 20);
0854         Btreefree(tree);
0855         /* - */
0856         tree=Bboolco ("'9'-'a'"); 
0857         assert_not_equal(tree, NULL);
0858         assert_equal(Bfloatev(p_ub, tree), 9);
0859         Btreefree(tree);
0860 
0861         tree=Bboolco ("'9'-'4'");
0862         assert_not_equal(tree, NULL);
0863         assert_equal(Bfloatev(p_ub, tree), 5);
0864         Btreefree(tree);
0865 
0866         tree=Bboolco ("T_CARRAY_FLD-0.4");
0867         assert_not_equal(tree, NULL);
0868         assert_equal(Bfloatev(p_ub, tree), 80);
0869         Btreefree(tree);
0870         /* field value */
0871         tree=Bboolco ("T_CARRAY_FLD");
0872         assert_not_equal(tree, NULL);
0873         assert_equal(Bfloatev(p_ub, tree), 80.4);
0874         Btreefree(tree);
0875         /* field value, logical */
0876         tree=Bboolco ("!T_CARRAY_FLD");
0877         assert_not_equal(tree, NULL);
0878         assert_equal(Bfloatev(p_ub, tree), 0);
0879         Btreefree(tree);
0880 
0881         tree=Bboolco ("!(!T_CARRAY_FLD)");
0882         assert_not_equal(tree, NULL);
0883         assert_equal(Bfloatev(p_ub, tree), 1);
0884         Btreefree(tree);
0885 
0886         tree=Bboolco ("T_STRING_FLD");
0887         assert_not_equal(tree, NULL);
0888         assert_equal(Bfloatev(p_ub, tree), 0);
0889         Btreefree(tree);
0890         
0891         tree=Bboolco ("T_STRING_FLD=='abc'");
0892         assert_not_equal(tree, NULL);
0893         assert_equal(Bfloatev(p_ub, tree), 1);
0894         Btreefree(tree);
0895 
0896         tree=Bboolco ("T_DOUBLE_FLD");
0897         assert_not_equal(tree, NULL);
0898         assert_double_equal(Bfloatev(p_ub, tree), 42);
0899         Btreefree(tree);
0900 
0901         tree=Bboolco ("T_LONG_FLD");
0902         assert_not_equal(tree, NULL);
0903         assert_double_equal(Bfloatev(p_ub, tree), -2980);
0904         Btreefree(tree);
0905         
0906 }
0907 
0908 /**
0909  * Relational: < , >, <=, >=, ==, !=
0910  */
0911 Ensure(test_expr_basic_relational)
0912 {
0913     char buf[1024];
0914     UBFH *p_ub = (UBFH *)buf;
0915     char *tree = NULL;
0916     assert_equal(Binit(p_ub, sizeof(buf)), EXSUCCEED);
0917     double d = 2312.2;
0918     int big_test;
0919     load_field_table(); /* set field table environment variable */
0920     /*----------------------------------------------------------*/
0921         /* test < */
0922         assert_equal(CBchg(p_ub, T_SHORT_FLD, 0, (char *)"252", 3, BFLD_STRING), EXSUCCEED);
0923         assert_equal(CBchg(p_ub, T_LONG_FLD, 0, (char *)"-2980", 3, BFLD_STRING), EXSUCCEED);
0924         assert_equal(CBchg(p_ub, T_CHAR_FLD, 0, (char *)"2", 3, BFLD_STRING), EXSUCCEED);
0925         assert_equal(CBchg(p_ub, T_FLOAT_2_FLD, 0, (char *)"-0.2", 3, BFLD_STRING), EXSUCCEED);
0926         assert_equal(CBchg(p_ub, T_DOUBLE_FLD, 0, (char *)"42", 3, BFLD_STRING), EXSUCCEED);
0927         assert_equal(CBchg(p_ub, T_STRING_FLD, 0, (char *)"66", 3, BFLD_STRING), EXSUCCEED);
0928         assert_equal(CBchg(p_ub, T_CARRAY_FLD, 0, (char *)"80.4", 3, BFLD_STRING), EXSUCCEED);
0929 
0930         tree=Bboolco ("10<100 "
0931                       "&& 100.10/2<51.05 "
0932                       "&& '2'<'322' " /* string cmp */
0933                       "&& -3<3"
0934                       "&& '1'<'a'"
0935                       /* short 252 */
0936                       "&& T_SHORT_FLD<300"
0937                       "&& T_SHORT_FLD<300.01"
0938                       "&& T_SHORT_FLD<'252'+1"
0939                       "&& !(T_SHORT_FLD<50) " /* should be false, but we invert. */
0940                       /* long -2980 */
0941                       "&& T_LONG_FLD<'-4000'" /* string comp */
0942                       "&& 100 < -T_LONG_FLD"
0943                       "&& T_LONG_FLD<'123'"
0944                       /* char: 2 */
0945                       "&& !(T_CHAR_FLD<1) "
0946                       "&& T_CHAR_FLD<'a'"
0947                       "&& T_CHAR_FLD<2.5"
0948                       "&& T_CHAR_FLD<'a'+3"
0949                       /* float -0.2 */
0950                       "&& T_FLOAT_2_FLD < 12"
0951                       "&& -0.2 < -T_FLOAT_2_FLD"
0952                       "&& !(T_FLOAT_2_FLD < -12.121)"
0953                       "&& -0.4 < T_FLOAT_2_FLD"
0954                       /* double: 42 */
0955                       "&& T_DOUBLE_FLD < 50"
0956                       "&& 30.1< T_DOUBLE_FLD"
0957                       "&& T_DOUBLE_FLD < 'abc'" /* string cmp */
0958                       /* string: 66 */
0959                       "&& T_STRING_FLD < 77"
0960                       "&& 40.01 < T_STRING_FLD"
0961                       "&& T_STRING_FLD < 'abc'"
0962                       "&& '0667' < T_STRING_FLD" /* string cmp */
0963                       "&& T_STRING_FLD < 100-40+55.6"
0964                       /* carray: 80.4 */
0965                       "&& T_CARRAY_FLD < 100"
0966                       "&& !(80.45 < T_CARRAY_FLD)"
0967                       "&& T_CARRAY_FLD < 'abc'"
0968                       "&& '00008000.40' < T_CARRAY_FLD"
0969                       "&& T_CARRAY_FLD < 80.4445"
0970                 );
0971         assert_not_equal(tree, NULL);
0972         assert_equal(Bboolev(p_ub, tree), EXTRUE);
0973         load_expr_test_data_2(p_ub);
0974         assert_equal(Bboolev(p_ub, tree), EXFALSE);
0975         Btreefree(tree);
0976         
0977         /*----------------------------------------------------------*/
0978         /* test > */
0979         assert_equal(CBchg(p_ub, T_SHORT_FLD, 0, (char *)"252", 3, BFLD_STRING), EXSUCCEED);
0980         assert_equal(CBchg(p_ub, T_LONG_FLD, 0, (char *)"-2980", 3, BFLD_STRING), EXSUCCEED);
0981         assert_equal(CBchg(p_ub, T_CHAR_FLD, 0, (char *)"2", 3, BFLD_STRING), EXSUCCEED);
0982         assert_equal(CBchg(p_ub, T_FLOAT_2_FLD, 0, (char *)"-0.2", 3, BFLD_STRING), EXSUCCEED);
0983         assert_equal(CBchg(p_ub, T_DOUBLE_FLD, 0, (char *)"42", 3, BFLD_STRING), EXSUCCEED);
0984         assert_equal(CBchg(p_ub, T_STRING_FLD, 0, (char *)"66", 3, BFLD_STRING), EXSUCCEED);
0985         assert_equal(CBchg(p_ub, T_CARRAY_FLD, 0, (char *)"80.4", 3, BFLD_STRING), EXSUCCEED);
0986 
0987         tree=Bboolco ("100>10 "
0988                       "&& 51.05>100.10/2 "
0989                       "&& '322'>'2' " /* string cmp */
0990                       "&& 3>-3"
0991                       "&& 'a'>'1'"
0992                       /* short 252 */
0993                       "&& 300>T_SHORT_FLD"
0994                       "&& 300.01>T_SHORT_FLD"
0995                       "&& '252'+1>T_SHORT_FLD"
0996                       "&& !(50>T_SHORT_FLD) " /* should be false, but we invert. */
0997                       /* long -2980 */
0998                       "&& '-4000'>T_LONG_FLD" /* string comp */
0999                       "&& -T_LONG_FLD>100 "
1000                       "&& '123'>T_LONG_FLD"
1001                       /* char: 2 */
1002                       "&& !(1>T_CHAR_FLD) "
1003                       "&& 'a'>T_CHAR_FLD"
1004                       "&& 2.5>T_CHAR_FLD"
1005                       "&& 'a'+3>T_CHAR_FLD"
1006                       /* float -0.2 */
1007                       "&& !(-0.3>T_FLOAT_2_FLD)"
1008                       "&& -T_FLOAT_2_FLD > -0.2"
1009                       "&& 12.121 > T_FLOAT_2_FLD"
1010                       "&& T_FLOAT_2_FLD > -0.4"
1011                       /* double: 42 */
1012                       "&& 50 > T_DOUBLE_FLD"
1013                       "&& !(T_DOUBLE_FLD > 50.1)"
1014                       "&& 'abc' > T_DOUBLE_FLD" /* string cmp */
1015                       /* string: 66 */
1016                       "&& 77 > T_STRING_FLD"
1017                       "&& !(T_STRING_FLD > 75.01)"
1018                       "&& 'abc' > T_STRING_FLD"
1019                       "&& 'T_STRING_FLD > 0667'" /* string cmp */
1020                       "&& 100-40+55.6 > T_STRING_FLD"
1021                       /* carray: 80.4 */
1022                       "&& 100 > T_CARRAY_FLD"
1023                       "&& !(T_CARRAY_FLD > 80.445)"
1024                       "&& 'abc' > T_CARRAY_FLD"
1025                       "&& T_CARRAY_FLD>'00008000.40'"
1026                       "&& 80.4445>T_CARRAY_FLD"
1027                 );
1028         assert_not_equal(tree, NULL);
1029         assert_equal(Bboolev(p_ub, tree), EXTRUE);
1030         load_expr_test_data_2(p_ub);
1031         assert_equal(Bboolev(p_ub, tree), EXFALSE);
1032         Btreefree(tree);
1033 
1034 
1035         /*----------------------------------------------------------*/
1036         /* test <= */
1037         assert_equal(CBchg(p_ub, T_SHORT_FLD, 0, (char *)"252", 3, BFLD_STRING), EXSUCCEED);
1038         assert_equal(CBchg(p_ub, T_LONG_FLD, 0, (char *)"-2980", 3, BFLD_STRING), EXSUCCEED);
1039         assert_equal(CBchg(p_ub, T_CHAR_FLD, 0, (char *)"2", 3, BFLD_STRING), EXSUCCEED);
1040         assert_equal(CBchg(p_ub, T_FLOAT_2_FLD, 0, (char *)"-0.2", 3, BFLD_STRING), EXSUCCEED);
1041         assert_equal(CBchg(p_ub, T_DOUBLE_FLD, 0, (char *)"42", 3, BFLD_STRING), EXSUCCEED);
1042         assert_equal(CBchg(p_ub, T_STRING_FLD, 0, (char *)"66", 3, BFLD_STRING), EXSUCCEED);
1043         assert_equal(CBchg(p_ub, T_CARRAY_FLD, 0, (char *)"abc", 3, BFLD_STRING), EXSUCCEED);
1044 
1045         tree=Bboolco ("100<=100 "
1046                       "&& 100.10/2<=51.05 "
1047                       "&& '321'<='322' " /* string cmp */
1048                       "&& -3<=3"
1049                       "&& 'a'<='a'"
1050                       /* short 252 */
1051                       "&& T_SHORT_FLD<=252"
1052                       "&& T_SHORT_FLD<=252.1"
1053                       "&& T_SHORT_FLD<='251'+1"
1054                       "&& !(T_SHORT_FLD<=251) " /* should be false, but we invert. */
1055                       /* long -2980 */
1056                       "&& T_LONG_FLD<='-2980'" /* string comp */
1057                       "&& 100 <= -T_LONG_FLD"
1058                       "&& T_LONG_FLD<='123'"
1059                       /* char: 2 */
1060                       "&& !(T_CHAR_FLD<=1) "
1061                       "&& T_CHAR_FLD<='a'"
1062                       "&& T_CHAR_FLD<=2.5"
1063                       "&& T_CHAR_FLD<='a'+2"
1064                       /* float -0.2 */
1065                       "&& T_FLOAT_2_FLD <= -0.2"
1066                       "&& 0.2 <= -T_FLOAT_2_FLD"
1067                       "&& !(T_FLOAT_2_FLD <= -12.121)"
1068                       "&& -0.4 <= T_FLOAT_2_FLD"
1069                       /* double: 42 */
1070                       "&& T_DOUBLE_FLD <= '42.0000000000000'"
1071                       "&& !(42.1<= T_DOUBLE_FLD)"
1072                       "&& T_DOUBLE_FLD <= 'abc'" /* string cmp */
1073                       /* string: 66 */
1074                       "&& T_STRING_FLD <= 66"
1075                       "&& 40.01 <= T_STRING_FLD"
1076                       "&& !(667 <= T_STRING_FLD)"
1077                       "&& '0667' <= T_STRING_FLD" /* string cmp */
1078                       "&& T_STRING_FLD <= 100-40+55.6"
1079                       /* carray: abc */
1080                       "&& T_CARRAY_FLD <= 0"
1081                       "&& !(10 <= T_CARRAY_FLD)"
1082                       "&& T_CARRAY_FLD <= 'abc'"
1083                       "&& -0.1 <= T_CARRAY_FLD"
1084                       "&& T_CARRAY_FLD <= 3"
1085                 );
1086         assert_not_equal(tree, NULL);
1087         assert_equal(Bboolev(p_ub, tree), EXTRUE);
1088         load_expr_test_data_2(p_ub);
1089         assert_equal(Bboolev(p_ub, tree), EXFALSE);
1090         Btreefree(tree);
1091         /*----------------------------------------------------------*/
1092         /* test >= */
1093         assert_equal(CBchg(p_ub, T_SHORT_FLD, 0, (char *)"252", 3, BFLD_STRING), EXSUCCEED);
1094         assert_equal(CBchg(p_ub, T_LONG_FLD, 0, (char *)"-2980", 3, BFLD_STRING), EXSUCCEED);
1095         assert_equal(CBchg(p_ub, T_CHAR_FLD, 0, (char *)"2", 3, BFLD_STRING), EXSUCCEED);
1096         assert_equal(CBchg(p_ub, T_FLOAT_2_FLD, 0, (char *)"-0.2", 3, BFLD_STRING), EXSUCCEED);
1097         assert_equal(CBchg(p_ub, T_DOUBLE_FLD, 0, (char *)"42", 3, BFLD_STRING), EXSUCCEED);
1098         assert_equal(CBchg(p_ub, T_STRING_FLD, 0, (char *)"66", 3, BFLD_STRING), EXSUCCEED);
1099         assert_equal(CBchg(p_ub, T_CARRAY_FLD, 0, (char *)"abc", 3, BFLD_STRING), EXSUCCEED);
1100 
1101         tree=Bboolco ("100>=100 "
1102                       "&& 51.05>=100.10/2 "
1103                       "&& '322'>='321'" /* string cmp */
1104                       "&& 3>=-3"
1105                       "&& 'a'>='a'"
1106                       /* short 252 */
1107                       "&& 252>=T_SHORT_FLD"
1108                       "&& 252.1>=T_SHORT_FLD"
1109                       "&& '251'+1>=T_SHORT_FLD"
1110                       "&& !(251>=T_SHORT_FLD) " /* should be false, but we invert. */
1111                       /* long -2980 */
1112                       "&& '-2980'>=T_LONG_FLD" /* string comp */
1113                       "&& -T_LONG_FLD>=100"
1114                       "&& '123'>=T_LONG_FLD"
1115                       /* char: 2 */
1116                       "&& !(1>=T_CHAR_FLD) "
1117                       "&& 'a'>=T_CHAR_FLD"
1118                       "&& 2.5>=T_CHAR_FLD"
1119                       "&& 'a'+2>=T_CHAR_FLD"
1120                       /* float -0.2 */
1121                       "&& -0.2>=T_FLOAT_2_FLD"
1122                       "&& -T_FLOAT_2_FLD>=0.2"
1123                       "&& !(-12.121>=T_FLOAT_2_FLD)"
1124                       "&& T_FLOAT_2_FLD>=-0.4"
1125                       /* double: 42 */
1126                       "&& '42.0000000000000'>=T_DOUBLE_FLD"
1127                       "&& !(T_DOUBLE_FLD>=42.1)"
1128                       "&& 'abc'>=T_DOUBLE_FLD" /* string cmp */
1129                       /* string: 66 */
1130                       "&& 66>=T_STRING_FLD"
1131                       "&& T_STRING_FLD>=40.01"
1132                       "&& !(T_STRING_FLD>=667)"
1133                       "&& T_STRING_FLD>='0667'" /* string cmp */
1134                       "&& 100-40+55.6>=T_STRING_FLD"
1135                       /* carray: abc */
1136                       "&& 0>=T_CARRAY_FLD"
1137                       "&& !(T_CARRAY_FLD>=10)"
1138                       "&& 'abc'>=T_CARRAY_FLD"
1139                       "&& T_CARRAY_FLD>=-0.1"
1140                       "&& 3>=T_CARRAY_FLD"
1141                 );
1142         assert_not_equal(tree, NULL);
1143         assert_equal(Bboolev(p_ub, tree), EXTRUE);
1144         load_expr_test_data_2(p_ub);
1145         assert_equal(Bboolev(p_ub, tree), EXFALSE);
1146         Btreefree(tree);
1147         /*----------------------------------------------------------*/
1148         /* test == */
1149         assert_equal(CBchg(p_ub, T_SHORT_FLD, 0, (char *)"12311", 3, BFLD_STRING), EXSUCCEED);
1150         assert_equal(CBchg(p_ub, T_LONG_FLD, 0, (char *)"558211", 3, BFLD_STRING), EXSUCCEED);
1151         assert_equal(CBchg(p_ub, T_CHAR_FLD, 0, (char *)"6", 3, BFLD_STRING), EXSUCCEED);
1152         assert_equal(CBchg(p_ub, T_FLOAT_2_FLD, 0, (char *)"-10", 3, BFLD_STRING), EXSUCCEED);
1153         assert_equal(CBchg(p_ub, T_DOUBLE_FLD, 0, (char *)"12.5", 3, BFLD_STRING), EXSUCCEED);
1154         assert_equal(CBchg(p_ub, T_STRING_FLD, 0, (char *)"7721", 3, BFLD_STRING), EXSUCCEED);
1155         assert_equal(CBchg(p_ub, T_CARRAY_FLD, 0, (char *)"12a", 3, BFLD_STRING), EXSUCCEED);
1156 
1157         tree=Bboolco ("100==100 "
1158                       "&& !(51.05==100.10/2) "
1159                       "&& '322'=='322'" /* string cmp */
1160                       "&& !(3==-3)"
1161                       "&& 'a'=='a'"
1162                       "&& 155.12==155.12-0.12+0.12"
1163                       /* short 12311 */
1164                       "&& T_SHORT_FLD==T_SHORT_FLD"
1165                       "&& 12311==T_SHORT_FLD"
1166                       "&& !(12312==T_SHORT_FLD)"
1167                       "&& '12311'==T_SHORT_FLD"
1168                       "&& !(1231==T_SHORT_FLD) "
1169                       /* long 558211 */
1170                       "&& '-558211'==-T_LONG_FLD"
1171                       "&& !(-T_LONG_FLD==100)"
1172                       "&& 558211==T_LONG_FLD"
1173                       "&& T_LONG_FLD==T_LONG_FLD"
1174                       /* char: 6 */
1175                       "&& T_CHAR_FLD==T_CHAR_FLD"
1176                       "&& T_CHAR_FLD+T_CHAR_FLD==T_CHAR_FLD*2"
1177                       "&& !(5==T_CHAR_FLD)"
1178                       "&& '6'==T_CHAR_FLD"
1179                       "&& 6.0==T_CHAR_FLD"
1180                       "&& 6==T_CHAR_FLD"
1181                       /* float -10 */
1182                       "&& T_FLOAT_2_FLD==T_FLOAT_2_FLD"
1183                       "&& -10==T_FLOAT_2_FLD"
1184                       "&& !(-T_FLOAT_2_FLD==-0.1)"
1185                       "&& !(-12.121==T_FLOAT_2_FLD)"
1186                       "&& T_FLOAT_2_FLD=='-10.0000000000000'"
1187                       /* double: 12.5 */
1188                       "&& T_DOUBLE_FLD==T_DOUBLE_FLD"
1189                       "&& '12.5000000000000'==T_DOUBLE_FLD"
1190                       "&& !(T_DOUBLE_FLD==42.1)"
1191                       "&& !('abc'==T_DOUBLE_FLD)"
1192                       /* string: 7721 */
1193                       "&& T_STRING_FLD==T_STRING_FLD"
1194                       "&& 7721==T_STRING_FLD"
1195                       "&& T_STRING_FLD=='7721'"
1196                       "&& !(T_STRING_FLD==667)"
1197                       "&& T_STRING_FLD==7721.000"
1198                       "&& !(0.2+0.2==T_STRING_FLD)"
1199                       /* carray: 12a */
1200                       "&& T_CARRAY_FLD==T_CARRAY_FLD"
1201                       "&& !(T_CARRAY_FLD==10)"
1202                       "&& '12a'==T_CARRAY_FLD"
1203                       "&& T_CARRAY_FLD==12.0"
1204                       "&& 12==T_CARRAY_FLD"
1205                       "&& 12325.5==T_CARRAY_FLD+T_FLOAT_2_FLD+T_SHORT_FLD+T_DOUBLE_FLD"
1206                 );
1207         assert_not_equal(tree, NULL);
1208         assert_equal(Bboolev(p_ub, tree), EXTRUE);
1209         load_expr_test_data_2(p_ub);
1210         assert_equal(Bboolev(p_ub, tree), EXFALSE);
1211         Btreefree(tree);
1212         
1213 
1214         /* test != */
1215         assert_equal(CBchg(p_ub, T_SHORT_FLD, 0, (char *)"12311", 3, BFLD_STRING), EXSUCCEED);
1216         assert_equal(CBchg(p_ub, T_LONG_FLD, 0, (char *)"558211", 3, BFLD_STRING), EXSUCCEED);
1217         assert_equal(CBchg(p_ub, T_CHAR_FLD, 0, (char *)"6", 3, BFLD_STRING), EXSUCCEED);
1218         assert_equal(CBchg(p_ub, T_FLOAT_2_FLD, 0, (char *)"-10", 3, BFLD_STRING), EXSUCCEED);
1219         assert_equal(CBchg(p_ub, T_DOUBLE_FLD, 0, (char *)"12.5", 3, BFLD_STRING), EXSUCCEED);
1220         assert_equal(CBchg(p_ub, T_STRING_FLD, 0, (char *)"7721", 3, BFLD_STRING), EXSUCCEED);
1221         assert_equal(CBchg(p_ub, T_CARRAY_FLD, 0, (char *)"12a", 3, BFLD_STRING), EXSUCCEED);
1222 
1223         tree=Bboolco ("!(100!=100) "
1224                       "&& 51.05!=100.10/2 "
1225                       "&& !('322'!='322')" /* string cmp */
1226                       "&& 3!=-3"
1227                       "&& !('a'!='a')"
1228                       "&& 155.0!=155.12-0.12+0.12"
1229                       /* short 12311 */
1230                       "&& !(T_SHORT_FLD!=T_SHORT_FLD)"
1231                       "&& !(12311!=T_SHORT_FLD)"
1232                       "&& 12312!=T_SHORT_FLD"
1233                       "&& !('12311'!=T_SHORT_FLD)"
1234                       "&& 1231!=T_SHORT_FLD "
1235                       /* long 558211 */
1236                       "&& !('-558211'!=-T_LONG_FLD)"
1237                       "&& -T_LONG_FLD!=100"
1238                       "&& !(558211!=T_LONG_FLD)"
1239                       "&& !(T_LONG_FLD!=T_LONG_FLD)"
1240                       /* char: 6 */
1241                       "&& !(T_CHAR_FLD!=T_CHAR_FLD)"
1242                       "&& !(T_CHAR_FLD+T_CHAR_FLD!=T_CHAR_FLD*2)"
1243                       "&&  5!=T_CHAR_FLD"
1244                       "&& !('6'!=T_CHAR_FLD)"
1245                       "&& !(6.0!=T_CHAR_FLD)"
1246                       "&& !(6!=T_CHAR_FLD)"
1247                       /* float -10 */
1248                       "&& !(T_FLOAT_2_FLD!=T_FLOAT_2_FLD)"
1249                       "&& !(-10!=T_FLOAT_2_FLD)"
1250                       "&& -T_FLOAT_2_FLD!=-0.1"
1251                       "&& -12.121!=T_FLOAT_2_FLD"
1252                       "&& !(T_FLOAT_2_FLD!='-10.0000000000000')"
1253                       /* double: 12.5 */
1254                       "&& !(T_DOUBLE_FLD!=T_DOUBLE_FLD)"
1255                       "&& !('12.5000000000000'!=T_DOUBLE_FLD)"
1256                       "&& T_DOUBLE_FLD!=42.1"
1257                       "&& 'abc'!=T_DOUBLE_FLD"
1258                       /* string: 7721 */
1259                       "&& !(T_STRING_FLD!=T_STRING_FLD)"
1260                       "&& !(7721!=T_STRING_FLD)"
1261                       "&& !(T_STRING_FLD!='7721')"
1262                       "&& T_STRING_FLD!=667"
1263                       "&& !(T_STRING_FLD!=7721.000)"
1264                       "&& 0.2+0.2!=T_STRING_FLD"
1265                       /* carray: 12a */
1266                       "&& !(T_CARRAY_FLD!=T_CARRAY_FLD)"
1267                       "&& T_CARRAY_FLD!=10"
1268                       "&& !('12a'!=T_CARRAY_FLD)"
1269                       "&& !(T_CARRAY_FLD!=12.0)"
1270                       "&& !(12!=T_CARRAY_FLD)"
1271                 );
1272         assert_not_equal(tree, NULL);
1273         assert_equal(Bboolev(p_ub, tree), EXTRUE);
1274         load_expr_test_data_2(p_ub);
1275         assert_equal(Bboolev(p_ub, tree), EXFALSE);
1276         Btreefree(tree);
1277 }
1278 
1279 Ensure(test_expr_basic_scopes)
1280 {
1281     char buf[1024];
1282     UBFH *p_ub = (UBFH *)buf;
1283     char *tree = NULL;
1284     assert_equal(Binit(p_ub, sizeof(buf)), EXSUCCEED);
1285     double d = 2312.2;
1286     load_field_table(); /* set field table environment variable */
1287     /*----------------------------------------------------------*/
1288 
1289         tree=Bboolco ("2*(5+6)==22"
1290                       "&& 190==(10*(5.0+2*(3+4)))");
1291         assert_not_equal(tree, NULL);
1292         assert_equal(Bboolev(p_ub, tree), EXTRUE);
1293         Btreefree(tree);
1294 }
1295 /**
1296  * Test expressions with manuplating with string field
1297  */
1298 Ensure(test_expr_short)
1299 {
1300     char buf[2048];
1301     UBFH *p_ub = (UBFH *)buf;
1302     char *tree = NULL;
1303     short short_val;
1304     assert_equal(Binit(p_ub, sizeof(buf)), EXSUCCEED);
1305     set_up_dummy_data(p_ub);
1306     load_field_table(); /* set field table environment variable */
1307 
1308     /*----------------------------------------------------------*/
1309         /* Compare short and do some math...*/
1310         short_val = 137;
1311         assert_equal(Badd(p_ub, T_SHORT_FLD, (char *)&short_val, 0), EXSUCCEED);
1312         tree=Bboolco ("T_SHORT_FLD==50*2+(30/2)*2+5+2");
1313         assert_not_equal(tree, NULL);
1314         assert_equal(Bboolev(p_ub, tree), EXTRUE);
1315         /*----------------------------------------------------------*/
1316         short_val = -137;
1317         assert_equal(Bchg(p_ub, T_SHORT_FLD, 0, (char *)&short_val, 0), EXSUCCEED);
1318         assert_equal(Bboolev(p_ub, tree), EXFALSE);
1319         /*----------------------------------------------------------*/
1320         short_val = 137;
1321         assert_equal(Bchg(p_ub, T_SHORT_FLD, 0, (char *)&short_val, 0), EXSUCCEED);
1322         assert_equal(Bboolev(p_ub, tree), EXTRUE);
1323         /* Free up tree */
1324         Btreefree(tree);
1325     /*----------------------------------------------------------*/
1326         /* Compare field against regular expression */
1327         short_val = 4112;
1328         assert_equal(Badd(p_ub, T_SHORT_FLD, (char *)&short_val, 0), EXSUCCEED);
1329         tree=Bboolco ("T_SHORT_FLD[1] %% '4..2'");
1330         assert_not_equal(tree, NULL);
1331         assert_equal(Bboolev(p_ub, tree), EXTRUE);
1332         /*----------------------------------------------------------*/
1333         short_val = 4442;
1334         assert_equal(Bchg(p_ub, T_SHORT_FLD, 1, (char *)&short_val, 0), EXSUCCEED);
1335         assert_equal(Bboolev(p_ub, tree), EXTRUE);
1336         /*----------------------------------------------------------*/
1337         short_val = 1442;
1338         assert_equal(Bchg(p_ub, T_SHORT_FLD, 1, (char *)&short_val, 0), EXSUCCEED);
1339         assert_equal(Bboolev(p_ub, tree), EXFALSE);
1340         
1341         /* Free up tree */
1342         Btreefree(tree);
1343     /*----------------------------------------------------------*/
1344         /* Compare the field against float & do some math stuff!
1345          * and do some unarray operation.
1346          */
1347         short_val = -4112;
1348         assert_equal(Bchg(p_ub, T_SHORT_FLD, 5, (char *)&short_val, 0), EXSUCCEED);
1349         tree=Bboolco ("-T_SHORT_FLD[5] == 4110+0.8+1.2 && 0.0==-1+1");
1350         assert_not_equal(tree, NULL);
1351         assert_equal(Bboolev(p_ub, tree), EXTRUE);
1352         /* Free up tree */
1353         Btreefree(tree);
1354     /*----------------------------------------------------------*/
1355     
1356 }
1357 
1358 /**
1359  * Test tree printing routine
1360  */
1361 Ensure(test_bboolpr)
1362 {
1363     char *tree;
1364     char buf[2048];
1365     UBFH *p_ub = (UBFH *)buf;
1366     char testbuf[2048];
1367     int read;
1368     assert_equal(Binit(p_ub, sizeof(buf)), EXSUCCEED);
1369     /* Simple test... */
1370     open_test_temp("w");
1371     assert_not_equal((tree=Bboolco ("2 * ( 4 + 5 ) || 5 && 'abc' %% '..b' && 2/2*4==5")), NULL);
1372     Bboolpr(tree, M_test_temp_file);
1373     close_test_temp();
1374     open_test_temp_for_read("r");
1375     assert_not_equal((read=fread (testbuf, 1, sizeof(testbuf), M_test_temp_file)),0);
1376     testbuf[read-1]=EXEOS; /* remove trainline newline */
1377     close_test_temp();
1378     remove_test_temp();
1379     assert_string_equal(testbuf,"((2*(4+5)) || ((5 && ('abc' %% '..b')) && (((2/2)*4) == 5)))");
1380     
1381     Btreefree(tree);
1382 
1383     /* test negation */
1384     
1385     open_test_temp("w");
1386     assert_not_equal((tree=Bboolco ("!( 'a'!='b' ) || !( 'c'&&'b' )")), NULL);
1387     Bboolpr(tree, M_test_temp_file);
1388     close_test_temp();
1389     open_test_temp_for_read("r");
1390     assert_not_equal((read=fread (testbuf, 1, sizeof(testbuf), M_test_temp_file)),0);
1391     testbuf[read-1]=EXEOS; /* remove trainline newline */
1392     close_test_temp();
1393     remove_test_temp();
1394     assert_string_equal(testbuf, "((!('a' != 'b')) || (!('c' && 'b')))");
1395     Btreefree(tree);
1396 
1397     /* Some other tests... */
1398     open_test_temp("w");
1399     assert_not_equal((tree=Bboolco ("1<1 && 2>1 && 2>=1 && 1<=~2 && 2^1")), NULL);
1400     Bboolpr(tree, M_test_temp_file);
1401     close_test_temp();
1402     open_test_temp_for_read("r");
1403     assert_not_equal((read=fread (testbuf, 1, sizeof(testbuf), M_test_temp_file)),0);
1404     testbuf[read-1]=EXEOS; /* remove trainline newline */
1405     close_test_temp();
1406     remove_test_temp();
1407     assert_string_equal(testbuf, "(((((1 < 1) && (2 > 1)) && (2 >= 1)) && (1 <= (~2))) && (2 ^ 1))");
1408     Btreefree(tree);
1409 }
1410 
1411 /**
1412  * Just add the data/concat data buffer to dataptr...
1413  * @param buffer token to print
1414  * @param datalen token len including EOS byte
1415  * @param dataptr1 output byte
1416  */
1417 exprivate int bboolprcb_callback(char *buffer, long datalen, void *dataptr1)
1418 {
1419     assert_equal(datalen, strlen(buffer)+1);
1420     strcat((char *)dataptr1, buffer);
1421     return EXSUCCEED;
1422 }
1423 
1424 /**
1425  * Test tree printing routine, with callback
1426  */
1427 Ensure(test_bboolprcb)
1428 {
1429     char *tree;
1430     char buf[2048];
1431     UBFH *p_ub = (UBFH *)buf;
1432     char testbuf[2048];
1433     
1434     assert_equal(Binit(p_ub, sizeof(buf)), EXSUCCEED);
1435     
1436     assert_not_equal((tree=Bboolco ("2 * ( 4 + 5 ) || 5 && 'abc' %% '..b' && 2/2*4==5")), NULL);
1437     testbuf[0] = EXEOS;
1438     Bboolprcb(tree, bboolprcb_callback, testbuf);
1439     
1440     /* clear off newlines from the testbuf */
1441     
1442     
1443     ndrx_str_strip(testbuf, " \n");
1444     assert_string_equal(testbuf,"((2*(4+5))||((5&&('abc'%%'..b'))&&(((2/2)*4)==5)))");
1445     
1446     Btreefree(tree);
1447 
1448     /* test negation */
1449     assert_not_equal((tree=Bboolco ("!( 'a'!='b' ) || !( 'c'&&'b' )")), NULL);
1450     testbuf[0] = EXEOS;
1451     Bboolprcb(tree, bboolprcb_callback, testbuf);
1452     ndrx_str_strip(testbuf, " \n");
1453     assert_string_equal(testbuf, "((!('a'!='b'))||(!('c'&&'b')))");
1454     Btreefree(tree);
1455 
1456     /* Some other tests... */
1457     assert_not_equal((tree=Bboolco ("1<1&&2>1&&2>=1&&1<=~2&&2^1")), NULL);
1458     testbuf[0] = EXEOS;
1459     Bboolprcb(tree, bboolprcb_callback, testbuf);
1460     ndrx_str_strip(testbuf, " \n");
1461     assert_string_equal(testbuf, "(((((1<1)&&(2>1))&&(2>=1))&&(1<=(~2)))&&(2^1))");
1462     Btreefree(tree);
1463 }
1464 
1465 /* -------------------------------------------------------------------------- */
1466 long callback_function_true(UBFH *p_ub, char *funcname)
1467 {
1468     assert_string_equal(funcname, "callback_function_true");
1469     return 1;
1470 }
1471 
1472 long callback_function_false(UBFH *p_ub, char *funcname)
1473 {
1474     assert_string_equal(funcname, "callback_function_false");
1475     UBF_LOG(log_debug, "callback_function_false() called!");
1476     return 0;
1477 }
1478 
1479 long callback_function_cond(UBFH *p_ub, char *funcname)
1480 {
1481     long ret;
1482     short short_val;
1483     
1484     assert_string_equal(funcname, "callback_function_cond");
1485     assert_equal(Bget(p_ub, T_SHORT_FLD, 0, (char *)&short_val, 0L), EXSUCCEED);
1486     
1487     if (137 == short_val)
1488         ret=EXTRUE;
1489     else
1490         ret=EXFALSE;
1491     
1492     return ret;
1493 }
1494 
1495 long callback_function_value(UBFH *p_ub, char *funcname)
1496 {
1497     assert_string_equal(funcname, "callback_function_value");
1498     long ret;
1499     
1500     ret = 177788;
1501     
1502     return ret;
1503 }
1504 
1505 
1506 long callback_w_args_HELLO(UBFH *p_ub, char *funcname, char *arg1)
1507 {
1508     assert_string_equal(funcname, "callback_w_args_HELLO");
1509     
1510     assert_equal(Bisubf(p_ub), EXTRUE);
1511     assert_string_equal(arg1, "HELLO WORLD");
1512     
1513     return 1;
1514 }
1515 
1516 long callback_w_args_empty(UBFH *p_ub, char *funcname, char *arg1)
1517 {
1518     assert_string_equal(funcname, "callback_w_args_empty");
1519     
1520     assert_equal(Bisubf(p_ub), EXTRUE);
1521     assert_string_equal(arg1, "");
1522     
1523     return 1;
1524 }
1525 
1526 long callback_w_args_pars(UBFH *p_ub, char *funcname, char *arg1)
1527 {
1528     assert_equal(Bisubf(p_ub), EXTRUE);
1529     
1530     return atol(arg1);
1531 }
1532 
1533 
1534 /**
1535  * Test callback functions
1536  */
1537 Ensure(test_cbfunc)
1538 {
1539     char buf[2048];
1540     UBFH *p_ub = (UBFH *)buf;
1541     char *tree = NULL;
1542     short short_val;
1543     long long_val;
1544     assert_equal(Binit(p_ub, sizeof(buf)), EXSUCCEED);
1545     set_up_dummy_data(p_ub);
1546     load_field_table(); /* set field table environment variable */
1547     
1548     assert_equal(Bboolsetcbf ("callback_function_true", callback_function_true), EXSUCCEED);
1549     assert_equal(Bboolsetcbf ("callback_function_false", callback_function_false), EXSUCCEED);
1550     assert_equal(Bboolsetcbf ("callback_function_cond", callback_function_cond), EXSUCCEED);
1551     assert_equal(Bboolsetcbf ("callback_function_value", callback_function_value), EXSUCCEED);
1552     assert_equal(Bboolsetcbf2 ("callback_w_args_HELLO", callback_w_args_HELLO), EXSUCCEED);
1553     assert_equal(Bboolsetcbf2 ("callback_w_args_empty", callback_w_args_empty), EXSUCCEED);
1554     assert_equal(Bboolsetcbf2 ("callback_w_args_pars", callback_w_args_pars), EXSUCCEED);
1555     assert_equal(Bboolsetcbf2 ("e", callback_w_args_pars), EXSUCCEED);
1556     
1557     
1558     short_val = 137;
1559     assert_equal(Badd(p_ub, T_SHORT_FLD, (char *)&short_val, 0), EXSUCCEED);
1560     long_val = 177788;
1561     assert_equal(Badd(p_ub, T_LONG_FLD, (char *)&long_val, 0), EXSUCCEED);
1562     
1563     /*----------------------------------------------------------*/
1564         /* This should be true */
1565         tree=Bboolco ("callback_function_true()");
1566         assert_not_equal(tree, NULL);
1567         assert_equal(Bboolev(p_ub, tree), EXTRUE);
1568         Btreefree(tree);
1569     /*----------------------------------------------------------*/
1570         /* This should be false */
1571         tree=Bboolco ("callback_function_false()");
1572         assert_not_equal(tree, NULL);
1573         assert_equal(Bboolev(p_ub, tree), EXFALSE);
1574         Btreefree(tree);
1575     /*----------------------------------------------------------*/
1576         /* This should be true as buffer contains 137 */
1577         tree=Bboolco ("callback_function_cond()");
1578         assert_not_equal(tree, NULL);
1579         assert_equal(Bboolev(p_ub, tree), EXTRUE);
1580         Btreefree(tree);
1581     /*----------------------------------------------------------*/
1582         /* This should be true */
1583         tree=Bboolco ("callback_function_value()==177788");
1584         assert_not_equal(tree, NULL);
1585         assert_equal(Bboolev(p_ub, tree), EXTRUE);
1586         Btreefree(tree);
1587     /*----------------------------------------------------------*/
1588         /* This should be false */
1589         tree=Bboolco ("callback_function_value()==177787");
1590         assert_not_equal(tree, NULL);
1591         assert_equal(Bboolev(p_ub, tree), EXFALSE);
1592         Btreefree(tree);
1593     /*----------------------------------------------------------*/
1594         /* This should be true too as value != 0 */
1595         tree=Bboolco ("callback_function_value()");
1596         assert_not_equal(tree, NULL);
1597         assert_equal(Bboolev(p_ub, tree), EXTRUE);
1598         Btreefree(tree);
1599     /*----------------------------------------------------------*/
1600         /* This should be true, too */
1601         tree=Bboolco ("callback_function_true()+callback_function_true()==2");
1602         assert_not_equal(tree, NULL);
1603         assert_equal(Bboolev(p_ub, tree), EXTRUE);
1604         Btreefree(tree);
1605     /*----------------------------------------------------------*/
1606         /* This should be false */
1607         tree=Bboolco ("callback_function_true()-callback_function_true()");
1608         assert_not_equal(tree, NULL);
1609         assert_equal(Bboolev(p_ub, tree), EXFALSE);
1610         Btreefree(tree);
1611     /*----------------------------------------------------------*/
1612         /* This should be true */
1613         tree=Bboolco ("callback_function_value()==T_LONG_FLD");
1614         assert_not_equal(tree, NULL);
1615         assert_equal(Bboolev(p_ub, tree), EXTRUE);
1616         Btreefree(tree);
1617     /*----------------------------------------------------------*/
1618         /* This should be true */
1619         tree=Bboolco ("callback_function_value()=='177788'");
1620         assert_not_equal(tree, NULL);
1621         assert_equal(Bboolev(p_ub, tree), EXTRUE);
1622         Btreefree(tree);
1623     /*----------------------------------------------------------*/
1624         /* This should not compile */
1625         tree=Bboolco ("callback_function_none()");
1626         assert_equal(tree, NULL);
1627         assert_not_equal(Berror, BBADNAME);
1628         Btreefree(tree);
1629     /*----------------------------------------------------------*/
1630         /* This should not compile - syntax error */
1631         tree=Bboolco ("callback_function_value() %% '177788'");
1632         assert_equal(tree, NULL);
1633         assert_equal(Berror, BSYNTAX);
1634         Btreefree(tree);
1635     /*----------------------------------------------------------*/
1636         /* This should be true */
1637         tree=Bboolco ("T_SHORT_FLD || callback_function_false()");
1638         assert_not_equal(tree, NULL);
1639         assert_equal(Bboolev(p_ub, tree), EXTRUE);
1640         Btreefree(tree);
1641     /*----------------------------------------------------------*/
1642         /* Test unset function */
1643         assert_equal(Bboolsetcbf ("callback_function_value", NULL), EXSUCCEED);
1644         tree=Bboolco ("callback_function_value()=='177788'");
1645         assert_equal(tree, NULL);
1646         Btreefree(tree);
1647     /*----------------------------------------------------------*/
1648         
1649         /* Check string arguments */
1650         tree=Bboolco ("callback_w_args_HELLO('HELLO WORLD')==1");
1651         assert_not_equal(tree, NULL);
1652         assert_equal(Bboolev(p_ub, tree), EXTRUE);
1653         Btreefree(tree);
1654         
1655         /* Check string arguments, empty */
1656         tree=Bboolco ("callback_w_args_empty('')==1");
1657         assert_not_equal(tree, NULL);
1658         assert_equal(Bboolev(p_ub, tree), EXTRUE);
1659         Btreefree(tree);
1660         
1661         /* Check string arguments, echo to long */
1662         tree=Bboolco ("callback_w_args_pars('998871')==998871");
1663         assert_not_equal(tree, NULL);
1664         assert_equal(Bboolev(p_ub, tree), EXTRUE);
1665         Btreefree(tree);
1666         
1667         tree=Bboolco ("e('777')==777");
1668         assert_not_equal(tree, NULL);
1669         assert_equal(Bboolev(p_ub, tree), EXTRUE);
1670         Btreefree(tree);
1671         
1672         
1673         /* try bad syntax */
1674         tree=Bboolco ("callback_w_args_empty('HELLO==1");
1675         assert_equal(tree, NULL);
1676         assert_equal(Berror, BSYNTAX);
1677 
1678         tree=Bboolco ("callback_w_args_empty(''");
1679         assert_equal(tree, NULL);
1680         assert_equal(Berror, BSYNTAX);
1681         
1682         tree=Bboolco ("callback_w_args_empty(ABC)");
1683         assert_equal(tree, NULL);
1684         assert_equal(Berror, BSYNTAX);
1685         
1686         /* should fail too long */
1687         tree=Bboolco ("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaffzz('ABC')");
1688         assert_equal(tree, NULL);
1689         assert_equal(Berror, BSYNTAX);
1690         
1691         
1692         /* too long arg */
1693         tree=Bboolco ("zz('ffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
1694                 "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
1695                 "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
1696                 "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
1697                 "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
1698                 "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
1699                 "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff')");
1700         assert_equal(tree, NULL);
1701         assert_equal(Berror, BSYNTAX);
1702         
1703 }
1704 /* -------------------------------------------------------------------------- */
1705 
1706 /**
1707  * Test invalid arguments to eval functions
1708  */
1709 Ensure(test_expr_argsval)
1710 {
1711     char buf[2048];
1712     UBFH *p_ub = (UBFH *)buf;
1713     char *tree = NULL;
1714     
1715     memset(buf, 0, sizeof(buf));
1716 
1717     /* This should be true */
1718     tree=Bboolco ("1==1");
1719     assert_not_equal(tree, NULL);
1720     
1721     assert_equal(Bboolev(p_ub, tree), EXFAIL);
1722     assert_equal(Berror, BNOTFLD);
1723     
1724     assert_double_equal(Bfloatev(p_ub, tree), -1);
1725     assert_equal(Berror, BNOTFLD);
1726     
1727     Btreefree(tree);
1728     tree = NULL;
1729     
1730     assert_equal(Binit(p_ub, sizeof(buf)), EXSUCCEED);
1731     
1732     assert_equal(Bboolev(p_ub, tree), EXFAIL);
1733     assert_equal(Berror, BEINVAL);
1734     
1735     assert_double_equal(Bfloatev(p_ub, tree), -1);
1736     assert_equal(Berror, BEINVAL);
1737     
1738 }
1739 
1740 /**
1741  * Validate expression on test buffer
1742  * @param UB ubf buffer on which to execute eval
1743  * @param EXP expression to compile
1744  * @param ERRNOCOMP compile shall fail with this error
1745  * @param ERRNOEVAL expression shall fail with this error
1746  * @param RES expected result from Bboolev
1747  */
1748 #define EXPR_TEST(UB, EXP, ERRNOCOMP, ERRNOEVAL, RES) do {\
1749         tree=Bboolco (EXP);\
1750         if (0 < ERRNOCOMP)\
1751         {\
1752             assert_equal(tree, NULL);\
1753             assert_equal(Berror, ERRNOCOMP);\
1754         }\
1755         else\
1756         {\
1757             assert_not_equal(tree, NULL);\
1758             assert_equal(Bboolev(UB, tree), RES);\
1759             if (0 < ERRNOEVAL)\
1760             {\
1761                 assert_equal(Berror, ERRNOEVAL);\
1762             }\
1763             Btreefree(tree);\
1764         }\
1765     } while (0)
1766 
1767 
1768 Ensure(test_expr_recursiv_idpars)
1769 {
1770     /* test ID parser */
1771     ndrx_ubf_rfldid_t rfldid;
1772     Berror=0;
1773     assert_equal(ndrx_ubf_rfldid_parse("T_UBF_FLD[1]..T_STRING_10_FLD[0]", &rfldid), EXFAIL);
1774     assert_equal(Berror, BSYNTAX);
1775     
1776     Berror=0;
1777     assert_equal(ndrx_ubf_rfldid_parse(".", &rfldid), EXFAIL);
1778     assert_equal(Berror, BSYNTAX);
1779     
1780     Berror=0;
1781     assert_equal(ndrx_ubf_rfldid_parse("[0]ABC", &rfldid), EXFAIL);
1782     assert_equal(Berror, BSYNTAX);
1783     
1784     Berror=0;
1785     assert_equal(ndrx_ubf_rfldid_parse("T_UBF_FLD[0][1]", &rfldid), EXFAIL);
1786     assert_equal(Berror, BSYNTAX);
1787     
1788     /* check view syntax */
1789     
1790     assert_equal(ndrx_ubf_rfldid_parse("T_VIEW_FLD", &rfldid), EXSUCCEED);
1791     ndrx_ubf_rfldid_free(&rfldid);
1792     
1793     assert_equal(ndrx_ubf_rfldid_parse("T_VIEW_FLD.hello", &rfldid), EXSUCCEED);
1794     assert_equal(rfldid.cname_occ, 0);
1795     assert_string_equal(rfldid.cname, "hello");
1796     ndrx_ubf_rfldid_free(&rfldid);
1797     
1798     assert_equal(ndrx_ubf_rfldid_parse("T_VIEW_FLD[1].hello", &rfldid), EXSUCCEED);
1799     assert_equal(rfldid.cname_occ, 0);
1800     assert_string_equal(rfldid.cname, "hello");
1801     ndrx_ubf_rfldid_free(&rfldid);
1802     
1803     assert_equal(ndrx_ubf_rfldid_parse("T_VIEW_FLD.hello[5]", &rfldid), EXSUCCEED);
1804     assert_equal(rfldid.cname_occ, 5);
1805     assert_string_equal(rfldid.cname, "hello");
1806     ndrx_ubf_rfldid_free(&rfldid);
1807     
1808     Berror=0;
1809     assert_equal(ndrx_ubf_rfldid_parse("T_VIEW_FLD.hello.zero", &rfldid), EXFAIL);
1810     assert_equal(Berror, BEBADOP);
1811     
1812     Berror=0;
1813     assert_equal(ndrx_ubf_rfldid_parse("T_VIEW_FLD.hello[0].zero", &rfldid), EXFAIL);
1814     assert_equal(Berror, BEBADOP);
1815     
1816     Berror=0;
1817     assert_equal(ndrx_ubf_rfldid_parse("T_VIEW_FLD[0].hello.zero", &rfldid), EXFAIL);
1818     assert_equal(Berror, BEBADOP);
1819     
1820     Berror=0;
1821     assert_equal(ndrx_ubf_rfldid_parse("T_VIEW_FLD[0].hello.zero[0]", &rfldid), EXFAIL);
1822     assert_equal(Berror, BEBADOP);
1823 
1824     Berror=0;
1825     assert_equal(ndrx_ubf_rfldid_parse("", &rfldid), EXFAIL);
1826     assert_equal(Berror, BSYNTAX);
1827     
1828 }
1829 
1830 /**
1831  * Test access to sub-ubf buffers..
1832  */
1833 Ensure(test_expr_recursiv_ubf)
1834 {
1835     char buf[56000];
1836     char *tree;
1837     UBFH *p_ub = (UBFH *)buf;
1838     
1839     assert_equal(Binit(p_ub, sizeof(buf)), EXSUCCEED);
1840     
1841     load_recursive_data(p_ub);
1842     
1843     EXPR_TEST(p_ub, "T_UBF_FLD.T_STRING_10_FLD=='HELLO WORLD5'", 0, 0, EXTRUE);
1844     EXPR_TEST(p_ub, "T_UBF_FLD[0].T_STRING_10_FLD[0]=='HELLO WORLD5'", 0, 0, EXTRUE);
1845     
1846     EXPR_TEST(p_ub, "T_UBF_2_FLD[1].T_UBF_FLD.T_UBF_2_FLD[0].T_STRING_9_FLD[2]==31", 0, 0, EXTRUE);
1847 
1848     EXPR_TEST(p_ub, "T_UBF_2_FLD[1].T_UBF_FLD.T_UBF_2_FLD[0].T_STRING_9_FLD[2]==32", 0, 0, EXFALSE);
1849     EXPR_TEST(p_ub, "T_UBF_2_FLD[1].T_UBF_FLD.T_UBF_2_FLD[0].T_STRING_9_FLD[2]", 0, 0, EXTRUE);
1850     EXPR_TEST(p_ub, "T_UBF_2_FLD[1].T_UBF_FLD.T_UBF_2_FLD[99].T_STRING_9_FLD[2]", 0, 0, EXFALSE);
1851     
1852     /* try invalid expression... */
1853     /* bad op, due to fact that it recognizes the token as UBF field and not the invalid occ */
1854     EXPR_TEST(p_ub, "T_UBF_FLD[X].T_STRING_10_FLD[0]=='HELLO WORLD5'", BEBADOP, EXFAIL, EXFAIL);
1855     EXPR_TEST(p_ub, "T_UBF_FLD[1]..T_STRING_10_FLD[0]=='HELLO WORLD5'", BEBADOP, EXFAIL, EXFAIL);
1856     EXPR_TEST(p_ub, "T_UBF_FLD..T_STRING_10_FLD=='HELLO WORLD5'", BEBADOP, EXFAIL, EXFAIL);
1857     EXPR_TEST(p_ub, "T_UBF_FLD.T_STRING_10_FLD.T_STRING_10_FLD=='HELLO WORLD5'", BEBADOP, EXFAIL, EXFAIL);
1858     EXPR_TEST(p_ub, "T_UBF_FLD.", BEBADOP, EXFAIL, EXFAIL);
1859     
1860     EXPR_TEST(p_ub, "1==1 && T_STRING_10_FLD==T_STRING_10_FLD && T_UBF_FLD==T_UBF_FLD", BEBADOP, EXFAIL, EXFAIL);
1861     
1862     
1863 }
1864 
1865 /**
1866  * Test view access
1867  */
1868 Ensure(test_expr_recursiv_view)
1869 {
1870     char buf[56000];
1871     char *tree;
1872     UBFH *p_ub = (UBFH *)buf;
1873     
1874     assert_equal(Binit(p_ub, sizeof(buf)), EXSUCCEED);
1875     
1876     load_recursive_data(p_ub);
1877 
1878     EXPR_TEST(p_ub, "T_UBF_2_FLD[1].T_UBF_FLD.T_UBF_2_FLD.T_VIEW_3_FLD[4].tfloat1==400", 0, 0, EXTRUE);
1879     
1880     /* test failure */
1881     EXPR_TEST(p_ub, "T_UBF_2_FLD[1].T_UBF_FLD.T_UBF_2_FLD.T_VIEW_3_FLD[4]==400", BEBADOP, EXFAIL, EXFAIL);
1882 
1883     /* test field presence */
1884     EXPR_TEST(p_ub, "T_UBF_2_FLD[1].T_UBF_FLD.T_UBF_2_FLD.T_VIEW_3_FLD[4].tfloat1", 0, 0, EXTRUE);
1885 
1886     EXPR_TEST(p_ub, "T_UBF_2_FLD[1].T_UBF_FLD.T_VIEW_FLD[1].tcarray3[8]", 0, 0, EXTRUE);
1887 
1888     /* test field presence, missing */
1889     EXPR_TEST(p_ub, "T_UBF_2_FLD[1].T_UBF_FLD.T_VIEW_FLD[1].tcarray3[9]", 0, 0, EXFALSE);
1890 
1891     /*inval occurrence shall generate error*/
1892     EXPR_TEST(p_ub, "T_UBF_2_FLD[1].T_UBF_FLD.T_VIEW_FLD[1].tcarray3[10]", 0, 0, EXFAIL);
1893 
1894 }
1895 
1896 /**
1897  * Test long string value handling
1898  */
1899 Ensure(test_expr_longstr)
1900 {
1901     char buf[2048];
1902     char val[1024];
1903     UBFH *p_ub = (UBFH *)buf;
1904     char *tree = NULL;
1905     
1906     memset(val, ' ', sizeof(val));
1907     
1908     val[sizeof(val)-1]=EXEOS;
1909     
1910     
1911     assert_equal(Binit(p_ub, sizeof(buf)), EXSUCCEED);
1912     
1913     assert_equal(Bchg(p_ub, T_STRING_10_FLD, 0, val, 0L), EXSUCCEED);
1914     
1915     tree=Bboolco ("T_STRING_10_FLD");
1916     assert_not_equal(tree, NULL);
1917     assert_equal(Bboolev(p_ub, tree), EXTRUE);
1918     assert_equal(Berror, 0);
1919     
1920     Btreefree(tree);
1921     tree = NULL;
1922     
1923 }
1924 
1925 TestSuite *ubf_expr_tests(void)
1926 {
1927     TestSuite *suite = create_test_suite();
1928 
1929     std_basic_setup();
1930     add_test(suite, test_expr_basic);
1931     add_test(suite, test_expr_basic_logic);
1932     add_test(suite, test_expr_basic_equality);
1933     add_test(suite, test_expr_basic_unary);
1934     add_test(suite, test_expr_basic_additive);
1935     add_test(suite, test_expr_basic_multiplicative);
1936     add_test(suite, test_expr_basic_relational);
1937     add_test(suite, test_expr_basic_scopes);
1938     add_test(suite, test_bboolpr);
1939     add_test(suite, test_bboolprcb);
1940     
1941     /* Test float ev */
1942     add_test(suite, test_expr_basic_floatev);
1943 
1944     /* Some other tests... */
1945     add_test(suite, test_expr_short);
1946     
1947     /* Function callback tests... */
1948     add_test(suite, test_cbfunc);
1949     
1950     /* #338 */
1951     add_test(suite, test_expr_argsval);
1952     
1953     add_test(suite, test_expr_recursiv_idpars);
1954     add_test(suite, test_expr_recursiv_ubf);
1955     add_test(suite, test_expr_recursiv_view);
1956     
1957     /* Support #633 */
1958     add_test(suite, test_expr_longstr);
1959 
1960     return suite;
1961 }
1962 
1963 /* vim: set ts=4 sw=4 et smartindent: */