diff options
Diffstat (limited to 'glib/tests')
-rw-r--r-- | glib/tests/hostutils.c | 61 | ||||
-rw-r--r-- | glib/tests/rand.c | 3 | ||||
-rw-r--r-- | glib/tests/regex.c | 2 | ||||
-rw-r--r-- | glib/tests/sequence.c | 76 | ||||
-rw-r--r-- | glib/tests/utils.c | 15 |
5 files changed, 156 insertions, 1 deletions
diff --git a/glib/tests/hostutils.c b/glib/tests/hostutils.c index 622a0ced5..218f51648 100644 --- a/glib/tests/hostutils.c +++ b/glib/tests/hostutils.c @@ -19,6 +19,7 @@ #include <glib/glib.h> +#include <stdio.h> #include <stdlib.h> #include <string.h> @@ -48,6 +49,23 @@ static const struct { }; static const gint num_idn_test_domains = G_N_ELEMENTS (idn_test_domains); +static const struct { + const gchar *orig_name, *ascii_name; + gboolean orig_is_unicode, ascii_is_encoded; +} non_round_trip_names[] = { + /* uppercase characters */ + { "EXAMPLE.COM", "example.com", FALSE, FALSE }, + { "\xc3\x89XAMPLE.COM", "xn--xample-9ua.com", TRUE, TRUE }, + + /* unicode that decodes to ascii */ + { "\xe2\x93\x94\xe2\x93\xa7\xe2\x93\x90\xe2\x93\x9c\xe2\x93\x9f\xe2\x93\x9b\xe2\x93\x94.com", "example.com", TRUE, FALSE }, + + /* non-standard dot characters */ + { "example\xe3\x80\x82" "com", "example.com", TRUE, FALSE }, + { "\xc3\xa9xample\xe3\x80\x82" "com", "xn--xample-9ua.com", TRUE, TRUE } +}; +static const gint num_non_round_trip_names = G_N_ELEMENTS (non_round_trip_names); + static const gchar *bad_names[] = { "disallowed\xef\xbf\xbd" "character", "non-utf\x88", @@ -73,6 +91,27 @@ test_to_ascii (void) g_free (ascii); } + for (i = 0; i < num_non_round_trip_names; i++) + { + if (non_round_trip_names[i].orig_is_unicode) + g_assert (g_hostname_is_non_ascii (non_round_trip_names[i].orig_name)); + else + g_assert (!g_hostname_is_non_ascii (non_round_trip_names[i].orig_name)); + + if (non_round_trip_names[i].ascii_is_encoded) + g_assert (g_hostname_is_ascii_encoded (non_round_trip_names[i].ascii_name)); + else + g_assert (!g_hostname_is_ascii_encoded (non_round_trip_names[i].ascii_name)); + + ascii = g_hostname_to_ascii (non_round_trip_names[i].orig_name); + g_assert_cmpstr (non_round_trip_names[i].ascii_name, ==, ascii); + g_free (ascii); + + ascii = g_hostname_to_ascii (non_round_trip_names[i].ascii_name); + g_assert_cmpstr (non_round_trip_names[i].ascii_name, ==, ascii); + g_free (ascii); + } + for (i = 0; i < num_bad_names; i++) { ascii = g_hostname_to_ascii (bad_names[i]); @@ -278,6 +317,28 @@ main (int argc, { g_test_init (&argc, &argv, NULL); + if (argc == 2 && argv[1][0] != '-') + { + const gchar *hostname = argv[1]; + gchar *converted; + + if (g_hostname_is_non_ascii (hostname)) + { + converted = g_hostname_to_ascii (hostname); + printf ("to_ascii: %s\n", converted); + g_free (converted); + } + else if (g_hostname_is_ascii_encoded (hostname)) + { + converted = g_hostname_to_unicode (hostname); + printf ("to_unicode: %s\n", converted); + g_free (converted); + } + else + printf ("hostname is neither unicode nor ACE encoded\n"); + return 0; + } + g_test_add_func ("/hostutils/to_ascii", test_to_ascii); g_test_add_func ("/hostutils/to_unicode", test_to_unicode); g_test_add_func ("/hostutils/is_ip_addr", test_is_ip_addr); diff --git a/glib/tests/rand.c b/glib/tests/rand.c index 62b5f7597..f1ff08d55 100644 --- a/glib/tests/rand.c +++ b/glib/tests/rand.c @@ -22,7 +22,8 @@ #include "glib.h" /* Outputs tested against the reference implementation mt19937ar.c from - http://www.math.keio.ac.jp/~matumoto/MT2002/emt19937ar.html */ + * http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/MT2002/emt19937ar.html + */ /* Tests for a simple seed, first number is the seed */ const guint32 first_numbers[] = diff --git a/glib/tests/regex.c b/glib/tests/regex.c index bd46a5e53..6e015e9ac 100644 --- a/glib/tests/regex.c +++ b/glib/tests/regex.c @@ -2357,6 +2357,8 @@ main (int argc, char *argv[]) TEST_SPLIT_SIMPLE3(",\\s*", "a, b, c", "a", "b", "c"); TEST_SPLIT_SIMPLE3("(,)\\s*", "a,b", "a", ",", "b"); TEST_SPLIT_SIMPLE3("(,)\\s*", "a, b", "a", ",", "b"); + TEST_SPLIT_SIMPLE2("\\s", "ab c", "ab", "c"); + TEST_SPLIT_SIMPLE3("\\s*", "ab c", "a", "b", "c"); /* Not matched sub-strings. */ TEST_SPLIT_SIMPLE2("a|(b)", "xay", "x", "y"); TEST_SPLIT_SIMPLE3("a|(b)", "xby", "x", "b", "y"); diff --git a/glib/tests/sequence.c b/glib/tests/sequence.c index f46761a90..e2a58f333 100644 --- a/glib/tests/sequence.c +++ b/glib/tests/sequence.c @@ -81,6 +81,7 @@ enum { GET_BEGIN_ITER, GET_END_ITER, GET_ITER_AT_POS, APPEND, PREPEND, INSERT_BEFORE, MOVE, SWAP, INSERT_SORTED, INSERT_SORTED_ITER, SORT_CHANGED, SORT_CHANGED_ITER, REMOVE, REMOVE_RANGE, MOVE_RANGE, SEARCH, SEARCH_ITER, + LOOKUP, LOOKUP_ITER, /* dereferencing */ GET, SET, @@ -200,6 +201,42 @@ seq_foreach (gpointer data, } static gint +simple_items_cmp (gconstpointer a, + gconstpointer b, + gpointer data) +{ + const Item *item_a = fix_pointer (a); + const Item *item_b = fix_pointer (b); + + if (item_a->number > item_b->number) + return +1; + else if (item_a->number < item_b->number) + return -1; + else + return 0; +} + +static gint +simple_iters_cmp (gconstpointer a, + gconstpointer b, + gpointer data) +{ + GSequence *seq = data; + GSequenceIter *iter_a = (GSequenceIter *)a; + GSequenceIter *iter_b = (GSequenceIter *)b; + gpointer item_a = g_sequence_get (iter_a); + gpointer item_b = g_sequence_get (iter_b); + + if (seq) + { + g_assert (g_sequence_iter_get_sequence (iter_a) == seq); + g_assert (g_sequence_iter_get_sequence (iter_b) == seq); + } + + return simple_items_cmp (item_a, item_b, data); +} + +static gint compare_items (gconstpointer a, gconstpointer b, gpointer data) @@ -884,6 +921,45 @@ run_random_tests (gconstpointer d) g_queue_insert_sorted (seq->queue, insert_iter, compare_iters, NULL); } break; + case LOOKUP: + { + Item *item; + GSequenceIter *lookup_iter; + GSequenceIter *insert_iter; + + g_sequence_sort (seq->sequence, compare_items, NULL); + g_queue_sort (seq->queue, compare_iters, NULL); + + check_sorted (seq); + + item = new_item (seq); + insert_iter = g_sequence_insert_sorted (seq->sequence, item, compare_items, NULL); + g_queue_insert_sorted (seq->queue, insert_iter, compare_iters, NULL); + + lookup_iter = g_sequence_lookup (seq->sequence, item, simple_items_cmp, NULL); + g_assert (simple_iters_cmp (insert_iter, lookup_iter, NULL) == 0); + } + break; + case LOOKUP_ITER: + { + Item *item; + GSequenceIter *lookup_iter; + GSequenceIter *insert_iter; + + g_sequence_sort (seq->sequence, compare_items, NULL); + g_queue_sort (seq->queue, compare_iters, NULL); + + check_sorted (seq); + + item = new_item (seq); + insert_iter = g_sequence_insert_sorted (seq->sequence, item, compare_items, NULL); + g_queue_insert_sorted (seq->queue, insert_iter, compare_iters, NULL); + + lookup_iter = g_sequence_lookup_iter (seq->sequence, item, + (GSequenceIterCompareFunc) simple_iters_cmp, NULL); + g_assert (simple_iters_cmp (insert_iter, lookup_iter, NULL) == 0); + } + break; /* dereferencing */ case GET: diff --git a/glib/tests/utils.c b/glib/tests/utils.c index f586aa131..cf7d8ddb6 100644 --- a/glib/tests/utils.c +++ b/glib/tests/utils.c @@ -73,6 +73,20 @@ test_language_names (void) } static void +test_locale_variants (void) +{ + char **v; + + v = g_get_locale_variants ("fr_BE"); + g_assert (strv_check ((const gchar * const *) v, "fr_BE", "fr", NULL)); + g_strfreev (v); + + v = g_get_locale_variants ("sr_SR@latin"); + g_assert (strv_check ((const gchar * const *) v, "sr_SR@latin", "sr@latin", "sr_SR", "sr", NULL)); + g_strfreev (v); +} + +static void test_version (void) { g_print ("(header %d.%d.%d library %d.%d.%d) ", @@ -152,6 +166,7 @@ main (int argc, g_test_bug_base ("http://bugzilla.gnome.org/"); g_test_add_func ("/utils/language-names", test_language_names); + g_test_add_func ("/utils/locale-variants", test_locale_variants); g_test_add_func ("/utils/version", test_version); g_test_add_func ("/utils/appname", test_appname); g_test_add_func ("/utils/tmpdir", test_tmpdir); |