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