Blame tests/type-test.c

Packit ae235b
/* GLIB - Library of useful routines for C programming
Packit ae235b
 * Copyright (C) 1995-1997  Peter Mattis, Spencer Kimball and Josh MacDonald
Packit ae235b
 *
Packit ae235b
 * This library is free software; you can redistribute it and/or
Packit ae235b
 * modify it under the terms of the GNU Lesser General Public
Packit ae235b
 * License as published by the Free Software Foundation; either
Packit ae235b
 * version 2.1 of the License, or (at your option) any later version.
Packit ae235b
 *
Packit ae235b
 * This library is distributed in the hope that it will be useful,
Packit ae235b
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit ae235b
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit ae235b
 * Lesser General Public License for more details.
Packit ae235b
 *
Packit ae235b
 * You should have received a copy of the GNU Lesser General Public
Packit ae235b
 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
Packit ae235b
 */
Packit ae235b
Packit ae235b
/*
Packit ae235b
 * Modified by the GLib Team and others 1997-2000.  See the AUTHORS
Packit ae235b
 * file for a list of people on the GLib Team.  See the ChangeLog
Packit ae235b
 * files for a list of changes.  These files are distributed with
Packit ae235b
 * GLib at ftp://ftp.gtk.org/pub/gtk/. 
Packit ae235b
 */
Packit ae235b
Packit ae235b
#undef G_DISABLE_ASSERT
Packit ae235b
#undef G_LOG_DOMAIN
Packit ae235b
Packit ae235b
#include <stdio.h>
Packit ae235b
#include <string.h>
Packit ae235b
#include "glib.h"
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
int
Packit ae235b
main (int   argc,
Packit ae235b
      char *argv[])
