#INCLUDE ONCE "file.bi" #DEFINE FNAM "res" ' filename for results #DEFINE CNAM "test_suite" ' config .h2bi file for tests #IFDEF __FB_UNIX__ #DEFINE H2BI "h2bi " ' call ./h_2_bi #DEFINE NL !"\n" #ELSE #DEFINE H2BI "h_2_bi.exe " ' call h_2_bi.exe #DEFINE NL !"\n\l" #ENDIF ' S = code to send ' R = expected return code ' I = init text for .h2bi file (optional) ' P = additional parameters (optional) SUB test(BYREF S AS STRING, BYREF R AS STRING, _ BYREF I AS STRING = "", BYREF P AS STRING = "") STATIC AS INTEGER n = 0 IF LEN(S) = 0 THEN ? NL & "Done, found " & n & " failure(s)." : EXIT SUB VAR c = H2BI, fnr = FREEFILE IF LEN(I) THEN ' create and use new .h2bi file c &= FNAM FILECOPY CNAM & ".h2bi", FNAM & ".h2bi" OPEN FNAM & ".h2bi" FOR APPEND AS #fnr PRINT #fnr, I CLOSE #fnr ELSE ' default .h2bi file c &= CNAM END IF c &= " " & P & " -g > " & FNAM & ".txt" ' command line OPEN PIPE c FOR OUTPUT AS #fnr ' send command, result in .txt file PRINT #fnr, S CLOSE #fnr OPEN FNAM & ".txt" FOR BINARY AS #fnr ' read .txt VAR t = STRING(LOF(fnr), 0) GET #fnr, , t CLOSE #fnr IF t = R & NL THEN ? "OK: ";S;" --> ";t; : EXIT SUB ' OK ? ? S;" --> Failure, expected:" ? R;" --> Got:" ? t n += 1 END SUB test( _ "#define x 12", _ "#DEFINE x 12") test( _ "#define x 12", _ "#DEFiNE x 12") ' simulate an error test( _ "int x[];", _ "DIM AS INTEGER x(...) '??? dimensioning") test( _ "#define L_STRING L""hello world""", _ "#DEFINE L_STRING WSTR(!""hello world"")") test( _ "#define some_string ""hello\t\t\n\\\""", _ "#DEFINE some_string !""hello\t\t\n\\\""") test( _ "#define some_string ""\U0010AB00""", _ "#DEFINE some_string !""\U0010AB00""") test( _ "typedef Tcl_Obj * (*Tcl_FSListVolumesProc) (void);", _ "TYPE Tcl_FSListVolumesProc AS FUNCTION CDECL() AS Tcl_Obj PTR") test( _ "typedef Tcl_Obj * (Tcl_FSListVolumesProc) (void);", _ "TYPE Tcl_FSListVolumesProc AS FUNCTION CDECL() AS Tcl_Obj PTR") test( _ "typedef void (*TestFunction)(CuTest *);", _ "TYPE TestFunction AS SUB CDECL( _" NL _ !"\tBYVAL _TJF AS CuTest PTR) '??? no name in parameter list") test( _ "#define X 21" NL _ "#define Y 44" NL _ "#define Z 6666", _ "#DEFINE X 21" NL _ "#DEFINE Y 44" NL _ "#DEFINE Z 6666") ' testing a macro test( _ "API(int, ulp);", _ "DIM AS INTEGER ulp", _ !"__MACROS__(){};" NL _ "#define API(typ, nam) typ nam") ' simulating an error (because of missing macro) test( _ "API(int, ulp);", _ "DIM AS INTEGER ulp") test( _ "", _ "") #IFNDEF __FB_UNIX__ SLEEP #ENDIF