#include <glib.h>

static void test (gchar *string)
{
	gint num_chars;
	gchar **p;
	gint i, j;

	g_assert (g_utf8_validate (string, -1, NULL));

	num_chars = g_utf8_strlen (string, -1);

	p = (gchar **) g_malloc (num_chars * sizeof (gchar *));

	p[0] = string;
	for (i = 1; i < num_chars; i++)
		p[i] = g_utf8_next_char (p[i-1]);
 
	for (i = 0; i < num_chars; i++)
		for (j = 0; j < num_chars; j++) {
			g_assert (g_utf8_offset_to_pointer (p[i], j - i) == p[j]);	
			g_assert (g_utf8_pointer_to_offset (p[i], p[j]) == j - i);	
		}

	g_free (p);
}

gchar *longline = "asdasdas dsaf asfd as fdasdf asfd asdf as dfas dfasdf a"
"asd fasdf asdf asdf asd fasfd as fdasfd asdf as fdççççççççças ffsd asfd as fdASASASAs As"
"Asfdsf sdfg sdfg dsfg dfg sdfgsdfgsdfgsdfg sdfgsdfg sdfg sdfg sdf gsdfg sdfg sd"
"asd fasdf asdf asdf asd fasfd as fdaèèèèèèè òòòòòòòòòòòòsfd asdf as fdas ffsd asfd as fdASASASAs D"
"Asfdsf sdfg sdfg dsfg dfg sdfgsdfgsdfgsdfg sdfgsdfg sdfgùùùùùùùùùùùùùù sdfg sdf gsdfg sdfg sd"
"asd fasdf asdf asdf asd fasfd as fdasfd asd@@@@@@@f as fdas ffsd asfd as fdASASASAs D "
"Asfdsf sdfg sdfg dsfg dfg sdfgsdfgsdfgsdfg sdfgsdf€€€€€€€€€€€€€€€€€€g sdfg sdfg sdf gsdfg sdfg sd"
"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";

int main (int argc, char *argv[])
{
	test (longline);
	
	return 0;
}
