Break some long lines.

2006-01-08  Matthias Clasen  <mclasen@redhat.com>

	* glib/gtree.c: Break some long lines.

	* tests/tree-test.c: Add more tests.
This commit is contained in:
Matthias Clasen 2006-01-09 04:11:12 +00:00 committed by Matthias Clasen
parent 0f3dfbfc86
commit a3a469192c
5 changed files with 192 additions and 57 deletions

View File

@ -1,5 +1,9 @@
2006-01-08 Matthias Clasen <mclasen@redhat.com>
* glib/gtree.c: Break some long lines.
* tests/tree-test.c: Add more tests.
* glib/gslice.c: Include config.h first, pointed out
by Bogdan Nicula.

View File

@ -1,5 +1,9 @@
2006-01-08 Matthias Clasen <mclasen@redhat.com>
* glib/gtree.c: Break some long lines.
* tests/tree-test.c: Add more tests.
* glib/gslice.c: Include config.h first, pointed out
by Bogdan Nicula.

View File

@ -1,5 +1,9 @@
2006-01-08 Matthias Clasen <mclasen@redhat.com>
* glib/gtree.c: Break some long lines.
* tests/tree-test.c: Add more tests.
* glib/gslice.c: Include config.h first, pointed out
by Bogdan Nicula.

View File

