1/*	$NetBSD: t_types.c,v 1.4 2012/03/18 07:14:08 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#include <sys/cdefs.h>
32__RCSID("$NetBSD: t_types.c,v 1.4 2012/03/18 07:14:08 jruoho Exp $");
33
34#include <sys/types.h>
35
36#include <atf-c.h>
37#include <limits.h>
38#include <stdint.h>
39
40#include <stdio.h>
41
42ATF_TC(types_limits);
43ATF_TC_HEAD(types_limits, tc)
44{
45	atf_tc_set_md_var(tc, "descr", "Known limits for types(3)");
46}
47
48ATF_TC_BODY(types_limits, tc)
49{
50	useconds_t usec;
51	ssize_t size;
52
53	/*
54	 * IEEE Std 1003.1-2008:
55	 *
56	 * "The type ssize_t shall be capable of storing
57	 *  values at least in the range [-1, {SSIZE_MAX}]."
58	 *
59	 */
60	size = SSIZE_MAX;
61	ATF_REQUIRE(size > 0);
62
63	size = size + 1;
64	ATF_REQUIRE(size < 0);
65
66	/*
67	 * IEEE Std 1003.1-2008:
68	 *
69	 * "The type suseconds_t shall be a signed integer type capable
70	 *  of storing values at least in the range [-1, 1000000]."
71	 */
72	usec = 1000000;
73	ATF_REQUIRE(usec > 0);
74}
75
76ATF_TC(types_signed);
77ATF_TC_HEAD(types_signed, tc)
78{
79	atf_tc_set_md_var(tc, "descr", "Signed types(3)"
80	    " (PR standards/44847)");
81}
82
83ATF_TC_BODY(types_signed, tc)
84{
85	blkcnt_t bc;
86	blksize_t bs;
87	ssize_t size;
88	off_t off;
89	pid_t pid;
90
91	/*
92	 * As noted in types(3), the following
93	 * types should be signed integers.
94	 */
95	bc = 0;
96	bs = 0;
97	off = 0;
98	pid = 0;
99	size = 0;
100
101	ATF_CHECK((bc - 1) <= 0);
102	ATF_CHECK((bs - 1) <= 0);
103	ATF_CHECK((off - 1) <= 0);
104	ATF_CHECK((pid - 1) <= 0);
105	ATF_CHECK((size - 1) <= 0);
106}
107
108ATF_TC(types_unsigned);
109ATF_TC_HEAD(types_unsigned, tc)
110{
111	atf_tc_set_md_var(tc, "descr", "Unsigned types(3)"
112		" (PR standards/18067)");
113}
114
115ATF_TC_BODY(types_unsigned, tc)
116{
117	fsblkcnt_t fb;
118	fsfilcnt_t ff;
119	size_t size;
120	rlim_t lim;
121	ino_t ino;
122
123	fb = 0;
124	ff = 0;
125	ino = 0;
126	lim = 0;
127	size = 0;
128
129	ATF_CHECK((fb - 1) > 0);
130	ATF_CHECK((ff - 1) > 0);
131	ATF_CHECK((ino - 1) > 0);
132	ATF_CHECK((lim - 1) > 0);
133	ATF_CHECK((size - 1) > 0);
134}
135
136ATF_TP_ADD_TCS(tp)
137{
138
139	ATF_TP_ADD_TC(tp, types_limits);
140	ATF_TP_ADD_TC(tp, types_signed);
141	ATF_TP_ADD_TC(tp, types_unsigned);
142
143	return atf_no_error();
144}
145