1998-06-11 01:21:14 +02:00
|
|
|
/* GLIB - Library of useful routines for C programming
|
|
|
|
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
2000-07-26 13:02:02 +02:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
1998-06-11 01:21:14 +02:00
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
2000-07-26 13:02:02 +02:00
|
|
|
* Lesser General Public License for more details.
|
1998-06-11 01:21:14 +02:00
|
|
|
*
|
2000-07-26 13:02:02 +02:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
1998-06-11 01:21:14 +02:00
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
1999-02-24 07:14:27 +01:00
|
|
|
|
|
|
|
/*
|
2000-07-26 13:02:02 +02:00
|
|
|
* Modified by the GLib Team and others 1997-2000. See the AUTHORS
|
1999-02-24 07:14:27 +01:00
|
|
|
* file for a list of people on the GLib Team. See the ChangeLog
|
|
|
|
* files for a list of changes. These files are distributed with
|
|
|
|
* GLib at ftp://ftp.gtk.org/pub/gtk/.
|
|
|
|
*/
|
|
|
|
|
2000-11-11 14:46:15 +01:00
|
|
|
#include "config.h"
|
|
|
|
|
2001-02-21 13:41:28 +01:00
|
|
|
#undef GLIB_COMPILATION
|
|
|
|
|
1998-06-11 01:21:14 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2000-11-11 00:43:33 +01:00
|
|
|
#include <errno.h>
|
2000-11-11 14:46:15 +01:00
|
|
|
|
1998-06-11 01:21:14 +02:00
|
|
|
#include "glib.h"
|
2008-04-18 17:40:38 +02:00
|
|
|
#include <glib/gstdio.h>
|
1998-06-11 01:21:14 +02:00
|
|
|
|
2007-12-12 16:09:08 +01:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
2000-11-11 14:46:15 +01:00
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
#include <io.h> /* For read(), write() etc */
|
|
|
|
#endif
|
|
|
|
|
1998-07-31 22:21:10 +02:00
|
|
|
|
1999-01-02 02:51:08 +01:00
|
|
|
#define GLIB_TEST_STRING "el dorado "
|
|
|
|
#define GLIB_TEST_STRING_5 "el do"
|
|
|
|
|
2007-12-12 16:09:08 +01:00
|
|
|
|
|
|
|
/* --- variables --- */
|
|
|
|
static gint test_nums[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
|
|
|
|
static gint more_nums[10] = { 8, 9, 7, 0, 3, 2, 5, 1, 4, 6};
|
|
|
|
|
|
|
|
/* --- functions --- */
|
|
|
|
static gint
|
|
|
|
my_list_compare_one (gconstpointer a, gconstpointer b)
|
|
|
|
{
|
|
|
|
gint one = *((const gint*)a);
|
|
|
|
gint two = *((const gint*)b);
|
|
|
|
return one-two;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
|
|
|
my_list_compare_two (gconstpointer a, gconstpointer b)
|
|
|
|
{
|
|
|
|
gint one = *((const gint*)a);
|
|
|
|
gint two = *((const gint*)b);
|
|
|
|
return two-one;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static void
|
|
|
|
my_list_print (gpointer a, gpointer b)
|
|
|
|
{
|
|
|
|
gint three = *((gint*)a);
|
|
|
|
g_print("%d", three);
|
|
|
|
}; */
|
|
|
|
|
|
|
|
static void
|
|
|
|
glist_test (void)
|
|
|
|
{
|
|
|
|
GList *list = NULL;
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
for (i = 0; i < 10; i++)
|
|
|
|
list = g_list_append (list, &test_nums[i]);
|
|
|
|
list = g_list_reverse (list);
|
|
|
|
|
|
|
|
for (i = 0; i < 10; i++)
|
|
|
|
{
|
|
|
|
GList *t = g_list_nth (list, i);
|
|
|
|
if (*((gint*) t->data) != (9 - i))
|
|
|
|
g_error ("Regular insert failed");
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < 10; i++)
|
|
|
|
if (g_list_position (list, g_list_nth (list, i)) != i)
|
|
|
|
g_error ("g_list_position does not seem to be the inverse of g_list_nth\n");
|
|
|
|
|
|
|
|
g_list_free (list);
|
|
|
|
list = NULL;
|
|
|
|
|
|
|
|
for (i = 0; i < 10; i++)
|
|
|
|
list = g_list_insert_sorted (list, &more_nums[i], my_list_compare_one);
|
|
|
|
|
|
|
|
/*
|
|
|
|
g_print("\n");
|
|
|
|
g_list_foreach (list, my_list_print, NULL);
|
|
|
|
*/
|
|
|
|
|
|
|
|
for (i = 0; i < 10; i++)
|
|
|
|
{
|
|
|
|
GList *t = g_list_nth (list, i);
|
|
|
|
if (*((gint*) t->data) != i)
|
|
|
|
g_error ("Sorted insert failed");
|
|
|
|
}
|
|
|
|
|
|
|
|
g_list_free (list);
|
|
|
|
list = NULL;
|
|
|
|
|
|
|
|
for (i = 0; i < 10; i++)
|
|
|
|
list = g_list_insert_sorted (list, &more_nums[i], my_list_compare_two);
|
|
|
|
|
|
|
|
/*
|
|
|
|
g_print("\n");
|
|
|
|
g_list_foreach (list, my_list_print, NULL);
|
|
|
|
*/
|
|
|
|
|
|
|
|
for (i = 0; i < 10; i++)
|
|
|
|
{
|
|
|
|
GList *t = g_list_nth (list, i);
|
|
|
|
if (*((gint*) t->data) != (9 - i))
|
|
|
|
g_error ("Sorted insert failed");
|
|
|
|
}
|
|
|
|
|
|
|
|
g_list_free (list);
|
|
|
|
list = NULL;
|
|
|
|
|
|
|
|
for (i = 0; i < 10; i++)
|
|
|
|
list = g_list_prepend (list, &more_nums[i]);
|
|
|
|
|
|
|
|
list = g_list_sort (list, my_list_compare_two);
|
|
|
|
|
|
|
|
/*
|
|
|
|
g_print("\n");
|
|
|
|
g_list_foreach (list, my_list_print, NULL);
|
|
|
|
*/
|
|
|
|
|
|
|
|
for (i = 0; i < 10; i++)
|
|
|
|
{
|
|
|
|
GList *t = g_list_nth (list, i);
|
|
|
|
if (*((gint*) t->data) != (9 - i))
|
|
|
|
g_error ("Merge sort failed");
|
|
|
|
}
|
|
|
|
|
|
|
|
g_list_free (list);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gslist_test (void)
|
|
|
|
{
|
|
|
|
GSList *slist = NULL;
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
for (i = 0; i < 10; i++)
|
|
|
|
slist = g_slist_append (slist, &test_nums[i]);
|
|
|
|
slist = g_slist_reverse (slist);
|
|
|
|
|
|
|
|
for (i = 0; i < 10; i++)
|
|
|
|
{
|
|
|
|
GSList *st = g_slist_nth (slist, i);
|
|
|
|
if (*((gint*) st->data) != (9 - i))
|
|
|
|
g_error ("failed");
|
|
|
|
}
|
|
|
|
|
|
|
|
g_slist_free (slist);
|
|
|
|
slist = NULL;
|
|
|
|
|
|
|
|
for (i = 0; i < 10; i++)
|
|
|
|
slist = g_slist_insert_sorted (slist, &more_nums[i], my_list_compare_one);
|
|
|
|
|
|
|
|
/*
|
|
|
|
g_print("\n");
|
|
|
|
g_slist_foreach (slist, my_list_print, NULL);
|
|
|
|
*/
|
|
|
|
|
|
|
|
for (i = 0; i < 10; i++)
|
|
|
|
{
|
|
|
|
GSList *st = g_slist_nth (slist, i);
|
|
|
|
if (*((gint*) st->data) != i)
|
|
|
|
g_error ("Sorted insert failed");
|
|
|
|
}
|
|
|
|
|
|
|
|
g_slist_free (slist);
|
|
|
|
slist = NULL;
|
|
|
|
|
|
|
|
for (i = 0; i < 10; i++)
|
|
|
|
slist = g_slist_insert_sorted (slist, &more_nums[i], my_list_compare_two);
|
|
|
|
|
|
|
|
/*
|
|
|
|
g_print("\n");
|
|
|
|
g_slist_foreach (slist, my_list_print, NULL);
|
|
|
|
*/
|
|
|
|
|
|
|
|
for (i = 0; i < 10; i++)
|
|
|
|
{
|
|
|
|
GSList *st = g_slist_nth (slist, i);
|
|
|
|
if (*((gint*) st->data) != (9 - i))
|
|
|
|
g_error("Sorted insert failed");
|
|
|
|
}
|
|
|
|
|
|
|
|
g_slist_free(slist);
|
|
|
|
slist = NULL;
|
|
|
|
|
|
|
|
for (i = 0; i < 10; i++)
|
|
|
|
slist = g_slist_prepend (slist, &more_nums[i]);
|
|
|
|
|
|
|
|
slist = g_slist_sort (slist, my_list_compare_two);
|
|
|
|
|
|
|
|
/*
|
|
|
|
g_print("\n");
|
|
|
|
g_slist_foreach (slist, my_list_print, NULL);
|
|
|
|
*/
|
|
|
|
|
|
|
|
for (i = 0; i < 10; i++)
|
|
|
|
{
|
|
|
|
GSList *st = g_slist_nth (slist, i);
|
|
|
|
if (*((gint*) st->data) != (9 - i))
|
|
|
|
g_error("Sorted insert failed");
|
|
|
|
}
|
|
|
|
|
|
|
|
g_slist_free(slist);
|
|
|
|
}
|
|
|
|
|
1998-07-31 22:21:10 +02:00
|
|
|
static gboolean
|
|
|
|
node_build_string (GNode *node,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
gchar **p = data;
|
|
|
|
gchar *string;
|
|
|
|
gchar c[2] = "_";
|
|
|
|
|
2008-08-04 20:12:11 +02:00
|
|
|
c[0] = ((gchar) ((gintptr) (node->data)));
|
1998-07-31 22:21:10 +02:00
|
|
|
|
|
|
|
string = g_strconcat (*p ? *p : "", c, NULL);
|
|
|
|
g_free (*p);
|
|
|
|
*p = string;
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-12-12 16:09:08 +01:00
|
|
|
gnode_test (void)
|
1998-07-31 22:21:10 +02:00
|
|
|
{
|
2007-12-12 16:09:08 +01:00
|
|
|
#define C2P(c) ((gpointer) ((long) (c)))
|
2008-08-04 20:12:11 +02:00
|
|
|
#define P2C(p) ((gchar) ((gintptr) (p)))
|
1998-07-31 22:21:10 +02:00
|
|
|
GNode *root;
|
|
|
|
GNode *node;
|
|
|
|
GNode *node_B;
|
|
|
|
GNode *node_F;
|
|
|
|
GNode *node_G;
|
|
|
|
GNode *node_J;
|
|
|
|
guint i;
|
2000-03-01 10:44:10 +01:00
|
|
|
gchar *tstring, *cstring;
|
1998-07-31 22:21:10 +02:00
|
|
|
|
|
|
|
root = g_node_new (C2P ('A'));
|
2007-12-12 16:09:08 +01:00
|
|
|
g_assert (g_node_depth (root) == 1 && g_node_max_height (root) == 1);
|
1998-07-31 22:21:10 +02:00
|
|
|
|
|
|
|
node_B = g_node_new (C2P ('B'));
|
|
|
|
g_node_append (root, node_B);
|
2007-12-12 16:09:08 +01:00
|
|
|
g_assert (root->children == node_B);
|
1998-07-31 22:21:10 +02:00
|
|
|
|
version bump to 1.1.1, binary age 1, interface age 0. updates. updates.
Tue Aug 4 15:17:54 1998 Tim Janik <timj@gtk.org>
* configure.in: version bump to 1.1.1, binary age 1, interface age 0.
* NEWS: updates.
* README: updates.
* INSTALL: updates and fixes.
* COPYING: include the GNU LGPL, rather than shipping an empty file.
* AUTHORS: listed original authors here, and added people who made
significant improvements to glib.
* glib.h:
* gutils.c: implement g_get_current_dir() which returns a newly
allocated string, instead of a g_getcwd() variant that operates
on a static buffer.
export glib_interface_age and glib_binary_age.
as a convenience, macro definitions have been added for
g_node_insert_data, g_node_insert_data_before, g_node_append_data and
g_node_prepend_data.
* testglib.c: minor cleanups, print current dir.
1998-08-04 16:26:27 +02:00
|
|
|
g_node_append_data (node_B, C2P ('E'));
|
|
|
|
g_node_prepend_data (node_B, C2P ('C'));
|
1998-07-31 22:21:10 +02:00
|
|
|
g_node_insert (node_B, 1, g_node_new (C2P ('D')));
|
|
|
|
|
|
|
|
node_F = g_node_new (C2P ('F'));
|
|
|
|
g_node_append (root, node_F);
|
2007-12-12 16:09:08 +01:00
|
|
|
g_assert (root->children->next == node_F);
|
1998-07-31 22:21:10 +02:00
|
|
|
|
|
|
|
node_G = g_node_new (C2P ('G'));
|
|
|
|
g_node_append (node_F, node_G);
|
|
|
|
node_J = g_node_new (C2P ('J'));
|
version bump to 1.1.1, binary age 1, interface age 0. updates. updates.
Tue Aug 4 15:17:54 1998 Tim Janik <timj@gtk.org>
* configure.in: version bump to 1.1.1, binary age 1, interface age 0.
* NEWS: updates.
* README: updates.
* INSTALL: updates and fixes.
* COPYING: include the GNU LGPL, rather than shipping an empty file.
* AUTHORS: listed original authors here, and added people who made
significant improvements to glib.
* glib.h:
* gutils.c: implement g_get_current_dir() which returns a newly
allocated string, instead of a g_getcwd() variant that operates
on a static buffer.
export glib_interface_age and glib_binary_age.
as a convenience, macro definitions have been added for
g_node_insert_data, g_node_insert_data_before, g_node_append_data and
g_node_prepend_data.
* testglib.c: minor cleanups, print current dir.
1998-08-04 16:26:27 +02:00
|
|
|
g_node_prepend (node_G, node_J);
|
1998-07-31 22:21:10 +02:00
|
|
|
g_node_insert (node_G, 42, g_node_new (C2P ('K')));
|
version bump to 1.1.1, binary age 1, interface age 0. updates. updates.
Tue Aug 4 15:17:54 1998 Tim Janik <timj@gtk.org>
* configure.in: version bump to 1.1.1, binary age 1, interface age 0.
* NEWS: updates.
* README: updates.
* INSTALL: updates and fixes.
* COPYING: include the GNU LGPL, rather than shipping an empty file.
* AUTHORS: listed original authors here, and added people who made
significant improvements to glib.
* glib.h:
* gutils.c: implement g_get_current_dir() which returns a newly
allocated string, instead of a g_getcwd() variant that operates
on a static buffer.
export glib_interface_age and glib_binary_age.
as a convenience, macro definitions have been added for
g_node_insert_data, g_node_insert_data_before, g_node_append_data and
g_node_prepend_data.
* testglib.c: minor cleanups, print current dir.
1998-08-04 16:26:27 +02:00
|
|
|
g_node_insert_data (node_G, 0, C2P ('H'));
|
1998-07-31 22:21:10 +02:00
|
|
|
g_node_insert (node_G, 1, g_node_new (C2P ('I')));
|
|
|
|
|
2007-12-12 16:09:08 +01:00
|
|
|
g_assert (g_node_depth (root) == 1);
|
|
|
|
g_assert (g_node_max_height (root) == 4);
|
|
|
|
g_assert (g_node_depth (node_G->children->next) == 4);
|
|
|
|
g_assert (g_node_n_nodes (root, G_TRAVERSE_LEAFS) == 7);
|
|
|
|
g_assert (g_node_n_nodes (root, G_TRAVERSE_NON_LEAFS) == 4);
|
|
|
|
g_assert (g_node_n_nodes (root, G_TRAVERSE_ALL) == 11);
|
|
|
|
g_assert (g_node_max_height (node_F) == 3);
|
|
|
|
g_assert (g_node_n_children (node_G) == 4);
|
|
|
|
g_assert (g_node_find_child (root, G_TRAVERSE_ALL, C2P ('F')) == node_F);
|
|
|
|
g_assert (g_node_find (root, G_LEVEL_ORDER, G_TRAVERSE_NON_LEAFS, C2P ('I')) == NULL);
|
|
|
|
g_assert (g_node_find (root, G_IN_ORDER, G_TRAVERSE_LEAFS, C2P ('J')) == node_J);
|
1998-07-31 22:21:10 +02:00
|
|
|
|
|
|
|
for (i = 0; i < g_node_n_children (node_B); i++)
|
|
|
|
{
|
|
|
|
node = g_node_nth_child (node_B, i);
|
2007-12-12 16:09:08 +01:00
|
|
|
g_assert (P2C (node->data) == ('C' + i));
|
1998-07-31 22:21:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < g_node_n_children (node_G); i++)
|
2007-12-12 16:09:08 +01:00
|
|
|
g_assert (g_node_child_position (node_G, g_node_nth_child (node_G, i)) == i);
|
1998-07-31 22:21:10 +02:00
|
|
|
|
|
|
|
/* we have built: A
|
|
|
|
* / \
|
|
|
|
* B F
|
|
|
|
* / | \ \
|
|
|
|
* C D E G
|
|
|
|
* / /\ \
|
|
|
|
* H I J K
|
|
|
|
*
|
|
|
|
* for in-order traversal, 'G' is considered to be the "left"
|
|
|
|
* child of 'F', which will cause 'F' to be the last node visited.
|
|
|
|
*/
|
|
|
|
|
|
|
|
tstring = NULL;
|
|
|
|
g_node_traverse (root, G_PRE_ORDER, G_TRAVERSE_ALL, -1, node_build_string, &tstring);
|
2007-12-12 16:09:08 +01:00
|
|
|
g_assert_cmpstr (tstring, ==, "ABCDEFGHIJK");
|
1998-07-31 22:21:10 +02:00
|
|
|
g_free (tstring); tstring = NULL;
|
|
|
|
g_node_traverse (root, G_POST_ORDER, G_TRAVERSE_ALL, -1, node_build_string, &tstring);
|
2007-12-12 16:09:08 +01:00
|
|
|
g_assert_cmpstr (tstring, ==, "CDEBHIJKGFA");
|
1998-07-31 22:21:10 +02:00
|
|
|
g_free (tstring); tstring = NULL;
|
|
|
|
g_node_traverse (root, G_IN_ORDER, G_TRAVERSE_ALL, -1, node_build_string, &tstring);
|
2007-12-12 16:09:08 +01:00
|
|
|
g_assert_cmpstr (tstring, ==, "CBDEAHGIJKF");
|
1998-07-31 22:21:10 +02:00
|
|
|
g_free (tstring); tstring = NULL;
|
|
|
|
g_node_traverse (root, G_LEVEL_ORDER, G_TRAVERSE_ALL, -1, node_build_string, &tstring);
|
2007-12-12 16:09:08 +01:00
|
|
|
g_assert_cmpstr (tstring, ==, "ABFCDEGHIJK");
|
1998-07-31 22:21:10 +02:00
|
|
|
g_free (tstring); tstring = NULL;
|
|
|
|
|
|
|
|
g_node_traverse (root, G_LEVEL_ORDER, G_TRAVERSE_LEAFS, -1, node_build_string, &tstring);
|
2007-12-12 16:09:08 +01:00
|
|
|
g_assert_cmpstr (tstring, ==, "CDEHIJK");
|
1998-07-31 22:21:10 +02:00
|
|
|
g_free (tstring); tstring = NULL;
|
|
|
|
g_node_traverse (root, G_PRE_ORDER, G_TRAVERSE_NON_LEAFS, -1, node_build_string, &tstring);
|
2007-12-12 16:09:08 +01:00
|
|
|
g_assert_cmpstr (tstring, ==, "ABFG");
|
1998-07-31 22:21:10 +02:00
|
|
|
g_free (tstring); tstring = NULL;
|
|
|
|
|
|
|
|
g_node_reverse_children (node_B);
|
|
|
|
g_node_reverse_children (node_G);
|
|
|
|
|
|
|
|
g_node_traverse (root, G_LEVEL_ORDER, G_TRAVERSE_ALL, -1, node_build_string, &tstring);
|
2007-12-12 16:09:08 +01:00
|
|
|
g_assert_cmpstr (tstring, ==, "ABFEDCGKJIH");
|
1998-07-31 22:21:10 +02:00
|
|
|
g_free (tstring); tstring = NULL;
|
2000-03-01 10:44:10 +01:00
|
|
|
|
|
|
|
cstring = NULL;
|
|
|
|
node = g_node_copy (root);
|
2007-12-12 16:09:08 +01:00
|
|
|
g_assert (g_node_n_nodes (root, G_TRAVERSE_ALL) == g_node_n_nodes (node, G_TRAVERSE_ALL));
|
|
|
|
g_assert (g_node_max_height (root) == g_node_max_height (node));
|
2000-03-01 10:44:10 +01:00
|
|
|
g_node_traverse (root, G_IN_ORDER, G_TRAVERSE_ALL, -1, node_build_string, &tstring);
|
|
|
|
g_node_traverse (node, G_IN_ORDER, G_TRAVERSE_ALL, -1, node_build_string, &cstring);
|
2007-12-12 16:09:08 +01:00
|
|
|
g_assert_cmpstr (tstring, ==, cstring);
|
2000-03-01 10:44:10 +01:00
|
|
|
g_free (tstring); tstring = NULL;
|
|
|
|
g_free (cstring); cstring = NULL;
|
|
|
|
g_node_destroy (node);
|
|
|
|
|
1998-07-31 22:21:10 +02:00
|
|
|
g_node_destroy (root);
|
|
|
|
|
|
|
|
/* allocation tests */
|
|
|
|
|
|
|
|
root = g_node_new (NULL);
|
|
|
|
node = root;
|
|
|
|
|
|
|
|
for (i = 0; i < 2048; i++)
|
|
|
|
{
|
|
|
|
g_node_append (node, g_node_new (NULL));
|
|
|
|
if ((i%5) == 4)
|
|
|
|
node = node->children->next;
|
|
|
|
}
|
2007-12-12 16:09:08 +01:00
|
|
|
g_assert (g_node_max_height (root) > 100);
|
|
|
|
g_assert (g_node_n_nodes (root, G_TRAVERSE_ALL) == 1 + 2048);
|
1998-07-31 22:21:10 +02:00
|
|
|
|
|
|
|
g_node_destroy (root);
|
2007-12-12 16:09:08 +01:00
|
|
|
#undef C2P
|
|
|
|
#undef P2C
|
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
|
|
|
my_compare (gconstpointer a,
|
|
|
|
gconstpointer b)
|
|
|
|
{
|
|
|
|
const char *cha = a;
|
|
|
|
const char *chb = b;
|
|
|
|
|
|
|
|
return *cha - *chb;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
|
|
|
my_traverse (gpointer key,
|
|
|
|
gpointer value,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
char *ch = key;
|
|
|
|
g_print ("%c ", *ch);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
binary_tree_test (void)
|
|
|
|
{
|
|
|
|
GTree *tree;
|
|
|
|
char chars[62];
|
|
|
|
guint i, j;
|
|
|
|
|
|
|
|
tree = g_tree_new (my_compare);
|
|
|
|
i = 0;
|
|
|
|
for (j = 0; j < 10; j++, i++)
|
|
|
|
{
|
|
|
|
chars[i] = '0' + j;
|
|
|
|
g_tree_insert (tree, &chars[i], &chars[i]);
|
|
|
|
}
|
|
|
|
for (j = 0; j < 26; j++, i++)
|
|
|
|
{
|
|
|
|
chars[i] = 'A' + j;
|
|
|
|
g_tree_insert (tree, &chars[i], &chars[i]);
|
|
|
|
}
|
|
|
|
for (j = 0; j < 26; j++, i++)
|
|
|
|
{
|
|
|
|
chars[i] = 'a' + j;
|
|
|
|
g_tree_insert (tree, &chars[i], &chars[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_assert_cmpint (g_tree_nnodes (tree), ==, 10 + 26 + 26);
|
|
|
|
g_assert_cmpint (g_tree_height (tree), ==, 6);
|
|
|
|
|
|
|
|
if (g_test_verbose())
|
|
|
|
{
|
|
|
|
g_print ("tree: ");
|
|
|
|
g_tree_foreach (tree, my_traverse, NULL);
|
|
|
|
g_print ("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < 10; i++)
|
|
|
|
g_tree_remove (tree, &chars[i]);
|
|
|
|
|
|
|
|
g_assert_cmpint (g_tree_nnodes (tree), ==, 26 + 26);
|
|
|
|
g_assert_cmpint (g_tree_height (tree), ==, 6);
|
|
|
|
|
|
|
|
if (g_test_verbose())
|
|
|
|
{
|
|
|
|
g_print ("tree: ");
|
|
|
|
g_tree_foreach (tree, my_traverse, NULL);
|
|
|
|
g_print ("\n");
|
|
|
|
}
|
1998-07-31 22:21:10 +02:00
|
|
|
}
|
1998-06-11 01:21:14 +02:00
|
|
|
|
1999-01-09 21:10:45 +01:00
|
|
|
static gboolean
|
1998-09-20 11:43:11 +02:00
|
|
|
my_hash_callback_remove (gpointer key,
|
|
|
|
gpointer value,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
int *d = value;
|
|
|
|
|
|
|
|
if ((*d) % 2)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
1999-01-09 21:10:45 +01:00
|
|
|
static void
|
1998-09-20 11:43:11 +02:00
|
|
|
my_hash_callback_remove_test (gpointer key,
|
|
|
|
gpointer value,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
int *d = value;
|
|
|
|
|
|
|
|
if ((*d) % 2)
|
|
|
|
g_print ("bad!\n");
|
|
|
|
}
|
|
|
|
|
1999-01-09 21:10:45 +01:00
|
|
|
static void
|
1998-06-11 01:21:14 +02:00
|
|
|
my_hash_callback (gpointer key,
|
|
|
|
gpointer value,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
int *d = value;
|
|
|
|
*d = 1;
|
|
|
|
}
|
|
|
|
|
1999-01-09 21:10:45 +01:00
|
|
|
static guint
|
1998-06-11 01:21:14 +02:00
|
|
|
my_hash (gconstpointer key)
|
|
|
|
{
|
|
|
|
return (guint) *((const gint*) key);
|
|
|
|
}
|
|
|
|
|
Introduced new function type GEqualFunc to return TRUE for equal params.
2000-10-30 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
* gcache.h, gcache.c, ghash.h, ghash.c, grel.c, grel.h, gtypes.h:
Introduced new function type GEqualFunc to return TRUE for equal
params. This is now used instead of GCompareFunc (which should
work akin to strcmp) here. This kind of fixes Bug #14412. Note
that technically GCompareFunc and GEqualFunc are still the same
types, as gint == gboolean.
* ghash.h, gutils.c: g_int_equal and g_direct_equal now return
gboolean to be really become GEqualFunc.
* gscanner.c, testglib.c, tests/hash-test.c: Some tiny changes to
follow the above change.
2000-10-30 15:34:52 +01:00
|
|
|
static gboolean
|
|
|
|
my_hash_equal (gconstpointer a,
|
|
|
|
gconstpointer b)
|
1998-06-11 01:21:14 +02:00
|
|
|
{
|
|
|
|
return *((const gint*) a) == *((const gint*) b);
|
|
|
|
}
|
|
|
|
|
2007-12-12 16:09:08 +01:00
|
|
|
static gboolean
|
|
|
|
find_first_that(gpointer key,
|
|
|
|
gpointer value,
|
|
|
|
gpointer user_data)
|
1998-06-11 01:21:14 +02:00
|
|
|
{
|
2007-12-12 16:09:08 +01:00
|
|
|
gint *v = value;
|
|
|
|
gint *test = user_data;
|
|
|
|
return (*v == *test);
|
1998-06-11 01:21:14 +02:00
|
|
|
}
|
|
|
|
|
2006-03-14 18:56:27 +01:00
|
|
|
static void
|
|
|
|
test_g_parse_debug_string (void)
|
|
|
|
{
|
2011-10-20 17:07:03 +02:00
|
|
|
GDebugKey keys[] = {
|
2006-03-14 18:56:27 +01:00
|
|
|
{ "foo", 1 },
|
|
|
|
{ "bar", 2 },
|
2011-10-20 17:07:03 +02:00
|
|
|
{ "baz", 4 },
|
|
|
|
{ "weird", 8 },
|
2006-03-14 18:56:27 +01:00
|
|
|
};
|
2011-02-16 11:48:22 +01:00
|
|
|
guint n_keys = G_N_ELEMENTS (keys);
|
2006-03-14 18:56:27 +01:00
|
|
|
guint result;
|
|
|
|
|
|
|
|
result = g_parse_debug_string ("bar:foo:blubb", keys, n_keys);
|
|
|
|
g_assert (result == 3);
|
|
|
|
|
|
|
|
result = g_parse_debug_string (":baz::_E@~!_::", keys, n_keys);
|
|
|
|
g_assert (result == 4);
|
|
|
|
|
|
|
|
result = g_parse_debug_string ("", keys, n_keys);
|
|
|
|
g_assert (result == 0);
|
|
|
|
|
|
|
|
result = g_parse_debug_string (" : ", keys, n_keys);
|
|
|
|
g_assert (result == 0);
|
2011-02-16 11:48:22 +01:00
|
|
|
|
|
|
|
result = g_parse_debug_string ("all", keys, n_keys);
|
|
|
|
g_assert_cmpuint (result, ==, (1 << n_keys) - 1);
|
2011-10-20 17:07:03 +02:00
|
|
|
|
|
|
|
/* Test subtracting debug flags from "all" */
|
|
|
|
result = g_parse_debug_string ("all:foo", keys, n_keys);
|
|
|
|
g_assert_cmpuint (result, ==, 2 | 4 | 8);
|
|
|
|
|
|
|
|
result = g_parse_debug_string ("foo baz,all", keys, n_keys);
|
|
|
|
g_assert_cmpuint (result, ==, 2 | 8);
|
|
|
|
|
|
|
|
result = g_parse_debug_string ("all,fooo,baz", keys, n_keys);
|
|
|
|
g_assert_cmpuint (result, ==, 1 | 2 | 8);
|
|
|
|
|
|
|
|
result = g_parse_debug_string ("all:weird", keys, n_keys);
|
|
|
|
g_assert_cmpuint (result, ==, 1 | 2 | 4);
|
2006-03-14 18:56:27 +01:00
|
|
|
}
|
|
|
|
|
2007-12-12 16:09:08 +01:00
|
|
|
static void
|
|
|
|
log_warning_error_tests (void)
|
|
|
|
{
|
|
|
|
if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDOUT | G_TEST_TRAP_SILENCE_STDERR))
|
|
|
|
{
|
|
|
|
g_message ("this is a g_message test.");
|
|
|
|
g_message ("non-printable UTF-8: \"\xc3\xa4\xda\x85\"");
|
|
|
|
g_message ("unsafe chars: \"\x10\x11\x12\n\t\x7f\x81\x82\x83\"");
|
|
|
|
exit (0);
|
|
|
|
}
|
|
|
|
g_test_trap_assert_passed();
|
|
|
|
g_test_trap_assert_stderr ("*is a g_message test*");
|
|
|
|
g_test_trap_assert_stderr ("*non-printable UTF-8*");
|
|
|
|
g_test_trap_assert_stderr ("*unsafe chars*");
|
|
|
|
if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDOUT | G_TEST_TRAP_SILENCE_STDERR))
|
|
|
|
{
|
|
|
|
g_warning ("harmless warning with parameters: %d %s %#x", 42, "Boo", 12345);
|
|
|
|
exit (0);
|
|
|
|
}
|
|
|
|
g_test_trap_assert_failed(); /* we have fatal-warnings enabled */
|
|
|
|
g_test_trap_assert_stderr ("*harmless warning*");
|
|
|
|
if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDOUT | G_TEST_TRAP_SILENCE_STDERR))
|
|
|
|
{
|
|
|
|
g_print (NULL);
|
|
|
|
exit (0);
|
|
|
|
}
|
|
|
|
g_test_trap_assert_failed(); /* we have fatal-warnings enabled */
|
|
|
|
g_test_trap_assert_stderr ("*g_print*assertion*failed*");
|
|
|
|
g_test_trap_assert_stderr ("*NULL*");
|
|
|
|
}
|
2006-03-14 18:56:27 +01:00
|
|
|
|
2007-12-12 16:09:08 +01:00
|
|
|
static void
|
|
|
|
timer_tests (void)
|
1998-06-11 01:21:14 +02:00
|
|
|
{
|
2004-01-22 20:56:28 +01:00
|
|
|
GTimer *timer, *timer2;
|
2005-03-20 11:43:38 +01:00
|
|
|
gdouble elapsed;
|
2007-12-12 16:09:08 +01:00
|
|
|
|
|
|
|
/* basic testing */
|
|
|
|
timer = g_timer_new ();
|
|
|
|
g_timer_start (timer);
|
|
|
|
elapsed = g_timer_elapsed (timer, NULL);
|
|
|
|
g_timer_stop (timer);
|
|
|
|
g_assert_cmpfloat (elapsed, <=, g_timer_elapsed (timer, NULL));
|
|
|
|
g_timer_destroy (timer);
|
|
|
|
|
|
|
|
if (g_test_slow())
|
|
|
|
{
|
|
|
|
if (g_test_verbose())
|
|
|
|
g_print ("checking timers...\n");
|
|
|
|
timer = g_timer_new ();
|
|
|
|
if (g_test_verbose())
|
|
|
|
g_print (" spinning for 3 seconds...\n");
|
|
|
|
g_timer_start (timer);
|
|
|
|
while (g_timer_elapsed (timer, NULL) < 3)
|
|
|
|
;
|
|
|
|
g_timer_stop (timer);
|
|
|
|
g_timer_destroy (timer);
|
|
|
|
if (g_test_verbose())
|
|
|
|
g_print ("ok\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (g_test_slow())
|
|
|
|
{
|
|
|
|
gulong elapsed_usecs;
|
|
|
|
if (g_test_verbose())
|
|
|
|
g_print ("checking g_timer_continue...\n");
|
|
|
|
timer2 = g_timer_new ();
|
|
|
|
if (g_test_verbose())
|
|
|
|
g_print ("\trun for 1 second...\n");
|
|
|
|
timer = g_timer_new();
|
|
|
|
g_usleep (G_USEC_PER_SEC); /* run timer for 1 second */
|
|
|
|
g_timer_stop (timer);
|
|
|
|
if (g_test_verbose())
|
|
|
|
g_print ("\tstop for 1 second...\n");
|
|
|
|
g_usleep (G_USEC_PER_SEC); /* wait for 1 second */
|
|
|
|
if (g_test_verbose())
|
|
|
|
g_print ("\trun for 2 seconds...\n");
|
|
|
|
g_timer_continue (timer);
|
|
|
|
g_usleep (2 * G_USEC_PER_SEC); /* run timer for 2 seconds */
|
|
|
|
g_timer_stop(timer);
|
|
|
|
if (g_test_verbose())
|
|
|
|
g_print ("\tstop for 1.5 seconds...\n");
|
|
|
|
g_usleep ((3 * G_USEC_PER_SEC) / 2); /* wait for 1.5 seconds */
|
|
|
|
if (g_test_verbose())
|
|
|
|
g_print ("\trun for 0.2 seconds...\n");
|
|
|
|
g_timer_continue (timer);
|
|
|
|
g_usleep (G_USEC_PER_SEC / 5); /* run timer for 0.2 seconds */
|
|
|
|
g_timer_stop (timer);
|
|
|
|
if (g_test_verbose())
|
|
|
|
g_print ("\tstop for 4 seconds...\n");
|
|
|
|
g_usleep (4 * G_USEC_PER_SEC); /* wait for 4 seconds */
|
|
|
|
if (g_test_verbose())
|
|
|
|
g_print ("\trun for 5.8 seconds...\n");
|
|
|
|
g_timer_continue (timer);
|
|
|
|
g_usleep ((29 * G_USEC_PER_SEC) / 5); /* run timer for 5.8 seconds */
|
|
|
|
g_timer_stop(timer);
|
|
|
|
elapsed = g_timer_elapsed (timer, &elapsed_usecs);
|
|
|
|
if (g_test_verbose())
|
|
|
|
g_print ("\t=> timer = %.6f = %d.%06ld (should be: 9.000000) (%.6f off)\n", elapsed, (int) elapsed, elapsed_usecs, ABS (elapsed - 9.));
|
|
|
|
g_assert_cmpfloat (elapsed, >, 8.8);
|
|
|
|
g_assert_cmpfloat (elapsed, <, 9.2);
|
|
|
|
if (g_test_verbose())
|
|
|
|
g_print ("g_timer_continue ... ok\n\n");
|
|
|
|
g_timer_stop (timer2);
|
|
|
|
elapsed = g_timer_elapsed (timer2, &elapsed_usecs);
|
|
|
|
if (g_test_verbose())
|
|
|
|
g_print ("\t=> timer2 = %.6f = %d.%06ld (should be: %.6f) (%.6f off)\n\n", elapsed, (int) elapsed, elapsed_usecs, 9.+6.5, ABS (elapsed - (9.+6.5)));
|
|
|
|
g_assert_cmpfloat (elapsed, >, 8.8 + 6.5);
|
|
|
|
g_assert_cmpfloat (elapsed, <, 9.2 + 6.5);
|
|
|
|
if (g_test_verbose())
|
|
|
|
g_print ("timer2 ... ok\n\n");
|
|
|
|
g_timer_destroy (timer);
|
|
|
|
g_timer_destroy (timer2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
type_sizes (void)
|
|
|
|
{
|
|
|
|
guint16 gu16t1 = 0x44afU, gu16t2 = 0xaf44U;
|
|
|
|
guint32 gu32t1 = 0x02a7f109U, gu32t2 = 0x09f1a702U;
|
|
|
|
guint64 gu64t1 = G_GINT64_CONSTANT(0x1d636b02300a7aa7U),
|
|
|
|
gu64t2 = G_GINT64_CONSTANT(0xa77a0a30026b631dU);
|
|
|
|
/* type sizes */
|
|
|
|
g_assert_cmpint (sizeof (gint8), ==, 1);
|
|
|
|
g_assert_cmpint (sizeof (gint16), ==, 2);
|
|
|
|
g_assert_cmpint (sizeof (gint32), ==, 4);
|
|
|
|
g_assert_cmpint (sizeof (gint64), ==, 8);
|
|
|
|
/* endian macros */
|
|
|
|
if (g_test_verbose())
|
|
|
|
g_print ("checking endian macros (host is %s)...\n",
|
|
|
|
G_BYTE_ORDER == G_BIG_ENDIAN ? "big endian" : "little endian");
|
|
|
|
g_assert (GUINT16_SWAP_LE_BE (gu16t1) == gu16t2);
|
|
|
|
g_assert (GUINT32_SWAP_LE_BE (gu32t1) == gu32t2);
|
|
|
|
g_assert (GUINT64_SWAP_LE_BE (gu64t1) == gu64t2);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_info (void)
|
|
|
|
{
|
|
|
|
const gchar *un, *rn, *hn;
|
|
|
|
const gchar *tmpdir, *homedir, *userdatadir, *uconfdir, *ucachedir;
|
2011-06-06 06:30:30 +02:00
|
|
|
const gchar *uddesktop, *udddocs, *uddpubshare, *uruntimedir;
|
2007-12-12 16:09:08 +01:00
|
|
|
gchar **sv, *cwd, *sdatadirs, *sconfdirs, *langnames;
|
2011-06-06 06:30:30 +02:00
|
|
|
const gchar *charset;
|
|
|
|
gboolean charset_is_utf8;
|
2007-12-12 16:09:08 +01:00
|
|
|
if (g_test_verbose())
|
|
|
|
g_print ("TestGLib v%u.%u.%u (i:%u b:%u)\n",
|
|
|
|
glib_major_version,
|
|
|
|
glib_minor_version,
|
|
|
|
glib_micro_version,
|
|
|
|
glib_interface_age,
|
|
|
|
glib_binary_age);
|
|
|
|
|
|
|
|
cwd = g_get_current_dir ();
|
|
|
|
un = g_get_user_name();
|
|
|
|
rn = g_get_real_name();
|
|
|
|
hn = g_get_host_name();
|
|
|
|
if (g_test_verbose())
|
|
|
|
{
|
|
|
|
g_print ("cwd: %s\n", cwd);
|
|
|
|
g_print ("user: %s\n", un);
|
|
|
|
g_print ("real: %s\n", rn);
|
|
|
|
g_print ("host: %s\n", hn);
|
|
|
|
}
|
|
|
|
g_free (cwd);
|
|
|
|
|
2011-06-06 06:30:30 +02:00
|
|
|
/* reload, just for fun */
|
|
|
|
g_reload_user_special_dirs_cache ();
|
|
|
|
g_reload_user_special_dirs_cache ();
|
|
|
|
|
2007-12-12 16:09:08 +01:00
|
|
|
tmpdir = g_get_tmp_dir();
|
|
|
|
g_assert (tmpdir != NULL);
|
|
|
|
homedir = g_get_home_dir ();
|
|
|
|
g_assert (homedir != NULL);
|
|
|
|
userdatadir = g_get_user_data_dir ();
|
|
|
|
g_assert (userdatadir != NULL);
|
|
|
|
uconfdir = g_get_user_config_dir ();
|
|
|
|
g_assert (uconfdir != NULL);
|
|
|
|
ucachedir = g_get_user_cache_dir ();
|
|
|
|
g_assert (ucachedir != NULL);
|
|
|
|
|
|
|
|
uddesktop = g_get_user_special_dir (G_USER_DIRECTORY_DESKTOP);
|
|
|
|
g_assert (uddesktop != NULL);
|
2008-03-10 16:13:29 +01:00
|
|
|
udddocs = g_get_user_special_dir (G_USER_DIRECTORY_DOCUMENTS);
|
|
|
|
uddpubshare = g_get_user_special_dir (G_USER_DIRECTORY_PUBLIC_SHARE);
|
2011-06-06 06:30:30 +02:00
|
|
|
uruntimedir = g_get_user_runtime_dir ();
|
|
|
|
g_assert (uruntimedir != NULL);
|
2007-12-12 16:09:08 +01:00
|
|
|
|
|
|
|
sv = (gchar **) g_get_system_data_dirs ();
|
|
|
|
sdatadirs = g_strjoinv (G_SEARCHPATH_SEPARATOR_S, sv);
|
|
|
|
sv = (gchar **) g_get_system_config_dirs ();
|
|
|
|
sconfdirs = g_strjoinv (G_SEARCHPATH_SEPARATOR_S, sv);
|
|
|
|
sv = (gchar **) g_get_language_names ();
|
|
|
|
langnames = g_strjoinv (":", sv);
|
|
|
|
|
|
|
|
if (g_test_verbose())
|
|
|
|
{
|
|
|
|
g_print ("tmp-dir: %s\n", tmpdir);
|
|
|
|
g_print ("home: %s\n", homedir);
|
|
|
|
g_print ("user_data: %s\n", userdatadir);
|
|
|
|
g_print ("user_config: %s\n", uconfdir);
|
|
|
|
g_print ("user_cache: %s\n", ucachedir);
|
2011-06-06 06:30:30 +02:00
|
|
|
g_print ("user_runtime: %s\n", uruntimedir);
|
2007-12-12 16:09:08 +01:00
|
|
|
g_print ("system_data: %s\n", sdatadirs);
|
|
|
|
g_print ("system_config: %s\n", sconfdirs);
|
|
|
|
g_print ("languages: %s\n", langnames);
|
|
|
|
g_print ("user_special[DESKTOP]: %s\n", uddesktop);
|
|
|
|
g_print ("user_special[DOCUMENTS]: %s\n", udddocs);
|
|
|
|
g_print ("user_special[PUBLIC_SHARE]: %s\n", uddpubshare);
|
|
|
|
}
|
|
|
|
g_free (sdatadirs);
|
|
|
|
g_free (sconfdirs);
|
|
|
|
g_free (langnames);
|
2011-06-06 06:30:30 +02:00
|
|
|
|
2011-06-13 15:27:28 +02:00
|
|
|
charset_is_utf8 = g_get_charset ((const char**)&charset);
|
2011-06-06 06:30:30 +02:00
|
|
|
|
2007-12-12 16:09:08 +01:00
|
|
|
if (g_test_verbose())
|
|
|
|
{
|
2011-06-06 06:30:30 +02:00
|
|
|
if (charset_is_utf8)
|
2007-12-12 16:09:08 +01:00
|
|
|
g_print ("current charset is UTF-8: %s\n", charset);
|
|
|
|
else
|
|
|
|
g_print ("current charset is not UTF-8: %s\n", charset);
|
2011-06-06 06:30:30 +02:00
|
|
|
}
|
2007-12-12 16:09:08 +01:00
|
|
|
|
2011-06-06 06:30:30 +02:00
|
|
|
if (g_test_verbose())
|
|
|
|
{
|
2007-12-12 16:09:08 +01:00
|
|
|
#ifdef G_PLATFORM_WIN32
|
|
|
|
g_print ("current locale: %s\n", g_win32_getlocale ());
|
|
|
|
|
|
|
|
g_print ("found more.com as %s\n", g_find_program_in_path ("more.com"));
|
|
|
|
g_print ("found regedit as %s\n", g_find_program_in_path ("regedit"));
|
|
|
|
|
|
|
|
g_print ("a Win32 error message: %s\n", g_win32_error_message (2));
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_paths (void)
|
|
|
|
{
|
1998-07-14 09:39:07 +02:00
|
|
|
struct {
|
|
|
|
gchar *filename;
|
|
|
|
gchar *dirname;
|
|
|
|
} dirname_checks[] = {
|
|
|
|
{ "/", "/" },
|
|
|
|
{ "////", "/" },
|
|
|
|
{ ".////", "." },
|
|
|
|
{ "../", ".." },
|
|
|
|
{ "..////", ".." },
|
|
|
|
{ "a/b", "a" },
|
|
|
|
{ "a/b/", "a/b" },
|
|
|
|
{ "c///", "c" },
|
2003-08-16 21:45:25 +02:00
|
|
|
#ifdef G_OS_WIN32
|
removed dummy structure definitions for struct _GCache, _GTree, _GTimer,
Tue Oct 27 03:00:50 1998 Tim Janik <timj@gtk.org>
* glib.h: removed dummy structure definitions for struct _GCache,
_GTree, _GTimer, _GMemChunk, _GListAllocator and _GStringChunk.
* gutils.c: implement glib's inline functions _after_ all include
statements have been processed.
removed Tor's MAXPATHLEN check since there already was one supplied
further down in this file.
(LibMain): special cased the #ifdef __LCC__ case for NATIVE_WIN32,
since lcc maybe used on other platforms as well. why in hell is this
stuff required?
(g_get_any_init): for windows, if the user name is supplied, use it as
realname also.
in general, if there is no homedir specified, use the tmpdir that
we already figured.
* gtimer.c (g_timer_elapsed): changed a g_assert() statement to
g_return_if_fail().
* applied glib-tml-981020-0.patch for WIN32 portability, added some
comments and g_return_if_fail() statements, minor indentation fixes.
ChangeLog entry from Tor Lillqvist is appended.
* glib.h (struct dirent): use lower case structure members.
* glib.h:
* makefile.lcc:
* makefile.msc:
s/COMPILING_GLIB/GLIB_COMPILATION/
1998-10-20: Tor Lillqvist <tml@iki.fi>
* README.win32 glib.def gmodule.def
* glibconfig.h.win32 gmodule/gmoduleconf.h.win32:
New files for the Windows port. The .def files list exported
symbols for the Microsoft linker and compatibles.
* configure.in:
Added checks for some platform-dependent headers: pwd.h sys/param.h
sys/select.h sys/time.h sys/times.h unistd.h, and the function lstat.
* gerror.c:
Conditionalized inclusion of system-dependent headers. Changes
for Windows: no gdb to do a stack trace. Just call abort().
* glib.h:
Changes for Windows:
Added macros G_DIR_SEPARATOR, G_DIR_SEPARATOR_S for
platform-dependent file name syntax elements. Added macros
G_SEARCHPATH_SEPARATOR, G_SEARCHPATH_SEPARATOR_S for
platform-dependent search path syntax conventions.
Added pragmas for Microsoft C to make it more pedantic.
Marked GLib's global variables for export from DLL.
Added the function g_strescape that escapes backslashes.
Added functions g_path_is_absolute and g_path_skip_root to
handle platform-dependent file name syntax.
Added the function g_getenv that expands environment variables
that contain references to other environment variables, as is
typical on Windows NT.
Added the GIOChannel structure which is used to encapsulate the
IPC mechanism used by the GIMP's plug-ins, and possibly other
things later. On Unix a GIOChannel encapsulates just a file
descriptor. On Windows it contains a file handle from _pipe() and a
few other things related to the implementation of gdk_input_add
and GIMP plug-in communication. Subject to change.
Removed duplicate declarations of the version variables.
For the Microsoft compiler, declare own implementation of
ftruncate and the <dirent.h> functions.
* gmem.c:
Define a symbolic name for the profiling table size.
* gmessages.c:
Conditionalized inclusion of unistd.h. On Windows, output using
stdio to stdout.
* gscanner.c:
Conditionalized inclusion of unistd.h. Added changes for
Microsoft C. Added CR to the skipped character set. Added small
workaround for MSC compiler bug in g_scanner_cur_value.
* gstrfuncs.c:
Added the function g_strescape, which escapes the backslash
character. Needed especially when printing Windows filenames.
* gtimer.c:
Conditionalized inclusion of unistd.h and sys/time.h. Added
implementations for Windows.
* gutils.c:
Conditionalized inclusion of platform-dependent headers. Use
the platform-independent file name syntax macros.
Conditionalize code on platform-dependent features. Added the
functions g_path_is_absolute g_path_skip_root and g_getenv.
Added the GIOChannel-related functions. Added
compiler-dependent Unix compatibility functions for Windows.
* makefile.lcc makefile.msc:
New files. Compiler-specific makefiles for LCC-Win32 and
Microsoft C. Only Microsoft C is actually supported currently.
* testglib.c:
Added pathname check cases for Windows. Added workaround for
bug in the Microsoft runtime library. Improved some tests a bit.
Tue Oct 27 04:00:11 1998 Tim Janik <timj@gtk.org>
* testgmodule.c (main): changed the #ifdef WIN32 test to NATIVE_WIN32,
this needs to be more constistent throughout the code, do we go for
NATIVE_WIN32 or WIN32?
* gmodule.c (LibMain): special cased the #ifdef __LCC__ case for
NATIVE_WIN32, since lcc maybe used on other platforms as well.
* libgplugin_a.c (LibMain):
* libgplugin_b.c (LibMain):
likewise. not sure i like this special requirement for lcc in here.
* gmodule-dl.c (_g_module_build_path):
feature empty "" directories and prepend the module name with "lib".
* gmodule-dld.c (_g_module_build_path):
* gmodule-win32.c (_g_module_build_path):
feature empty "" directories.
* we need some more magic in the _g_module_build_path variants
so we don't append/prepend lib and .so, .sl or .dll for those names
that already contain it.
* applied patch from Tor Lillqvist for g_module_build_path() and
windows support.
1998-10-20: Tor Lillqvist <tml@iki.fi>
* gmodule/gmodule-win32.c:
New file.
* gmodule/gmodule.c gmodule/gmodule.h:
Added the funcion g_module_build_path that builds the path to
a module file, decorating the name according to the system's
conventions. Added the Windows implementation.
* gmodule/libgplugin_a.c gmodule/libgplugin_b.c:
Added LibMain for LCC-Win32.
* gmodule/testgmodule.c:
Handle Windows dll names.
1998-10-27 05:11:34 +01:00
|
|
|
{ "\\", "\\" },
|
|
|
|
{ ".\\\\\\\\", "." },
|
|
|
|
{ "..\\", ".." },
|
|
|
|
{ "..\\\\\\\\", ".." },
|
|
|
|
{ "a\\b", "a" },
|
2003-08-16 21:45:25 +02:00
|
|
|
{ "a\\b/", "a\\b" },
|
|
|
|
{ "a/b\\", "a/b" },
|
|
|
|
{ "c\\\\/", "c" },
|
|
|
|
{ "//\\", "/" },
|
2001-03-09 22:31:21 +01:00
|
|
|
#endif
|
|
|
|
#ifdef G_WITH_CYGWIN
|
|
|
|
{ "//server/share///x", "//server/share" },
|
removed dummy structure definitions for struct _GCache, _GTree, _GTimer,
Tue Oct 27 03:00:50 1998 Tim Janik <timj@gtk.org>
* glib.h: removed dummy structure definitions for struct _GCache,
_GTree, _GTimer, _GMemChunk, _GListAllocator and _GStringChunk.
* gutils.c: implement glib's inline functions _after_ all include
statements have been processed.
removed Tor's MAXPATHLEN check since there already was one supplied
further down in this file.
(LibMain): special cased the #ifdef __LCC__ case for NATIVE_WIN32,
since lcc maybe used on other platforms as well. why in hell is this
stuff required?
(g_get_any_init): for windows, if the user name is supplied, use it as
realname also.
in general, if there is no homedir specified, use the tmpdir that
we already figured.
* gtimer.c (g_timer_elapsed): changed a g_assert() statement to
g_return_if_fail().
* applied glib-tml-981020-0.patch for WIN32 portability, added some
comments and g_return_if_fail() statements, minor indentation fixes.
ChangeLog entry from Tor Lillqvist is appended.
* glib.h (struct dirent): use lower case structure members.
* glib.h:
* makefile.lcc:
* makefile.msc:
s/COMPILING_GLIB/GLIB_COMPILATION/
1998-10-20: Tor Lillqvist <tml@iki.fi>
* README.win32 glib.def gmodule.def
* glibconfig.h.win32 gmodule/gmoduleconf.h.win32:
New files for the Windows port. The .def files list exported
symbols for the Microsoft linker and compatibles.
* configure.in:
Added checks for some platform-dependent headers: pwd.h sys/param.h
sys/select.h sys/time.h sys/times.h unistd.h, and the function lstat.
* gerror.c:
Conditionalized inclusion of system-dependent headers. Changes
for Windows: no gdb to do a stack trace. Just call abort().
* glib.h:
Changes for Windows:
Added macros G_DIR_SEPARATOR, G_DIR_SEPARATOR_S for
platform-dependent file name syntax elements. Added macros
G_SEARCHPATH_SEPARATOR, G_SEARCHPATH_SEPARATOR_S for
platform-dependent search path syntax conventions.
Added pragmas for Microsoft C to make it more pedantic.
Marked GLib's global variables for export from DLL.
Added the function g_strescape that escapes backslashes.
Added functions g_path_is_absolute and g_path_skip_root to
handle platform-dependent file name syntax.
Added the function g_getenv that expands environment variables
that contain references to other environment variables, as is
typical on Windows NT.
Added the GIOChannel structure which is used to encapsulate the
IPC mechanism used by the GIMP's plug-ins, and possibly other
things later. On Unix a GIOChannel encapsulates just a file
descriptor. On Windows it contains a file handle from _pipe() and a
few other things related to the implementation of gdk_input_add
and GIMP plug-in communication. Subject to change.
Removed duplicate declarations of the version variables.
For the Microsoft compiler, declare own implementation of
ftruncate and the <dirent.h> functions.
* gmem.c:
Define a symbolic name for the profiling table size.
* gmessages.c:
Conditionalized inclusion of unistd.h. On Windows, output using
stdio to stdout.
* gscanner.c:
Conditionalized inclusion of unistd.h. Added changes for
Microsoft C. Added CR to the skipped character set. Added small
workaround for MSC compiler bug in g_scanner_cur_value.
* gstrfuncs.c:
Added the function g_strescape, which escapes the backslash
character. Needed especially when printing Windows filenames.
* gtimer.c:
Conditionalized inclusion of unistd.h and sys/time.h. Added
implementations for Windows.
* gutils.c:
Conditionalized inclusion of platform-dependent headers. Use
the platform-independent file name syntax macros.
Conditionalize code on platform-dependent features. Added the
functions g_path_is_absolute g_path_skip_root and g_getenv.
Added the GIOChannel-related functions. Added
compiler-dependent Unix compatibility functions for Windows.
* makefile.lcc makefile.msc:
New files. Compiler-specific makefiles for LCC-Win32 and
Microsoft C. Only Microsoft C is actually supported currently.
* testglib.c:
Added pathname check cases for Windows. Added workaround for
bug in the Microsoft runtime library. Improved some tests a bit.
Tue Oct 27 04:00:11 1998 Tim Janik <timj@gtk.org>
* testgmodule.c (main): changed the #ifdef WIN32 test to NATIVE_WIN32,
this needs to be more constistent throughout the code, do we go for
NATIVE_WIN32 or WIN32?
* gmodule.c (LibMain): special cased the #ifdef __LCC__ case for
NATIVE_WIN32, since lcc maybe used on other platforms as well.
* libgplugin_a.c (LibMain):
* libgplugin_b.c (LibMain):
likewise. not sure i like this special requirement for lcc in here.
* gmodule-dl.c (_g_module_build_path):
feature empty "" directories and prepend the module name with "lib".
* gmodule-dld.c (_g_module_build_path):
* gmodule-win32.c (_g_module_build_path):
feature empty "" directories.
* we need some more magic in the _g_module_build_path variants
so we don't append/prepend lib and .so, .sl or .dll for those names
that already contain it.
* applied patch from Tor Lillqvist for g_module_build_path() and
windows support.
1998-10-20: Tor Lillqvist <tml@iki.fi>
* gmodule/gmodule-win32.c:
New file.
* gmodule/gmodule.c gmodule/gmodule.h:
Added the funcion g_module_build_path that builds the path to
a module file, decorating the name according to the system's
conventions. Added the Windows implementation.
* gmodule/libgplugin_a.c gmodule/libgplugin_b.c:
Added LibMain for LCC-Win32.
* gmodule/testgmodule.c:
Handle Windows dll names.
1998-10-27 05:11:34 +01:00
|
|
|
#endif
|
2001-01-05 21:19:37 +01:00
|
|
|
{ ".", "." },
|
|
|
|
{ "..", "." },
|
|
|
|
{ "", "." },
|
1998-07-14 09:39:07 +02:00
|
|
|
};
|
2007-12-12 16:09:08 +01:00
|
|
|
const guint n_dirname_checks = G_N_ELEMENTS (dirname_checks);
|
2001-01-05 21:19:37 +01:00
|
|
|
struct {
|
|
|
|
gchar *filename;
|
|
|
|
gchar *without_root;
|
|
|
|
} skip_root_checks[] = {
|
|
|
|
{ "/", "" },
|
|
|
|
{ "//", "" },
|
|
|
|
{ "/foo", "foo" },
|
|
|
|
{ "//foo", "foo" },
|
|
|
|
{ "a/b", NULL },
|
2003-08-16 21:45:25 +02:00
|
|
|
#ifdef G_OS_WIN32
|
2001-01-05 21:19:37 +01:00
|
|
|
{ "\\", "" },
|
|
|
|
{ "\\foo", "foo" },
|
|
|
|
{ "\\\\server\\foo", "" },
|
|
|
|
{ "\\\\server\\foo\\bar", "bar" },
|
|
|
|
{ "a\\b", NULL },
|
2001-03-09 22:31:21 +01:00
|
|
|
#endif
|
|
|
|
#ifdef G_WITH_CYGWIN
|
|
|
|
{ "//server/share///x", "//x" },
|
2001-01-05 21:19:37 +01:00
|
|
|
#endif
|
|
|
|
{ ".", NULL },
|
|
|
|
{ "", NULL },
|
|
|
|
};
|
2007-12-12 16:09:08 +01:00
|
|
|
const guint n_skip_root_checks = G_N_ELEMENTS (skip_root_checks);
|
|
|
|
gchar *string;
|
|
|
|
guint i;
|
|
|
|
if (g_test_verbose())
|
|
|
|
g_print ("checking g_path_get_basename()...");
|
2001-09-20 07:41:52 +02:00
|
|
|
string = g_path_get_basename (G_DIR_SEPARATOR_S "foo" G_DIR_SEPARATOR_S "dir" G_DIR_SEPARATOR_S);
|
2001-09-18 18:33:20 +02:00
|
|
|
g_assert (strcmp (string, "dir") == 0);
|
|
|
|
g_free (string);
|
2001-09-20 07:41:52 +02:00
|
|
|
string = g_path_get_basename (G_DIR_SEPARATOR_S "foo" G_DIR_SEPARATOR_S "file");
|
2001-09-18 18:33:20 +02:00
|
|
|
g_assert (strcmp (string, "file") == 0);
|
|
|
|
g_free (string);
|
2007-12-12 16:09:08 +01:00
|
|
|
if (g_test_verbose())
|
|
|
|
g_print ("ok\n");
|
|
|
|
|
2003-08-16 21:45:25 +02:00
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
string = g_path_get_basename ("/foo/dir/");
|
|
|
|
g_assert (strcmp (string, "dir") == 0);
|
|
|
|
g_free (string);
|
|
|
|
string = g_path_get_basename ("/foo/file");
|
|
|
|
g_assert (strcmp (string, "file") == 0);
|
|
|
|
g_free (string);
|
|
|
|
#endif
|
2001-09-18 18:33:20 +02:00
|
|
|
|
2007-12-12 16:09:08 +01:00
|
|
|
if (g_test_verbose())
|
|
|
|
g_print ("checking g_path_get_dirname()...");
|
1998-07-14 09:39:07 +02:00
|
|
|
for (i = 0; i < n_dirname_checks; i++)
|
|
|
|
{
|
2007-12-12 16:09:08 +01:00
|
|
|
gchar *dirname = g_path_get_dirname (dirname_checks[i].filename);
|
1998-07-14 09:39:07 +02:00
|
|
|
if (strcmp (dirname, dirname_checks[i].dirname) != 0)
|
|
|
|
{
|
2007-12-12 16:09:08 +01:00
|
|
|
g_error ("\nfailed for \"%s\"==\"%s\" (returned: \"%s\")\n",
|
1998-07-14 09:39:07 +02:00
|
|
|
dirname_checks[i].filename,
|
|
|
|
dirname_checks[i].dirname,
|
|
|
|
dirname);
|
|
|
|
}
|
|
|
|
g_free (dirname);
|
|
|
|
}
|
2007-12-12 16:09:08 +01:00
|
|
|
if (g_test_verbose())
|
1998-07-14 09:39:07 +02:00
|
|
|
g_print ("ok\n");
|
|
|
|
|
2007-12-12 16:09:08 +01:00
|
|
|
if (g_test_verbose())
|
|
|
|
g_print ("checking g_path_skip_root()...");
|
2001-01-05 21:19:37 +01:00
|
|
|
for (i = 0; i < n_skip_root_checks; i++)
|
|
|
|
{
|
2007-12-12 16:09:08 +01:00
|
|
|
const gchar *skipped = g_path_skip_root (skip_root_checks[i].filename);
|
2001-01-05 21:19:37 +01:00
|
|
|
if ((skipped && !skip_root_checks[i].without_root) ||
|
|
|
|
(!skipped && skip_root_checks[i].without_root) ||
|
|
|
|
((skipped && skip_root_checks[i].without_root) &&
|
|
|
|
strcmp (skipped, skip_root_checks[i].without_root)))
|
|
|
|
{
|
2007-12-12 16:09:08 +01:00
|
|
|
g_error ("\nfailed for \"%s\"==\"%s\" (returned: \"%s\")\n",
|
2001-01-05 21:19:37 +01:00
|
|
|
skip_root_checks[i].filename,
|
|
|
|
(skip_root_checks[i].without_root ?
|
|
|
|
skip_root_checks[i].without_root : "<NULL>"),
|
|
|
|
(skipped ? skipped : "<NULL>"));
|
|
|
|
}
|
|
|
|
}
|
2007-12-12 16:09:08 +01:00
|
|
|
if (g_test_verbose())
|
2005-06-22 11:43:37 +02:00
|
|
|
g_print ("ok\n");
|
2007-12-12 16:09:08 +01:00
|
|
|
}
|
2005-06-22 11:43:37 +02:00
|
|
|
|
2007-12-12 16:09:08 +01:00
|
|
|
static void
|
|
|
|
test_file_functions (void)
|
|
|
|
{
|
|
|
|
const char hello[] = "Hello, World";
|
|
|
|
const int hellolen = sizeof (hello) - 1;
|
|
|
|
GError *error;
|
|
|
|
char template[32];
|
|
|
|
char *name_used, chars[62];
|
|
|
|
gint fd, n;
|
|
|
|
|
|
|
|
strcpy (template, "foobar");
|
|
|
|
fd = g_mkstemp (template);
|
|
|
|
if (g_test_verbose() && fd != -1)
|
|
|
|
g_print ("g_mkstemp works even if template doesn't end in XXXXXX\n");
|
2010-10-07 11:04:52 +02:00
|
|
|
if (fd != -1)
|
|
|
|
close (fd);
|
2007-12-12 16:09:08 +01:00
|
|
|
strcpy (template, "fooXXXXXX");
|
|
|
|
fd = g_mkstemp (template);
|
|
|
|
if (fd == -1)
|
|
|
|
g_error ("g_mkstemp didn't work for template %s\n", template);
|
|
|
|
n = write (fd, hello, hellolen);
|
|
|
|
if (n == -1)
|
|
|
|
g_error ("write() failed: %s\n", g_strerror (errno));
|
|
|
|
else if (n != hellolen)
|
|
|
|
g_error ("write() should have written %d bytes, wrote %d\n", hellolen, n);
|
1998-11-13 21:50:41 +01:00
|
|
|
|
2007-12-12 16:09:08 +01:00
|
|
|
lseek (fd, 0, 0);
|
|
|
|
n = read (fd, chars, sizeof (chars));
|
|
|
|
if (n == -1)
|
|
|
|
g_error ("read() failed: %s\n", g_strerror (errno));
|
|
|
|
else if (n != hellolen)
|
|
|
|
g_error ("read() should have read %d bytes, got %d\n", hellolen, n);
|
1998-11-13 21:50:41 +01:00
|
|
|
|
2007-12-12 16:09:08 +01:00
|
|
|
chars[n] = 0;
|
|
|
|
if (strcmp (chars, hello) != 0)
|
|
|
|
g_error ("wrote '%s', but got '%s'\n", hello, chars);
|
1998-11-13 21:50:41 +01:00
|
|
|
|
2007-12-12 16:09:08 +01:00
|
|
|
close (fd);
|
|
|
|
remove (template);
|
1998-11-13 21:50:41 +01:00
|
|
|
|
2007-12-12 16:09:08 +01:00
|
|
|
error = NULL;
|
|
|
|
strcpy (template, "zap" G_DIR_SEPARATOR_S "barXXXXXX");
|
|
|
|
fd = g_file_open_tmp (template, &name_used, &error);
|
|
|
|
if (g_test_verbose())
|
1998-06-11 01:21:14 +02:00
|
|
|
{
|
2007-12-12 16:09:08 +01:00
|
|
|
if (fd != -1)
|
|
|
|
g_print ("g_file_open_tmp works even if template contains '%s'\n", G_DIR_SEPARATOR_S);
|
|
|
|
else
|
|
|
|
g_print ("g_file_open_tmp correctly returns error: %s\n", error->message);
|
1998-06-11 01:21:14 +02:00
|
|
|
}
|
2011-12-12 16:55:59 +01:00
|
|
|
if (fd != -1)
|
|
|
|
close (fd);
|
2007-12-12 16:09:08 +01:00
|
|
|
g_clear_error (&error);
|
1998-09-02 09:44:02 +02:00
|
|
|
|
2007-12-12 16:09:08 +01:00
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
strcpy (template, "zap/barXXXXXX");
|
|
|
|
fd = g_file_open_tmp (template, &name_used, &error);
|
|
|
|
if (g_test_verbose())
|
1998-06-11 01:21:14 +02:00
|
|
|
{
|
2007-12-12 16:09:08 +01:00
|
|
|
if (fd != -1)
|
|
|
|
g_print ("g_file_open_tmp works even if template contains '/'\n");
|
|
|
|
else
|
|
|
|
g_print ("g_file_open_tmp correctly returns error: %s\n", error->message);
|
1998-06-11 01:21:14 +02:00
|
|
|
}
|
2007-12-12 16:09:08 +01:00
|
|
|
close (fd);
|
|
|
|
g_clear_error (&error);
|
|
|
|
#endif
|
1998-06-11 01:21:14 +02:00
|
|
|
|
2007-12-12 16:09:08 +01:00
|
|
|
strcpy (template, "zapXXXXXX");
|
|
|
|
fd = g_file_open_tmp (template, &name_used, &error);
|
|
|
|
if (fd == -1)
|
|
|
|
g_error ("g_file_open_tmp didn't work for template '%s': %s\n", template, error->message);
|
|
|
|
else if (g_test_verbose())
|
|
|
|
g_print ("g_file_open_tmp for template '%s' used name '%s'\n", template, name_used);
|
|
|
|
close (fd);
|
|
|
|
g_clear_error (&error);
|
|
|
|
remove (name_used);
|
1998-07-31 22:21:10 +02:00
|
|
|
|
2007-12-12 16:09:08 +01:00
|
|
|
fd = g_file_open_tmp (NULL, &name_used, &error);
|
|
|
|
if (fd == -1)
|
|
|
|
g_error ("g_file_open_tmp didn't work for a NULL template: %s\n", error->message);
|
|
|
|
close (fd);
|
|
|
|
g_clear_error (&error);
|
|
|
|
remove (name_used);
|
|
|
|
}
|
1998-06-11 01:21:14 +02:00
|
|
|
|
2007-12-12 16:09:08 +01:00
|
|
|
static void
|
|
|
|
test_arrays (void)
|
|
|
|
{
|
|
|
|
GByteArray *gbarray;
|
|
|
|
GPtrArray *gparray;
|
|
|
|
GArray *garray;
|
|
|
|
guint i;
|
1998-06-11 01:21:14 +02:00
|
|
|
|
2007-12-12 16:09:08 +01:00
|
|
|
gparray = g_ptr_array_new ();
|
1998-06-11 01:21:14 +02:00
|
|
|
for (i = 0; i < 10000; i++)
|
2007-12-12 16:09:08 +01:00
|
|
|
g_ptr_array_add (gparray, GINT_TO_POINTER (i));
|
|
|
|
for (i = 0; i < 10000; i++)
|
|
|
|
if (g_ptr_array_index (gparray, i) != GINT_TO_POINTER (i))
|
|
|
|
g_error ("array fails: %p ( %p )\n", g_ptr_array_index (gparray, i), GINT_TO_POINTER (i));
|
|
|
|
g_ptr_array_free (gparray, TRUE);
|
1998-06-11 01:21:14 +02:00
|
|
|
|
2007-12-12 16:09:08 +01:00
|
|
|
gbarray = g_byte_array_new ();
|
|
|
|
for (i = 0; i < 10000; i++)
|
|
|
|
g_byte_array_append (gbarray, (guint8*) "abcd", 4);
|
1998-06-11 01:21:14 +02:00
|
|
|
for (i = 0; i < 10000; i++)
|
|
|
|
{
|
2007-12-12 16:09:08 +01:00
|
|
|
g_assert (gbarray->data[4*i] == 'a');
|
|
|
|
g_assert (gbarray->data[4*i+1] == 'b');
|
|
|
|
g_assert (gbarray->data[4*i+2] == 'c');
|
|
|
|
g_assert (gbarray->data[4*i+3] == 'd');
|
1998-06-11 01:21:14 +02:00
|
|
|
}
|
2007-12-12 16:09:08 +01:00
|
|
|
g_byte_array_free (gbarray, TRUE);
|
1998-06-11 01:21:14 +02:00
|
|
|
|
2007-12-12 16:09:08 +01:00
|
|
|
garray = g_array_new (FALSE, FALSE, sizeof (gint));
|
|
|
|
for (i = 0; i < 10000; i++)
|
|
|
|
g_array_append_val (garray, i);
|
|
|
|
for (i = 0; i < 10000; i++)
|
|
|
|
if (g_array_index (garray, gint, i) != i)
|
|
|
|
g_error ("failure: %d ( %d )\n", g_array_index (garray, gint, i), i);
|
|
|
|
g_array_free (garray, TRUE);
|
1998-06-11 01:21:14 +02:00
|
|
|
|
2007-12-12 16:09:08 +01:00
|
|
|
garray = g_array_new (FALSE, FALSE, sizeof (gint));
|
|
|
|
for (i = 0; i < 100; i++)
|
|
|
|
g_array_prepend_val (garray, i);
|
|
|
|
for (i = 0; i < 100; i++)
|
|
|
|
if (g_array_index (garray, gint, i) != (100 - i - 1))
|
|
|
|
g_error ("failure: %d ( %d )\n", g_array_index (garray, gint, i), 100 - i - 1);
|
|
|
|
g_array_free (garray, TRUE);
|
|
|
|
}
|
1998-06-11 01:21:14 +02:00
|
|
|
|
2007-12-12 16:09:08 +01:00
|
|
|
static void
|
|
|
|
hash_table_tests (void)
|
|
|
|
{
|
|
|
|
GHashTable *hash_table;
|
|
|
|
int array[10000];
|
|
|
|
gint *pvalue = NULL;
|
|
|
|
gint value = 120;
|
|
|
|
guint i;
|
1998-06-11 01:21:14 +02:00
|
|
|
|
Introduced new function type GEqualFunc to return TRUE for equal params.
2000-10-30 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
* gcache.h, gcache.c, ghash.h, ghash.c, grel.c, grel.h, gtypes.h:
Introduced new function type GEqualFunc to return TRUE for equal
params. This is now used instead of GCompareFunc (which should
work akin to strcmp) here. This kind of fixes Bug #14412. Note
that technically GCompareFunc and GEqualFunc are still the same
types, as gint == gboolean.
* ghash.h, gutils.c: g_int_equal and g_direct_equal now return
gboolean to be really become GEqualFunc.
* gscanner.c, testglib.c, tests/hash-test.c: Some tiny changes to
follow the above change.
2000-10-30 15:34:52 +01:00
|
|
|
hash_table = g_hash_table_new (my_hash, my_hash_equal);
|
1998-06-11 01:21:14 +02:00
|
|
|
for (i = 0; i < 10000; i++)
|
|
|
|
{
|
|
|
|
array[i] = i;
|
|
|
|
g_hash_table_insert (hash_table, &array[i], &array[i]);
|
|
|
|
}
|
2004-02-20 03:05:36 +01:00
|
|
|
pvalue = g_hash_table_find (hash_table, find_first_that, &value);
|
|
|
|
if (*pvalue != value)
|
2007-12-12 16:09:08 +01:00
|
|
|
g_error ("g_hash_table_find failed");
|
1998-06-11 01:21:14 +02:00
|
|
|
g_hash_table_foreach (hash_table, my_hash_callback, NULL);
|
|
|
|
for (i = 0; i < 10000; i++)
|
|
|
|
if (array[i] == 0)
|
2007-12-12 16:09:08 +01:00
|
|
|
g_error ("hashtable-test: wrong value: %d\n", i);
|
1998-06-11 01:21:14 +02:00
|
|
|
for (i = 0; i < 10000; i++)
|
|
|
|
g_hash_table_remove (hash_table, &array[i]);
|
1998-09-20 11:43:11 +02:00
|
|
|
for (i = 0; i < 10000; i++)
|
|
|
|
{
|
|
|
|
array[i] = i;
|
|
|
|
g_hash_table_insert (hash_table, &array[i], &array[i]);
|
|
|
|
}
|
|
|
|
if (g_hash_table_foreach_remove (hash_table, my_hash_callback_remove, NULL) != 5000 ||
|
|
|
|
g_hash_table_size (hash_table) != 5000)
|
2007-12-12 16:09:08 +01:00
|
|
|
g_error ("hashtable removal failed\n");
|
1998-09-20 11:43:11 +02:00
|
|
|
g_hash_table_foreach (hash_table, my_hash_callback_remove_test, NULL);
|
1998-06-11 01:21:14 +02:00
|
|
|
g_hash_table_destroy (hash_table);
|
2007-12-12 16:09:08 +01:00
|
|
|
}
|
1998-06-11 01:21:14 +02:00
|
|
|
|
2010-12-28 06:12:19 +01:00
|
|
|
#ifndef G_DISABLE_DEPRECATED
|
2007-12-12 16:09:08 +01:00
|
|
|
static void
|
|
|
|
relation_test (void)
|
|
|
|
{
|
|
|
|
GRelation *relation = g_relation_new (2);
|
|
|
|
GTuples *tuples;
|
|
|
|
gint data [1024];
|
|
|
|
guint i;
|
1998-06-11 01:21:14 +02:00
|
|
|
|
2007-12-12 16:09:08 +01:00
|
|
|
g_relation_index (relation, 0, g_int_hash, g_int_equal);
|
|
|
|
g_relation_index (relation, 1, g_int_hash, g_int_equal);
|
1998-06-11 01:21:14 +02:00
|
|
|
|
2007-12-12 16:09:08 +01:00
|
|
|
for (i = 0; i < 1024; i += 1)
|
|
|
|
data[i] = i;
|
1998-06-11 01:21:14 +02:00
|
|
|
|
2007-12-12 16:09:08 +01:00
|
|
|
for (i = 1; i < 1023; i += 1)
|
1998-06-11 01:21:14 +02:00
|
|
|
{
|
2007-12-12 16:09:08 +01:00
|
|
|
g_relation_insert (relation, data + i, data + i + 1);
|
|
|
|
g_relation_insert (relation, data + i, data + i - 1);
|
1998-06-11 01:21:14 +02:00
|
|
|
}
|
|
|
|
|
2007-12-12 16:09:08 +01:00
|
|
|
for (i = 2; i < 1022; i += 1)
|
|
|
|
{
|
|
|
|
g_assert (! g_relation_exists (relation, data + i, data + i));
|
|
|
|
g_assert (! g_relation_exists (relation, data + i, data + i + 2));
|
|
|
|
g_assert (! g_relation_exists (relation, data + i, data + i - 2));
|
|
|
|
}
|
1998-06-11 01:21:14 +02:00
|
|
|
|
2007-12-12 16:09:08 +01:00
|
|
|
for (i = 1; i < 1023; i += 1)
|
|
|
|
{
|
|
|
|
g_assert (g_relation_exists (relation, data + i, data + i + 1));
|
|
|
|
g_assert (g_relation_exists (relation, data + i, data + i - 1));
|
|
|
|
}
|
1998-06-11 01:21:14 +02:00
|
|
|
|
2007-12-12 16:09:08 +01:00
|
|
|
for (i = 2; i < 1022; i += 1)
|
|
|
|
{
|
|
|
|
g_assert (g_relation_count (relation, data + i, 0) == 2);
|
|
|
|
g_assert (g_relation_count (relation, data + i, 1) == 2);
|
|
|
|
}
|
1998-06-11 01:21:14 +02:00
|
|
|
|
2007-12-12 16:09:08 +01:00
|
|
|
g_assert (g_relation_count (relation, data, 0) == 0);
|
1998-06-11 01:21:14 +02:00
|
|
|
|
2007-12-12 16:09:08 +01:00
|
|
|
g_assert (g_relation_count (relation, data + 42, 0) == 2);
|
|
|
|
g_assert (g_relation_count (relation, data + 43, 1) == 2);
|
|
|
|
g_assert (g_relation_count (relation, data + 41, 1) == 2);
|
|
|
|
g_relation_delete (relation, data + 42, 0);
|
|
|
|
g_assert (g_relation_count (relation, data + 42, 0) == 0);
|
|
|
|
g_assert (g_relation_count (relation, data + 43, 1) == 1);
|
|
|
|
g_assert (g_relation_count (relation, data + 41, 1) == 1);
|
1998-06-11 01:21:14 +02:00
|
|
|
|
2007-12-12 16:09:08 +01:00
|
|
|
tuples = g_relation_select (relation, data + 200, 0);
|
1998-06-11 01:21:14 +02:00
|
|
|
|
2007-12-12 16:09:08 +01:00
|
|
|
g_assert (tuples->len == 2);
|
1998-06-11 01:21:14 +02:00
|
|
|
|
2007-12-12 16:09:08 +01:00
|
|
|
#if 0
|
|
|
|
for (i = 0; i < tuples->len; i += 1)
|
|
|
|
{
|
|
|
|
printf ("%d %d\n",
|
|
|
|
*(gint*) g_tuples_index (tuples, i, 0),
|
|
|
|
*(gint*) g_tuples_index (tuples, i, 1));
|
|
|
|
}
|
|
|
|
#endif
|
1998-06-11 01:21:14 +02:00
|
|
|
|
2007-12-12 16:09:08 +01:00
|
|
|
g_assert (g_relation_exists (relation, data + 300, data + 301));
|
|
|
|
g_relation_delete (relation, data + 300, 0);
|
|
|
|
g_assert (!g_relation_exists (relation, data + 300, data + 301));
|
1998-06-11 01:21:14 +02:00
|
|
|
|
2007-12-12 16:09:08 +01:00
|
|
|
g_tuples_destroy (tuples);
|
1998-06-11 01:21:14 +02:00
|
|
|
|
2007-12-12 16:09:08 +01:00
|
|
|
g_relation_destroy (relation);
|
1998-06-11 01:21:14 +02:00
|
|
|
|
2007-12-12 16:09:08 +01:00
|
|
|
relation = NULL;
|
|
|
|
}
|
2010-12-28 06:12:19 +01:00
|
|
|
#endif
|
1998-06-11 01:21:14 +02:00
|
|
|
|
2007-12-12 16:09:08 +01:00
|
|
|
static void
|
|
|
|
gstring_tests (void)
|
|
|
|
{
|
|
|
|
GString *string1, *string2;
|
|
|
|
guint i;
|
1998-06-11 01:21:14 +02:00
|
|
|
|
2007-12-12 16:09:08 +01:00
|
|
|
if (g_test_verbose())
|
|
|
|
g_print ("test GString basics\n");
|
1998-06-11 01:21:14 +02:00
|
|
|
|
|
|
|
string1 = g_string_new ("hi pete!");
|
|
|
|
string2 = g_string_new ("");
|
|
|
|
|
|
|
|
g_assert (strcmp ("hi pete!", string1->str) == 0);
|
|
|
|
|
|
|
|
for (i = 0; i < 10000; i++)
|
|
|
|
g_string_append_c (string1, 'a'+(i%26));
|
|
|
|
|
1999-10-04 04:32:50 +02:00
|
|
|
#ifndef G_OS_WIN32
|
1999-04-24 15:52:51 +02:00
|
|
|
/* MSVC, mingw32 and LCC use the same run-time C library, which doesn't like
|
removed dummy structure definitions for struct _GCache, _GTree, _GTimer,
Tue Oct 27 03:00:50 1998 Tim Janik <timj@gtk.org>
* glib.h: removed dummy structure definitions for struct _GCache,
_GTree, _GTimer, _GMemChunk, _GListAllocator and _GStringChunk.
* gutils.c: implement glib's inline functions _after_ all include
statements have been processed.
removed Tor's MAXPATHLEN check since there already was one supplied
further down in this file.
(LibMain): special cased the #ifdef __LCC__ case for NATIVE_WIN32,
since lcc maybe used on other platforms as well. why in hell is this
stuff required?
(g_get_any_init): for windows, if the user name is supplied, use it as
realname also.
in general, if there is no homedir specified, use the tmpdir that
we already figured.
* gtimer.c (g_timer_elapsed): changed a g_assert() statement to
g_return_if_fail().
* applied glib-tml-981020-0.patch for WIN32 portability, added some
comments and g_return_if_fail() statements, minor indentation fixes.
ChangeLog entry from Tor Lillqvist is appended.
* glib.h (struct dirent): use lower case structure members.
* glib.h:
* makefile.lcc:
* makefile.msc:
s/COMPILING_GLIB/GLIB_COMPILATION/
1998-10-20: Tor Lillqvist <tml@iki.fi>
* README.win32 glib.def gmodule.def
* glibconfig.h.win32 gmodule/gmoduleconf.h.win32:
New files for the Windows port. The .def files list exported
symbols for the Microsoft linker and compatibles.
* configure.in:
Added checks for some platform-dependent headers: pwd.h sys/param.h
sys/select.h sys/time.h sys/times.h unistd.h, and the function lstat.
* gerror.c:
Conditionalized inclusion of system-dependent headers. Changes
for Windows: no gdb to do a stack trace. Just call abort().
* glib.h:
Changes for Windows:
Added macros G_DIR_SEPARATOR, G_DIR_SEPARATOR_S for
platform-dependent file name syntax elements. Added macros
G_SEARCHPATH_SEPARATOR, G_SEARCHPATH_SEPARATOR_S for
platform-dependent search path syntax conventions.
Added pragmas for Microsoft C to make it more pedantic.
Marked GLib's global variables for export from DLL.
Added the function g_strescape that escapes backslashes.
Added functions g_path_is_absolute and g_path_skip_root to
handle platform-dependent file name syntax.
Added the function g_getenv that expands environment variables
that contain references to other environment variables, as is
typical on Windows NT.
Added the GIOChannel structure which is used to encapsulate the
IPC mechanism used by the GIMP's plug-ins, and possibly other
things later. On Unix a GIOChannel encapsulates just a file
descriptor. On Windows it contains a file handle from _pipe() and a
few other things related to the implementation of gdk_input_add
and GIMP plug-in communication. Subject to change.
Removed duplicate declarations of the version variables.
For the Microsoft compiler, declare own implementation of
ftruncate and the <dirent.h> functions.
* gmem.c:
Define a symbolic name for the profiling table size.
* gmessages.c:
Conditionalized inclusion of unistd.h. On Windows, output using
stdio to stdout.
* gscanner.c:
Conditionalized inclusion of unistd.h. Added changes for
Microsoft C. Added CR to the skipped character set. Added small
workaround for MSC compiler bug in g_scanner_cur_value.
* gstrfuncs.c:
Added the function g_strescape, which escapes the backslash
character. Needed especially when printing Windows filenames.
* gtimer.c:
Conditionalized inclusion of unistd.h and sys/time.h. Added
implementations for Windows.
* gutils.c:
Conditionalized inclusion of platform-dependent headers. Use
the platform-independent file name syntax macros.
Conditionalize code on platform-dependent features. Added the
functions g_path_is_absolute g_path_skip_root and g_getenv.
Added the GIOChannel-related functions. Added
compiler-dependent Unix compatibility functions for Windows.
* makefile.lcc makefile.msc:
New files. Compiler-specific makefiles for LCC-Win32 and
Microsoft C. Only Microsoft C is actually supported currently.
* testglib.c:
Added pathname check cases for Windows. Added workaround for
bug in the Microsoft runtime library. Improved some tests a bit.
Tue Oct 27 04:00:11 1998 Tim Janik <timj@gtk.org>
* testgmodule.c (main): changed the #ifdef WIN32 test to NATIVE_WIN32,
this needs to be more constistent throughout the code, do we go for
NATIVE_WIN32 or WIN32?
* gmodule.c (LibMain): special cased the #ifdef __LCC__ case for
NATIVE_WIN32, since lcc maybe used on other platforms as well.
* libgplugin_a.c (LibMain):
* libgplugin_b.c (LibMain):
likewise. not sure i like this special requirement for lcc in here.
* gmodule-dl.c (_g_module_build_path):
feature empty "" directories and prepend the module name with "lib".
* gmodule-dld.c (_g_module_build_path):
* gmodule-win32.c (_g_module_build_path):
feature empty "" directories.
* we need some more magic in the _g_module_build_path variants
so we don't append/prepend lib and .so, .sl or .dll for those names
that already contain it.
* applied patch from Tor Lillqvist for g_module_build_path() and
windows support.
1998-10-20: Tor Lillqvist <tml@iki.fi>
* gmodule/gmodule-win32.c:
New file.
* gmodule/gmodule.c gmodule/gmodule.h:
Added the funcion g_module_build_path that builds the path to
a module file, decorating the name according to the system's
conventions. Added the Windows implementation.
* gmodule/libgplugin_a.c gmodule/libgplugin_b.c:
Added LibMain for LCC-Win32.
* gmodule/testgmodule.c:
Handle Windows dll names.
1998-10-27 05:11:34 +01:00
|
|
|
the %10000.10000f format... */
|
2002-10-16 00:16:57 +02:00
|
|
|
g_string_printf (string2, "%s|%0100d|%s|%s|%0*d|%*.*f|%10000.10000f",
|
|
|
|
"this pete guy sure is a wuss, like he's the number ",
|
|
|
|
1,
|
|
|
|
" wuss. everyone agrees.\n",
|
|
|
|
string1->str,
|
|
|
|
10, 666, 15, 15, 666.666666666, 666.666666666);
|
removed dummy structure definitions for struct _GCache, _GTree, _GTimer,
Tue Oct 27 03:00:50 1998 Tim Janik <timj@gtk.org>
* glib.h: removed dummy structure definitions for struct _GCache,
_GTree, _GTimer, _GMemChunk, _GListAllocator and _GStringChunk.
* gutils.c: implement glib's inline functions _after_ all include
statements have been processed.
removed Tor's MAXPATHLEN check since there already was one supplied
further down in this file.
(LibMain): special cased the #ifdef __LCC__ case for NATIVE_WIN32,
since lcc maybe used on other platforms as well. why in hell is this
stuff required?
(g_get_any_init): for windows, if the user name is supplied, use it as
realname also.
in general, if there is no homedir specified, use the tmpdir that
we already figured.
* gtimer.c (g_timer_elapsed): changed a g_assert() statement to
g_return_if_fail().
* applied glib-tml-981020-0.patch for WIN32 portability, added some
comments and g_return_if_fail() statements, minor indentation fixes.
ChangeLog entry from Tor Lillqvist is appended.
* glib.h (struct dirent): use lower case structure members.
* glib.h:
* makefile.lcc:
* makefile.msc:
s/COMPILING_GLIB/GLIB_COMPILATION/
1998-10-20: Tor Lillqvist <tml@iki.fi>
* README.win32 glib.def gmodule.def
* glibconfig.h.win32 gmodule/gmoduleconf.h.win32:
New files for the Windows port. The .def files list exported
symbols for the Microsoft linker and compatibles.
* configure.in:
Added checks for some platform-dependent headers: pwd.h sys/param.h
sys/select.h sys/time.h sys/times.h unistd.h, and the function lstat.
* gerror.c:
Conditionalized inclusion of system-dependent headers. Changes
for Windows: no gdb to do a stack trace. Just call abort().
* glib.h:
Changes for Windows:
Added macros G_DIR_SEPARATOR, G_DIR_SEPARATOR_S for
platform-dependent file name syntax elements. Added macros
G_SEARCHPATH_SEPARATOR, G_SEARCHPATH_SEPARATOR_S for
platform-dependent search path syntax conventions.
Added pragmas for Microsoft C to make it more pedantic.
Marked GLib's global variables for export from DLL.
Added the function g_strescape that escapes backslashes.
Added functions g_path_is_absolute and g_path_skip_root to
handle platform-dependent file name syntax.
Added the function g_getenv that expands environment variables
that contain references to other environment variables, as is
typical on Windows NT.
Added the GIOChannel structure which is used to encapsulate the
IPC mechanism used by the GIMP's plug-ins, and possibly other
things later. On Unix a GIOChannel encapsulates just a file
descriptor. On Windows it contains a file handle from _pipe() and a
few other things related to the implementation of gdk_input_add
and GIMP plug-in communication. Subject to change.
Removed duplicate declarations of the version variables.
For the Microsoft compiler, declare own implementation of
ftruncate and the <dirent.h> functions.
* gmem.c:
Define a symbolic name for the profiling table size.
* gmessages.c:
Conditionalized inclusion of unistd.h. On Windows, output using
stdio to stdout.
* gscanner.c:
Conditionalized inclusion of unistd.h. Added changes for
Microsoft C. Added CR to the skipped character set. Added small
workaround for MSC compiler bug in g_scanner_cur_value.
* gstrfuncs.c:
Added the function g_strescape, which escapes the backslash
character. Needed especially when printing Windows filenames.
* gtimer.c:
Conditionalized inclusion of unistd.h and sys/time.h. Added
implementations for Windows.
* gutils.c:
Conditionalized inclusion of platform-dependent headers. Use
the platform-independent file name syntax macros.
Conditionalize code on platform-dependent features. Added the
functions g_path_is_absolute g_path_skip_root and g_getenv.
Added the GIOChannel-related functions. Added
compiler-dependent Unix compatibility functions for Windows.
* makefile.lcc makefile.msc:
New files. Compiler-specific makefiles for LCC-Win32 and
Microsoft C. Only Microsoft C is actually supported currently.
* testglib.c:
Added pathname check cases for Windows. Added workaround for
bug in the Microsoft runtime library. Improved some tests a bit.
Tue Oct 27 04:00:11 1998 Tim Janik <timj@gtk.org>
* testgmodule.c (main): changed the #ifdef WIN32 test to NATIVE_WIN32,
this needs to be more constistent throughout the code, do we go for
NATIVE_WIN32 or WIN32?
* gmodule.c (LibMain): special cased the #ifdef __LCC__ case for
NATIVE_WIN32, since lcc maybe used on other platforms as well.
* libgplugin_a.c (LibMain):
* libgplugin_b.c (LibMain):
likewise. not sure i like this special requirement for lcc in here.
* gmodule-dl.c (_g_module_build_path):
feature empty "" directories and prepend the module name with "lib".
* gmodule-dld.c (_g_module_build_path):
* gmodule-win32.c (_g_module_build_path):
feature empty "" directories.
* we need some more magic in the _g_module_build_path variants
so we don't append/prepend lib and .so, .sl or .dll for those names
that already contain it.
* applied patch from Tor Lillqvist for g_module_build_path() and
windows support.
1998-10-20: Tor Lillqvist <tml@iki.fi>
* gmodule/gmodule-win32.c:
New file.
* gmodule/gmodule.c gmodule/gmodule.h:
Added the funcion g_module_build_path that builds the path to
a module file, decorating the name according to the system's
conventions. Added the Windows implementation.
* gmodule/libgplugin_a.c gmodule/libgplugin_b.c:
Added LibMain for LCC-Win32.
* gmodule/testgmodule.c:
Handle Windows dll names.
1998-10-27 05:11:34 +01:00
|
|
|
#else
|
2002-10-16 00:16:57 +02:00
|
|
|
g_string_printf (string2, "%s|%0100d|%s|%s|%0*d|%*.*f|%100.100f",
|
|
|
|
"this pete guy sure is a wuss, like he's the number ",
|
|
|
|
1,
|
|
|
|
" wuss. everyone agrees.\n",
|
|
|
|
string1->str,
|
|
|
|
10, 666, 15, 15, 666.666666666, 666.666666666);
|
removed dummy structure definitions for struct _GCache, _GTree, _GTimer,
Tue Oct 27 03:00:50 1998 Tim Janik <timj@gtk.org>
* glib.h: removed dummy structure definitions for struct _GCache,
_GTree, _GTimer, _GMemChunk, _GListAllocator and _GStringChunk.
* gutils.c: implement glib's inline functions _after_ all include
statements have been processed.
removed Tor's MAXPATHLEN check since there already was one supplied
further down in this file.
(LibMain): special cased the #ifdef __LCC__ case for NATIVE_WIN32,
since lcc maybe used on other platforms as well. why in hell is this
stuff required?
(g_get_any_init): for windows, if the user name is supplied, use it as
realname also.
in general, if there is no homedir specified, use the tmpdir that
we already figured.
* gtimer.c (g_timer_elapsed): changed a g_assert() statement to
g_return_if_fail().
* applied glib-tml-981020-0.patch for WIN32 portability, added some
comments and g_return_if_fail() statements, minor indentation fixes.
ChangeLog entry from Tor Lillqvist is appended.
* glib.h (struct dirent): use lower case structure members.
* glib.h:
* makefile.lcc:
* makefile.msc:
s/COMPILING_GLIB/GLIB_COMPILATION/
1998-10-20: Tor Lillqvist <tml@iki.fi>
* README.win32 glib.def gmodule.def
* glibconfig.h.win32 gmodule/gmoduleconf.h.win32:
New files for the Windows port. The .def files list exported
symbols for the Microsoft linker and compatibles.
* configure.in:
Added checks for some platform-dependent headers: pwd.h sys/param.h
sys/select.h sys/time.h sys/times.h unistd.h, and the function lstat.
* gerror.c:
Conditionalized inclusion of system-dependent headers. Changes
for Windows: no gdb to do a stack trace. Just call abort().
* glib.h:
Changes for Windows:
Added macros G_DIR_SEPARATOR, G_DIR_SEPARATOR_S for
platform-dependent file name syntax elements. Added macros
G_SEARCHPATH_SEPARATOR, G_SEARCHPATH_SEPARATOR_S for
platform-dependent search path syntax conventions.
Added pragmas for Microsoft C to make it more pedantic.
Marked GLib's global variables for export from DLL.
Added the function g_strescape that escapes backslashes.
Added functions g_path_is_absolute and g_path_skip_root to
handle platform-dependent file name syntax.
Added the function g_getenv that expands environment variables
that contain references to other environment variables, as is
typical on Windows NT.
Added the GIOChannel structure which is used to encapsulate the
IPC mechanism used by the GIMP's plug-ins, and possibly other
things later. On Unix a GIOChannel encapsulates just a file
descriptor. On Windows it contains a file handle from _pipe() and a
few other things related to the implementation of gdk_input_add
and GIMP plug-in communication. Subject to change.
Removed duplicate declarations of the version variables.
For the Microsoft compiler, declare own implementation of
ftruncate and the <dirent.h> functions.
* gmem.c:
Define a symbolic name for the profiling table size.
* gmessages.c:
Conditionalized inclusion of unistd.h. On Windows, output using
stdio to stdout.
* gscanner.c:
Conditionalized inclusion of unistd.h. Added changes for
Microsoft C. Added CR to the skipped character set. Added small
workaround for MSC compiler bug in g_scanner_cur_value.
* gstrfuncs.c:
Added the function g_strescape, which escapes the backslash
character. Needed especially when printing Windows filenames.
* gtimer.c:
Conditionalized inclusion of unistd.h and sys/time.h. Added
implementations for Windows.
* gutils.c:
Conditionalized inclusion of platform-dependent headers. Use
the platform-independent file name syntax macros.
Conditionalize code on platform-dependent features. Added the
functions g_path_is_absolute g_path_skip_root and g_getenv.
Added the GIOChannel-related functions. Added
compiler-dependent Unix compatibility functions for Windows.
* makefile.lcc makefile.msc:
New files. Compiler-specific makefiles for LCC-Win32 and
Microsoft C. Only Microsoft C is actually supported currently.
* testglib.c:
Added pathname check cases for Windows. Added workaround for
bug in the Microsoft runtime library. Improved some tests a bit.
Tue Oct 27 04:00:11 1998 Tim Janik <timj@gtk.org>
* testgmodule.c (main): changed the #ifdef WIN32 test to NATIVE_WIN32,
this needs to be more constistent throughout the code, do we go for
NATIVE_WIN32 or WIN32?
* gmodule.c (LibMain): special cased the #ifdef __LCC__ case for
NATIVE_WIN32, since lcc maybe used on other platforms as well.
* libgplugin_a.c (LibMain):
* libgplugin_b.c (LibMain):
likewise. not sure i like this special requirement for lcc in here.
* gmodule-dl.c (_g_module_build_path):
feature empty "" directories and prepend the module name with "lib".
* gmodule-dld.c (_g_module_build_path):
* gmodule-win32.c (_g_module_build_path):
feature empty "" directories.
* we need some more magic in the _g_module_build_path variants
so we don't append/prepend lib and .so, .sl or .dll for those names
that already contain it.
* applied patch from Tor Lillqvist for g_module_build_path() and
windows support.
1998-10-20: Tor Lillqvist <tml@iki.fi>
* gmodule/gmodule-win32.c:
New file.
* gmodule/gmodule.c gmodule/gmodule.h:
Added the funcion g_module_build_path that builds the path to
a module file, decorating the name according to the system's
conventions. Added the Windows implementation.
* gmodule/libgplugin_a.c gmodule/libgplugin_b.c:
Added LibMain for LCC-Win32.
* gmodule/testgmodule.c:
Handle Windows dll names.
1998-10-27 05:11:34 +01:00
|
|
|
#endif
|
|
|
|
|
2007-12-12 16:09:08 +01:00
|
|
|
if (g_test_verbose())
|
|
|
|
g_print ("string2 length = %lu...\n", (gulong)string2->len);
|
removed dummy structure definitions for struct _GCache, _GTree, _GTimer,
Tue Oct 27 03:00:50 1998 Tim Janik <timj@gtk.org>
* glib.h: removed dummy structure definitions for struct _GCache,
_GTree, _GTimer, _GMemChunk, _GListAllocator and _GStringChunk.
* gutils.c: implement glib's inline functions _after_ all include
statements have been processed.
removed Tor's MAXPATHLEN check since there already was one supplied
further down in this file.
(LibMain): special cased the #ifdef __LCC__ case for NATIVE_WIN32,
since lcc maybe used on other platforms as well. why in hell is this
stuff required?
(g_get_any_init): for windows, if the user name is supplied, use it as
realname also.
in general, if there is no homedir specified, use the tmpdir that
we already figured.
* gtimer.c (g_timer_elapsed): changed a g_assert() statement to
g_return_if_fail().
* applied glib-tml-981020-0.patch for WIN32 portability, added some
comments and g_return_if_fail() statements, minor indentation fixes.
ChangeLog entry from Tor Lillqvist is appended.
* glib.h (struct dirent): use lower case structure members.
* glib.h:
* makefile.lcc:
* makefile.msc:
s/COMPILING_GLIB/GLIB_COMPILATION/
1998-10-20: Tor Lillqvist <tml@iki.fi>
* README.win32 glib.def gmodule.def
* glibconfig.h.win32 gmodule/gmoduleconf.h.win32:
New files for the Windows port. The .def files list exported
symbols for the Microsoft linker and compatibles.
* configure.in:
Added checks for some platform-dependent headers: pwd.h sys/param.h
sys/select.h sys/time.h sys/times.h unistd.h, and the function lstat.
* gerror.c:
Conditionalized inclusion of system-dependent headers. Changes
for Windows: no gdb to do a stack trace. Just call abort().
* glib.h:
Changes for Windows:
Added macros G_DIR_SEPARATOR, G_DIR_SEPARATOR_S for
platform-dependent file name syntax elements. Added macros
G_SEARCHPATH_SEPARATOR, G_SEARCHPATH_SEPARATOR_S for
platform-dependent search path syntax conventions.
Added pragmas for Microsoft C to make it more pedantic.
Marked GLib's global variables for export from DLL.
Added the function g_strescape that escapes backslashes.
Added functions g_path_is_absolute and g_path_skip_root to
handle platform-dependent file name syntax.
Added the function g_getenv that expands environment variables
that contain references to other environment variables, as is
typical on Windows NT.
Added the GIOChannel structure which is used to encapsulate the
IPC mechanism used by the GIMP's plug-ins, and possibly other
things later. On Unix a GIOChannel encapsulates just a file
descriptor. On Windows it contains a file handle from _pipe() and a
few other things related to the implementation of gdk_input_add
and GIMP plug-in communication. Subject to change.
Removed duplicate declarations of the version variables.
For the Microsoft compiler, declare own implementation of
ftruncate and the <dirent.h> functions.
* gmem.c:
Define a symbolic name for the profiling table size.
* gmessages.c:
Conditionalized inclusion of unistd.h. On Windows, output using
stdio to stdout.
* gscanner.c:
Conditionalized inclusion of unistd.h. Added changes for
Microsoft C. Added CR to the skipped character set. Added small
workaround for MSC compiler bug in g_scanner_cur_value.
* gstrfuncs.c:
Added the function g_strescape, which escapes the backslash
character. Needed especially when printing Windows filenames.
* gtimer.c:
Conditionalized inclusion of unistd.h and sys/time.h. Added
implementations for Windows.
* gutils.c:
Conditionalized inclusion of platform-dependent headers. Use
the platform-independent file name syntax macros.
Conditionalize code on platform-dependent features. Added the
functions g_path_is_absolute g_path_skip_root and g_getenv.
Added the GIOChannel-related functions. Added
compiler-dependent Unix compatibility functions for Windows.
* makefile.lcc makefile.msc:
New files. Compiler-specific makefiles for LCC-Win32 and
Microsoft C. Only Microsoft C is actually supported currently.
* testglib.c:
Added pathname check cases for Windows. Added workaround for
bug in the Microsoft runtime library. Improved some tests a bit.
Tue Oct 27 04:00:11 1998 Tim Janik <timj@gtk.org>
* testgmodule.c (main): changed the #ifdef WIN32 test to NATIVE_WIN32,
this needs to be more constistent throughout the code, do we go for
NATIVE_WIN32 or WIN32?
* gmodule.c (LibMain): special cased the #ifdef __LCC__ case for
NATIVE_WIN32, since lcc maybe used on other platforms as well.
* libgplugin_a.c (LibMain):
* libgplugin_b.c (LibMain):
likewise. not sure i like this special requirement for lcc in here.
* gmodule-dl.c (_g_module_build_path):
feature empty "" directories and prepend the module name with "lib".
* gmodule-dld.c (_g_module_build_path):
* gmodule-win32.c (_g_module_build_path):
feature empty "" directories.
* we need some more magic in the _g_module_build_path variants
so we don't append/prepend lib and .so, .sl or .dll for those names
that already contain it.
* applied patch from Tor Lillqvist for g_module_build_path() and
windows support.
1998-10-20: Tor Lillqvist <tml@iki.fi>
* gmodule/gmodule-win32.c:
New file.
* gmodule/gmodule.c gmodule/gmodule.h:
Added the funcion g_module_build_path that builds the path to
a module file, decorating the name according to the system's
conventions. Added the Windows implementation.
* gmodule/libgplugin_a.c gmodule/libgplugin_b.c:
Added LibMain for LCC-Win32.
* gmodule/testgmodule.c:
Handle Windows dll names.
1998-10-27 05:11:34 +01:00
|
|
|
string2->str[70] = '\0';
|
2007-12-12 16:09:08 +01:00
|
|
|
if (g_test_verbose())
|
|
|
|
g_print ("first 70 chars:\n%s\n", string2->str);
|
removed dummy structure definitions for struct _GCache, _GTree, _GTimer,
Tue Oct 27 03:00:50 1998 Tim Janik <timj@gtk.org>
* glib.h: removed dummy structure definitions for struct _GCache,
_GTree, _GTimer, _GMemChunk, _GListAllocator and _GStringChunk.
* gutils.c: implement glib's inline functions _after_ all include
statements have been processed.
removed Tor's MAXPATHLEN check since there already was one supplied
further down in this file.
(LibMain): special cased the #ifdef __LCC__ case for NATIVE_WIN32,
since lcc maybe used on other platforms as well. why in hell is this
stuff required?
(g_get_any_init): for windows, if the user name is supplied, use it as
realname also.
in general, if there is no homedir specified, use the tmpdir that
we already figured.
* gtimer.c (g_timer_elapsed): changed a g_assert() statement to
g_return_if_fail().
* applied glib-tml-981020-0.patch for WIN32 portability, added some
comments and g_return_if_fail() statements, minor indentation fixes.
ChangeLog entry from Tor Lillqvist is appended.
* glib.h (struct dirent): use lower case structure members.
* glib.h:
* makefile.lcc:
* makefile.msc:
s/COMPILING_GLIB/GLIB_COMPILATION/
1998-10-20: Tor Lillqvist <tml@iki.fi>
* README.win32 glib.def gmodule.def
* glibconfig.h.win32 gmodule/gmoduleconf.h.win32:
New files for the Windows port. The .def files list exported
symbols for the Microsoft linker and compatibles.
* configure.in:
Added checks for some platform-dependent headers: pwd.h sys/param.h
sys/select.h sys/time.h sys/times.h unistd.h, and the function lstat.
* gerror.c:
Conditionalized inclusion of system-dependent headers. Changes
for Windows: no gdb to do a stack trace. Just call abort().
* glib.h:
Changes for Windows:
Added macros G_DIR_SEPARATOR, G_DIR_SEPARATOR_S for
platform-dependent file name syntax elements. Added macros
G_SEARCHPATH_SEPARATOR, G_SEARCHPATH_SEPARATOR_S for
platform-dependent search path syntax conventions.
Added pragmas for Microsoft C to make it more pedantic.
Marked GLib's global variables for export from DLL.
Added the function g_strescape that escapes backslashes.
Added functions g_path_is_absolute and g_path_skip_root to
handle platform-dependent file name syntax.
Added the function g_getenv that expands environment variables
that contain references to other environment variables, as is
typical on Windows NT.
Added the GIOChannel structure which is used to encapsulate the
IPC mechanism used by the GIMP's plug-ins, and possibly other
things later. On Unix a GIOChannel encapsulates just a file
descriptor. On Windows it contains a file handle from _pipe() and a
few other things related to the implementation of gdk_input_add
and GIMP plug-in communication. Subject to change.
Removed duplicate declarations of the version variables.
For the Microsoft compiler, declare own implementation of
ftruncate and the <dirent.h> functions.
* gmem.c:
Define a symbolic name for the profiling table size.
* gmessages.c:
Conditionalized inclusion of unistd.h. On Windows, output using
stdio to stdout.
* gscanner.c:
Conditionalized inclusion of unistd.h. Added changes for
Microsoft C. Added CR to the skipped character set. Added small
workaround for MSC compiler bug in g_scanner_cur_value.
* gstrfuncs.c:
Added the function g_strescape, which escapes the backslash
character. Needed especially when printing Windows filenames.
* gtimer.c:
Conditionalized inclusion of unistd.h and sys/time.h. Added
implementations for Windows.
* gutils.c:
Conditionalized inclusion of platform-dependent headers. Use
the platform-independent file name syntax macros.
Conditionalize code on platform-dependent features. Added the
functions g_path_is_absolute g_path_skip_root and g_getenv.
Added the GIOChannel-related functions. Added
compiler-dependent Unix compatibility functions for Windows.
* makefile.lcc makefile.msc:
New files. Compiler-specific makefiles for LCC-Win32 and
Microsoft C. Only Microsoft C is actually supported currently.
* testglib.c:
Added pathname check cases for Windows. Added workaround for
bug in the Microsoft runtime library. Improved some tests a bit.
Tue Oct 27 04:00:11 1998 Tim Janik <timj@gtk.org>
* testgmodule.c (main): changed the #ifdef WIN32 test to NATIVE_WIN32,
this needs to be more constistent throughout the code, do we go for
NATIVE_WIN32 or WIN32?
* gmodule.c (LibMain): special cased the #ifdef __LCC__ case for
NATIVE_WIN32, since lcc maybe used on other platforms as well.
* libgplugin_a.c (LibMain):
* libgplugin_b.c (LibMain):
likewise. not sure i like this special requirement for lcc in here.
* gmodule-dl.c (_g_module_build_path):
feature empty "" directories and prepend the module name with "lib".
* gmodule-dld.c (_g_module_build_path):
* gmodule-win32.c (_g_module_build_path):
feature empty "" directories.
* we need some more magic in the _g_module_build_path variants
so we don't append/prepend lib and .so, .sl or .dll for those names
that already contain it.
* applied patch from Tor Lillqvist for g_module_build_path() and
windows support.
1998-10-20: Tor Lillqvist <tml@iki.fi>
* gmodule/gmodule-win32.c:
New file.
* gmodule/gmodule.c gmodule/gmodule.h:
Added the funcion g_module_build_path that builds the path to
a module file, decorating the name according to the system's
conventions. Added the Windows implementation.
* gmodule/libgplugin_a.c gmodule/libgplugin_b.c:
Added LibMain for LCC-Win32.
* gmodule/testgmodule.c:
Handle Windows dll names.
1998-10-27 05:11:34 +01:00
|
|
|
string2->str[141] = '\0';
|
2007-12-12 16:09:08 +01:00
|
|
|
if (g_test_verbose())
|
|
|
|
g_print ("next 70 chars:\n%s\n", string2->str+71);
|
removed dummy structure definitions for struct _GCache, _GTree, _GTimer,
Tue Oct 27 03:00:50 1998 Tim Janik <timj@gtk.org>
* glib.h: removed dummy structure definitions for struct _GCache,
_GTree, _GTimer, _GMemChunk, _GListAllocator and _GStringChunk.
* gutils.c: implement glib's inline functions _after_ all include
statements have been processed.
removed Tor's MAXPATHLEN check since there already was one supplied
further down in this file.
(LibMain): special cased the #ifdef __LCC__ case for NATIVE_WIN32,
since lcc maybe used on other platforms as well. why in hell is this
stuff required?
(g_get_any_init): for windows, if the user name is supplied, use it as
realname also.
in general, if there is no homedir specified, use the tmpdir that
we already figured.
* gtimer.c (g_timer_elapsed): changed a g_assert() statement to
g_return_if_fail().
* applied glib-tml-981020-0.patch for WIN32 portability, added some
comments and g_return_if_fail() statements, minor indentation fixes.
ChangeLog entry from Tor Lillqvist is appended.
* glib.h (struct dirent): use lower case structure members.
* glib.h:
* makefile.lcc:
* makefile.msc:
s/COMPILING_GLIB/GLIB_COMPILATION/
1998-10-20: Tor Lillqvist <tml@iki.fi>
* README.win32 glib.def gmodule.def
* glibconfig.h.win32 gmodule/gmoduleconf.h.win32:
New files for the Windows port. The .def files list exported
symbols for the Microsoft linker and compatibles.
* configure.in:
Added checks for some platform-dependent headers: pwd.h sys/param.h
sys/select.h sys/time.h sys/times.h unistd.h, and the function lstat.
* gerror.c:
Conditionalized inclusion of system-dependent headers. Changes
for Windows: no gdb to do a stack trace. Just call abort().
* glib.h:
Changes for Windows:
Added macros G_DIR_SEPARATOR, G_DIR_SEPARATOR_S for
platform-dependent file name syntax elements. Added macros
G_SEARCHPATH_SEPARATOR, G_SEARCHPATH_SEPARATOR_S for
platform-dependent search path syntax conventions.
Added pragmas for Microsoft C to make it more pedantic.
Marked GLib's global variables for export from DLL.
Added the function g_strescape that escapes backslashes.
Added functions g_path_is_absolute and g_path_skip_root to
handle platform-dependent file name syntax.
Added the function g_getenv that expands environment variables
that contain references to other environment variables, as is
typical on Windows NT.
Added the GIOChannel structure which is used to encapsulate the
IPC mechanism used by the GIMP's plug-ins, and possibly other
things later. On Unix a GIOChannel encapsulates just a file
descriptor. On Windows it contains a file handle from _pipe() and a
few other things related to the implementation of gdk_input_add
and GIMP plug-in communication. Subject to change.
Removed duplicate declarations of the version variables.
For the Microsoft compiler, declare own implementation of
ftruncate and the <dirent.h> functions.
* gmem.c:
Define a symbolic name for the profiling table size.
* gmessages.c:
Conditionalized inclusion of unistd.h. On Windows, output using
stdio to stdout.
* gscanner.c:
Conditionalized inclusion of unistd.h. Added changes for
Microsoft C. Added CR to the skipped character set. Added small
workaround for MSC compiler bug in g_scanner_cur_value.
* gstrfuncs.c:
Added the function g_strescape, which escapes the backslash
character. Needed especially when printing Windows filenames.
* gtimer.c:
Conditionalized inclusion of unistd.h and sys/time.h. Added
implementations for Windows.
* gutils.c:
Conditionalized inclusion of platform-dependent headers. Use
the platform-independent file name syntax macros.
Conditionalize code on platform-dependent features. Added the
functions g_path_is_absolute g_path_skip_root and g_getenv.
Added the GIOChannel-related functions. Added
compiler-dependent Unix compatibility functions for Windows.
* makefile.lcc makefile.msc:
New files. Compiler-specific makefiles for LCC-Win32 and
Microsoft C. Only Microsoft C is actually supported currently.
* testglib.c:
Added pathname check cases for Windows. Added workaround for
bug in the Microsoft runtime library. Improved some tests a bit.
Tue Oct 27 04:00:11 1998 Tim Janik <timj@gtk.org>
* testgmodule.c (main): changed the #ifdef WIN32 test to NATIVE_WIN32,
this needs to be more constistent throughout the code, do we go for
NATIVE_WIN32 or WIN32?
* gmodule.c (LibMain): special cased the #ifdef __LCC__ case for
NATIVE_WIN32, since lcc maybe used on other platforms as well.
* libgplugin_a.c (LibMain):
* libgplugin_b.c (LibMain):
likewise. not sure i like this special requirement for lcc in here.
* gmodule-dl.c (_g_module_build_path):
feature empty "" directories and prepend the module name with "lib".
* gmodule-dld.c (_g_module_build_path):
* gmodule-win32.c (_g_module_build_path):
feature empty "" directories.
* we need some more magic in the _g_module_build_path variants
so we don't append/prepend lib and .so, .sl or .dll for those names
that already contain it.
* applied patch from Tor Lillqvist for g_module_build_path() and
windows support.
1998-10-20: Tor Lillqvist <tml@iki.fi>
* gmodule/gmodule-win32.c:
New file.
* gmodule/gmodule.c gmodule/gmodule.h:
Added the funcion g_module_build_path that builds the path to
a module file, decorating the name according to the system's
conventions. Added the Windows implementation.
* gmodule/libgplugin_a.c gmodule/libgplugin_b.c:
Added LibMain for LCC-Win32.
* gmodule/testgmodule.c:
Handle Windows dll names.
1998-10-27 05:11:34 +01:00
|
|
|
string2->str[212] = '\0';
|
2007-12-12 16:09:08 +01:00
|
|
|
if (g_test_verbose())
|
|
|
|
g_print ("and next 70:\n%s\n", string2->str+142);
|
|
|
|
if (g_test_verbose())
|
|
|
|
g_print ("last 70 chars:\n%s\n", string2->str+string2->len - 70);
|
1998-06-11 01:21:14 +02:00
|
|
|
|
2000-02-17 12:57:35 +01:00
|
|
|
g_string_free (string1, TRUE);
|
|
|
|
g_string_free (string2, TRUE);
|
|
|
|
|
|
|
|
/* append */
|
|
|
|
string1 = g_string_new ("firsthalf");
|
|
|
|
g_string_append (string1, "lasthalf");
|
|
|
|
g_assert (strcmp (string1->str, "firsthalflasthalf") == 0);
|
|
|
|
g_string_free (string1, TRUE);
|
|
|
|
|
|
|
|
/* append_len */
|
|
|
|
string1 = g_string_new ("firsthalf");
|
|
|
|
g_string_append_len (string1, "lasthalfjunkjunk", strlen ("lasthalf"));
|
|
|
|
g_assert (strcmp (string1->str, "firsthalflasthalf") == 0);
|
2007-12-12 16:09:08 +01:00
|
|
|
g_string_free (string1, TRUE);
|
|
|
|
|
2000-02-17 12:57:35 +01:00
|
|
|
/* prepend */
|
|
|
|
string1 = g_string_new ("lasthalf");
|
|
|
|
g_string_prepend (string1, "firsthalf");
|
|
|
|
g_assert (strcmp (string1->str, "firsthalflasthalf") == 0);
|
|
|
|
g_string_free (string1, TRUE);
|
|
|
|
|
|
|
|
/* prepend_len */
|
|
|
|
string1 = g_string_new ("lasthalf");
|
|
|
|
g_string_prepend_len (string1, "firsthalfjunkjunk", strlen ("firsthalf"));
|
|
|
|
g_assert (strcmp (string1->str, "firsthalflasthalf") == 0);
|
|
|
|
g_string_free (string1, TRUE);
|
2007-12-12 16:09:08 +01:00
|
|
|
|
2000-02-17 12:57:35 +01:00
|
|
|
/* insert */
|
|
|
|
string1 = g_string_new ("firstlast");
|
|
|
|
g_string_insert (string1, 5, "middle");
|
|
|
|
g_assert (strcmp (string1->str, "firstmiddlelast") == 0);
|
|
|
|
g_string_free (string1, TRUE);
|
|
|
|
|
|
|
|
/* insert with pos == end of the string */
|
|
|
|
string1 = g_string_new ("firstmiddle");
|
|
|
|
g_string_insert (string1, strlen ("firstmiddle"), "last");
|
|
|
|
g_assert (strcmp (string1->str, "firstmiddlelast") == 0);
|
|
|
|
g_string_free (string1, TRUE);
|
|
|
|
|
2007-12-12 16:09:08 +01:00
|
|
|
/* insert_len */
|
2000-02-17 12:57:35 +01:00
|
|
|
string1 = g_string_new ("firstlast");
|
|
|
|
g_string_insert_len (string1, 5, "middlejunkjunk", strlen ("middle"));
|
|
|
|
g_assert (strcmp (string1->str, "firstmiddlelast") == 0);
|
|
|
|
g_string_free (string1, TRUE);
|
|
|
|
|
|
|
|
/* insert_len with magic -1 pos for append */
|
|
|
|
string1 = g_string_new ("first");
|
|
|
|
g_string_insert_len (string1, -1, "lastjunkjunk", strlen ("last"));
|
|
|
|
g_assert (strcmp (string1->str, "firstlast") == 0);
|
|
|
|
g_string_free (string1, TRUE);
|
2007-12-12 16:09:08 +01:00
|
|
|
|
2000-02-17 12:57:35 +01:00
|
|
|
/* insert_len with magic -1 len for strlen-the-string */
|
|
|
|
string1 = g_string_new ("first");
|
|
|
|
g_string_insert_len (string1, 5, "last", -1);
|
|
|
|
g_assert (strcmp (string1->str, "firstlast") == 0);
|
|
|
|
g_string_free (string1, TRUE);
|
1998-06-11 01:21:14 +02:00
|
|
|
|
2000-06-29 22:09:36 +02:00
|
|
|
/* g_string_equal */
|
|
|
|
string1 = g_string_new ("test");
|
|
|
|
string2 = g_string_new ("te");
|
|
|
|
g_assert (! g_string_equal(string1, string2));
|
|
|
|
g_string_append (string2, "st");
|
|
|
|
g_assert (g_string_equal(string1, string2));
|
|
|
|
g_string_free (string1, TRUE);
|
|
|
|
g_string_free (string2, TRUE);
|
2007-12-12 16:09:08 +01:00
|
|
|
|
2000-06-29 22:09:36 +02:00
|
|
|
/* Check handling of embedded ASCII 0 (NUL) characters in GString. */
|
2007-12-12 16:09:08 +01:00
|
|
|
if (g_test_verbose())
|
|
|
|
g_print ("test embedded ASCII 0 (NUL) characters in GString\n");
|
2000-06-29 22:09:36 +02:00
|
|
|
string1 = g_string_new ("fiddle");
|
|
|
|
string2 = g_string_new ("fiddle");
|
|
|
|
g_assert (g_string_equal(string1, string2));
|
|
|
|
g_string_append_c(string1, '\0');
|
|
|
|
g_assert (! g_string_equal(string1, string2));
|
|
|
|
g_string_append_c(string2, '\0');
|
|
|
|
g_assert (g_string_equal(string1, string2));
|
|
|
|
g_string_append_c(string1, 'x');
|
|
|
|
g_string_append_c(string2, 'y');
|
|
|
|
g_assert (! g_string_equal(string1, string2));
|
|
|
|
g_assert (string1->len == 8);
|
|
|
|
g_string_append(string1, "yzzy");
|
|
|
|
g_assert (string1->len == 12);
|
|
|
|
g_assert ( memcmp(string1->str, "fiddle\0xyzzy", 13) == 0);
|
|
|
|
g_string_insert(string1, 1, "QED");
|
|
|
|
g_assert ( memcmp(string1->str, "fQEDiddle\0xyzzy", 16) == 0);
|
|
|
|
g_string_free (string1, TRUE);
|
|
|
|
g_string_free (string2, TRUE);
|
2007-12-12 16:09:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
various_string_tests (void)
|
|
|
|
{
|
|
|
|
GStringChunk *string_chunk;
|
|
|
|
GTimeVal ref_date, date;
|
|
|
|
gchar *tmp_string = NULL, *tmp_string_2, *string, *date_str;
|
|
|
|
guint i;
|
2010-06-09 10:23:39 +02:00
|
|
|
const gchar *tz;
|
2007-12-12 16:09:08 +01:00
|
|
|
|
|
|
|
if (g_test_verbose())
|
|
|
|
g_print ("checking string chunks...");
|
|
|
|
string_chunk = g_string_chunk_new (1024);
|
|
|
|
for (i = 0; i < 100000; i ++)
|
|
|
|
{
|
|
|
|
tmp_string = g_string_chunk_insert (string_chunk, "hi pete");
|
|
|
|
if (strcmp ("hi pete", tmp_string) != 0)
|
|
|
|
g_error ("string chunks are broken.\n");
|
|
|
|
}
|
|
|
|
tmp_string_2 = g_string_chunk_insert_const (string_chunk, tmp_string);
|
|
|
|
g_assert (tmp_string_2 != tmp_string && strcmp (tmp_string_2, tmp_string) == 0);
|
|
|
|
tmp_string = g_string_chunk_insert_const (string_chunk, tmp_string);
|
|
|
|
g_assert (tmp_string_2 == tmp_string);
|
|
|
|
g_string_chunk_free (string_chunk);
|
|
|
|
|
|
|
|
if (g_test_verbose())
|
|
|
|
g_print ("test positional printf formats (not supported):");
|
2000-09-08 01:08:25 +02:00
|
|
|
string = g_strdup_printf ("%.*s%s", 5, "a", "b");
|
|
|
|
tmp_string = g_strdup_printf ("%2$*1$s", 5, "c");
|
2007-12-12 16:09:08 +01:00
|
|
|
if (g_test_verbose())
|
|
|
|
g_print ("%s%s\n", string, tmp_string);
|
2000-09-08 01:08:25 +02:00
|
|
|
g_free (tmp_string);
|
|
|
|
g_free (string);
|
|
|
|
|
2008-06-19 06:14:25 +02:00
|
|
|
#define REF_INVALID1 "Wed Dec 19 17:20:20 GMT 2007"
|
|
|
|
#define REF_INVALID2 "1980-02-22T10:36:00Zulu"
|
2010-08-24 23:18:23 +02:00
|
|
|
#define REF_INVALID3 "1980-02-22T"
|
2008-06-19 06:14:25 +02:00
|
|
|
#define REF_SEC_UTC 320063760
|
|
|
|
#define REF_STR_UTC "1980-02-22T10:36:00Z"
|
2009-09-01 15:37:48 +02:00
|
|
|
#define REF_STR_LOCAL "1980-02-22T13:36:00"
|
2008-06-19 06:14:25 +02:00
|
|
|
#define REF_STR_CEST "1980-02-22T12:36:00+02:00"
|
|
|
|
#define REF_STR_EST "19800222T053600-0500"
|
2009-04-08 16:26:11 +02:00
|
|
|
#define REF_STR_NST "1980-02-22T07:06:00-03:30"
|
2008-06-19 06:14:25 +02:00
|
|
|
#define REF_USEC_UTC 50000
|
|
|
|
#define REF_STR_USEC_UTC "1980-02-22T10:36:00.050000Z"
|
|
|
|
#define REF_STR_USEC_CEST "19800222T123600.050000000+0200"
|
2009-04-08 16:26:11 +02:00
|
|
|
#define REF_STR_USEC_EST "1980-02-22T05:36:00,05-05:00"
|
|
|
|
#define REF_STR_USEC_NST "19800222T070600,0500-0330"
|
2010-08-24 23:18:23 +02:00
|
|
|
#define REF_STR_DATE_ONLY "1980-02-22"
|
2006-03-23 03:54:29 +01:00
|
|
|
|
2007-12-12 16:09:08 +01:00
|
|
|
if (g_test_verbose())
|
|
|
|
g_print ("checking g_time_val_from_iso8601...\n");
|
2006-03-23 03:54:29 +01:00
|
|
|
ref_date.tv_sec = REF_SEC_UTC;
|
|
|
|
ref_date.tv_usec = 0;
|
2008-06-19 06:14:25 +02:00
|
|
|
g_assert (g_time_val_from_iso8601 (REF_INVALID1, &date) == FALSE);
|
|
|
|
g_assert (g_time_val_from_iso8601 (REF_INVALID2, &date) == FALSE);
|
2010-08-24 23:18:23 +02:00
|
|
|
g_assert (g_time_val_from_iso8601 (REF_INVALID3, &date) == FALSE);
|
|
|
|
g_assert (g_time_val_from_iso8601 (REF_STR_DATE_ONLY, &date) != FALSE);
|
2006-03-23 03:54:29 +01:00
|
|
|
g_assert (g_time_val_from_iso8601 (REF_STR_UTC, &date) != FALSE);
|
2007-12-12 16:09:08 +01:00
|
|
|
if (g_test_verbose())
|
2008-06-19 06:14:25 +02:00
|
|
|
g_print ("\t=> UTC stamp = %ld.%06ld (should be: %ld.%06ld) (%ld.%06ld off)\n",
|
|
|
|
date.tv_sec, date.tv_usec, ref_date.tv_sec, ref_date.tv_usec,
|
|
|
|
date.tv_sec - ref_date.tv_sec, date.tv_usec - ref_date.tv_usec);
|
|
|
|
g_assert (date.tv_sec == ref_date.tv_sec && date.tv_usec == ref_date.tv_usec);
|
2006-03-23 03:54:29 +01:00
|
|
|
|
2009-09-01 15:37:48 +02:00
|
|
|
/* predefine time zone */
|
|
|
|
tz = g_getenv("TZ");
|
|
|
|
g_setenv("TZ", "UTC-03:00", 1);
|
|
|
|
tzset();
|
|
|
|
|
|
|
|
g_assert (g_time_val_from_iso8601 (REF_STR_LOCAL, &date) != FALSE);
|
|
|
|
if (g_test_verbose())
|
|
|
|
g_print ("\t=> LOCAL stamp = %ld.%06ld (should be: %ld.%06ld) (%ld.%06ld off)\n",
|
|
|
|
date.tv_sec, date.tv_usec, ref_date.tv_sec, ref_date.tv_usec,
|
|
|
|
date.tv_sec - ref_date.tv_sec, date.tv_usec - ref_date.tv_usec);
|
|
|
|
g_assert (date.tv_sec == ref_date.tv_sec && date.tv_usec == ref_date.tv_usec);
|
|
|
|
|
|
|
|
/* revert back user defined time zone */
|
|
|
|
if (tz)
|
|
|
|
g_setenv("TZ", tz, TRUE);
|
|
|
|
else
|
|
|
|
g_unsetenv("TZ");
|
|
|
|
tzset();
|
|
|
|
|
2006-03-23 03:54:29 +01:00
|
|
|
g_assert (g_time_val_from_iso8601 (REF_STR_CEST, &date) != FALSE);
|
2007-12-12 16:09:08 +01:00
|
|
|
if (g_test_verbose())
|
2008-06-19 06:14:25 +02:00
|
|
|
g_print ("\t=> CEST stamp = %ld.%06ld (should be: %ld.%06ld) (%ld.%06ld off)\n",
|
|
|
|
date.tv_sec, date.tv_usec, ref_date.tv_sec, ref_date.tv_usec,
|
|
|
|
date.tv_sec - ref_date.tv_sec, date.tv_usec - ref_date.tv_usec);
|
|
|
|
g_assert (date.tv_sec == ref_date.tv_sec && date.tv_usec == ref_date.tv_usec);
|
2007-12-12 16:09:08 +01:00
|
|
|
|
2006-03-23 03:54:29 +01:00
|
|
|
g_assert (g_time_val_from_iso8601 (REF_STR_EST, &date) != FALSE);
|
2007-12-12 16:09:08 +01:00
|
|
|
if (g_test_verbose())
|
2008-06-19 06:14:25 +02:00
|
|
|
g_print ("\t=> EST stamp = %ld.%06ld (should be: %ld.%06ld) (%ld.%06ld off)\n",
|
|
|
|
date.tv_sec, date.tv_usec, ref_date.tv_sec, ref_date.tv_usec,
|
|
|
|
date.tv_sec - ref_date.tv_sec, date.tv_usec - ref_date.tv_usec);
|
|
|
|
g_assert (date.tv_sec == ref_date.tv_sec && date.tv_usec == ref_date.tv_usec);
|
|
|
|
|
2009-04-08 16:26:11 +02:00
|
|
|
g_assert (g_time_val_from_iso8601 (REF_STR_NST, &date) != FALSE);
|
|
|
|
if (g_test_verbose())
|
|
|
|
g_print ("\t=> NST stamp = %ld.%06ld (should be: %ld.%06ld) (%ld.%06ld off)\n",
|
|
|
|
date.tv_sec, date.tv_usec, ref_date.tv_sec, ref_date.tv_usec,
|
|
|
|
date.tv_sec - ref_date.tv_sec, date.tv_usec - ref_date.tv_usec);
|
|
|
|
g_assert (date.tv_sec == ref_date.tv_sec && date.tv_usec == ref_date.tv_usec);
|
|
|
|
|
2008-06-19 06:14:25 +02:00
|
|
|
ref_date.tv_usec = REF_USEC_UTC;
|
|
|
|
g_assert (g_time_val_from_iso8601 (REF_STR_USEC_UTC, &date) != FALSE);
|
|
|
|
if (g_test_verbose())
|
|
|
|
g_print ("\t=> UTC stamp = %ld.%06ld (should be: %ld.%06ld) (%ld.%06ld off)\n",
|
|
|
|
date.tv_sec, date.tv_usec, ref_date.tv_sec, ref_date.tv_usec,
|
|
|
|
date.tv_sec - ref_date.tv_sec, date.tv_usec - ref_date.tv_usec);
|
|
|
|
g_assert (date.tv_sec == ref_date.tv_sec && date.tv_usec == ref_date.tv_usec);
|
|
|
|
|
|
|
|
g_assert (g_time_val_from_iso8601 (REF_STR_USEC_CEST, &date) != FALSE);
|
|
|
|
if (g_test_verbose())
|
|
|
|
g_print ("\t=> CEST stamp = %ld.%06ld (should be: %ld.%06ld) (%ld.%06ld off)\n",
|
|
|
|
date.tv_sec, date.tv_usec, ref_date.tv_sec, ref_date.tv_usec,
|
|
|
|
date.tv_sec - ref_date.tv_sec, date.tv_usec - ref_date.tv_usec);
|
|
|
|
g_assert (date.tv_sec == ref_date.tv_sec && date.tv_usec == ref_date.tv_usec);
|
|
|
|
|
|
|
|
g_assert (g_time_val_from_iso8601 (REF_STR_USEC_EST, &date) != FALSE);
|
|
|
|
if (g_test_verbose())
|
|
|
|
g_print ("\t=> EST stamp = %ld.%06ld (should be: %ld.%06ld) (%ld.%06ld off)\n",
|
|
|
|
date.tv_sec, date.tv_usec, ref_date.tv_sec, ref_date.tv_usec,
|
|
|
|
date.tv_sec - ref_date.tv_sec, date.tv_usec - ref_date.tv_usec);
|
|
|
|
g_assert (date.tv_sec == ref_date.tv_sec && date.tv_usec == ref_date.tv_usec);
|
2009-04-08 16:26:11 +02:00
|
|
|
|
|
|
|
g_assert (g_time_val_from_iso8601 (REF_STR_USEC_NST, &date) != FALSE);
|
|
|
|
if (g_test_verbose())
|
|
|
|
g_print ("\t=> NST stamp = %ld.%06ld (should be: %ld.%06ld) (%ld.%06ld off)\n",
|
|
|
|
date.tv_sec, date.tv_usec, ref_date.tv_sec, ref_date.tv_usec,
|
|
|
|
date.tv_sec - ref_date.tv_sec, date.tv_usec - ref_date.tv_usec);
|
|
|
|
g_assert (date.tv_sec == ref_date.tv_sec && date.tv_usec == ref_date.tv_usec);
|
2007-12-12 16:09:08 +01:00
|
|
|
|
|
|
|
if (g_test_verbose())
|
|
|
|
g_print ("checking g_time_val_to_iso8601...\n");
|
2006-03-23 03:54:29 +01:00
|
|
|
ref_date.tv_sec = REF_SEC_UTC;
|
2008-06-19 06:14:25 +02:00
|
|
|
ref_date.tv_usec = 0;
|
2006-03-23 03:54:29 +01:00
|
|
|
date_str = g_time_val_to_iso8601 (&ref_date);
|
|
|
|
g_assert (date_str != NULL);
|
2007-12-12 16:09:08 +01:00
|
|
|
if (g_test_verbose())
|
|
|
|
g_print ("\t=> date string = %s (should be: %s)\n", date_str, REF_STR_UTC);
|
2006-03-23 03:54:29 +01:00
|
|
|
g_assert (strcmp (date_str, REF_STR_UTC) == 0);
|
|
|
|
g_free (date_str);
|
|
|
|
|
2008-06-19 06:14:25 +02:00
|
|
|
ref_date.tv_usec = REF_USEC_UTC;
|
|
|
|
date_str = g_time_val_to_iso8601 (&ref_date);
|
|
|
|
g_assert (date_str != NULL);
|
|
|
|
if (g_test_verbose())
|
|
|
|
g_print ("\t=> date string = %s (should be: %s)\n", date_str, REF_STR_USEC_UTC);
|
|
|
|
g_assert (strcmp (date_str, REF_STR_USEC_UTC) == 0);
|
|
|
|
g_free (date_str);
|
|
|
|
|
2007-12-12 16:09:08 +01:00
|
|
|
if (g_test_verbose())
|
|
|
|
g_print ("checking g_ascii_strcasecmp...");
|
2001-06-30 18:54:33 +02:00
|
|
|
g_assert (g_ascii_strcasecmp ("FroboZZ", "frobozz") == 0);
|
|
|
|
g_assert (g_ascii_strcasecmp ("frobozz", "frobozz") == 0);
|
|
|
|
g_assert (g_ascii_strcasecmp ("frobozz", "FROBOZZ") == 0);
|
|
|
|
g_assert (g_ascii_strcasecmp ("FROBOZZ", "froboz") > 0);
|
|
|
|
g_assert (g_ascii_strcasecmp ("", "") == 0);
|
|
|
|
g_assert (g_ascii_strcasecmp ("!#%&/()", "!#%&/()") == 0);
|
|
|
|
g_assert (g_ascii_strcasecmp ("a", "b") < 0);
|
|
|
|
g_assert (g_ascii_strcasecmp ("a", "B") < 0);
|
|
|
|
g_assert (g_ascii_strcasecmp ("A", "b") < 0);
|
|
|
|
g_assert (g_ascii_strcasecmp ("A", "B") < 0);
|
|
|
|
g_assert (g_ascii_strcasecmp ("b", "a") > 0);
|
|
|
|
g_assert (g_ascii_strcasecmp ("b", "A") > 0);
|
|
|
|
g_assert (g_ascii_strcasecmp ("B", "a") > 0);
|
|
|
|
g_assert (g_ascii_strcasecmp ("B", "A") > 0);
|
removed dummy structure definitions for struct _GCache, _GTree, _GTimer,
Tue Oct 27 03:00:50 1998 Tim Janik <timj@gtk.org>
* glib.h: removed dummy structure definitions for struct _GCache,
_GTree, _GTimer, _GMemChunk, _GListAllocator and _GStringChunk.
* gutils.c: implement glib's inline functions _after_ all include
statements have been processed.
removed Tor's MAXPATHLEN check since there already was one supplied
further down in this file.
(LibMain): special cased the #ifdef __LCC__ case for NATIVE_WIN32,
since lcc maybe used on other platforms as well. why in hell is this
stuff required?
(g_get_any_init): for windows, if the user name is supplied, use it as
realname also.
in general, if there is no homedir specified, use the tmpdir that
we already figured.
* gtimer.c (g_timer_elapsed): changed a g_assert() statement to
g_return_if_fail().
* applied glib-tml-981020-0.patch for WIN32 portability, added some
comments and g_return_if_fail() statements, minor indentation fixes.
ChangeLog entry from Tor Lillqvist is appended.
* glib.h (struct dirent): use lower case structure members.
* glib.h:
* makefile.lcc:
* makefile.msc:
s/COMPILING_GLIB/GLIB_COMPILATION/
1998-10-20: Tor Lillqvist <tml@iki.fi>
* README.win32 glib.def gmodule.def
* glibconfig.h.win32 gmodule/gmoduleconf.h.win32:
New files for the Windows port. The .def files list exported
symbols for the Microsoft linker and compatibles.
* configure.in:
Added checks for some platform-dependent headers: pwd.h sys/param.h
sys/select.h sys/time.h sys/times.h unistd.h, and the function lstat.
* gerror.c:
Conditionalized inclusion of system-dependent headers. Changes
for Windows: no gdb to do a stack trace. Just call abort().
* glib.h:
Changes for Windows:
Added macros G_DIR_SEPARATOR, G_DIR_SEPARATOR_S for
platform-dependent file name syntax elements. Added macros
G_SEARCHPATH_SEPARATOR, G_SEARCHPATH_SEPARATOR_S for
platform-dependent search path syntax conventions.
Added pragmas for Microsoft C to make it more pedantic.
Marked GLib's global variables for export from DLL.
Added the function g_strescape that escapes backslashes.
Added functions g_path_is_absolute and g_path_skip_root to
handle platform-dependent file name syntax.
Added the function g_getenv that expands environment variables
that contain references to other environment variables, as is
typical on Windows NT.
Added the GIOChannel structure which is used to encapsulate the
IPC mechanism used by the GIMP's plug-ins, and possibly other
things later. On Unix a GIOChannel encapsulates just a file
descriptor. On Windows it contains a file handle from _pipe() and a
few other things related to the implementation of gdk_input_add
and GIMP plug-in communication. Subject to change.
Removed duplicate declarations of the version variables.
For the Microsoft compiler, declare own implementation of
ftruncate and the <dirent.h> functions.
* gmem.c:
Define a symbolic name for the profiling table size.
* gmessages.c:
Conditionalized inclusion of unistd.h. On Windows, output using
stdio to stdout.
* gscanner.c:
Conditionalized inclusion of unistd.h. Added changes for
Microsoft C. Added CR to the skipped character set. Added small
workaround for MSC compiler bug in g_scanner_cur_value.
* gstrfuncs.c:
Added the function g_strescape, which escapes the backslash
character. Needed especially when printing Windows filenames.
* gtimer.c:
Conditionalized inclusion of unistd.h and sys/time.h. Added
implementations for Windows.
* gutils.c:
Conditionalized inclusion of platform-dependent headers. Use
the platform-independent file name syntax macros.
Conditionalize code on platform-dependent features. Added the
functions g_path_is_absolute g_path_skip_root and g_getenv.
Added the GIOChannel-related functions. Added
compiler-dependent Unix compatibility functions for Windows.
* makefile.lcc makefile.msc:
New files. Compiler-specific makefiles for LCC-Win32 and
Microsoft C. Only Microsoft C is actually supported currently.
* testglib.c:
Added pathname check cases for Windows. Added workaround for
bug in the Microsoft runtime library. Improved some tests a bit.
Tue Oct 27 04:00:11 1998 Tim Janik <timj@gtk.org>
* testgmodule.c (main): changed the #ifdef WIN32 test to NATIVE_WIN32,
this needs to be more constistent throughout the code, do we go for
NATIVE_WIN32 or WIN32?
* gmodule.c (LibMain): special cased the #ifdef __LCC__ case for
NATIVE_WIN32, since lcc maybe used on other platforms as well.
* libgplugin_a.c (LibMain):
* libgplugin_b.c (LibMain):
likewise. not sure i like this special requirement for lcc in here.
* gmodule-dl.c (_g_module_build_path):
feature empty "" directories and prepend the module name with "lib".
* gmodule-dld.c (_g_module_build_path):
* gmodule-win32.c (_g_module_build_path):
feature empty "" directories.
* we need some more magic in the _g_module_build_path variants
so we don't append/prepend lib and .so, .sl or .dll for those names
that already contain it.
* applied patch from Tor Lillqvist for g_module_build_path() and
windows support.
1998-10-20: Tor Lillqvist <tml@iki.fi>
* gmodule/gmodule-win32.c:
New file.
* gmodule/gmodule.c gmodule/gmodule.h:
Added the funcion g_module_build_path that builds the path to
a module file, decorating the name according to the system's
conventions. Added the Windows implementation.
* gmodule/libgplugin_a.c gmodule/libgplugin_b.c:
Added LibMain for LCC-Win32.
* gmodule/testgmodule.c:
Handle Windows dll names.
1998-10-27 05:11:34 +01:00
|
|
|
|
2007-12-12 16:09:08 +01:00
|
|
|
if (g_test_verbose())
|
|
|
|
g_print ("checking g_strdup...\n");
|
|
|
|
g_assert (g_strdup (NULL) == NULL);
|
|
|
|
string = g_strdup (GLIB_TEST_STRING);
|
|
|
|
g_assert (string != NULL);
|
|
|
|
g_assert (strcmp(string, GLIB_TEST_STRING) == 0);
|
|
|
|
g_free (string);
|
1999-01-02 04:05:36 +01:00
|
|
|
|
2007-12-12 16:09:08 +01:00
|
|
|
if (g_test_verbose())
|
|
|
|
g_print ("checking g_strconcat...\n");
|
|
|
|
string = g_strconcat (GLIB_TEST_STRING, NULL);
|
|
|
|
g_assert (string != NULL);
|
|
|
|
g_assert (strcmp (string, GLIB_TEST_STRING) == 0);
|
|
|
|
g_free (string);
|
|
|
|
string = g_strconcat (GLIB_TEST_STRING, GLIB_TEST_STRING,
|
|
|
|
GLIB_TEST_STRING, NULL);
|
|
|
|
g_assert (string != NULL);
|
|
|
|
g_assert (strcmp (string, GLIB_TEST_STRING GLIB_TEST_STRING
|
|
|
|
GLIB_TEST_STRING) == 0);
|
|
|
|
g_free (string);
|
1999-01-02 04:05:36 +01:00
|
|
|
|
2007-12-12 16:09:08 +01:00
|
|
|
if (g_test_verbose())
|
|
|
|
g_print ("checking g_strlcpy/g_strlcat...");
|
added g_strlcat() and g_strlcpy() wrappers, supplied by David Wheeler
Wed Jul 26 05:47:48 2000 Tim Janik <timj@gtk.org>
* configure.in:
* testglib.c:
* gstrfuncs.c:
* glib.h: added g_strlcat() and g_strlcpy() wrappers, supplied by
David Wheeler <dwheeler@ida.org>:
* glib.h, gstrfuncs.c: added g_strlcpy and g_strlcat to support
safe manipulation of fixed-length string buffers.
These functions were originally developed by Todd Miller to simplify
development of security-related programs, and
are available on many (but not all) Unix-like systems,
including OpenBSD, FreeBSD, and Solaris. See
ftp://ftp.openbsd.org/pub/OpenBSD/src/lib/libc/string/strlcpy.3
and http://www.openbsd.org/security.html.
If there's a strlcpy/strlcat on the system, it's called, otherwise
an implementation is provided.
* testglib.c: Added tests for g_strlcpy, g_strlcat.
2000-07-26 05:51:07 +02:00
|
|
|
/* The following is a torture test for strlcpy/strlcat, with lots of
|
|
|
|
* checking; normal users wouldn't use them this way!
|
|
|
|
*/
|
|
|
|
string = g_malloc (6);
|
|
|
|
*(string + 5) = 'Z'; /* guard value, shouldn't change during test */
|
|
|
|
*string = 'q';
|
|
|
|
g_assert (g_strlcpy(string, "" , 5) == 0);
|
|
|
|
g_assert ( *string == '\0' );
|
|
|
|
*string = 'q';
|
|
|
|
g_assert (g_strlcpy(string, "abc" , 5) == 3);
|
|
|
|
g_assert ( *(string + 3) == '\0' );
|
|
|
|
g_assert (g_str_equal(string, "abc"));
|
|
|
|
g_assert (g_strlcpy(string, "abcd" , 5) == 4);
|
|
|
|
g_assert ( *(string + 4) == '\0' );
|
|
|
|
g_assert ( *(string + 5) == 'Z' );
|
|
|
|
g_assert (g_str_equal(string, "abcd"));
|
|
|
|
g_assert (g_strlcpy(string, "abcde" , 5) == 5);
|
|
|
|
g_assert ( *(string + 4) == '\0' );
|
|
|
|
g_assert ( *(string + 5) == 'Z' );
|
|
|
|
g_assert (g_str_equal(string, "abcd"));
|
|
|
|
g_assert (g_strlcpy(string, "abcdef" , 5) == 6);
|
|
|
|
g_assert ( *(string + 4) == '\0' );
|
|
|
|
g_assert ( *(string + 5) == 'Z' );
|
|
|
|
g_assert (g_str_equal(string, "abcd"));
|
|
|
|
*string = 'Y';
|
|
|
|
*(string + 1)= '\0';
|
|
|
|
g_assert (g_strlcpy(string, "Hello" , 0) == 5);
|
|
|
|
g_assert (*string == 'Y');
|
|
|
|
*string = '\0';
|
|
|
|
g_assert (g_strlcat(string, "123" , 5) == 3);
|
|
|
|
g_assert ( *(string + 3) == '\0' );
|
|
|
|
g_assert (g_str_equal(string, "123"));
|
|
|
|
g_assert (g_strlcat(string, "" , 5) == 3);
|
|
|
|
g_assert ( *(string + 3) == '\0' );
|
|
|
|
g_assert (g_str_equal(string, "123"));
|
|
|
|
g_assert (g_strlcat(string, "4", 5) == 4);
|
|
|
|
g_assert (g_str_equal(string, "1234"));
|
|
|
|
g_assert (g_strlcat(string, "5", 5) == 5);
|
|
|
|
g_assert ( *(string + 4) == '\0' );
|
|
|
|
g_assert (g_str_equal(string, "1234"));
|
|
|
|
g_assert ( *(string + 5) == 'Z' );
|
|
|
|
*string = 'Y';
|
|
|
|
*(string + 1)= '\0';
|
|
|
|
g_assert (g_strlcat(string, "123" , 0) == 3);
|
|
|
|
g_assert (*string == 'Y');
|
2007-12-12 16:09:08 +01:00
|
|
|
|
added g_strlcat() and g_strlcpy() wrappers, supplied by David Wheeler
Wed Jul 26 05:47:48 2000 Tim Janik <timj@gtk.org>
* configure.in:
* testglib.c:
* gstrfuncs.c:
* glib.h: added g_strlcat() and g_strlcpy() wrappers, supplied by
David Wheeler <dwheeler@ida.org>:
* glib.h, gstrfuncs.c: added g_strlcpy and g_strlcat to support
safe manipulation of fixed-length string buffers.
These functions were originally developed by Todd Miller to simplify
development of security-related programs, and
are available on many (but not all) Unix-like systems,
including OpenBSD, FreeBSD, and Solaris. See
ftp://ftp.openbsd.org/pub/OpenBSD/src/lib/libc/string/strlcpy.3
and http://www.openbsd.org/security.html.
If there's a strlcpy/strlcat on the system, it's called, otherwise
an implementation is provided.
* testglib.c: Added tests for g_strlcpy, g_strlcat.
2000-07-26 05:51:07 +02:00
|
|
|
/* A few more tests, demonstrating more "normal" use */
|
|
|
|
g_assert (g_strlcpy(string, "hi", 5) == 2);
|
|
|
|
g_assert (g_str_equal(string, "hi"));
|
|
|
|
g_assert (g_strlcat(string, "t", 5) == 3);
|
|
|
|
g_assert (g_str_equal(string, "hit"));
|
|
|
|
g_free(string);
|
|
|
|
|
2007-12-12 16:09:08 +01:00
|
|
|
if (g_test_verbose())
|
|
|
|
g_print ("checking g_strdup_printf...\n");
|
1999-01-02 22:45:39 +01:00
|
|
|
string = g_strdup_printf ("%05d %-5s", 21, "test");
|
|
|
|
g_assert (string != NULL);
|
|
|
|
g_assert (strcmp(string, "00021 test ") == 0);
|
|
|
|
g_free (string);
|
|
|
|
|
1998-06-11 01:21:14 +02:00
|
|
|
/* g_debug (argv[0]); */
|
2007-12-12 16:09:08 +01:00
|
|
|
}
|
1998-06-11 01:21:14 +02:00
|
|
|
|
2008-08-14 05:05:17 +02:00
|
|
|
#ifndef G_DISABLE_DEPRECATED
|
2007-12-12 16:09:08 +01:00
|
|
|
static void
|
|
|
|
test_mem_chunks (void)
|
|
|
|
{
|
|
|
|
GMemChunk *mem_chunk = g_mem_chunk_new ("test mem chunk", 50, 100, G_ALLOC_AND_FREE);
|
|
|
|
gchar *mem[10000];
|
|
|
|
guint i;
|
1998-06-12 11:38:32 +02:00
|
|
|
for (i = 0; i < 10000; i++)
|
|
|
|
{
|
2007-12-12 16:09:08 +01:00
|
|
|
guint j;
|
|
|
|
mem[i] = g_chunk_new (gchar, mem_chunk);
|
|
|
|
for (j = 0; j < 50; j++)
|
|
|
|
mem[i][j] = i * j;
|
1998-06-12 11:38:32 +02:00
|
|
|
}
|
2007-12-12 16:09:08 +01:00
|
|
|
for (i = 0; i < 10000; i++)
|
|
|
|
g_mem_chunk_free (mem_chunk, mem[i]);
|
1998-06-11 01:21:14 +02:00
|
|
|
}
|
2008-08-14 05:05:17 +02:00
|
|
|
#endif
|
1999-01-02 02:51:08 +01:00
|
|
|
|
2007-12-12 16:09:08 +01:00
|
|
|
int
|
|
|
|
main (int argc,
|
|
|
|
char *argv[])
|
|
|
|
{
|
|
|
|
g_test_init (&argc, &argv, NULL);
|
|
|
|
|
|
|
|
g_test_add_func ("/testglib/Infos", test_info);
|
|
|
|
g_test_add_func ("/testglib/Types Sizes", type_sizes);
|
|
|
|
g_test_add_func ("/testglib/GStrings", gstring_tests);
|
|
|
|
g_test_add_func ("/testglib/Various Strings", various_string_tests);
|
|
|
|
g_test_add_func ("/testglib/GList", glist_test);
|
|
|
|
g_test_add_func ("/testglib/GSList", gslist_test);
|
|
|
|
g_test_add_func ("/testglib/GNode", gnode_test);
|
|
|
|
g_test_add_func ("/testglib/GTree", binary_tree_test);
|
|
|
|
g_test_add_func ("/testglib/Arrays", test_arrays);
|
|
|
|
g_test_add_func ("/testglib/GHashTable", hash_table_tests);
|
2010-12-28 06:12:19 +01:00
|
|
|
#ifndef G_DISABLE_DEPRECATED
|
|
|
|
g_test_add_func ("/testglib/Relation (deprecated)", relation_test);
|
|
|
|
#endif
|
2007-12-12 16:09:08 +01:00
|
|
|
g_test_add_func ("/testglib/File Paths", test_paths);
|
|
|
|
g_test_add_func ("/testglib/File Functions", test_file_functions);
|
|
|
|
g_test_add_func ("/testglib/Parse Debug Strings", test_g_parse_debug_string);
|
2008-08-14 05:05:17 +02:00
|
|
|
#ifndef G_DISABLE_DEPRECATED
|
2007-12-12 16:09:08 +01:00
|
|
|
g_test_add_func ("/testglib/GMemChunk (deprecated)", test_mem_chunks);
|
2008-08-14 05:05:17 +02:00
|
|
|
#endif
|
2007-12-12 16:09:08 +01:00
|
|
|
g_test_add_func ("/testglib/Warnings & Errors", log_warning_error_tests);
|
|
|
|
g_test_add_func ("/testglib/Timers (slow)", timer_tests);
|
|
|
|
|
|
|
|
return g_test_run();
|
|
|
|
}
|