Packit ae235b
{
Packit ae235b
  gchar *string;
Packit ae235b
  gushort gus;
Packit ae235b
  guint gui;
Packit ae235b
  gulong gul;
Packit ae235b
  gsize gsz;
Packit ae235b
  gshort gs;
Packit ae235b
  gint gi;
Packit ae235b
  glong gl;
Packit ae235b
  gint16 gi16t1;
Packit ae235b
  gint16 gi16t2;
Packit ae235b
  gint32 gi32t1;
Packit ae235b
  gint32 gi32t2;
Packit ae235b
  guint16 gu16t1 = 0x44afU, gu16t2 = 0xaf44U;
Packit ae235b
  guint32 gu32t1 = 0x02a7f109U, gu32t2 = 0x09f1a702U;
Packit ae235b
  guint64 gu64t1 = G_GINT64_CONSTANT(0x1d636b02300a7aa7U),
Packit ae235b
	  gu64t2 = G_GINT64_CONSTANT(0xa77a0a30026b631dU);
Packit ae235b
  gint64 gi64t1;
Packit ae235b
  gint64 gi64t2;
Packit ae235b
  gssize gsst1;
Packit ae235b
  gssize gsst2;
Packit ae235b
  gsize  gst1;
Packit ae235b
  gsize  gst2;
Packit ae235b
Packit ae235b
  /* type sizes */
Packit ae235b
  g_assert (sizeof (gint8) == 1);
Packit ae235b
  g_assert (sizeof (gint16) == 2);
Packit ae235b
  g_assert (sizeof (gint32) == 4);
Packit ae235b
  g_assert (sizeof (gint64) == 8);
Packit ae235b
Packit ae235b
  g_assert (GUINT16_SWAP_LE_BE (gu16t1) == gu16t2);
Packit ae235b
  g_assert (GUINT32_SWAP_LE_BE (gu32t1) == gu32t2);
Packit ae235b
  g_assert (GUINT64_SWAP_LE_BE (gu64t1) == gu64t2);
Packit ae235b
Packit ae235b
  /* Test the G_(MIN|MAX|MAXU)(SHORT|INT|LONG) macros */
Packit ae235b
Packit ae235b
  gus = G_MAXUSHORT;
Packit ae235b
  gus++;
Packit ae235b
  g_assert (gus == 0);
Packit ae235b
Packit ae235b
  gui = G_MAXUINT;
Packit ae235b
  gui++;
Packit ae235b
  g_assert (gui == 0);
Packit ae235b
Packit ae235b
  gul = G_MAXULONG;
Packit ae235b
  gul++;
Packit ae235b
  g_assert (gul == 0);
Packit ae235b
Packit ae235b
  gsz = G_MAXSIZE;
Packit ae235b
  gsz++;
Packit ae235b
  
Packit ae235b
  g_assert (gsz == 0);
Packit ae235b
Packit ae235b
  gs = G_MAXSHORT;
Packit ae235b
  gs = (gshort) (1 + (gushort) gs);
Packit ae235b
  g_assert (gs == G_MINSHORT);
Packit ae235b
Packit ae235b
  gi = G_MAXINT;
Packit ae235b
  gi = (gint) (1 + (guint) gi);
Packit ae235b
  g_assert (gi == G_MININT);
Packit ae235b
Packit ae235b
  gl = G_MAXLONG;
Packit ae235b
  gl = (glong) (1 + (gulong) gl);
Packit ae235b
  g_assert (gl == G_MINLONG);
Packit ae235b
Packit ae235b
  /* Test the G_G(U)?INT(16|32|64)_FORMAT macros */
Packit ae235b
Packit ae235b
  gi16t1 = -0x3AFA;
Packit ae235b
  gu16t1 = 0xFAFA;
Packit ae235b
  gi32t1 = -0x3AFAFAFA;
Packit ae235b
  gu32t1 = 0xFAFAFAFA; 
Packit ae235b
Packit ae235b
#define FORMAT "%" G_GINT16_FORMAT " %" G_GINT32_FORMAT \
Packit ae235b
               " %" G_GUINT16_FORMAT " %" G_GUINT32_FORMAT "\n"
Packit ae235b
  string = g_strdup_printf (FORMAT, gi16t1, gi32t1, gu16t1, gu32t1);
Packit ae235b
  sscanf (string, FORMAT, &gi16t2, &gi32t2, &gu16t2, &gu32t2);
Packit ae235b
  g_free (string);
Packit ae235b
  g_assert (gi16t1 == gi16t2);
Packit ae235b
  g_assert (gi32t1 == gi32t2);
Packit ae235b
  g_assert (gu16t1 == gu16t2);
Packit ae235b
  g_assert (gu32t1 == gu32t2);
Packit ae235b
Packit ae235b
  gi64t1 = G_GINT64_CONSTANT (-0x3AFAFAFAFAFAFAFA);
Packit ae235b
  gu64t1 = G_GINT64_CONSTANT (0xFAFAFAFAFAFAFAFA); 
Packit ae235b
Packit ae235b
#define FORMAT64 "%" G_GINT64_FORMAT " %" G_GUINT64_FORMAT "\n"
Packit ae235b
  string = g_strdup_printf (FORMAT64, gi64t1, gu64t1);
Packit ae235b
  sscanf (string, FORMAT64, &gi64t2, &gu64t2);
Packit ae235b
  g_free (string);
Packit ae235b
  g_assert (gi64t1 == gi64t2);
Packit ae235b
  g_assert (gu64t1 == gu64t2);
Packit ae235b
Packit ae235b
  gsst1 = -0x3AFAFAFA;
Packit ae235b
  gst1 = 0xFAFAFAFA; 
Packit ae235b
Packit ae235b
#define FORMATSIZE "%" G_GSSIZE_FORMAT " %" G_GSIZE_FORMAT "\n"
Packit ae235b
  string = g_strdup_printf (FORMATSIZE, gsst1, gst1);
Packit ae235b
  sscanf (string, FORMATSIZE, &gsst2, &gst2);
Packit ae235b
  g_free (string);
Packit ae235b
  g_assert (gsst1 == gsst2);
Packit ae235b
  g_assert (gst1 == gst2);
Packit ae235b
  
Packit ae235b
  return 0;
Packit ae235b
}