home *** CD-ROM | disk | FTP | other *** search
- /* t4expr.c
-
- (c)Copyright Sequiter Software Inc., 1987-1990. All rights reserved.
-
- Tests Code Base Expression Evaluation Routines.
- */
-
- #include "p4misc.h"
- #include "d4all.h"
- #include "w4.h"
- #include "u4error.h"
-
- #include <string.h>
-
- static FIELD testfields[] =
- {
- /* Name , Type, Width, Dec, Offset */
- {"N1", 'F', 5, 2, 0 },
- {"N2", 'N', 10, 0, 0 },
- {"C1", 'C', 10, 0, 0 },
- {"C2", 'C', 10, 0, 0 },
- {"C3", 'C', 10, 0, 0 },
- {"C4", 'C', 15, 0, 0 },
- {"C5", 'C', 15, 0, 0 },
- {"D1", 'D', 8, 0, 0 },
- {"D2", 'D', 8, 0, 0 },
- {"L1", 'L', 1, 0, 0 },
- {"L2", 'L', 1, 0, 0 }
- };
-
- typedef struct test_expr_st
- {
- char expr[30] ;
- char result[30] ;
- char result_type ;
- } TEST_EXPR ;
-
-
- static TEST_EXPR test_expr[] =
- {
- { "5>4.AND.6.7>4.3 ",
- "1 ",
- 'L'
- },
-
- { ".NOT. .F. ",
- "1 ",
- 'L'
- },
-
- { "\"NEW \" - \"ME \" ",
- "NEWME \0 ",
- 'C'
- },
-
- { ".T. .AND. .F. ",
- "0 ",
- 'L'
- },
-
- { "IIF(C1=\"SMUR\",\"TRUE\",\"FALSE\")",
- "FALSE\0 ",
- 'C'
- },
-
- { "((((7))))*(1+2) ",
- "21 ",
- 'N'
- },
-
- { "N1+N2 ",
- "12 ",
- 'N'
- },
-
- { "N1-N2 ",
- "8 ",
- 'N'
- },
-
- { "N1*N2 ",
- "20 ",
- 'N'
- },
-
- { "N1/N2 ",
- "5 ",
- 'N'
- },
-
- #ifndef NO_POW
- #ifndef ZORTECH
- /* Zortech fails because Zortech 'pow' does not round the result. */
- { "N1^N2 ",
- "100 ",
- 'N'
- },
-
- { "2^4 ",
- "16 ",
- 'N'
- },
-
- { "3**5 ",
- "243 ",
- 'N'
- },
- #endif
- #endif
-
- { "C1+C2 ",
- "character1CHARACTER2\0 ",
- 'C'
- },
-
- { "C1-C2 ",
- "character1CHARACTER2\0 ",
- 'C'
- },
-
- { "C1=C2 ",
- "0 ",
- 'L'
- },
-
- { "C1=C3 ",
- "0 ",
- 'L'
- },
-
- { "C1>C2 ",
- "1 ",
- 'L'
- },
-
- { "C1<C2 ",
- "0 ",
- 'L'
- },
-
- { "C1<>C2 ",
- "1 ",
- 'L'
- },
-
- { "C1#C2 ",
- "1 ",
- 'L'
- },
-
- { "C1<>C3 ",
- "1 ",
- 'L'
- },
-
- { "C1$C2 ",
- "0 ",
- 'L'
- },
-
- { "\"ST\"$\"MOST\" ",
- "1 ",
- 'L'
- },
-
- { "CTOD(\"02/01/88\") ",
- "19880201\0 ",
- 'D'
- },
-
- { "STOD(C4) ",
- "19880201\0 ",
- 'D'
- },
-
- { "DTOC(D2) ",
- "03/23/88\0 ",
- 'C'
- },
-
- { "DTOS(D2) ",
- "19880323\0 ",
- 'C'
- },
-
- { "D1=STOD(C4) ",
- "1 ",
- 'L'
- },
-
- { "C5=DTOS(D2) ",
- "1 ",
- 'L'
- },
-
- { "IIF(C1=\"SMUR\",\"TRUE\",\"FALSE\")",
- "FALSE\0 ",
- 'C'
- },
-
- { "RECCOUNT() ",
- "1 ",
- 'N'
- },
-
- { "RECNO() ",
- "1 ",
- 'N'
- },
-
- #ifndef ZORTECH
- { "STR(22.2,5,1) ",
- " 22.2\0 ",
- 'C'
- },
- #endif
-
- { "STR(5.7,4,2) ",
- "5.70\0 ",
- 'C'
- },
-
- #ifndef ZORTECH
- { "STR(21.5,6,0) ",
- " 22\0 ",
- 'C'
- },
- #endif
-
- { "VAL(\"2323\") ",
- "2323 ",
- 'N'
- },
-
- { "SUBSTR(C1,2,2) ",
- "ha\0 ",
- 'C'
- },
-
- { "3*4-2 ",
- "10 ",
- 'N'
- },
-
- { "L1 ",
- "0 ",
- 'L'
- },
-
- { ".NOT. .T. ",
- "0 ",
- 'L'
- },
-
- { ".NOT. .F. ",
- "1 ",
- 'L'
- },
-
- { ".T. ",
- "1 ",
- 'L'
- },
-
- { ".T. .OR. .F. ",
- "1 ",
- 'L'
- },
-
- { ".T. .AND. .F. ",
- "0 ",
- 'L'
- },
-
- { "\"A \" + \"B \" ",
- "A B \0 ",
- 'C'
- },
-
- { "\"NEW \" - \"ME \" ",
- "NEWME \0 ",
- 'C'
- },
-
- { "\" \" - \" ab\" ",
- " ab \0 ",
- 'C'
- },
-
- { "((((7))))*(1+2) ",
- "21 ",
- 'N'
- },
-
- { " IIF( .F. , 1, 2) ",
- "2 ",
- 'N'
- },
-
- { " IIF ( .T., \"GOOD\", \"BAD\" )",
- "GOOD\0 ",
- 'C'
- },
-
- { "\0 ",
- " ",
- '\0'
- },
-
- };
-
-
- main()
- {
- int logical, i ;
- double d ;
- void *ptr ;
-
- #ifdef NO_HUGE
- #ifdef IS_386
- d4init() ;
- #else
- d4initialize( 4, 4, 20, 1000, 20000L ) ;
- #endif
- #else
- d4init() ;
- #endif
-
- if ( d4create( "T4EXPR", 11, testfields, 0) < 0 )
- {
- u4error( 0, "t4expr: d4create", (char *) 0 ) ;
- w4exit(1) ;
- }
-
- f4replace( f4ref("c1"), "character1" );
- f4replace( f4ref("c2"), "CHARACTER2" );
- f4replace( f4ref("c3"), "ChArAcTeR3" );
- f4replace( f4ref("c4"), "19880201" );
- f4replace( f4ref("c5"), "19880323" );
-
- d = 10.0 ; f4replace( f4ref("n1"), &d ) ;
- d = 2.0 ; f4replace( f4ref("n2"), &d );
-
- f4replace( f4ref("d1"), "19880201" );
- f4replace( f4ref("d2"), "19880323" );
-
- logical = 0 ; f4replace( f4ref("l1"), &logical ) ;
- logical = 1 ; f4replace( f4ref("l2"), &logical );
-
- if ( d4append() < 0 )
- {
- u4error( 0, "t4expr: d4write", (char *) 0 ) ;
- w4exit(1) ;
- }
-
- for ( i=0; test_expr[i].result_type != '\0'; i++ )
- {
- w4( w4row()+1,0, "\nOn Expression: " ) ;
- w4( w4row(),0, test_expr[i].expr ) ;
-
- ptr = e4eval( test_expr[i].expr ) ;
- if ( ptr == (void *) 0 )
- {
- u4error( 0, "t4expr: e4eval", (char *) 0 ) ;
- w4exit(1) ;
- }
-
- if ( e4type() != test_expr[i].result_type )
- {
- u4error( 0, "t4expr: e4type", (char *) 0 ) ;
- w4exit(1) ;
- }
-
- switch (e4type())
- {
- case 'C' :
- if ( strcmp( (char *) ptr, test_expr[i].result) != 0 )
- {
- u4error( 0, "t4expr EXPR:", test_expr[i].expr, (char *) 0 ) ;
- w4exit(1) ;
- }
- break ;
-
- case 'L' :
- if ( (*(int *) ptr) && ! c4atoi( test_expr[i].result,30 ) ||
- ! (*(int *) ptr) && c4atoi( test_expr[i].result,30 ) )
- {
- u4error( 0, "t4expr EXPR:", test_expr[i].expr, (char *) 0 ) ;
- w4exit(1) ;
- }
- break;
-
- case 'N' :
- case 'F' :
- if ( (*(double *) ptr) != c4atod(test_expr[i].result,30))
- {
- u4error( 0, "t4expr EXPR:", test_expr[i].expr, (char *) 0 ) ;
- w4exit(1) ;
- }
- break;
-
- case 'D' :
- if ( strncmp((char *) ptr, test_expr[i].result, 8 ) != 0 )
- {
- u4error( 0, "t4expr EXPR:", test_expr[i].expr, (char *) 0 ) ;
- w4exit(1) ;
- }
- break;
- }
- }
-
- d4close_all() ;
-
- #ifdef H4TEST
- {
- int rc ;
- d4init_undo() ;
- rc = h4free_check(32000) ;
- d4init() ;
- if ( rc != 0 )
- {
- u4error( 0, "t4expr: Memory items not freed", (char *) 0 );
- w4exit(1) ;
- }
- }
- #endif
-
- w4handle(1) ;
- w4( w4row()+1,0, "t4expr: SUCCESS" ) ;
-
- w4exit(0) ;
- }
-
-
-