Add tests for g_utf8_strlen().

2006-02-24  Matthias Clasen  <mclasen@redhat.com>

        * tests/utf8-pointer.c: Add tests for g_utf8_strlen().

        * glib/gutf8.c: Fix boundary cases in g_utf8_strlen().
        (#332435)
This commit is contained in:
Matthias Clasen 2006-02-24 13:56:58 +00:00 committed by Matthias Clasen
parent a629b3f02d
commit 8b3b3adb6d
5 changed files with 49 additions and 2 deletions

View File

@ -1,3 +1,10 @@
2006-02-24 Matthias Clasen <mclasen@redhat.com>
* tests/utf8-pointer.c: Add tests for g_utf8_strlen().
* glib/gutf8.c: Fix boundary cases in g_utf8_strlen().
(#332435)
2006-02-23 Kjartan Maraas <kmaraas@gnome.org>
* tests/completion-test.c: (main): Plug leaks reported by

View File

@ -1,3 +1,10 @@
2006-02-24 Matthias Clasen <mclasen@redhat.com>
* tests/utf8-pointer.c: Add tests for g_utf8_strlen().
* glib/gutf8.c: Fix boundary cases in g_utf8_strlen().
(#332435)
2006-02-23 Kjartan Maraas <kmaraas@gnome.org>
* tests/completion-test.c: (main): Plug leaks reported by

View File

@ -1,3 +1,10 @@
2006-02-24 Matthias Clasen <mclasen@redhat.com>
* tests/utf8-pointer.c: Add tests for g_utf8_strlen().
* glib/gutf8.c: Fix boundary cases in g_utf8_strlen().
(#332435)
2006-02-23 Kjartan Maraas <kmaraas@gnome.org>
* tests/completion-test.c: (main): Plug leaks reported by

View File

@ -242,7 +242,7 @@ g_utf8_strlen (const gchar *p,
/* only do the last len increment if we got a complete
* char (don't count partial chars)
*/
if (p - start == max)
if (p - start <= max)
++len;
}

View File

@ -64,9 +64,35 @@ gchar *longline = "asdasdas dsaf asfd as fdasdf asfd asdf as dfas dfasdf a"
"asd fasdf asdf asdf asd fasfd as fdasfd asdf as fdas ffsd asfd as fdASASASAs D"
"Asfdsf sdfg sdfg dsfg dfg sdfgsdfgsdfgsdfg sdfgsdfg sdfg sdfg sdf gsdfg sdfg sd\n\nlalala\n";
static void
test_length (void)
{
g_assert (g_utf8_strlen ("1234", -1) == 4);
g_assert (g_utf8_strlen ("1234", 0) == 0);
g_assert (g_utf8_strlen ("1234", 1) == 1);
g_assert (g_utf8_strlen ("1234", 2) == 2);
g_assert (g_utf8_strlen ("1234", 3) == 3);
g_assert (g_utf8_strlen ("1234", 4) == 4);
g_assert (g_utf8_strlen ("1234", 5) == 4);
g_assert (g_utf8_strlen (longline, -1) == 762);
g_assert (g_utf8_strlen (longline, strlen (longline)) == 762);
g_assert (g_utf8_strlen (longline, 1024) == 762);
g_assert (g_utf8_strlen (NULL, 0) == 0);
g_assert (g_utf8_strlen ("a\340\250\201c", -1) == 3);
g_assert (g_utf8_strlen ("a\340\250\201c", 1) == 1);
g_assert (g_utf8_strlen ("a\340\250\201c", 2) == 1);
g_assert (g_utf8_strlen ("a\340\250\201c", 3) == 1);
g_assert (g_utf8_strlen ("a\340\250\201c", 4) == 2);
g_assert (g_utf8_strlen ("a\340\250\201c", 5) == 3);
}
int main (int argc, char *argv[])
{
test_utf8 (longline);
test_length ();
return 0;
}