@ -317,7 +317,8 @@ g_tree_replace (GTree *tree,
* make sure that any dynamically allocated values are freed yourself.
* If the key does not exist in the #GTree, the function does nothing.
*
* Returns: %TRUE if the key was found (prior to 2.8, this function returned nothing)
* Returns: %TRUE if the key was found (prior to 2.8, this function returned
* nothing)
**/
gboolean
g_tree_remove (GTree *tree,
@ -342,7 +343,8 @@ g_tree_remove (GTree *tree,
*
* If the key does not exist in the #GTree, the function does nothing.
*
* Returns: %TRUE if the key was found (prior to 2.8, this function returned nothing)
* Returns: %TRUE if the key was found (prior to 2.8, this function returned
* nothing)
**/
gboolean
g_tree_steal (GTree *tree,
@ -507,11 +509,12 @@ g_tree_traverse (GTree *tree,
*
* Searches a #GTree using @search_func.
*
* The @search_func is called with a pointer to the key of a key/value pair in the tree,
* and the passed in @user_data. If @search_func returns 0 for a key/value pair, then
* g_tree_search_func() will return the value of that pair. If @search_func returns -1,
* searching will proceed among the key/value pairs that have a smaller key; if @search_func
* returns 1, searching will proceed among the key/value pairs that have a larger key.
* The @search_func is called with a pointer to the key of a key/value pair in
* the tree, and the passed in @user_data. If @search_func returns 0 for a
* key/value pair, then g_tree_search_func() will return the value of that
* pair. If @search_func returns -1, searching will proceed among the
* key/value pairs that have a smaller key; if @search_func returns 1,
* searching will proceed among the key/value pairs that have a larger key.
*
* Return value: the value corresponding to the found key, or %NULL if the key
* was not found.

View File

@ -31,31 +31,6 @@
#include <string.h>
#include "glib.h"
int array[10000];
gboolean failed = FALSE;
#define TEST(m,cond) G_STMT_START { failed = !(cond); \
if (failed) \
{ if (!m) \
g_print ("\n(%s:%d) failed for: %s\n", __FILE__, __LINE__, ( # cond )); \
else \
g_print ("\n(%s:%d) failed for: %s: (%s)\n", __FILE__, __LINE__, ( # cond ), (gchar*)m); \
} \
else \
g_print ("."); fflush (stdout); \
} G_STMT_END
#define C2P(c) ((gpointer) ((long) (c)))
#define P2C(p) ((gchar) ((long) (p)))
#define GLIB_TEST_STRING "el dorado "
#define GLIB_TEST_STRING_5 "el do"
typedef struct {
guint age;
gchar name[40];
} GlibTestInfo;
static gint
my_compare (gconstpointer a,
@ -67,6 +42,28 @@ my_compare (gconstpointer a,
return *cha - *chb;
}
static gint
my_search (gconstpointer a,
gconstpointer b)
{
return my_compare (b, a);
}
static gpointer destroyed_key = NULL;
static gpointer destroyed_value = NULL;
static void
my_key_destroy (gpointer key)
{
destroyed_key = key;
}
static void
my_value_destroy (gpointer value)
{
destroyed_value = value;
}
static gint
my_traverse (gpointer key,
gpointer value,
@ -77,43 +74,60 @@ my_traverse (gpointer key,
return FALSE;
}
char chars[] =
"0123456789"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz";
char chars2[] =
"0123456789"
"abcdefghijklmnopqrstuvwxyz";
static gint
check_order (gpointer key,
gpointer value,
gpointer data)
{
char **p = data;
char *ch = key;
g_assert (**p == *ch);
(*p)++;
return FALSE;
}
int
main (int argc,
char *argv[])
{
gint i, j;
gint i;
GTree *tree;
gboolean removed;
char chars[62];
char c;
char c, d;
char *p;
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]);
}
for (i = 0; chars[i]; i++)
g_tree_insert (tree, &chars[i], &chars[i]);
g_tree_foreach (tree, my_traverse, NULL);
g_assert (g_tree_nnodes (tree) == (10 + 26 + 26));
g_assert (g_tree_nnodes (tree) == strlen (chars));
g_assert (g_tree_height (tree) == 6);
p = chars;
g_tree_foreach (tree, check_order, &p);
for (i = 0; i < 10; i++)
{
removed = g_tree_remove (tree, &chars[i]);
g_assert (removed);
}
for (i = 0; i < 26; i++)
{
removed = g_tree_remove (tree, &chars[i + 10]);
g_assert (removed);
}
c = '\0';
removed = g_tree_remove (tree, &c);
@ -121,6 +135,112 @@ main (int argc,
g_tree_foreach (tree, my_traverse, NULL);
g_assert (g_tree_nnodes (tree) == strlen (chars2));
g_assert (g_tree_height (tree) == 6);
p = chars2;
g_tree_foreach (tree, check_order, &p);
for (i = 25; i >= 0; i--)
g_tree_insert (tree, &chars[i + 10], &chars[i + 10]);
p = chars;
g_tree_foreach (tree, check_order, &p);
c = '0';
p = g_tree_lookup (tree, &c);
g_assert (p && *p == c);
c = 'A';
p = g_tree_lookup (tree, &c);
g_assert (p && *p == c);
c = 'a';
p = g_tree_lookup (tree, &c);
g_assert (p && *p == c);
c = 'z';
p = g_tree_lookup (tree, &c);
g_assert (p && *p == c);
c = '!';
p = g_tree_lookup (tree, &c);
g_assert (p == NULL);
c = '=';
p = g_tree_lookup (tree, &c);
g_assert (p == NULL);
c = '|';
p = g_tree_lookup (tree, &c);
g_assert (p == NULL);
c = '0';
p = g_tree_search (tree, my_search, &c);
g_assert (p && *p == c);
c = 'A';
p = g_tree_search (tree, my_search, &c);
g_assert (p && *p == c);
c = 'a';
p = g_tree_search (tree, my_search, &c);
g_assert (p &&*p == c);
c = 'z';
p = g_tree_search (tree, my_search, &c);
g_assert (p && *p == c);
c = '!';
p = g_tree_search (tree, my_search, &c);
g_assert (p == NULL);
c = '=';
p = g_tree_search (tree, my_search, &c);
g_assert (p == NULL);
c = '|';
p = g_tree_search (tree, my_search, &c);
g_assert (p == NULL);
g_tree_destroy (tree);
tree = g_tree_new_full (my_compare, NULL,
my_key_destroy,
my_value_destroy);
for (i = 0; chars[i]; i++)
g_tree_insert (tree, &chars[i], &chars[i]);
c = '0';
g_tree_insert (tree, &c, &c);
g_assert (destroyed_key == &c);
g_assert (destroyed_value == &chars[0]);
destroyed_key = NULL;
destroyed_value = NULL;
d = '1';
g_tree_replace (tree, &d, &d);
g_assert (destroyed_key == &chars[1]);
g_assert (destroyed_value == &chars[1]);
destroyed_key = NULL;
destroyed_value = NULL;
c = '2';
removed = g_tree_remove (tree, &c);
g_assert (removed);
g_assert (destroyed_key == &chars[2]);
g_assert (destroyed_value == &chars[2]);
destroyed_key = NULL;
destroyed_value = NULL;
c = '3';
removed = g_tree_steal (tree, &c);
g_assert (removed);
g_assert (destroyed_key == NULL);
g_assert (destroyed_value == NULL);
return 0;
}