1e1f2d32ngie/*	$NetBSD: t_efun.c,v 1.3 2012/11/04 23:37:02 christos Exp $ */
2e1f2d32ngie
3e1f2d32ngie/*-
4e1f2d32ngie * Copyright (c) 2011 The NetBSD Foundation, Inc.
5e1f2d32ngie * All rights reserved.
6e1f2d32ngie *
7e1f2d32ngie * This code is derived from software contributed to The NetBSD Foundation
8e1f2d32ngie * by Jukka Ruohonen.
9e1f2d32ngie *
10e1f2d32ngie * Redistribution and use in source and binary forms, with or without
11e1f2d32ngie * modification, are permitted provided that the following conditions
12e1f2d32ngie * are met:
13e1f2d32ngie * 1. Redistributions of source code must retain the above copyright
14e1f2d32ngie *    notice, this list of conditions and the following disclaimer.
15e1f2d32ngie * 2. Redistributions in binary form must reproduce the above copyright
16e1f2d32ngie *    notice, this list of conditions and the following disclaimer in the
17e1f2d32ngie *    documentation and/or other materials provided with the distribution.
18e1f2d32ngie *
19e1f2d32ngie * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20e1f2d32ngie * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21e1f2d32ngie * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22e1f2d32ngie * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23e1f2d32ngie * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24e1f2d32ngie * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25e1f2d32ngie * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26e1f2d32ngie * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27e1f2d32ngie * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28e1f2d32ngie * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29e1f2d32ngie * POSSIBILITY OF SUCH DAMAGE.
30e1f2d32ngie */
31e1f2d32ngie#include <sys/cdefs.h>
32e1f2d32ngie__RCSID("$NetBSD: t_efun.c,v 1.3 2012/11/04 23:37:02 christos Exp $");
33e1f2d32ngie
34e1f2d32ngie#include <atf-c.h>
35e1f2d32ngie
36e1f2d32ngie#include <stdio.h>
37e1f2d32ngie#include <stdint.h>
38e1f2d32ngie#include <stdlib.h>
39e1f2d32ngie#include <util.h>
40e1f2d32ngie
41e1f2d32ngiestatic bool	fail;
42e1f2d32ngiestatic void	handler(int, const char *, ...);
43e1f2d32ngie
44e1f2d32ngiestatic void
45e1f2d32ngiehandler(int ef, const char *fmt, ...)
46e1f2d32ngie{
47e1f2d32ngie	fail = false;
48e1f2d32ngie}
49e1f2d32ngie
50e1f2d32ngieATF_TC(ecalloc);
51e1f2d32ngieATF_TC_HEAD(ecalloc, tc)
52e1f2d32ngie{
53e1f2d32ngie	atf_tc_set_md_var(tc, "descr", "A basic test of ecalloc(3)");
54e1f2d32ngie}
55e1f2d32ngie
56e1f2d32ngieATF_TC_BODY(ecalloc, tc)
57e1f2d32ngie{
58e1f2d32ngie	char *x;
59e1f2d32ngie
60e1f2d32ngie	fail = true;
61e1f2d32ngie	x = ecalloc(-1, 1);
62e1f2d32ngie
63e1f2d32ngie	ATF_REQUIRE(x == NULL);
64e1f2d32ngie	ATF_REQUIRE(fail != true);
65e1f2d32ngie
66e1f2d32ngie	fail = true;
67e1f2d32ngie	x = ecalloc(SIZE_MAX, 2);
68e1f2d32ngie
69e1f2d32ngie	ATF_REQUIRE(x == NULL);
70e1f2d32ngie	ATF_REQUIRE(fail != true);
71e1f2d32ngie}
72e1f2d32ngie
73e1f2d32ngieATF_TC(efopen);
74e1f2d32ngieATF_TC_HEAD(efopen, tc)
75e1f2d32ngie{
76e1f2d32ngie	atf_tc_set_md_var(tc, "descr", "A basic test of efopen(3)");
77e1f2d32ngie}
78e1f2d32ngie
79e1f2d32ngieATF_TC_BODY(efopen, tc)
80e1f2d32ngie{
81e1f2d32ngie	FILE *f;
82e1f2d32ngie
83e1f2d32ngie	fail = true;
84e1f2d32ngie	f = efopen("XXX", "XXX");
85e1f2d32ngie
86e1f2d32ngie	ATF_REQUIRE(f == NULL);
87e1f2d32ngie	ATF_REQUIRE(fail != true);
88e1f2d32ngie}
89e1f2d32ngie
90e1f2d32ngieATF_TC(emalloc);
91e1f2d32ngieATF_TC_HEAD(emalloc, tc)
92e1f2d32ngie{
93e1f2d32ngie	atf_tc_set_md_var(tc, "descr", "A basic test of emalloc(3)");
94e1f2d32ngie}
95e1f2d32ngie
96e1f2d32ngieATF_TC_BODY(emalloc, tc)
97e1f2d32ngie{
98e1f2d32ngie	char *x;
99e1f2d32ngie
100e1f2d32ngie	fail = true;
101e1f2d32ngie	x = emalloc(-1);
102e1f2d32ngie
103e1f2d32ngie	ATF_REQUIRE(x == NULL);
104e1f2d32ngie	ATF_REQUIRE(fail != true);
105e1f2d32ngie}
106e1f2d32ngie
107e1f2d32ngieATF_TC(erealloc);
108e1f2d32ngieATF_TC_HEAD(erealloc, tc)
109e1f2d32ngie{
110e1f2d32ngie	atf_tc_set_md_var(tc, "descr", "A basic test of erealloc(3)");
111e1f2d32ngie}
112e1f2d32ngie
113e1f2d32ngieATF_TC_BODY(erealloc, tc)
114e1f2d32ngie{
115e1f2d32ngie	char *x;
116e1f2d32ngie
117e1f2d32ngie	fail = true;
118e1f2d32ngie	x = erealloc(NULL, -1);
119e1f2d32ngie
120e1f2d32ngie	ATF_REQUIRE(x == NULL);
121e1f2d32ngie	ATF_REQUIRE(fail != true);
122e1f2d32ngie}
123e1f2d32ngie
124e1f2d32ngieATF_TP_ADD_TCS(tp)
125e1f2d32ngie{
126e1f2d32ngie
127e1f2d32ngie	ATF_REQUIRE(esetfunc(handler) != NULL);
128e1f2d32ngie
129e1f2d32ngie	ATF_TP_ADD_TC(tp, ecalloc);
130e1f2d32ngie	ATF_TP_ADD_TC(tp, efopen);
131e1f2d32ngie	ATF_TP_ADD_TC(tp, emalloc);
132e1f2d32ngie	ATF_TP_ADD_TC(tp, erealloc);
133e1f2d32ngie
134e1f2d32ngie	return atf_no_error();
135e1f2d32ngie}
136