1*11be35a1SLionel Sambuc // Copyright 2012 Google Inc.
2*11be35a1SLionel Sambuc // All rights reserved.
3*11be35a1SLionel Sambuc //
4*11be35a1SLionel Sambuc // Redistribution and use in source and binary forms, with or without
5*11be35a1SLionel Sambuc // modification, are permitted provided that the following conditions are
6*11be35a1SLionel Sambuc // met:
7*11be35a1SLionel Sambuc //
8*11be35a1SLionel Sambuc // * Redistributions of source code must retain the above copyright
9*11be35a1SLionel Sambuc // notice, this list of conditions and the following disclaimer.
10*11be35a1SLionel Sambuc // * Redistributions in binary form must reproduce the above copyright
11*11be35a1SLionel Sambuc // notice, this list of conditions and the following disclaimer in the
12*11be35a1SLionel Sambuc // documentation and/or other materials provided with the distribution.
13*11be35a1SLionel Sambuc // * Neither the name of Google Inc. nor the names of its contributors
14*11be35a1SLionel Sambuc // may be used to endorse or promote products derived from this software
15*11be35a1SLionel Sambuc // without specific prior written permission.
16*11be35a1SLionel Sambuc //
17*11be35a1SLionel Sambuc // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18*11be35a1SLionel Sambuc // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19*11be35a1SLionel Sambuc // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20*11be35a1SLionel Sambuc // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21*11be35a1SLionel Sambuc // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22*11be35a1SLionel Sambuc // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23*11be35a1SLionel Sambuc // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24*11be35a1SLionel Sambuc // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25*11be35a1SLionel Sambuc // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26*11be35a1SLionel Sambuc // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27*11be35a1SLionel Sambuc // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28*11be35a1SLionel Sambuc
29*11be35a1SLionel Sambuc #include "error.h"
30*11be35a1SLionel Sambuc
31*11be35a1SLionel Sambuc #include <errno.h>
32*11be35a1SLionel Sambuc #include <stdint.h>
33*11be35a1SLionel Sambuc #include <stdio.h>
34*11be35a1SLionel Sambuc #include <stdlib.h>
35*11be35a1SLionel Sambuc #include <string.h>
36*11be35a1SLionel Sambuc
37*11be35a1SLionel Sambuc #include <atf-c.h>
38*11be35a1SLionel Sambuc
39*11be35a1SLionel Sambuc
40*11be35a1SLionel Sambuc ATF_TC_WITHOUT_HEAD(error_new__oom);
ATF_TC_BODY(error_new__oom,tc)41*11be35a1SLionel Sambuc ATF_TC_BODY(error_new__oom, tc)
42*11be35a1SLionel Sambuc {
43*11be35a1SLionel Sambuc void* invalid = (void*)1;
44*11be35a1SLionel Sambuc kyua_error_t error = kyua_error_new("test_error", invalid, SIZE_MAX, NULL);
45*11be35a1SLionel Sambuc ATF_REQUIRE(kyua_error_is_type(error, kyua_oom_error_type));
46*11be35a1SLionel Sambuc ATF_REQUIRE(kyua_error_data(error) == NULL);
47*11be35a1SLionel Sambuc kyua_error_free(error);
48*11be35a1SLionel Sambuc }
49*11be35a1SLionel Sambuc
50*11be35a1SLionel Sambuc
51*11be35a1SLionel Sambuc ATF_TC_WITHOUT_HEAD(error_subsume__none);
ATF_TC_BODY(error_subsume__none,tc)52*11be35a1SLionel Sambuc ATF_TC_BODY(error_subsume__none, tc)
53*11be35a1SLionel Sambuc {
54*11be35a1SLionel Sambuc kyua_error_t primary = kyua_error_ok();
55*11be35a1SLionel Sambuc kyua_error_t secondary = kyua_error_ok();
56*11be35a1SLionel Sambuc ATF_REQUIRE(!kyua_error_is_set(kyua_error_subsume(primary, secondary)));
57*11be35a1SLionel Sambuc }
58*11be35a1SLionel Sambuc
59*11be35a1SLionel Sambuc
60*11be35a1SLionel Sambuc ATF_TC_WITHOUT_HEAD(error_subsume__primary);
ATF_TC_BODY(error_subsume__primary,tc)61*11be35a1SLionel Sambuc ATF_TC_BODY(error_subsume__primary, tc)
62*11be35a1SLionel Sambuc {
63*11be35a1SLionel Sambuc kyua_error_t primary = kyua_error_new("primary_error", NULL, 0, NULL);
64*11be35a1SLionel Sambuc kyua_error_t secondary = kyua_error_new("secondary_error", NULL, 0, NULL);
65*11be35a1SLionel Sambuc kyua_error_t error = kyua_error_subsume(primary, secondary);
66*11be35a1SLionel Sambuc ATF_REQUIRE(kyua_error_is_type(error, "primary_error"));
67*11be35a1SLionel Sambuc kyua_error_free(error);
68*11be35a1SLionel Sambuc }
69*11be35a1SLionel Sambuc
70*11be35a1SLionel Sambuc
71*11be35a1SLionel Sambuc ATF_TC_WITHOUT_HEAD(error_subsume__secondary);
ATF_TC_BODY(error_subsume__secondary,tc)72*11be35a1SLionel Sambuc ATF_TC_BODY(error_subsume__secondary, tc)
73*11be35a1SLionel Sambuc {
74*11be35a1SLionel Sambuc kyua_error_t primary = kyua_error_ok();
75*11be35a1SLionel Sambuc kyua_error_t secondary = kyua_error_new("secondary_error", NULL, 0, NULL);
76*11be35a1SLionel Sambuc kyua_error_t error = kyua_error_subsume(primary, secondary);
77*11be35a1SLionel Sambuc ATF_REQUIRE(kyua_error_is_type(error, "secondary_error"));
78*11be35a1SLionel Sambuc kyua_error_free(error);
79*11be35a1SLionel Sambuc }
80*11be35a1SLionel Sambuc
81*11be35a1SLionel Sambuc
82*11be35a1SLionel Sambuc ATF_TC_WITHOUT_HEAD(error_is_type__match);
ATF_TC_BODY(error_is_type__match,tc)83*11be35a1SLionel Sambuc ATF_TC_BODY(error_is_type__match, tc)
84*11be35a1SLionel Sambuc {
85*11be35a1SLionel Sambuc kyua_error_t error = kyua_error_new("test_error", NULL, 0, NULL);
86*11be35a1SLionel Sambuc ATF_REQUIRE(kyua_error_is_type(error, "test_error"));
87*11be35a1SLionel Sambuc kyua_error_free(error);
88*11be35a1SLionel Sambuc }
89*11be35a1SLionel Sambuc
90*11be35a1SLionel Sambuc
91*11be35a1SLionel Sambuc ATF_TC_WITHOUT_HEAD(error_is_type__not_match);
ATF_TC_BODY(error_is_type__not_match,tc)92*11be35a1SLionel Sambuc ATF_TC_BODY(error_is_type__not_match, tc)
93*11be35a1SLionel Sambuc {
94*11be35a1SLionel Sambuc kyua_error_t error = kyua_error_new("test_error", NULL, 0, NULL);
95*11be35a1SLionel Sambuc ATF_REQUIRE(!kyua_error_is_type(error, "test_erro"));
96*11be35a1SLionel Sambuc ATF_REQUIRE(!kyua_error_is_type(error, "test_error2"));
97*11be35a1SLionel Sambuc ATF_REQUIRE(!kyua_error_is_type(error, "foo"));
98*11be35a1SLionel Sambuc kyua_error_free(error);
99*11be35a1SLionel Sambuc }
100*11be35a1SLionel Sambuc
101*11be35a1SLionel Sambuc
102*11be35a1SLionel Sambuc ATF_TC_WITHOUT_HEAD(error_data__none);
ATF_TC_BODY(error_data__none,tc)103*11be35a1SLionel Sambuc ATF_TC_BODY(error_data__none, tc)
104*11be35a1SLionel Sambuc {
105*11be35a1SLionel Sambuc kyua_error_t error = kyua_error_new("test_error", NULL, 0, NULL);
106*11be35a1SLionel Sambuc ATF_REQUIRE(kyua_error_data(error) == NULL);
107*11be35a1SLionel Sambuc kyua_error_free(error);
108*11be35a1SLionel Sambuc }
109*11be35a1SLionel Sambuc
110*11be35a1SLionel Sambuc
111*11be35a1SLionel Sambuc ATF_TC_WITHOUT_HEAD(error_data__some);
ATF_TC_BODY(error_data__some,tc)112*11be35a1SLionel Sambuc ATF_TC_BODY(error_data__some, tc)
113*11be35a1SLionel Sambuc {
114*11be35a1SLionel Sambuc int data = 5;
115*11be35a1SLionel Sambuc kyua_error_t error = kyua_error_new("test_data_error", &data, sizeof(data),
116*11be35a1SLionel Sambuc NULL);
117*11be35a1SLionel Sambuc ATF_REQUIRE(kyua_error_data(error) != NULL);
118*11be35a1SLionel Sambuc ATF_REQUIRE_EQ(*((const int*)kyua_error_data(error)), 5);
119*11be35a1SLionel Sambuc kyua_error_free(error);
120*11be35a1SLionel Sambuc }
121*11be35a1SLionel Sambuc
122*11be35a1SLionel Sambuc
123*11be35a1SLionel Sambuc ATF_TC_WITHOUT_HEAD(error_is_set__no);
ATF_TC_BODY(error_is_set__no,tc)124*11be35a1SLionel Sambuc ATF_TC_BODY(error_is_set__no, tc)
125*11be35a1SLionel Sambuc {
126*11be35a1SLionel Sambuc kyua_error_t error = kyua_error_ok();
127*11be35a1SLionel Sambuc ATF_REQUIRE(!kyua_error_is_set(error));
128*11be35a1SLionel Sambuc }
129*11be35a1SLionel Sambuc
130*11be35a1SLionel Sambuc
131*11be35a1SLionel Sambuc ATF_TC_WITHOUT_HEAD(error_is_set__yes);
ATF_TC_BODY(error_is_set__yes,tc)132*11be35a1SLionel Sambuc ATF_TC_BODY(error_is_set__yes, tc)
133*11be35a1SLionel Sambuc {
134*11be35a1SLionel Sambuc kyua_error_t error = kyua_error_new("test_error", NULL, 0, NULL);
135*11be35a1SLionel Sambuc ATF_REQUIRE(kyua_error_is_set(error));
136*11be35a1SLionel Sambuc kyua_error_free(error);
137*11be35a1SLionel Sambuc }
138*11be35a1SLionel Sambuc
139*11be35a1SLionel Sambuc
140*11be35a1SLionel Sambuc ATF_TC_WITHOUT_HEAD(error_format__default);
ATF_TC_BODY(error_format__default,tc)141*11be35a1SLionel Sambuc ATF_TC_BODY(error_format__default, tc)
142*11be35a1SLionel Sambuc {
143*11be35a1SLionel Sambuc kyua_error_t error = kyua_error_new("test_error", NULL, 0, NULL);
144*11be35a1SLionel Sambuc char buffer[1024];
145*11be35a1SLionel Sambuc kyua_error_format(error, buffer, sizeof(buffer));
146*11be35a1SLionel Sambuc ATF_REQUIRE_STREQ("Error 'test_error'", buffer);
147*11be35a1SLionel Sambuc kyua_error_free(error);
148*11be35a1SLionel Sambuc }
149*11be35a1SLionel Sambuc
150*11be35a1SLionel Sambuc
151*11be35a1SLionel Sambuc /// Error-specific formatting function for testing purposes.
152*11be35a1SLionel Sambuc static int
test_format(const kyua_error_t error,char * const output_buffer,const size_t output_size)153*11be35a1SLionel Sambuc test_format(const kyua_error_t error, char* const output_buffer,
154*11be35a1SLionel Sambuc const size_t output_size)
155*11be35a1SLionel Sambuc {
156*11be35a1SLionel Sambuc ATF_REQUIRE(kyua_error_is_type(error, "test_error"));
157*11be35a1SLionel Sambuc return snprintf(output_buffer, output_size, "Test formatting function");
158*11be35a1SLionel Sambuc }
159*11be35a1SLionel Sambuc
160*11be35a1SLionel Sambuc
161*11be35a1SLionel Sambuc ATF_TC_WITHOUT_HEAD(error_format__custom__ok);
ATF_TC_BODY(error_format__custom__ok,tc)162*11be35a1SLionel Sambuc ATF_TC_BODY(error_format__custom__ok, tc)
163*11be35a1SLionel Sambuc {
164*11be35a1SLionel Sambuc kyua_error_t error = kyua_error_new("test_error", NULL, 0, test_format);
165*11be35a1SLionel Sambuc const char* exp_message = "Test formatting function";
166*11be35a1SLionel Sambuc char buffer[1024];
167*11be35a1SLionel Sambuc ATF_REQUIRE_EQ((int)strlen(exp_message),
168*11be35a1SLionel Sambuc kyua_error_format(error, buffer, sizeof(buffer)));
169*11be35a1SLionel Sambuc ATF_REQUIRE_STREQ(exp_message, buffer);
170*11be35a1SLionel Sambuc kyua_error_free(error);
171*11be35a1SLionel Sambuc }
172*11be35a1SLionel Sambuc
173*11be35a1SLionel Sambuc
174*11be35a1SLionel Sambuc ATF_TC_WITHOUT_HEAD(error_format__custom__error);
ATF_TC_BODY(error_format__custom__error,tc)175*11be35a1SLionel Sambuc ATF_TC_BODY(error_format__custom__error, tc)
176*11be35a1SLionel Sambuc {
177*11be35a1SLionel Sambuc kyua_error_t error = kyua_error_new("test_error", NULL, 0, test_format);
178*11be35a1SLionel Sambuc char buffer[5];
179*11be35a1SLionel Sambuc ATF_REQUIRE(kyua_error_format(error, buffer, sizeof(buffer))
180*11be35a1SLionel Sambuc >= (int)sizeof(buffer));
181*11be35a1SLionel Sambuc kyua_error_free(error);
182*11be35a1SLionel Sambuc }
183*11be35a1SLionel Sambuc
184*11be35a1SLionel Sambuc
185*11be35a1SLionel Sambuc ATF_TC_WITHOUT_HEAD(err);
ATF_TC_BODY(err,tc)186*11be35a1SLionel Sambuc ATF_TC_BODY(err, tc)
187*11be35a1SLionel Sambuc {
188*11be35a1SLionel Sambuc const pid_t pid = atf_utils_fork();
189*11be35a1SLionel Sambuc if (pid == 0) {
190*11be35a1SLionel Sambuc kyua_error_t error = kyua_usage_error_new("A usage error");
191*11be35a1SLionel Sambuc kyua_error_err(15, error, "The %s message", "1st");
192*11be35a1SLionel Sambuc }
193*11be35a1SLionel Sambuc atf_utils_wait(pid, 15, "", "error_test: The 1st message: A usage error\n");
194*11be35a1SLionel Sambuc }
195*11be35a1SLionel Sambuc
196*11be35a1SLionel Sambuc
197*11be35a1SLionel Sambuc ATF_TC_WITHOUT_HEAD(fprintf);
ATF_TC_BODY(fprintf,tc)198*11be35a1SLionel Sambuc ATF_TC_BODY(fprintf, tc)
199*11be35a1SLionel Sambuc {
200*11be35a1SLionel Sambuc FILE* output = fopen("output", "w");
201*11be35a1SLionel Sambuc const kyua_error_t error = kyua_usage_error_new("A usage error");
202*11be35a1SLionel Sambuc kyua_error_fprintf(output, error, "The %s message", "1st");
203*11be35a1SLionel Sambuc kyua_error_free(error);
204*11be35a1SLionel Sambuc fclose(output);
205*11be35a1SLionel Sambuc
206*11be35a1SLionel Sambuc ATF_REQUIRE(atf_utils_grep_file("The 1st message: A usage error",
207*11be35a1SLionel Sambuc "output"));
208*11be35a1SLionel Sambuc }
209*11be35a1SLionel Sambuc
210*11be35a1SLionel Sambuc
211*11be35a1SLionel Sambuc ATF_TC_WITHOUT_HEAD(warn);
ATF_TC_BODY(warn,tc)212*11be35a1SLionel Sambuc ATF_TC_BODY(warn, tc)
213*11be35a1SLionel Sambuc {
214*11be35a1SLionel Sambuc const pid_t pid = atf_utils_fork();
215*11be35a1SLionel Sambuc if (pid == 0) {
216*11be35a1SLionel Sambuc kyua_error_t error = kyua_usage_error_new("A usage error");
217*11be35a1SLionel Sambuc kyua_error_warn(error, "The %s message", "1st");
218*11be35a1SLionel Sambuc kyua_error_free(error);
219*11be35a1SLionel Sambuc exit(51);
220*11be35a1SLionel Sambuc }
221*11be35a1SLionel Sambuc atf_utils_wait(pid, 51, "", "error_test: The 1st message: A usage error\n");
222*11be35a1SLionel Sambuc }
223*11be35a1SLionel Sambuc
224*11be35a1SLionel Sambuc
225*11be35a1SLionel Sambuc ATF_TC_WITHOUT_HEAD(generic_error_type);
ATF_TC_BODY(generic_error_type,tc)226*11be35a1SLionel Sambuc ATF_TC_BODY(generic_error_type, tc)
227*11be35a1SLionel Sambuc {
228*11be35a1SLionel Sambuc kyua_error_t error = kyua_generic_error_new("Nothing");
229*11be35a1SLionel Sambuc ATF_REQUIRE(kyua_error_is_type(error, kyua_generic_error_type));
230*11be35a1SLionel Sambuc kyua_error_free(error);
231*11be35a1SLionel Sambuc }
232*11be35a1SLionel Sambuc
233*11be35a1SLionel Sambuc
234*11be35a1SLionel Sambuc ATF_TC_WITHOUT_HEAD(generic_error_format__plain);
ATF_TC_BODY(generic_error_format__plain,tc)235*11be35a1SLionel Sambuc ATF_TC_BODY(generic_error_format__plain, tc)
236*11be35a1SLionel Sambuc {
237*11be35a1SLionel Sambuc kyua_error_t error = kyua_generic_error_new("Test message");
238*11be35a1SLionel Sambuc char buffer[1024];
239*11be35a1SLionel Sambuc kyua_error_format(error, buffer, sizeof(buffer));
240*11be35a1SLionel Sambuc ATF_REQUIRE_STREQ("Test message", buffer);
241*11be35a1SLionel Sambuc kyua_error_free(error);
242*11be35a1SLionel Sambuc }
243*11be35a1SLionel Sambuc
244*11be35a1SLionel Sambuc
245*11be35a1SLionel Sambuc ATF_TC_WITHOUT_HEAD(generic_error_format__args);
ATF_TC_BODY(generic_error_format__args,tc)246*11be35a1SLionel Sambuc ATF_TC_BODY(generic_error_format__args, tc)
247*11be35a1SLionel Sambuc {
248*11be35a1SLionel Sambuc kyua_error_t error = kyua_generic_error_new("%s message %d", "A", 123);
249*11be35a1SLionel Sambuc char buffer[1024];
250*11be35a1SLionel Sambuc kyua_error_format(error, buffer, sizeof(buffer));
251*11be35a1SLionel Sambuc ATF_REQUIRE_STREQ("A message 123", buffer);
252*11be35a1SLionel Sambuc kyua_error_free(error);
253*11be35a1SLionel Sambuc }
254*11be35a1SLionel Sambuc
255*11be35a1SLionel Sambuc
256*11be35a1SLionel Sambuc ATF_TC_WITHOUT_HEAD(libc_error_type);
ATF_TC_BODY(libc_error_type,tc)257*11be35a1SLionel Sambuc ATF_TC_BODY(libc_error_type, tc)
258*11be35a1SLionel Sambuc {
259*11be35a1SLionel Sambuc kyua_error_t error = kyua_libc_error_new(ENOMEM, "Nothing");
260*11be35a1SLionel Sambuc ATF_REQUIRE(kyua_error_is_type(error, kyua_libc_error_type));
261*11be35a1SLionel Sambuc kyua_error_free(error);
262*11be35a1SLionel Sambuc }
263*11be35a1SLionel Sambuc
264*11be35a1SLionel Sambuc
265*11be35a1SLionel Sambuc ATF_TC_WITHOUT_HEAD(libc_error_errno);
ATF_TC_BODY(libc_error_errno,tc)266*11be35a1SLionel Sambuc ATF_TC_BODY(libc_error_errno, tc)
267*11be35a1SLionel Sambuc {
268*11be35a1SLionel Sambuc kyua_error_t error = kyua_libc_error_new(EPERM, "Doesn't matter");
269*11be35a1SLionel Sambuc ATF_REQUIRE_EQ(EPERM, kyua_libc_error_errno(error));
270*11be35a1SLionel Sambuc kyua_error_free(error);
271*11be35a1SLionel Sambuc }
272*11be35a1SLionel Sambuc
273*11be35a1SLionel Sambuc
274*11be35a1SLionel Sambuc ATF_TC_WITHOUT_HEAD(libc_error_format__plain);
ATF_TC_BODY(libc_error_format__plain,tc)275*11be35a1SLionel Sambuc ATF_TC_BODY(libc_error_format__plain, tc)
276*11be35a1SLionel Sambuc {
277*11be35a1SLionel Sambuc kyua_error_t error = kyua_libc_error_new(ENOMEM, "Test message");
278*11be35a1SLionel Sambuc char buffer[1024];
279*11be35a1SLionel Sambuc kyua_error_format(error, buffer, sizeof(buffer));
280*11be35a1SLionel Sambuc ATF_REQUIRE(strstr(buffer, strerror(ENOMEM)) != NULL);
281*11be35a1SLionel Sambuc ATF_REQUIRE(strstr(buffer, "Test message") != NULL);
282*11be35a1SLionel Sambuc kyua_error_free(error);
283*11be35a1SLionel Sambuc }
284*11be35a1SLionel Sambuc
285*11be35a1SLionel Sambuc
286*11be35a1SLionel Sambuc ATF_TC_WITHOUT_HEAD(libc_error_format__args);
ATF_TC_BODY(libc_error_format__args,tc)287*11be35a1SLionel Sambuc ATF_TC_BODY(libc_error_format__args, tc)
288*11be35a1SLionel Sambuc {
289*11be35a1SLionel Sambuc kyua_error_t error = kyua_libc_error_new(EPERM, "%s message %d", "A", 123);
290*11be35a1SLionel Sambuc char buffer[1024];
291*11be35a1SLionel Sambuc kyua_error_format(error, buffer, sizeof(buffer));
292*11be35a1SLionel Sambuc ATF_REQUIRE(strstr(buffer, strerror(EPERM)) != NULL);
293*11be35a1SLionel Sambuc ATF_REQUIRE(strstr(buffer, "A message 123") != NULL);
294*11be35a1SLionel Sambuc kyua_error_free(error);
295*11be35a1SLionel Sambuc }
296*11be35a1SLionel Sambuc
297*11be35a1SLionel Sambuc
298*11be35a1SLionel Sambuc ATF_TC_WITHOUT_HEAD(oom_error_type);
ATF_TC_BODY(oom_error_type,tc)299*11be35a1SLionel Sambuc ATF_TC_BODY(oom_error_type, tc)
300*11be35a1SLionel Sambuc {
301*11be35a1SLionel Sambuc kyua_error_t error = kyua_oom_error_new();
302*11be35a1SLionel Sambuc ATF_REQUIRE(kyua_error_is_type(error, kyua_oom_error_type));
303*11be35a1SLionel Sambuc kyua_error_free(error);
304*11be35a1SLionel Sambuc }
305*11be35a1SLionel Sambuc
306*11be35a1SLionel Sambuc
307*11be35a1SLionel Sambuc ATF_TC_WITHOUT_HEAD(oom_error_data);
ATF_TC_BODY(oom_error_data,tc)308*11be35a1SLionel Sambuc ATF_TC_BODY(oom_error_data, tc)
309*11be35a1SLionel Sambuc {
310*11be35a1SLionel Sambuc kyua_error_t error = kyua_oom_error_new();
311*11be35a1SLionel Sambuc ATF_REQUIRE(kyua_error_data(error) == NULL);
312*11be35a1SLionel Sambuc kyua_error_free(error);
313*11be35a1SLionel Sambuc }
314*11be35a1SLionel Sambuc
315*11be35a1SLionel Sambuc
316*11be35a1SLionel Sambuc ATF_TC_WITHOUT_HEAD(oom_error_format);
ATF_TC_BODY(oom_error_format,tc)317*11be35a1SLionel Sambuc ATF_TC_BODY(oom_error_format, tc)
318*11be35a1SLionel Sambuc {
319*11be35a1SLionel Sambuc kyua_error_t error = kyua_oom_error_new();
320*11be35a1SLionel Sambuc char buffer[1024];
321*11be35a1SLionel Sambuc kyua_error_format(error, buffer, sizeof(buffer));
322*11be35a1SLionel Sambuc ATF_REQUIRE_STREQ("Not enough memory", buffer);
323*11be35a1SLionel Sambuc kyua_error_free(error);
324*11be35a1SLionel Sambuc }
325*11be35a1SLionel Sambuc
326*11be35a1SLionel Sambuc
327*11be35a1SLionel Sambuc ATF_TC_WITHOUT_HEAD(oom_error_reuse);
ATF_TC_BODY(oom_error_reuse,tc)328*11be35a1SLionel Sambuc ATF_TC_BODY(oom_error_reuse, tc)
329*11be35a1SLionel Sambuc {
330*11be35a1SLionel Sambuc {
331*11be35a1SLionel Sambuc kyua_error_t error = kyua_oom_error_new();
332*11be35a1SLionel Sambuc ATF_REQUIRE(kyua_error_is_type(error, kyua_oom_error_type));
333*11be35a1SLionel Sambuc ATF_REQUIRE(kyua_error_data(error) == NULL);
334*11be35a1SLionel Sambuc kyua_error_free(error);
335*11be35a1SLionel Sambuc }
336*11be35a1SLionel Sambuc
337*11be35a1SLionel Sambuc {
338*11be35a1SLionel Sambuc kyua_error_t error = kyua_oom_error_new();
339*11be35a1SLionel Sambuc ATF_REQUIRE(kyua_error_is_type(error, kyua_oom_error_type));
340*11be35a1SLionel Sambuc ATF_REQUIRE(kyua_error_data(error) == NULL);
341*11be35a1SLionel Sambuc kyua_error_free(error);
342*11be35a1SLionel Sambuc }
343*11be35a1SLionel Sambuc }
344*11be35a1SLionel Sambuc
345*11be35a1SLionel Sambuc
346*11be35a1SLionel Sambuc ATF_TC_WITHOUT_HEAD(usage_error_type);
ATF_TC_BODY(usage_error_type,tc)347*11be35a1SLionel Sambuc ATF_TC_BODY(usage_error_type, tc)
348*11be35a1SLionel Sambuc {
349*11be35a1SLionel Sambuc kyua_error_t error = kyua_usage_error_new("Nothing");
350*11be35a1SLionel Sambuc ATF_REQUIRE(kyua_error_is_type(error, kyua_usage_error_type));
351*11be35a1SLionel Sambuc kyua_error_free(error);
352*11be35a1SLionel Sambuc }
353*11be35a1SLionel Sambuc
354*11be35a1SLionel Sambuc
355*11be35a1SLionel Sambuc ATF_TC_WITHOUT_HEAD(usage_error_format__plain);
ATF_TC_BODY(usage_error_format__plain,tc)356*11be35a1SLionel Sambuc ATF_TC_BODY(usage_error_format__plain, tc)
357*11be35a1SLionel Sambuc {
358*11be35a1SLionel Sambuc kyua_error_t error = kyua_usage_error_new("Test message");
359*11be35a1SLionel Sambuc char buffer[1024];
360*11be35a1SLionel Sambuc kyua_error_format(error, buffer, sizeof(buffer));
361*11be35a1SLionel Sambuc ATF_REQUIRE_STREQ("Test message", buffer);
362*11be35a1SLionel Sambuc kyua_error_free(error);
363*11be35a1SLionel Sambuc }
364*11be35a1SLionel Sambuc
365*11be35a1SLionel Sambuc
366*11be35a1SLionel Sambuc ATF_TC_WITHOUT_HEAD(usage_error_format__args);
ATF_TC_BODY(usage_error_format__args,tc)367*11be35a1SLionel Sambuc ATF_TC_BODY(usage_error_format__args, tc)
368*11be35a1SLionel Sambuc {
369*11be35a1SLionel Sambuc kyua_error_t error = kyua_usage_error_new("%s message %d", "A", 123);
370*11be35a1SLionel Sambuc char buffer[1024];
371*11be35a1SLionel Sambuc kyua_error_format(error, buffer, sizeof(buffer));
372*11be35a1SLionel Sambuc ATF_REQUIRE_STREQ("A message 123", buffer);
373*11be35a1SLionel Sambuc kyua_error_free(error);
374*11be35a1SLionel Sambuc }
375*11be35a1SLionel Sambuc
376*11be35a1SLionel Sambuc
ATF_TP_ADD_TCS(tp)377*11be35a1SLionel Sambuc ATF_TP_ADD_TCS(tp)
378*11be35a1SLionel Sambuc {
379*11be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, error_new__oom);
380*11be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, error_subsume__none);
381*11be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, error_subsume__primary);
382*11be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, error_subsume__secondary);
383*11be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, error_is_type__match);
384*11be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, error_is_type__not_match);
385*11be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, error_data__none);
386*11be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, error_data__some);
387*11be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, error_is_set__no);
388*11be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, error_is_set__yes);
389*11be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, error_format__default);
390*11be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, error_format__custom__ok);
391*11be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, error_format__custom__error);
392*11be35a1SLionel Sambuc
393*11be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, err);
394*11be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, fprintf);
395*11be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, warn);
396*11be35a1SLionel Sambuc
397*11be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, generic_error_type);
398*11be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, generic_error_format__plain);
399*11be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, generic_error_format__args);
400*11be35a1SLionel Sambuc
401*11be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, libc_error_type);
402*11be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, libc_error_errno);
403*11be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, libc_error_format__plain);
404*11be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, libc_error_format__args);
405*11be35a1SLionel Sambuc
406*11be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, oom_error_type);
407*11be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, oom_error_data);
408*11be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, oom_error_format);
409*11be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, oom_error_reuse);
410*11be35a1SLionel Sambuc
411*11be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, usage_error_type);
412*11be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, usage_error_format__plain);
413*11be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, usage_error_format__args);
414*11be35a1SLionel Sambuc
415*11be35a1SLionel Sambuc return atf_no_error();
416*11be35a1SLionel Sambuc }
417