PicoTest
A minimalist unit testing framework for C programs
Loading...
Searching...
No Matches
fixtures.c File Reference

Demonstrates test fixture call sequences. More...

Detailed Description

Demonstrates test fixture call sequences.

#include <stdio.h>
#include <picotest.h>
/* Hooks */
PicoTestCaseEnterProc logCaseEnter;
PicoTestCaseLeaveProc logCaseLeave;
#undef PICOTEST_CASE_ENTER
#undef PICOTEST_CASE_LEAVE
#undef PICOTEST_FIXTURE_BEFORE_SETUP
#undef PICOTEST_FIXTURE_BEFORE_TEARDOWN
#define PICOTEST_CASE_ENTER logCaseEnter
#define PICOTEST_CASE_LEAVE logCaseLeave
#define PICOTEST_FIXTURE_BEFORE_SETUP logSetup
#define PICOTEST_FIXTURE_BEFORE_TEARDOWN logTeardown
int level = 0;
void indent(int level) {
while (level--) printf(" ");
}
void logCaseEnter(const char *name) {
indent(level++);
printf("running test case %s\n", name);
}
void logCaseLeave(const char *name, int fail) {
indent(--level);
if (fail) {
printf("test case %s failed\n", name);
} else {
printf("test case %s completed successfully\n", name);
}
}
void logSetup(const char *fixture, const char *test) {
indent(level+1);
printf("fixture setup %s before test case %s\n", fixture, test);
}
void logTeardown(const char *fixture, const char *test, int fail) {
indent(level+1);
if (fail) {
printf("fixture teardown %s after failed test case %s\n", fixture, test);
} else {
printf("fixture teardown %s after successful test case %s\n", fixture, test);
}
}
/* Main test suite */
#include "mainSuite.inc"
void main() {
mainSuite(NULL);
}
void PicoTestFixtureBeforeSetupProc(const char *fixtureName, const char *testName)
Function signature of test fixture before setup hooks.
Definition picotest.h:1165
void PicoTestFixtureBeforeTeardownProc(const char *fixtureName, const char *testName, int fail)
Function signature of test fixture before teardown hooks.
Definition picotest.h:1264
void PicoTestCaseEnterProc(const char *testName)
Function signature of test case enter hooks.
Definition picotest.h:633
void PicoTestCaseLeaveProc(const char *testName, int fail)
Function signature of test case leave hooks.
Definition picotest.h:681
Example of a simple PicoTest suite.
This file defines a minimalist unit testing framework for C programs.