Move doc comments inline.
[glib.git] / tests / type-test.c
blobcbaaa7d51a102a80c8d76fab53a2a1f9b34b86bc
1 /* GLIB - Library of useful routines for C programming
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
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 of the License, or (at your option) any later version.
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.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GLib Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GLib Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GLib at ftp://ftp.gtk.org/pub/gtk/.
27 #undef G_DISABLE_ASSERT
28 #undef G_LOG_DOMAIN
30 #include <stdio.h>
31 #include <string.h>
32 #include "glib.h"
36 int
37 main (int argc,
38 char *argv[])
40 gchar *string;
41 gushort gus;
42 guint gui;
43 gulong gul;
44 gsize gsz;
45 gshort gs;
46 gint gi;
47 glong gl;
48 gint16 gi16t1;
49 gint16 gi16t2;
50 gint32 gi32t1;
51 gint32 gi32t2;
52 guint16 gu16t1 = 0x44afU, gu16t2 = 0xaf44U;
53 guint32 gu32t1 = 0x02a7f109U, gu32t2 = 0x09f1a702U;
54 guint64 gu64t1 = G_GINT64_CONSTANT(0x1d636b02300a7aa7U),
55 gu64t2 = G_GINT64_CONSTANT(0xa77a0a30026b631dU);
56 gint64 gi64t1;
57 gint64 gi64t2;
58 gssize gsst1;
59 gssize gsst2;
60 gsize gst1;
61 gsize gst2;
63 /* type sizes */
64 g_assert (sizeof (gint8) == 1);
65 g_assert (sizeof (gint16) == 2);
66 g_assert (sizeof (gint32) == 4);
67 g_assert (sizeof (gint64) == 8);
69 g_assert (GUINT16_SWAP_LE_BE (gu16t1) == gu16t2);
70 g_assert (GUINT32_SWAP_LE_BE (gu32t1) == gu32t2);
71 g_assert (GUINT64_SWAP_LE_BE (gu64t1) == gu64t2);
73 /* Test the G_(MIN|MAX|MAXU)(SHORT|INT|LONG) macros */
75 gus = G_MAXUSHORT;
76 gus++;
77 g_assert (gus == 0);
79 gui = G_MAXUINT;
80 gui++;
81 g_assert (gui == 0);
83 gul = G_MAXULONG;
84 gul++;
85 g_assert (gul == 0);
87 gsz = G_MAXSIZE;
88 gsz++;
90 g_assert (gsz == 0);
92 gs = G_MAXSHORT;
93 gs++;
94 g_assert (gs == G_MINSHORT);
96 gi = G_MAXINT;
97 gi++;
98 g_assert (gi == G_MININT);
100 gl = G_MAXLONG;
101 gl++;
102 g_assert (gl == G_MINLONG);
104 /* Test the G_G(U)?INT(16|32|64)_FORMAT macros */
106 gi16t1 = -0x3AFA;
107 gu16t1 = 0xFAFA;
108 gi32t1 = -0x3AFAFAFA;
109 gu32t1 = 0xFAFAFAFA;
111 #define FORMAT "%" G_GINT16_FORMAT " %" G_GINT32_FORMAT \
112 " %" G_GUINT16_FORMAT " %" G_GUINT32_FORMAT "\n"
113 string = g_strdup_printf (FORMAT, gi16t1, gi32t1, gu16t1, gu32t1);
114 sscanf (string, FORMAT, &gi16t2, &gi32t2, &gu16t2, &gu32t2);
115 g_free (string);
116 g_assert (gi16t1 == gi16t2);
117 g_assert (gi32t1 == gi32t2);
118 g_assert (gu16t1 == gu16t2);
119 g_assert (gu32t1 == gu32t2);
121 gi64t1 = G_GINT64_CONSTANT (-0x3AFAFAFAFAFAFAFA);
122 gu64t1 = G_GINT64_CONSTANT (0xFAFAFAFAFAFAFAFA);
124 #define FORMAT64 "%" G_GINT64_FORMAT " %" G_GUINT64_FORMAT "\n"
125 string = g_strdup_printf (FORMAT64, gi64t1, gu64t1);
126 sscanf (string, FORMAT64, &gi64t2, &gu64t2);
127 g_free (string);
128 g_assert (gi64t1 == gi64t2);
129 g_assert (gu64t1 == gu64t2);
131 gsst1 = -0x3AFAFAFA;
132 gst1 = 0xFAFAFAFA;
134 #define FORMATSIZE "%" G_GSSIZE_FORMAT " %" G_GSIZE_FORMAT "\n"
135 string = g_strdup_printf (FORMATSIZE, gsst1, gst1);
136 sscanf (string, FORMATSIZE, &gsst2, &gst2);
137 g_free (string);
138 g_assert (gsst1 == gsst2);
139 g_assert (gst1 == gst2);
141 return 0;