1/* GLIB - Library of useful routines for C programming
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
16 */
17
18/*
19 * Modified by the GLib Team and others 1997-2000. See the AUTHORS
20 * file for a list of people on the GLib Team. See the ChangeLog
21 * files for a list of changes. These files are distributed with
22 * GLib at ftp://ftp.gtk.org/pub/gtk/.
23 */
24
25#undef G_DISABLE_ASSERT
26#undef G_LOG_DOMAIN
27
28#include <stdio.h>
29#include <string.h>
30#include "glib.h"
31
32
33
34int
35main (int argc,
36 char *argv[])
37{
38 gchar *string;
39 gushort gus;
40 guint gui;
41 gulong gul;
42 gsize gsz;
43 gshort gs;
44 gint gi;
45 glong gl;
46 gint16 gi16t1;
47 gint16 gi16t2;
48 gint32 gi32t1;
49 gint32 gi32t2;
50 guint16 gu16t1 = 0x44afU, gu16t2 = 0xaf44U;
51 guint32 gu32t1 = 0x02a7f109U, gu32t2 = 0x09f1a702U;
52 guint64 gu64t1 = G_GINT64_CONSTANT(0x1d636b02300a7aa7U),
53 gu64t2 = G_GINT64_CONSTANT(0xa77a0a30026b631dU);
54 gint64 gi64t1;
55 gint64 gi64t2;
56 gssize gsst1;
57 gssize gsst2;
58 gsize gst1;
59 gsize gst2;
60
61 /* type sizes */
62 g_assert (sizeof (gint8) == 1);
63 g_assert (sizeof (gint16) == 2);
64 g_assert (sizeof (gint32) == 4);
65 g_assert (sizeof (gint64) == 8);
66
67 g_assert (GUINT16_SWAP_LE_BE (gu16t1) == gu16t2);
68 g_assert (GUINT32_SWAP_LE_BE (gu32t1) == gu32t2);
69 g_assert (GUINT64_SWAP_LE_BE (gu64t1) == gu64t2);
70
71 /* Test the G_(MIN|MAX|MAXU)(SHORT|INT|LONG) macros */
72
73 gus = G_MAXUSHORT;
74 gus++;
75 g_assert (gus == 0);
76
77 gui = G_MAXUINT;
78 gui++;
79 g_assert (gui == 0);
80
81 gul = G_MAXULONG;
82 gul++;
83 g_assert (gul == 0);
84
85 gsz = G_MAXSIZE;
86 gsz++;
87
88 g_assert (gsz == 0);
89
90 gs = G_MAXSHORT;
91 gs = (gshort) (1 + (gushort) gs);
92 g_assert (gs == G_MINSHORT);
93
94 gi = G_MAXINT;
95 gi = (gint) (1 + (guint) gi);
96 g_assert (gi == G_MININT);
97
98 gl = G_MAXLONG;
99 gl = (glong) (1 + (gulong) gl);
100 g_assert (gl == G_MINLONG);
101
102 /* Test the G_G(U)?INT(16|32|64)_FORMAT macros */
103
104 gi16t1 = -0x3AFA;
105 gu16t1 = 0xFAFA;
106 gi32t1 = -0x3AFAFAFA;
107 gu32t1 = 0xFAFAFAFA;
108
109#define FORMAT "%" G_GINT16_FORMAT " %" G_GINT32_FORMAT \
110 " %" G_GUINT16_FORMAT " %" G_GUINT32_FORMAT "\n"
111 string = g_strdup_printf (FORMAT, gi16t1, gi32t1, gu16t1, gu32t1);
112 sscanf (s: string, FORMAT, &gi16t2, &gi32t2, &gu16t2, &gu32t2);
113 g_free (mem: string);
114 g_assert (gi16t1 == gi16t2);
115 g_assert (gi32t1 == gi32t2);
116 g_assert (gu16t1 == gu16t2);
117 g_assert (gu32t1 == gu32t2);
118
119 gi64t1 = G_GINT64_CONSTANT (-0x3AFAFAFAFAFAFAFA);
120 gu64t1 = G_GINT64_CONSTANT (0xFAFAFAFAFAFAFAFA);
121
122#define FORMAT64 "%" G_GINT64_FORMAT " %" G_GUINT64_FORMAT "\n"
123#ifndef G_OS_WIN32
124# define SCAN_FORMAT64 FORMAT64
125#else
126# define sscanf sscanf_s
127# define SCAN_FORMAT64 "%I64d %I64u\n"
128#endif
129 string = g_strdup_printf (FORMAT64, gi64t1, gu64t1);
130 sscanf (s: string, SCAN_FORMAT64, &gi64t2, &gu64t2);
131 g_free (mem: string);
132 g_assert (gi64t1 == gi64t2);
133 g_assert (gu64t1 == gu64t2);
134
135 gsst1 = -0x3AFAFAFA;
136 gst1 = 0xFAFAFAFA;
137
138#define FORMATSIZE "%" G_GSSIZE_FORMAT " %" G_GSIZE_FORMAT "\n"
139#ifndef G_OS_WIN32
140# define SCAN_FORMATSIZE FORMATSIZE
141#else
142# define sscanf sscanf_s
143# define SCAN_FORMATSIZE "%Id %Iu\n"
144#endif
145 string = g_strdup_printf (FORMATSIZE, gsst1, gst1);
146 sscanf (s: string, SCAN_FORMATSIZE, &gsst2, &gst2);
147 g_free (mem: string);
148 g_assert (gsst1 == gsst2);
149 g_assert (gst1 == gst2);
150
151 return 0;
152}
153

source code of gtk/subprojects/glib/tests/type-test.c