[1870] | 1 | /* $Id: testlib.h,v 1.1 1999-11-28 23:10:13 bird Exp $
|
---|
| 2 | *
|
---|
| 3 | * General test helpers and structures.
|
---|
| 4 | *
|
---|
| 5 | * Copyright (c) 1999 knut st. osmundsen
|
---|
| 6 | *
|
---|
| 7 | * Project Odin Software License can be found in LICENSE.TXT
|
---|
| 8 | *
|
---|
| 9 | */
|
---|
| 10 |
|
---|
| 11 | #ifndef _TESTLIB_H_
|
---|
| 12 | #define _TESTLIB_H_
|
---|
| 13 |
|
---|
| 14 | /*******************************************************************************
|
---|
| 15 | * Defined Constants And Macros *
|
---|
| 16 | *******************************************************************************/
|
---|
| 17 | /*
|
---|
| 18 | * LastError macros
|
---|
| 19 | */
|
---|
| 20 | #define TSTCHECKLASTERROR(errorno) \
|
---|
| 21 | (GetLastError() != (errorno) \
|
---|
| 22 | ? TstError(__FILE__, __LINE__, "LastError %d != %d", \
|
---|
| 23 | GetLastError(), (errorno)) \
|
---|
| 24 | : (void)0)
|
---|
| 25 |
|
---|
| 26 | #define TSTINFOLASTERROR() \
|
---|
| 27 | TstInfo(__FILE__, __LINE__, "LastError %d", GetLastError())
|
---|
| 28 |
|
---|
| 29 | /*
|
---|
| 30 | * Assert like macros...
|
---|
| 31 | */
|
---|
| 32 | #define TSTCHECK(expr) \
|
---|
| 33 | (!(expr) \
|
---|
| 34 | ? TstError(__FILE__, __LINE__, #expr) \
|
---|
| 35 | : (void)0)
|
---|
| 36 |
|
---|
| 37 | #define TSTCHECK1D(expr,d1) \
|
---|
| 38 | (!(expr) \
|
---|
| 39 | ? TstError(__FILE__, __LINE__, #expr "; "#d1"=%d", d1) \
|
---|
| 40 | : (void)0)
|
---|
| 41 |
|
---|
| 42 | #define TSTCHECK1S(expr,s1) \
|
---|
| 43 | (!(expr) \
|
---|
| 44 | ? TstError(__FILE__, __LINE__, #expr "; "#s1"='%s'", s1) \
|
---|
| 45 | : (void)0)
|
---|
| 46 |
|
---|
| 47 | #define TSTCHECK2D(expr,d1,d2) \
|
---|
| 48 | (!(expr) \
|
---|
| 49 | ? TstError(__FILE__, __LINE__, #expr "; "#d1"=%d, "#d2"=%d", d1,d2) \
|
---|
| 50 | : (void)0)
|
---|
| 51 |
|
---|
| 52 |
|
---|
| 53 | #define TSTCHECKW(expr) \
|
---|
| 54 | (!(expr) \
|
---|
| 55 | ? TstWarning(__FILE__, __LINE__, #expr) \
|
---|
| 56 | : (void)0)
|
---|
| 57 |
|
---|
| 58 | #define TSTCHECKW1D(expr,d1) \
|
---|
| 59 | (!(expr) \
|
---|
| 60 | ? TstWarning(__FILE__, __LINE__, #expr "; "#d1"=%d", d1) \
|
---|
| 61 | : (void)0)
|
---|
| 62 |
|
---|
| 63 | #define TSTCHECKW1S(expr,s1) \
|
---|
| 64 | (!(expr) \
|
---|
| 65 | ? TstWarning(__FILE__, __LINE__, #expr "; "#s1"='%s'", s1) \
|
---|
| 66 | : (void)0)
|
---|
| 67 |
|
---|
| 68 | #define TSTCHECKW2D(expr,d1,d2) \
|
---|
| 69 | (!(expr) \
|
---|
| 70 | ? TstWarning(__FILE__, __LINE__, #expr "; "#d1"=%d, "#d2"=%d", d1, d2) \
|
---|
| 71 | : (void)0)
|
---|
| 72 |
|
---|
| 73 |
|
---|
| 74 | /*******************************************************************************
|
---|
| 75 | * Structures and Typedefs *
|
---|
| 76 | *******************************************************************************/
|
---|
| 77 | /*
|
---|
| 78 | * Returns a boolean: TRUE no errors or warnings, FALSE warnings and/or errors.
|
---|
| 79 | * (informational only)
|
---|
| 80 | */
|
---|
| 81 | typedef void (* PTESTFUNC)(void);
|
---|
| 82 |
|
---|
| 83 |
|
---|
| 84 | /*
|
---|
| 85 | * An entry in a test table.
|
---|
| 86 | */
|
---|
| 87 | typedef struct _TestEntry
|
---|
| 88 | {
|
---|
| 89 | PTESTFUNC pfnTest; /* Pointer to test function. */
|
---|
| 90 | char * pszName; /* Pointer to string containing a name for the test. (not too long, please.) */
|
---|
| 91 | unsigned cErrors; /* Number of errors registered in this test. */
|
---|
| 92 | unsigned cWarnings; /* Number of warnings registered in this test. */
|
---|
| 93 | } TESTENTRY, *PTESTENTRY;
|
---|
| 94 |
|
---|
| 95 | /*
|
---|
| 96 | * Test table
|
---|
| 97 | */
|
---|
| 98 | typedef struct _TestTable
|
---|
| 99 | {
|
---|
| 100 | char * pszTableDescription; /* Pointer to string describing the this testtable. */
|
---|
| 101 | unsigned cErrors; /* Number of errors accumulated. */
|
---|
| 102 | unsigned cWarnings; /* Number of warnings accumulated. */
|
---|
| 103 | PTESTENTRY paTest; /* Pointer to array of TestEntries. */
|
---|
| 104 | unsigned uLevel; /* !internal! Nesting of testtables in processing */
|
---|
| 105 | int fPrinted; /* !internal! TRUE: description is printed. FALSE: not printed. */
|
---|
| 106 | int iCurrentTest; /* !internal! Index of the entry currently being executed. */
|
---|
| 107 | } TESTTABLE, *PTESTTABLE;
|
---|
| 108 |
|
---|
| 109 |
|
---|
| 110 | /*******************************************************************************
|
---|
| 111 | * Functions *
|
---|
| 112 | *******************************************************************************/
|
---|
| 113 | void TstProcessTestTable(PTESTTABLE pTestTable);
|
---|
| 114 | void TstError(const char *pszFile, unsigned uLine, const char *pszFormat, ...);
|
---|
| 115 | void TstWarning(const char *pszFile, unsigned uLine, const char *pszFormat, ...);
|
---|
| 116 | void TstInfo(const char *pszFormat, ...);
|
---|
| 117 | void TstInfo(const char *pszFile, unsigned uLine, const char *pszFormat, ...);
|
---|
| 118 |
|
---|
| 119 | #endif
|
---|