xref: /freebsd/lib/libc/tests/stdlib/set_constraint_handler_s_test.c (revision 559a218c9b257775fb249b67945fe4a05b7a6b9f)
1*9851b340SKonstantin Belousov /*-
2*9851b340SKonstantin Belousov  * Copyright (c) 2017 Juniper Networks.  All rights reserved.
3*9851b340SKonstantin Belousov  *
4*9851b340SKonstantin Belousov  * Redistribution and use in source and binary forms, with or without
5*9851b340SKonstantin Belousov  * modification, are permitted provided that the following conditions
6*9851b340SKonstantin Belousov  * are met:
7*9851b340SKonstantin Belousov  * 1. Redistributions of source code must retain the above copyright
8*9851b340SKonstantin Belousov  *    notice, this list of conditions and the following disclaimer.
9*9851b340SKonstantin Belousov  * 2. Redistributions in binary form must reproduce the above copyright
10*9851b340SKonstantin Belousov  *    notice, this list of conditions and the following disclaimer in the
11*9851b340SKonstantin Belousov  *    documentation and/or other materials provided with the distribution.
12*9851b340SKonstantin Belousov  *
13*9851b340SKonstantin Belousov  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
14*9851b340SKonstantin Belousov  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15*9851b340SKonstantin Belousov  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16*9851b340SKonstantin Belousov  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
17*9851b340SKonstantin Belousov  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18*9851b340SKonstantin Belousov  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19*9851b340SKonstantin Belousov  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20*9851b340SKonstantin Belousov  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21*9851b340SKonstantin Belousov  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22*9851b340SKonstantin Belousov  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23*9851b340SKonstantin Belousov  * SUCH DAMAGE.
24*9851b340SKonstantin Belousov  */
25*9851b340SKonstantin Belousov 
26*9851b340SKonstantin Belousov #include <assert.h>
27*9851b340SKonstantin Belousov #include <stdlib.h>
28*9851b340SKonstantin Belousov 
29*9851b340SKonstantin Belousov #include <atf-c.h>
30*9851b340SKonstantin Belousov 
31*9851b340SKonstantin Belousov /* null */
32*9851b340SKonstantin Belousov ATF_TC_WITHOUT_HEAD(null_handler);
ATF_TC_BODY(null_handler,tc)33*9851b340SKonstantin Belousov ATF_TC_BODY(null_handler, tc)
34*9851b340SKonstantin Belousov {
35*9851b340SKonstantin Belousov 	assert(set_constraint_handler_s(abort_handler_s) == NULL);
36*9851b340SKonstantin Belousov }
37*9851b340SKonstantin Belousov 
38*9851b340SKonstantin Belousov /* abort handler */
39*9851b340SKonstantin Belousov ATF_TC_WITHOUT_HEAD(abort_handler);
ATF_TC_BODY(abort_handler,tc)40*9851b340SKonstantin Belousov ATF_TC_BODY(abort_handler, tc)
41*9851b340SKonstantin Belousov {
42*9851b340SKonstantin Belousov 	set_constraint_handler_s(abort_handler_s);
43*9851b340SKonstantin Belousov 	assert(set_constraint_handler_s(ignore_handler_s) == abort_handler_s);
44*9851b340SKonstantin Belousov }
45*9851b340SKonstantin Belousov 
46*9851b340SKonstantin Belousov /* ignore handler */
47*9851b340SKonstantin Belousov ATF_TC_WITHOUT_HEAD(ignore_handler);
ATF_TC_BODY(ignore_handler,tc)48*9851b340SKonstantin Belousov ATF_TC_BODY(ignore_handler, tc)
49*9851b340SKonstantin Belousov {
50*9851b340SKonstantin Belousov 	set_constraint_handler_s(ignore_handler_s);
51*9851b340SKonstantin Belousov 	assert(set_constraint_handler_s(abort_handler_s) == ignore_handler_s);
52*9851b340SKonstantin Belousov }
53*9851b340SKonstantin Belousov 
ATF_TP_ADD_TCS(tp)54*9851b340SKonstantin Belousov ATF_TP_ADD_TCS(tp)
55*9851b340SKonstantin Belousov {
56*9851b340SKonstantin Belousov 	ATF_TP_ADD_TC(tp, null_handler);
57*9851b340SKonstantin Belousov 	ATF_TP_ADD_TC(tp, abort_handler);
58*9851b340SKonstantin Belousov 	ATF_TP_ADD_TC(tp, ignore_handler);
59*9851b340SKonstantin Belousov 	return (atf_no_error());
60*9851b340SKonstantin Belousov }
61