Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief This implements shared test functions (shared between UBF and ATMI
0003  *  series tests)
0004  *
0005  * @file testfunc.c
0006  */
0007 /* -----------------------------------------------------------------------------
0008  * Enduro/X Middleware Platform for Distributed Transaction Processing
0009  * Copyright (C) 2009-2016, ATR Baltic, Ltd. All Rights Reserved.
0010  * Copyright (C) 2017-2023, Mavimax, Ltd. All Rights Reserved.
0011  * This software is released under one of the following licenses:
0012  * AGPL (with Java and Go exceptions) or Mavimax's license for commercial use.
0013  * See LICENSE file for full text.
0014  * -----------------------------------------------------------------------------
0015  * AGPL license:
0016  *
0017  * This program is free software; you can redistribute it and/or modify it under
0018  * the terms of the GNU Affero General Public License, version 3 as published
0019  * by the Free Software Foundation;
0020  *
0021  * This program is distributed in the hope that it will be useful, but WITHOUT ANY
0022  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
0023  * PARTICULAR PURPOSE. See the GNU Affero General Public License, version 3
0024  * for more details.
0025  *
0026  * You should have received a copy of the GNU Affero General Public License along 
0027  * with this program; if not, write to the Free Software Foundation, Inc.,
0028  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
0029  *
0030  * -----------------------------------------------------------------------------
0031  * A commercial use license is available from Mavimax, Ltd
0032  * contact@mavimax.com
0033  * -----------------------------------------------------------------------------
0034  */
0035 
0036 /*---------------------------Includes-----------------------------------*/
0037 #include <ndrx_config.h>
0038 
0039 #include <stdio.h>
0040 #include <stdlib.h>
0041 #include <ndrstandard.h>
0042 #include <ndebug.h>
0043 #include <userlog.h>
0044 #include <extest.h>
0045 #include <cgreen/cgreen.h>
0046 #include <test.fd.h>
0047 
0048 /*---------------------------Externs------------------------------------*/
0049 /*---------------------------Macros-------------------------------------*/
0050 /*---------------------------Enums--------------------------------------*/
0051 /*---------------------------Typedefs-----------------------------------*/
0052 /*---------------------------Globals------------------------------------*/
0053 /*---------------------------Statics------------------------------------*/
0054 /*---------------------------Prototypes---------------------------------*/
0055 
0056 /**
0057  * Load the view test data
0058  * @param v
0059  */
0060 expublic void extest_init_UBTESTVIEW1(struct UBTESTVIEW1 *v)
0061 {
0062     int i, j;
0063         
0064     v->tshort1=15556;   /* null=2000 */
0065 
0066     v->C_tshort2=2;
0067     v->tshort2[0]=9999; /* null=2001 */
0068     v->tshort2[1]=8888; /* null=2001 */
0069 
0070     v->C_tshort3 = 2;
0071     v->tshort3[0]=7777; /* null=2001 */
0072     v->tshort3[1]=-7777;    /* null=2001 */
0073     v->tshort3[2]=-7777;    /* null=2001 */
0074 
0075     v->tshort4=-10; /* null=NONE */
0076 
0077     v->tlong1=33333333; /* null=0 */
0078 
0079     v->tint2[0]=54545;  /* null=0 */
0080     v->tint2[1]=23232;  /* null=0 */
0081     v->tint3=-100;
0082     v->tint4[0]=1010101;    /* null=-1 */
0083     v->tint4[1]=989898; /* null=-1 */
0084 
0085     v->tchar1='A';  /* null="\n" */
0086 
0087     v->C_tchar2=5;
0088     v->tchar2[0]='A';   /* null="A" */
0089     v->tchar2[1]='B';
0090     v->tchar2[2]='C';
0091     v->tchar2[3]='\n';
0092     v->tchar2[4]='\t';
0093 
0094     v->C_tchar3=0;
0095     v->tchar3[0]='C';   /* null="A" */
0096     v->tchar3[1]='D';   /* null="A" */
0097 
0098     v->tfloat1[0]=-0.11;    /* null=1.1 */
0099     v->tfloat1[1]=-0.22;    /* null=1.1 */
0100     v->tfloat1[2]=0.33; /* null=1.1 */
0101     v->tfloat1[3]=0.44; /* null=1.1 */
0102 
0103     v->tfloat2[0]=100.1;    /* null=1.1 */
0104     v->tfloat2[1]=200.2;    /* null=1.1 */
0105     v->tfloat3=333.111; /* null=9999.99 */
0106 
0107     v->tdouble1[0]=99999.111111;    /* null=55555.99 */
0108     v->tdouble1[1]=11111.999999;    /* null=55555.99 */
0109     v->tdouble2=-999.123;   /* null=-999.123 */
0110 
0111     NDRX_STRCPY_SAFE(v->tstring0[0], "HELLO Enduro/X"); /* null="\n\t\f\\\'\"\vHELLOWORLD" */
0112     NDRX_STRCPY_SAFE(v->tstring0[1], "");   /* null="\n\t\f\\\'\"\vHELLOWORLD" */
0113     NDRX_STRCPY_SAFE(v->tstring0[2], "\nABC\n");    /* null="\n\t\f\\\'\"\vHELLOWORLD" */
0114 
0115     NDRX_STRCPY_SAFE(v->tstring1[0], "Pack my box");    /* null="HELLO WORLDB" */
0116     NDRX_STRCPY_SAFE(v->tstring1[1], "BOX MY PACK");    /* null="HELLO WORLDB" */
0117     NDRX_STRCPY_SAFE(v->tstring1[2], "\nEnduro/X\n");   /* null="HELLO WORLDB" */
0118 
0119     /* Test the L length indicator, must be set to number of bytes transfered */
0120     v->C_tstring2=2;
0121 
0122     NDRX_STRCPY_SAFE(v->tstring2[0], "CCCCAAAADDDD");
0123     NDRX_STRCPY_SAFE(v->tstring2[1], "EEEFFFGGG");
0124     NDRX_STRCPY_SAFE(v->tstring2[2], "IIIIJJJJKKK");
0125 
0126     v->C_tstring3=4;
0127 
0128     NDRX_STRCPY_SAFE(v->tstring3[0], "LLLLLL"); /* null="TESTEST" */
0129     NDRX_STRCPY_SAFE(v->tstring3[1], "MMMMMM"); /* null="TESTEST" */
0130     NDRX_STRCPY_SAFE(v->tstring3[2], "");   /* null="TESTEST" */
0131     NDRX_STRCPY_SAFE(v->tstring3[3], "NNNNNN"); /* null="TESTEST" */
0132 
0133     NDRX_STRCPY_SAFE(v->tstring4, "Some string");   /* null="HELLO TEST" */
0134     
0135     NDRX_STRCPY_SAFE(v->tstring5, "MEGA TEST");
0136 
0137     for (i=0; i<30; i++)
0138     {
0139         v->tcarray1[i]=i;
0140     }
0141 
0142     v->L_tcarray2 = 5;
0143     for (i=0; i<25; i++)
0144     {
0145         v->tcarray2[i]=i+1;
0146     }
0147     
0148     v->C_tcarray3 = 9;
0149             
0150     for (j=0; j<9; j++)
0151     {
0152         v->L_tcarray3[j]=j+1;
0153         
0154         for (i=0; i<16+j; i++)
0155         {
0156             v->tcarray3[j][i]=i+2;
0157         }
0158     }
0159     
0160     for (i=0; i<5; i++)
0161     {
0162         v->tcarray4[i]=i+3;
0163     }
0164     
0165     for (i=0; i<5; i++)
0166     {
0167         v->tcarray5[i]=i+4;
0168     }
0169     
0170 }
0171 
0172 /**
0173  * Test UBF data
0174  * @param p_ub UBF buffer to validate the data
0175  * @param flags see EXTEST_PROC_PTR, EXTEST_PROC_UBF, EXTEST_PROC_VIEW bitmask of
0176  */
0177 void extest_ubf_do_dummy_data_test(UBFH *p_ub, long flags)
0178 {
0179     char buf[128];
0180     int len;
0181     ndrx_longptr_t ptr;
0182     BVIEWFLD vf;
0183     struct UBTESTVIEW2 v;
0184     char tmp[1024];
0185     long l;
0186     UBFH* p_ub_tmp=(UBFH *)tmp;
0187     
0188     assert_equal(CBget(p_ub, T_STRING_9_FLD, 0, buf, 0, BFLD_STRING), EXSUCCEED);
0189     assert_string_equal(buf, "01");
0190     assert_equal(CBget(p_ub, T_STRING_9_FLD, 1, buf, 0, BFLD_STRING), EXSUCCEED);
0191     assert_string_equal(buf, "20");
0192     assert_equal(CBget(p_ub, T_STRING_9_FLD, 2, buf, 0, BFLD_STRING), EXSUCCEED);
0193     assert_string_equal(buf, "31");
0194 
0195     assert_equal(CBget(p_ub, T_DOUBLE_3_FLD, 0, buf, 0, BFLD_STRING), EXSUCCEED);
0196     assert_equal(strncmp(buf, "1.11", 4), 0);
0197     assert_equal(CBget(p_ub, T_DOUBLE_3_FLD, 1,buf, 0, BFLD_STRING), EXSUCCEED);
0198     assert_equal(strncmp(buf, "2.41231", 4), 0);
0199 
0200     assert_equal(CBget(p_ub, T_STRING_4_FLD, 0, buf, 0, BFLD_STRING), EXSUCCEED);
0201     assert_string_equal(buf, "HELLO WORLD");
0202     assert_equal(CBget(p_ub, T_STRING_8_FLD, 0, buf, 0, BFLD_STRING), EXSUCCEED);
0203     assert_string_equal(buf, "HELLO WORLD1");
0204     assert_equal(CBget(p_ub, T_STRING_5_FLD, 0, buf, 0, BFLD_STRING), EXSUCCEED);
0205     assert_string_equal(buf, "HELLO WORLD2");
0206     assert_equal(CBget(p_ub, T_STRING_7_FLD, 0, buf, 0, BFLD_STRING), EXSUCCEED);
0207     assert_string_equal(buf, "HELLO WORLD3");
0208     assert_equal(CBget(p_ub, T_STRING_6_FLD, 0, buf, 0, BFLD_STRING), EXSUCCEED);
0209     assert_string_equal(buf, "HELLO WORLD4");
0210     assert_equal(CBget(p_ub, T_STRING_10_FLD, 0, buf, 0, BFLD_STRING), EXSUCCEED);
0211     assert_string_equal(buf, "HELLO WORLD5");
0212     assert_equal(CBget(p_ub, T_STRING_4_FLD, 1, buf, 0, BFLD_STRING), EXSUCCEED);
0213     assert_string_equal(buf, "HELLO WORLD6");
0214     assert_equal(CBget(p_ub, T_STRING_3_FLD, 0, buf, 0, BFLD_STRING), EXSUCCEED);
0215     assert_string_equal(buf, "HELLO WORLD7");
0216     /* Another carray test */
0217     len = sizeof(buf);
0218     assert_equal(CBget(p_ub, T_CARRAY_2_FLD, 1, buf, 0, BFLD_STRING), EXSUCCEED);
0219     assert_string_equal(buf, "TEST CARRAY");
0220     
0221     /*  Test some PTR, VIEW and UBF */
0222     if (flags & EXTEST_PROC_PTR)
0223     {
0224         assert_equal(CBget(p_ub, T_PTR_3_FLD, 0, (char *)&ptr, 0L, BFLD_LONG), EXSUCCEED);
0225         assert_equal(ptr, 199);
0226         assert_equal(CBget(p_ub, T_PTR_3_FLD, 1, (char *)&ptr, 0L, BFLD_LONG), EXSUCCEED);
0227         assert_equal(ptr, 299);
0228     }
0229     
0230     if (flags & EXTEST_PROC_VIEW)
0231     {
0232         vf.data = (char *)&v;
0233 
0234         assert_equal(Bget(p_ub, T_VIEW_3_FLD, 0, (char *)&vf, 0L), EXSUCCEED);
0235 
0236         assert_string_equal(vf.vname, "UBTESTVIEW2");
0237         assert_equal(vf.vflags, 0);
0238 
0239         assert_equal(v.tshort1, 100);
0240         assert_equal(v.tlong1, 200);
0241         assert_equal(v.tchar1, 'G');
0242         assert_equal(v.tfloat1, 400);
0243         assert_equal(v.tdouble1, 500);
0244         assert_string_equal(v.tstring1, "6XX");
0245         assert_string_equal(v.tcarray1, "7XX");
0246 
0247         assert_equal(Bget(p_ub, T_VIEW_3_FLD, 4, (char *)&vf, 0L), EXSUCCEED);
0248         assert_equal(v.tchar1, 'Z');
0249         assert_string_equal(v.tstring1, "6YY");
0250         assert_string_equal(v.tcarray1, "7YY");
0251     }
0252     
0253     if (flags & EXTEST_PROC_UBF)
0254     {
0255         assert_equal(Bget(p_ub, T_UBF_3_FLD, 2, (char *)p_ub_tmp, 0L), EXSUCCEED);
0256         assert_equal(Bget(p_ub_tmp, T_STRING_9_FLD, 3, (char *)buf, 0L), EXSUCCEED);
0257         assert_string_equal(buf, "HELLO WORLD UB");
0258 
0259 
0260         assert_equal(Bget(p_ub, T_UBF_3_FLD, 3, (char *)p_ub_tmp, 0L), EXSUCCEED);
0261         assert_equal(Bget(p_ub_tmp, T_STRING_7_FLD, 2, (char *)buf, 0L), EXSUCCEED);
0262         assert_string_equal(buf, "ANOTHER UB");    
0263         assert_equal(Bget(p_ub_tmp, T_STRING_9_FLD, 3, (char *)buf, 0L), EXSUCCEED);
0264         assert_string_equal(buf, "HELLO WORLD UB");
0265 
0266         assert_equal(Bget(p_ub, T_LONG_3_FLD, 3, (char *)&l, 0L), EXSUCCEED);
0267         assert_equal(l, 889991);
0268     }
0269     
0270 }
0271 
0272 /**
0273  * Load test data
0274  * @param p_ub UBF buffer where to store the data
0275  * @param flags see EXTEST_PROC_PTR, EXTEST_PROC_UBF, EXTEST_PROC_VIEW bitmask of
0276  */
0277 void extest_ubf_set_up_dummy_data(UBFH *p_ub, long flags)
0278 {
0279     char buf[128];
0280     int len;
0281     long ptr;
0282     BVIEWFLD vf;
0283     struct UBTESTVIEW2 v;
0284     char tmp[1024];
0285     long l;
0286     UBFH* p_ub_tmp=(UBFH *)tmp;
0287     
0288     memset(&v, 14, sizeof(v));
0289     memset(tmp, 15, sizeof(tmp));
0290     
0291     assert_equal(CBadd(p_ub, T_STRING_9_FLD, "01", 0, BFLD_STRING), EXSUCCEED);
0292     
0293     assert_equal(CBget(p_ub, T_STRING_9_FLD, 0, buf, 0, BFLD_STRING), EXSUCCEED);
0294     assert_string_equal(buf, "01");
0295     
0296     assert_equal(CBadd(p_ub, T_STRING_9_FLD, "20", 0, BFLD_STRING), EXSUCCEED);
0297     
0298     assert_equal(CBget(p_ub, T_STRING_9_FLD, 1, buf, 0, BFLD_STRING), EXSUCCEED);
0299     assert_string_equal(buf, "20");
0300     
0301     assert_equal(CBadd(p_ub, T_STRING_9_FLD, "31", 0, BFLD_STRING), EXSUCCEED);
0302     
0303     assert_equal(CBget(p_ub, T_STRING_9_FLD, 2, buf, 0, BFLD_STRING), EXSUCCEED);
0304     assert_string_equal(buf, "31");
0305     
0306 
0307     assert_equal(CBadd(p_ub, T_DOUBLE_3_FLD, "1.11", 0, BFLD_STRING), EXSUCCEED);
0308     
0309     assert_equal(CBget(p_ub, T_DOUBLE_3_FLD, 0, buf, 0, BFLD_STRING), EXSUCCEED);
0310     assert_equal(strncmp(buf, "1.11", 4), 0);
0311     
0312     assert_equal(CBadd(p_ub, T_DOUBLE_3_FLD, "2.41231", 0, BFLD_STRING), EXSUCCEED);
0313     
0314     assert_equal(CBget(p_ub, T_DOUBLE_3_FLD, 1,buf, 0, BFLD_STRING), EXSUCCEED);
0315     assert_equal(strncmp(buf, "2.41231", 4), 0);
0316     
0317 
0318     assert_equal(CBadd(p_ub, T_STRING_4_FLD, "HELLO WORLD", 0, BFLD_STRING), EXSUCCEED);
0319     
0320     assert_equal(CBget(p_ub, T_STRING_4_FLD, 0, buf, 0, BFLD_STRING), EXSUCCEED);
0321     assert_string_equal(buf, "HELLO WORLD");
0322     
0323     
0324     assert_equal(CBadd(p_ub, T_STRING_8_FLD, "HELLO WORLD1", 0, BFLD_STRING), EXSUCCEED);
0325     
0326     assert_equal(CBget(p_ub, T_STRING_8_FLD, 0, buf, 0, BFLD_STRING), EXSUCCEED);
0327     assert_string_equal(buf, "HELLO WORLD1");
0328     
0329     assert_equal(CBadd(p_ub, T_STRING_5_FLD, "HELLO WORLD2", 0, BFLD_STRING), EXSUCCEED);
0330     
0331     assert_string_equal(buf, "HELLO WORLD1");
0332     assert_equal(CBget(p_ub, T_STRING_5_FLD, 0, buf, 0, BFLD_STRING), EXSUCCEED);
0333     
0334     assert_equal(CBadd(p_ub, T_STRING_7_FLD, "HELLO WORLD3", 0, BFLD_STRING), EXSUCCEED);
0335     
0336     assert_equal(CBget(p_ub, T_STRING_7_FLD, 0, buf, 0, BFLD_STRING), EXSUCCEED);
0337     assert_string_equal(buf, "HELLO WORLD3");
0338     
0339     assert_equal(CBadd(p_ub, T_STRING_6_FLD, "HELLO WORLD4", 0, BFLD_STRING), EXSUCCEED);
0340     
0341     assert_equal(CBget(p_ub, T_STRING_6_FLD, 0, buf, 0, BFLD_STRING), EXSUCCEED);
0342     assert_string_equal(buf, "HELLO WORLD4");
0343     
0344     assert_equal(CBadd(p_ub, T_STRING_10_FLD, "HELLO WORLD5", 0, BFLD_STRING), EXSUCCEED);
0345     assert_equal(CBget(p_ub, T_STRING_10_FLD, 0, buf, 0, BFLD_STRING), EXSUCCEED);
0346     assert_string_equal(buf, "HELLO WORLD5");
0347     
0348     
0349     assert_equal(CBadd(p_ub, T_STRING_4_FLD, "HELLO WORLD6", 0, BFLD_STRING), EXSUCCEED);
0350     
0351     assert_equal(CBget(p_ub, T_STRING_4_FLD, 1, buf, 0, BFLD_STRING), EXSUCCEED);
0352     assert_string_equal(buf, "HELLO WORLD6");
0353     
0354     assert_equal(CBadd(p_ub, T_STRING_3_FLD, "HELLO WORLD7", 0, BFLD_STRING), EXSUCCEED);
0355     
0356     assert_equal(CBget(p_ub, T_STRING_3_FLD, 0, buf, 0, BFLD_STRING), EXSUCCEED);
0357     assert_string_equal(buf, "HELLO WORLD7");
0358     
0359     assert_equal(CBchg(p_ub, T_CARRAY_2_FLD, 1, "TEST CARRAY", 0, BFLD_STRING), EXSUCCEED);
0360     
0361     /* Another carray test */
0362     len = sizeof(buf);
0363     assert_equal(CBget(p_ub, T_CARRAY_2_FLD, 1, buf, 0, BFLD_STRING), EXSUCCEED);
0364     assert_string_equal(buf, "TEST CARRAY");
0365     
0366     /* Load some PTR, VIEW and UBF */
0367     if (flags & EXTEST_PROC_PTR)
0368     {
0369         ptr=199;
0370         assert_equal(CBchg(p_ub, T_PTR_3_FLD, 0, (char *)&ptr, 0L, BFLD_LONG), EXSUCCEED);
0371         ptr=299;
0372         assert_equal(CBchg(p_ub, T_PTR_3_FLD, 1, (char *)&ptr, 0L, BFLD_LONG), EXSUCCEED);
0373     }
0374     
0375     if (flags & EXTEST_PROC_VIEW)
0376     {
0377         NDRX_STRCPY_SAFE(vf.vname, "UBTESTVIEW2");
0378         vf.vflags=0;
0379         vf.data = (char *)&v;
0380 
0381         v.tshort1=100;
0382         v.tlong1=200;
0383         v.tchar1='G';
0384         v.tfloat1=400;
0385         v.tdouble1=500;
0386         NDRX_STRCPY_SAFE(v.tstring1, "6XX");
0387         NDRX_STRCPY_SAFE(v.tcarray1, "7XX");
0388 
0389         assert_equal(Bchg(p_ub, T_VIEW_3_FLD, 0, (char *)&vf, 0L), EXSUCCEED);
0390 
0391         NDRX_STRCPY_SAFE(v.tstring1, "6YY");
0392         NDRX_STRCPY_SAFE(v.tcarray1, "7YY");
0393         v.tchar1='Z';
0394         assert_equal(Bchg(p_ub, T_VIEW_3_FLD, 4, (char *)&vf, 0L), EXSUCCEED);
0395     }
0396     
0397     if (flags & EXTEST_PROC_UBF)
0398     {
0399         /* And some ubf... */
0400         assert_equal(Binit(p_ub_tmp, sizeof(tmp)), EXSUCCEED);
0401         assert_equal(Bchg(p_ub_tmp, T_STRING_9_FLD, 3, "HELLO WORLD UB", 0L), EXSUCCEED);
0402         assert_equal(Bchg(p_ub, T_UBF_3_FLD, 2, (char *)p_ub_tmp, 0L), EXSUCCEED);
0403 
0404         
0405         l=889991;
0406         assert_equal(Bchg(p_ub_tmp, T_LONG_3_FLD, 3, (char *)&l, 0L), EXSUCCEED);
0407         
0408         assert_equal(Bchg(p_ub_tmp, T_STRING_7_FLD, 2, "ANOTHER UB", 0L), EXSUCCEED);
0409         assert_equal(CBchg(p_ub_tmp, T_DOUBLE_FLD, 0, "3.14159", 0L, BFLD_STRING), EXSUCCEED);
0410         assert_equal(Bchg(p_ub, T_UBF_3_FLD, 3, (char *)p_ub_tmp, 0L), EXSUCCEED);
0411         
0412         
0413         assert_equal(Bchg(p_ub, T_LONG_3_FLD, 3, (char *)&l, 0L), EXSUCCEED);
0414         
0415     }
0416     
0417 }
0418 
0419 /* vim: set ts=4 sw=4 et smartindent: */