xref: /aosp_15_r20/external/libexif/test/test-integers.c (revision 735d6239c16e246968a03ef6e2db00d67bad6cdc)
1*735d6239SKiyoung Kim /** \file test-integers.c
2*735d6239SKiyoung Kim  * \brief Check assumptions about integer types (sizes, ranges).
3*735d6239SKiyoung Kim  *
4*735d6239SKiyoung Kim  * Copyright (C) 2007 Hans Ulrich Niedermann <[email protected]>
5*735d6239SKiyoung Kim  *
6*735d6239SKiyoung Kim  * This library is free software; you can redistribute it and/or
7*735d6239SKiyoung Kim  * modify it under the terms of the GNU Lesser General Public
8*735d6239SKiyoung Kim  * License as published by the Free Software Foundation; either
9*735d6239SKiyoung Kim  * version 2 of the License, or (at your option) any later version.
10*735d6239SKiyoung Kim  *
11*735d6239SKiyoung Kim  * This library is distributed in the hope that it will be useful,
12*735d6239SKiyoung Kim  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13*735d6239SKiyoung Kim  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14*735d6239SKiyoung Kim  * Lesser General Public License for more details.
15*735d6239SKiyoung Kim  *
16*735d6239SKiyoung Kim  * You should have received a copy of the GNU Lesser General Public
17*735d6239SKiyoung Kim  * License along with this library; if not, write to the
18*735d6239SKiyoung Kim  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19*735d6239SKiyoung Kim  * Boston, MA  02110-1301  USA.
20*735d6239SKiyoung Kim  */
21*735d6239SKiyoung Kim 
22*735d6239SKiyoung Kim 
23*735d6239SKiyoung Kim #include "libexif/_stdint.h"
24*735d6239SKiyoung Kim #include <stdlib.h>
25*735d6239SKiyoung Kim #include <stdio.h>
26*735d6239SKiyoung Kim 
27*735d6239SKiyoung Kim 
28*735d6239SKiyoung Kim typedef enum {
29*735d6239SKiyoung Kim    EN_A,
30*735d6239SKiyoung Kim    EN_B,
31*735d6239SKiyoung Kim    EN_C,
32*735d6239SKiyoung Kim    EN_D,
33*735d6239SKiyoung Kim    EN_E,
34*735d6239SKiyoung Kim    EN_F
35*735d6239SKiyoung Kim } enum_t;
36*735d6239SKiyoung Kim 
37*735d6239SKiyoung Kim 
38*735d6239SKiyoung Kim #if defined(__GNUC__) && (__GNUC__ >= 4)
39*735d6239SKiyoung Kim # define CHECK(condition)					     \
40*735d6239SKiyoung Kim 	if (!(condition)) {					     \
41*735d6239SKiyoung Kim 		fprintf(stderr, "%s:%d: check failed: %s\n",	     \
42*735d6239SKiyoung Kim 			__FILE__, __LINE__, #condition);	     \
43*735d6239SKiyoung Kim 		errors++;					     \
44*735d6239SKiyoung Kim 	}
45*735d6239SKiyoung Kim #else
46*735d6239SKiyoung Kim # define CHECK(condition)					     \
47*735d6239SKiyoung Kim 	if (!(condition)) {					     \
48*735d6239SKiyoung Kim 		abort();					     \
49*735d6239SKiyoung Kim 	}
50*735d6239SKiyoung Kim #endif
51*735d6239SKiyoung Kim 
52*735d6239SKiyoung Kim 
main()53*735d6239SKiyoung Kim int main()
54*735d6239SKiyoung Kim {
55*735d6239SKiyoung Kim   unsigned int errors = 0;
56*735d6239SKiyoung Kim 
57*735d6239SKiyoung Kim   /* libexif assumes unsigned ints are not smaller than 32bit in many places */
58*735d6239SKiyoung Kim   CHECK(sizeof(unsigned int) >= sizeof(uint32_t));
59*735d6239SKiyoung Kim 
60*735d6239SKiyoung Kim   /* libexif assumes that enums fit into ints */
61*735d6239SKiyoung Kim   CHECK(sizeof(enum_t) <= sizeof(int));
62*735d6239SKiyoung Kim 
63*735d6239SKiyoung Kim   return (errors>0)?1:0;
64*735d6239SKiyoung Kim }
65