void test_case( const char *msg, Fn testFunc ) { ++total_; cout << "Test begin: " << msg << endl; if ( try_func( setup_ ) ) { const bool passed = try_func( testFunc ); if ( try_func( tearDown_ ) ) { if ( passed ) { ++succeed_; cout << "Test passed." << endl; } } else cerr << "tearDown failed." << endl; } else cerr << "setup failed." << endl; }
void test_case_must_fail( const char *msg, Fn testFunc ) { ++total_; cout << "Test begin, expected to fail: " << msg << endl; if ( try_func( setup_ ) ) { const bool passed = try_func( testFunc ); if ( try_func( tearDown_ ) ) { if ( passed ) { cout << "Test didn't fail." << endl; } else { ++succeed_; cout << "Test failed as expected." << endl; } } else cerr << "tearDown failed unexpectedly." << endl; } else cerr << "setup failed unexpectedly." << endl; }
static void multiple() { char rbuf[BUFSIZ]; char *field[5]; char *scan; int i; regexp *r; errreport = 1; lineno = 0; while (fgets(rbuf, sizeof(rbuf), stdin) != NULL) { rbuf[strlen(rbuf)-1] = '\0'; /* Dispense with \n. */ lineno++; scan = rbuf; for (i = 0; i < 5; i++) { field[i] = scan; if (field[i] == NULL) { complain("bad testfile format", ""); exit(1); } scan = strchr(scan, '\t'); if (scan != NULL) *scan++ = '\0'; } try_func(field); } /* And finish up with some internal testing... */ lineno = 9990; errseen = NULL; if (regcomp((char *)NULL) != NULL || errseen == NULL) complain("regcomp(NULL) doesn't complain", ""); lineno = 9991; errseen = NULL; if (regexec((regexp *)NULL, "foo") || errseen == NULL) complain("regexec(NULL, ...) doesn't complain", ""); lineno = 9992; r = regcomp("foo"); if (r == NULL) { complain("regcomp(\"foo\") fails", ""); return; } lineno = 9993; errseen = NULL; if (regexec(r, (char *)NULL) || errseen == NULL) complain("regexec(..., NULL) doesn't complain", ""); lineno = 9994; errseen = NULL; regsub((regexp *)NULL, "foo", rbuf); if (errseen == NULL) complain("regsub(NULL, ..., ...) doesn't complain", ""); lineno = 9995; errseen = NULL; regsub(r, (char *)NULL, rbuf); if (errseen == NULL) complain("regsub(..., NULL, ...) doesn't complain", ""); lineno = 9996; errseen = NULL; regsub(r, "foo", (char *)NULL); if (errseen == NULL) complain("regsub(..., ..., NULL) doesn't complain", ""); lineno = 9997; errseen = NULL; if (regexec(&badregexp, "foo") || errseen == NULL) complain("regexec(nonsense, ...) doesn't complain", ""); lineno = 9998; errseen = NULL; regsub(&badregexp, "foo", rbuf); if (errseen == NULL) complain("regsub(nonsense, ..., ...) doesn't complain", ""); }