xref: /freebsd/contrib/mandoc/test-strtonum.c (revision 8df8b2d3e51d1b816201d8a1fe8bc29fe192e562)
1 /*	$Id: test-strtonum.c,v 1.2 2015/10/06 18:32:20 schwarze Exp $	*/
2 /*
3  * Copyright (c) 2015 Ingo Schwarze <schwarze@openbsd.org>
4  *
5  * Permission to use, copy, modify, and distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16  */
17 
18 #include <stdlib.h>
19 
20 int
21 main(void)
22 {
23 	const char *errstr;
24 
25 	if (strtonum("1", 0, 2, &errstr) != 1)
26 		return 1;
27 	if (errstr != NULL)
28 		return 2;
29 	if (strtonum("1x", 0, 2, &errstr) != 0)
30 		return 3;
31 	if (errstr == NULL)
32 		return 4;
33 	if (strtonum("2", 0, 1, &errstr) != 0)
34 		return 5;
35 	if (errstr == NULL)
36 		return 6;
37 	if (strtonum("0", 1, 2, &errstr) != 0)
38 		return 7;
39 	if (errstr == NULL)
40 		return 8;
41 	return 0;
42 }
43