Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief View unit tests, shared functions between unit testing & integration testing
0003  *
0004  * @file shared.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 <unistd.h>
0038 #include <ubf.h>
0039 #include <ndrstandard.h>
0040 #include <string.h>
0041 #include "test.fd.h"
0042 #include "ndebug.h"
0043 #include <fdatatype.h>
0044 #include <math.h>
0045 
0046 #include "test040.h"
0047 
0048 #define TEST_NUM_EQUAL(X, Y)  if (X!=Y) {NDRX_LOG(log_error, \
0049                 "TESTERROR: %s -> failed! %d vs %d", #X, X, Y); ret=EXFAIL;};
0050 
0051 #define TEST_DOUBLE_EQUAL(X, Y)  if (fabs(X-Y)>0.1) {NDRX_LOG(log_error, \
0052                 "TESTERROR: %s -> failed! %lf vs %lf", #X, X, Y); ret=EXFAIL;};
0053 
0054 #define TEST_STRING_EQUAL(X, Y)  if (0!=strcmp(X,Y)) {NDRX_LOG(log_error, \
0055                 "TESTERROR: %s -> failed! [%s] vs [%s]", #X, X, Y); ret=EXFAIL;};
0056 
0057 /**
0058  * Init view 3
0059  * @param v
0060  */
0061 expublic void init_MYVIEW3(struct MYVIEW3 *v)
0062 {
0063     v->tshort1 = 1;
0064     v->tshort2 = 2;
0065     v->tshort3 = 3;
0066 }
0067 
0068 /**
0069  * Validate view 3
0070  * @param v
0071  * @return 
0072  */
0073 expublic int validate_MYVIEW3(struct MYVIEW3 *v)
0074 {
0075     int ret = EXSUCCEED;
0076     
0077     TEST_NUM_EQUAL(v->tshort1, 1);
0078     TEST_NUM_EQUAL(v->tshort2, 2);
0079     TEST_NUM_EQUAL(v->tshort3, 3);
0080     
0081     return ret;
0082 }
0083 
0084 /**
0085  * Init the 
0086  * @param v
0087  */
0088 expublic void init_MYVIEW1(struct MYVIEW1 *v)
0089 {
0090     int i, j;
0091         
0092     v->tshort1=15556;   /* null=2000 */
0093 
0094     v->C_tshort2=2;
0095     v->tshort2[0]=9999; /* null=2001 */
0096     v->tshort2[1]=8888; /* null=2001 */
0097 
0098     v->C_tshort3 = 2;
0099     v->tshort3[0]=7777; /* null=2001 */
0100     v->tshort3[1]=-7777;    /* null=2001 */
0101     v->tshort3[2]=-7777;    /* null=2001 */
0102 
0103     v->tshort4=-10; /* null=NONE */
0104 
0105     v->tlong1=33333333; /* null=0 */
0106 
0107     v->tint2[0]=54545;  /* null=0 */
0108     v->tint2[1]=23232;  /* null=0 */
0109     v->tint3=-100;
0110     v->tint4[0]=1010101;    /* null=-1 */
0111     v->tint4[1]=989898; /* null=-1 */
0112 
0113     v->tchar1='A';  /* null="\n" */
0114 
0115     v->C_tchar2=5;
0116     v->tchar2[0]='A';   /* null="A" */
0117     v->tchar2[1]='B';
0118     v->tchar2[2]='C';
0119     v->tchar2[3]='\n';
0120     v->tchar2[4]='\t';
0121 
0122     v->C_tchar3=0;
0123     v->tchar3[0]='C';   /* null="A" */
0124     v->tchar3[1]='D';   /* null="A" */
0125 
0126     v->tfloat1[0]=-0.11;    /* null=1.1 */
0127     v->tfloat1[1]=-0.22;    /* null=1.1 */
0128     v->tfloat1[2]=0.33; /* null=1.1 */
0129     v->tfloat1[3]=0.44; /* null=1.1 */
0130 
0131     v->tfloat2[0]=100000.1; /* null=1.1 */
0132     v->tfloat2[1]=200000.2; /* null=1.1 */
0133 
0134     v->tfloat3=333333.111;  /* null=9999.99 */
0135 
0136     v->tdouble1[0]=99999.111111;    /* null=55555.99 */
0137     v->tdouble1[1]=11111.999999;    /* null=55555.99 */
0138     v->tdouble2=-999.123;   /* null=-999.123 */
0139 
0140     NDRX_STRCPY_SAFE(v->tstring0[0], "HELLO Enduro/X"); /* null="\n\t\f\\\'\"\vHELLOWORLD" */
0141     NDRX_STRCPY_SAFE(v->tstring0[1], "");   /* null="\n\t\f\\\'\"\vHELLOWORLD" */
0142     NDRX_STRCPY_SAFE(v->tstring0[2], "\nABC\n");    /* null="\n\t\f\\\'\"\vHELLOWORLD" */
0143 
0144     NDRX_STRCPY_SAFE(v->tstring1[0], "Pack my box");    /* null="HELLO WORLDB" */
0145     NDRX_STRCPY_SAFE(v->tstring1[1], "BOX MY PACK");    /* null="HELLO WORLDB" */
0146     NDRX_STRCPY_SAFE(v->tstring1[2], "\nEnduro/X\n");   /* null="HELLO WORLDB" */
0147 
0148     /* Test the L length indicator, must be set to number of bytes transfered */
0149     v->C_tstring2=2;
0150 
0151     NDRX_STRCPY_SAFE(v->tstring2[0], "CCCCAAAADDDD");
0152     NDRX_STRCPY_SAFE(v->tstring2[1], "EEEFFFGGG");
0153     NDRX_STRCPY_SAFE(v->tstring2[2], "IIIIJJJJKKK");
0154 
0155     v->C_tstring3=4;
0156 
0157     NDRX_STRCPY_SAFE(v->tstring3[0], "LLLLLL"); /* null="TESTEST" */
0158     NDRX_STRCPY_SAFE(v->tstring3[1], "MMMMMM"); /* null="TESTEST" */
0159     NDRX_STRCPY_SAFE(v->tstring3[2], "");   /* null="TESTEST" */
0160     NDRX_STRCPY_SAFE(v->tstring3[3], "NNNNNN"); /* null="TESTEST" */
0161 
0162     NDRX_STRCPY_SAFE(v->tstring4, "Some string");   /* null="HELLO TEST" */
0163     
0164     NDRX_STRCPY_SAFE(v->tstring5, "MEGA TEST");
0165 
0166     for (i=0; i<30; i++)
0167     {
0168         v->tcarray1[i]=i;
0169     }
0170 
0171     v->L_tcarray2 = 5;
0172     for (i=0; i<25; i++)
0173     {
0174         v->tcarray2[i]=i+1;
0175     }
0176     
0177     v->C_tcarray3 = 9;
0178             
0179     for (j=0; j<9; j++)
0180     {
0181         v->L_tcarray3[j]=j+1;
0182         
0183         for (i=0; i<16+j; i++)
0184         {
0185             v->tcarray3[j][i]=i+2;
0186         }
0187     }
0188     
0189     for (i=0; i<5; i++)
0190     {
0191         v->tcarray4[i]=i+3;
0192     }
0193     
0194     for (i=0; i<5; i++)
0195     {
0196         v->tcarray5[i]=i+4;
0197     }
0198     
0199 }
0200 
0201 /**
0202  * Validate demo data (data received over the TP buffers)
0203  * @param v
0204  */
0205 expublic int validate_MYVIEW1(struct MYVIEW1 *v)
0206 {
0207     int i, j;
0208     int ret = EXSUCCEED;
0209         
0210     TEST_NUM_EQUAL(v->tshort1, 15556);
0211 
0212     TEST_NUM_EQUAL(v->C_tshort2, 2);
0213     TEST_NUM_EQUAL(v->tshort2[0], 9999);
0214     TEST_NUM_EQUAL(v->tshort2[1], 8888);
0215     
0216 
0217     TEST_NUM_EQUAL(v->C_tshort3, 2);
0218     TEST_NUM_EQUAL(v->tshort3[0], 7777);
0219     TEST_NUM_EQUAL(v->tshort3[1], -7777);
0220     
0221     /* because we transfer only 2x elements... 
0222      * Due to count set to 2.
0223      * TODO: Add this note to the VIEW files. That if
0224      * Count is used, then during service calls, count also is used..
0225      */
0226     /* TEST_NUM_EQUAL(v->tshort3[2], 0); - do not test, network no send, local send */
0227     
0228     TEST_NUM_EQUAL(v->tshort4, -10);
0229 
0230     TEST_NUM_EQUAL(v->tlong1, 33333333);
0231 
0232     TEST_NUM_EQUAL(v->tint2[0], 54545);
0233     TEST_NUM_EQUAL(v->tint2[1], 23232);
0234     TEST_NUM_EQUAL(v->tint3, -100);
0235     TEST_NUM_EQUAL(v->tint4[0], 1010101);
0236     TEST_NUM_EQUAL(v->tint4[1], 989898);
0237 
0238 
0239 
0240     TEST_NUM_EQUAL(v->tchar1, 'A');
0241 
0242     TEST_NUM_EQUAL(v->C_tchar2, 5);
0243     TEST_NUM_EQUAL(v->tchar2[0], 'A');
0244     TEST_NUM_EQUAL(v->tchar2[1], 'B');
0245     TEST_NUM_EQUAL(v->tchar2[2], 'C');
0246     TEST_NUM_EQUAL(v->tchar2[3], '\n');
0247     TEST_NUM_EQUAL(v->tchar2[4], '\t');
0248 
0249     TEST_NUM_EQUAL(v->C_tchar3, 0);
0250     /* due to count set to 0 */
0251     /*TEST_NUM_EQUAL(v->tchar3[0], 0); - local blob send, so has this */
0252     /*TEST_NUM_EQUAL(v->tchar3[1], 0); -local blob send has */
0253 
0254     TEST_DOUBLE_EQUAL(v->tfloat1[0],-0.11);
0255     TEST_DOUBLE_EQUAL(v->tfloat1[1],-0.22);
0256     TEST_DOUBLE_EQUAL(v->tfloat1[2],0.33);
0257     TEST_DOUBLE_EQUAL(v->tfloat1[3],0.44);
0258 
0259     TEST_DOUBLE_EQUAL(v->tfloat2[0],100000.1);
0260     TEST_DOUBLE_EQUAL(v->tfloat2[1],200000.2);
0261 
0262     TEST_DOUBLE_EQUAL(v->tfloat3,333333.111);
0263 
0264     TEST_DOUBLE_EQUAL(v->tdouble1[0],99999.111111);
0265     TEST_DOUBLE_EQUAL(v->tdouble1[1],11111.999999);
0266     TEST_DOUBLE_EQUAL(v->tdouble2,-999.123);
0267 
0268     TEST_STRING_EQUAL(v->tstring0[0], "HELLO Enduro/X");
0269     TEST_STRING_EQUAL(v->tstring0[1], "");
0270     TEST_STRING_EQUAL(v->tstring0[2], "\nABC\n");
0271 
0272     TEST_STRING_EQUAL(v->tstring1[0], "Pack my box");
0273     TEST_STRING_EQUAL(v->tstring1[1], "BOX MY PACK");
0274     TEST_STRING_EQUAL(v->tstring1[2], "\nEnduro/X\n");
0275 
0276     
0277     /* Test the L length indicator, must be set to number of bytes transfered */
0278     TEST_NUM_EQUAL(v->C_tstring2, 2);
0279 
0280     TEST_STRING_EQUAL(v->tstring2[0], "CCCCAAAADDDD");
0281     TEST_STRING_EQUAL(v->tstring2[1], "EEEFFFGGG");
0282     /*TEST_STRING_EQUAL(v->tstring2[2], ""); - local blob*/
0283 
0284     TEST_NUM_EQUAL(v->C_tstring3, 4);
0285 
0286     TEST_STRING_EQUAL(v->tstring3[0], "LLLLLL");
0287     TEST_STRING_EQUAL(v->tstring3[1], "MMMMMM");
0288     TEST_STRING_EQUAL(v->tstring3[2], "");
0289     TEST_STRING_EQUAL(v->tstring3[3], "NNNNNN");
0290 
0291     TEST_STRING_EQUAL(v->tstring4, "Some string");
0292     
0293     TEST_STRING_EQUAL(v->tstring5, "MEGA TEST");
0294 
0295 
0296     for (i=0; i<30; i++)
0297     {
0298         TEST_NUM_EQUAL(v->tcarray1[i], i);
0299     }
0300 
0301 
0302     TEST_NUM_EQUAL(v->L_tcarray2, 5);
0303     
0304     for (i=0; i<5; i++)
0305     {
0306         TEST_NUM_EQUAL(v->tcarray2[i], i+1);
0307     }
0308     
0309     /* This is not sent over because of indicator.. 
0310      * Really cannot test, because null initialisers might
0311      * fill with other data...
0312     TEST_NUM_EQUAL(v->tcarray2[5], 0);
0313     TEST_NUM_EQUAL(v->tcarray2[6], 0);
0314      * */
0315 
0316     TEST_NUM_EQUAL(v->C_tcarray3, 9);
0317             
0318     for (j=0; j<9; j++)
0319     {
0320         TEST_NUM_EQUAL(v->L_tcarray3[j], j+1);
0321         
0322         for (i=0; i<j+1; i++)
0323         {
0324             TEST_NUM_EQUAL(v->tcarray3[j][i], i+2);
0325         }
0326     }
0327     
0328     /* Last not used... */
0329     TEST_NUM_EQUAL(v->tcarray3[9][0], 0);
0330     
0331     for (i=0; i<5; i++)
0332     {
0333         TEST_NUM_EQUAL(v->tcarray4[i], i+3);
0334     }
0335     
0336     for (i=0; i<5; i++)
0337     {
0338         TEST_NUM_EQUAL(v->tcarray5[i], i+4);
0339     }
0340     
0341     return ret;
0342     
0343 }
0344 
0345 /* vim: set ts=4 sw=4 et smartindent: */