netatalk: test.h Source File

netatalk 4.5.0
Free and Open Source Apple Filing Protocol (AFP) Server
Loading...
Searching...
No Matches
test.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2010 Frank Lahm <franklahm@gmail.com>
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13*/
14
15#ifndef TEST_H
16#define TEST_H
17
18#ifdef HAVE_CONFIG_H
19#include "config.h"
20#endif /* HAVE_CONFIG_H */
21
22#include <errno.h>
23#include <stdio.h>
24#include <stdlib.h>
25#include <string.h>
26
27#include <atalk/cnid.h>
28#include <atalk/directory.h>
29#include <atalk/globals.h>
30#include <atalk/logger.h>
31#include <atalk/queue.h>
32#include <atalk/util.h>
33#include <atalk/volume.h>
34
35#include "afp_config.h"
36#include "dircache.h"
37#include "directory.h"
38#include "hash.h"
39#include "subtests.h"
40#include "volume.h"
41
42extern int test_output_tap;
43extern int test_case_num;
44extern FILE *test_report_stream;
45
46 static inline FILE *test_stream(void)
47{
48 return test_report_stream ? test_report_stream : stdout;
49}
50
51 static inline void alignok(int len)
52{
53 int i = 1;
54
55 if (len < 80) {
56 i = 80 - len;
57 }
58
59 while (i--) {
60 fprintf(test_stream(), " ");
61 }
62}
63
64 static inline void test_plan(int count)
65{
66 if (test_output_tap) {
67 fprintf(test_stream(), "1..%d\n", count);
68 fflush(test_stream());
69 }
70}
71
72 static inline void test_section(const char *title, const char *underline)
73{
74 if (!test_output_tap) {
75 fprintf(test_stream(), "%s\n%s\n", title, underline);
76 }
77}
78
79 static inline void test_begin(const char *name)
80{
81 if (!test_output_tap) {
82 int name_len;
83 fprintf(test_stream(), "Testing: ");
84 name_len = fprintf(test_stream(), "%s", name);
85 fprintf(test_stream(), " ... ");
86
87 if (name_len >= 0) {
88 alignok(name_len);
89 }
90 }
91}
92
93 static inline void test_ok(const char *name)
94{
95 if (test_output_tap) {
96 fprintf(test_stream(), "ok %d - %s\n", ++test_case_num, name);
97 fflush(test_stream());
98 } else {
99 fprintf(test_stream(), "[ok]\n");
100 }
101}
102
103 static inline void test_fail(const char *name, const char *file, int line)
104{
105 if (test_output_tap) {
106 fprintf(test_stream(), "not ok %d - %s\n", ++test_case_num, name);
107 fprintf(test_stream(), "# failed at %s:%d\n", file, line);
108 fflush(test_stream());
109 } else {
110 fprintf(test_stream(), "[error]\n");
111 }
112}
113
114 static inline void test_fail_int(const char *name, int got, int expected,
115 const char *file, int line)
116{
117 test_fail(name, file, line);
118
119 if (test_output_tap) {
120 fprintf(test_stream(), "# got: %d\n", got);
121 fprintf(test_stream(), "# expected: %d\n", expected);
122 fflush(test_stream());
123 }
124}
125
126 static inline void test_abort(void)
127{
128 if (test_output_tap) {
129 fprintf(test_stream(), "Bail out! stopping after failed assertion\n");
130 fflush(test_stream());
131 }
132}
133
134#define TEST(a) \
135 do { \
136 test_begin(#a); \
137 a; \
138 test_ok(#a); \
139 } while (0)
140
141#define TEST_int(a, b) \
142 do { \
143 test_begin(#a); \
144 if ((reti = (a)) != b) { \
145 test_fail_int(#a, reti, b, __FILE__, \
146 __LINE__); \
147 test_abort(); \
148 exit(1); \
149 } else { \
150 test_ok(#a); \
151 } \
152 } while (0)
153
154#define TEST_expr(a, b) \
155 do { \
156 test_begin(#a); \
157 a; \
158 if (b) { \
159 test_ok(#a); \
160 } else { \
161 test_fail(#a, __FILE__, __LINE__); \
162 test_abort(); \
163 exit(1); \
164 } \
165 } while (0)
166#endif /* TEST_H */
afp_config.h
cnid.h
config.h
dircache.h
globals.h
directory.h
util.h
Netatalk utility functions.
volume.h
logger.h
queue.h
count
int count
Definition server_ipc.c:89
subtests.h
test_case_num
int test_case_num
Definition test.c:50
test_output_tap
int test_output_tap
Definition test.c:49
test_report_stream
FILE * test_report_stream
Definition test.c:51
test_plan
static void test_plan(int count)
Definition test.h:64
test_section
static void test_section(const char *title, const char *underline)
Definition test.h:72
test_ok
static void test_ok(const char *name)
Definition test.h:93
test_abort
static void test_abort(void)
Definition test.h:126
test_begin
static void test_begin(const char *name)
Definition test.h:79
alignok
static void alignok(int len)
Definition test.h:51
test_fail_int
static void test_fail_int(const char *name, int got, int expected, const char *file, int line)
Definition test.h:114
test_fail
static void test_fail(const char *name, const char *file, int line)
Definition test.h:103
test_stream
static FILE * test_stream(void)
Definition test.h:46