sdk-world v2026.11.05
PS2 SDK - world tier (copyleft-allowed, non-essential packages)
Loading...
Searching...
No Matches
tap.h
Go to the documentation of this file.
1/*
2libtap - Write tests in C
3Copyright 2012 Jake Gelbman <gelbman@gmail.com>
4This file is licensed under the LGPL
5*/
6
11#ifndef __TAP_H__
12#define __TAP_H__
13
14#ifdef __cplusplus
15extern "C" {
16#endif
17
18#ifndef va_copy
19#ifdef __va_copy
20#define va_copy __va_copy
21#else
22#define va_copy(d, s) ((d) = (s))
23#endif
24#endif
25
26#include <stdio.h>
27#include <stdlib.h>
28#include <stdarg.h>
29
30int vok_at_loc (const char *file, int line, int test, const char *fmt,
31 va_list args);
32int ok_at_loc (const char *file, int line, int test, const char *fmt,
33 ...);
34int is_at_loc (const char *file, int line, const char *got,
35 const char *expected, const char *fmt, ...);
36int isnt_at_loc (const char *file, int line, const char *got,
37 const char *expected, const char *fmt, ...);
38int cmp_ok_at_loc (const char *file, int line, int a, const char *op,
39 int b, const char *fmt, ...);
40int cmp_mem_at_loc (const char *file, int line, const void *got,
41 const void *expected, size_t n, const char *fmt, ...);
42int bail_out (int ignore, const char *fmt, ...);
43void tap_plan (int tests, const char *fmt, ...);
44int diag (const char *fmt, ...);
45int exit_status (void);
46void tap_skip (int n, const char *fmt, ...);
47void tap_todo (int ignore, const char *fmt, ...);
48void tap_end_todo (void);
49
50#define NO_PLAN -1
51#define SKIP_ALL -2
52#define ok(...) ok_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
53#define is(...) is_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
54#define isnt(...) isnt_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
55#define cmp_ok(...) cmp_ok_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
56#define cmp_mem(...) cmp_mem_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
57#define plan(...) tap_plan(__VA_ARGS__, NULL)
58#define done_testing() return exit_status()
59#define BAIL_OUT(...) bail_out(0, "" __VA_ARGS__, NULL)
60#define pass(...) ok(1, "" __VA_ARGS__)
61#define fail(...) ok(0, "" __VA_ARGS__)
62
63#define skip(test, ...) do {if (test) {tap_skip(__VA_ARGS__, NULL); break;}
64#define end_skip } while (0)
65
66#define todo(...) tap_todo(0, "" __VA_ARGS__, NULL)
67#define end_todo tap_end_todo()
68
69#define dies_ok(...) dies_ok_common(1, __VA_ARGS__)
70#define lives_ok(...) dies_ok_common(0, __VA_ARGS__)
71
72#if defined(_WIN32) || defined(_EE)
73#define like(...) tap_skip(1, "like is not implemented on Windows or PlayStation 2")
74#define unlike(...) tap_skip(1, "unlike is not implemented on Windows")
75#define dies_ok_common(...) \
76 tap_skip(1, "Death detection is not supported on Windows or PlayStation 2")
77#else
78#define like(...) like_at_loc(1, __FILE__, __LINE__, __VA_ARGS__, NULL)
79#define unlike(...) like_at_loc(0, __FILE__, __LINE__, __VA_ARGS__, NULL)
80int like_at_loc (int for_match, const char *file, int line,
81 const char *got, const char *expected,
82 const char *fmt, ...);
83#include <unistd.h>
84#include <sys/types.h>
85#include <sys/wait.h>
86int tap_test_died (int status);
87#define dies_ok_common(for_death, code, ...) \
88 do { \
89 int cpid; \
90 int it_died; \
91 tap_test_died(1); \
92 cpid = fork(); \
93 switch (cpid) { \
94 case -1: \
95 perror("fork error"); \
96 exit(1); \
97 case 0: \
98 close(1); \
99 close(2); \
100 code \
101 tap_test_died(0); \
102 exit(0); \
103 } \
104 if (waitpid(cpid, NULL, 0) < 0) { \
105 perror("waitpid error"); \
106 exit(1); \
107 } \
108 it_died = tap_test_died(0); \
109 if (!it_died) \
110 {code} \
111 ok(for_death ? it_died : !it_died, "" __VA_ARGS__); \
112 } while (0)
113#endif
114
115#ifdef __cplusplus
116}
117#endif
118
119#endif