10 compare_strings_utf8_pos (const gchar *expected, const gchar *actual, glong size)
13 for (i = 0; i < size; i++)
14 if (expected [i] != actual [i])
20 compare_strings_utf8_RESULT (const gchar *expected, const gchar *actual, glong size)
24 ret = compare_strings_utf8_pos (expected, actual, size);
27 return FAILED ("Incorrect output: expected '%s' but was '%s', differ at %d\n", expected, actual, ret);
31 gchar_to_gunichar2 (gunichar2 ret[], const gchar *src)
35 for (i = 0; src [i]; i++)
41 compare_utf16_to_utf8_explicit (const gchar *expected, const gunichar2 *utf16, glong len_in, glong len_out, glong size_spec)
46 glong in_read, out_read;
51 ret = g_utf16_to_utf8 (utf16, size_spec, &in_read, &out_read, &error);
53 result = FAILED ("The error is %d %s\n", (error)->code, (error)->message);
59 if (in_read != len_in)
60 result = FAILED ("Read size is incorrect: expected %d but was %d\n", len_in, in_read);
61 else if (out_read != len_out)
62 result = FAILED ("Converted size is incorrect: expected %d but was %d\n", len_out, out_read);
64 result = compare_strings_utf8_RESULT (expected, ret, len_out);
74 compare_utf16_to_utf8 (const gchar *expected, const gunichar2 *utf16, glong len_in, glong len_out)
78 result = compare_utf16_to_utf8_explicit (expected, utf16, len_in, len_out, -1);
81 return compare_utf16_to_utf8_explicit (expected, utf16, len_in, len_out, len_in);
87 const gchar *src0 = "", *src1 = "ABCDE", *src2 = "\xE5\xB9\xB4\x27", *src3 = "\xEF\xBC\xA1", *src4 = "\xEF\xBD\x81", *src5 = "\xF0\x90\x90\x80";
88 gunichar2 str0 [] = {0}, str1 [6], str2 [] = {0x5E74, 39, 0}, str3 [] = {0xFF21, 0}, str4 [] = {0xFF41, 0}, str5 [] = {0xD801, 0xDC00, 0};
91 gchar_to_gunichar2 (str1, src1);
94 result = compare_utf16_to_utf8 (src0, str0, 0, 0);
98 result = compare_utf16_to_utf8 (src1, str1, 5, 5);
101 result = compare_utf16_to_utf8 (src2, str2, 2, 4);
104 result = compare_utf16_to_utf8 (src3, str3, 1, 3);
107 result = compare_utf16_to_utf8 (src4, str4, 1, 3);
110 result = compare_utf16_to_utf8 (src5, str5, 2, 4);
122 compare_strings_utf16_pos (const gunichar2 *expected, const gunichar2 *actual, glong size)
125 for (i = 0; i < size; i++)
126 if (expected [i] != actual [i])
132 compare_strings_utf16_RESULT (const gunichar2 *expected, const gunichar2 *actual, glong size)
136 ret = compare_strings_utf16_pos (expected, actual, size);
139 return FAILED ("Incorrect output: expected '%s' but was '%s'\n", expected, actual);
143 compare_utf8_to_utf16_explicit (const gunichar2 *expected, const gchar *utf8, glong len_in, glong len_out, glong size_spec)
148 glong in_read, out_read;
153 ret = g_utf8_to_utf16 (utf8, size_spec, &in_read, &out_read, &error);
155 result = FAILED ("The error is %d %s\n", (error)->code, (error)->message);
156 g_error_free (error);
161 if (in_read != len_in)
162 result = FAILED ("Read size is incorrect: expected %d but was %d\n", len_in, in_read);
163 else if (out_read != len_out)
164 result = FAILED ("Converted size is incorrect: expected %d but was %d\n", len_out, out_read);
166 result = compare_strings_utf16_RESULT (expected, ret, len_out);
177 compare_utf8_to_utf16 (const gunichar2 *expected, const gchar *utf8, glong len_in, glong len_out)
181 result = compare_utf8_to_utf16_explicit (expected, utf8, len_in, len_out, -1);
184 return compare_utf8_to_utf16_explicit (expected, utf8, len_in, len_out, len_in);
190 const gchar *src = "\xE5\xB9\xB4\x27";
191 glong in_read, out_read;
192 //gunichar2 expected [6];
193 GError *error = NULL;
196 //printf ("got: %s\n", src);
197 dst = g_utf8_to_utf16 (src, (glong)strlen (src), &in_read, &out_read, &error);
199 return error->message;
203 return FAILED ("in_read is expected to be 4 but was %d\n", in_read);
206 return FAILED ("out_read is expected to be 2 but was %d\n", out_read);
214 test_utf8_to_utf16 ()
216 const gchar *src0 = "", *src1 = "ABCDE", *src2 = "\xE5\xB9\xB4\x27", *src3 = "\xEF\xBC\xA1", *src4 = "\xEF\xBD\x81";
217 gunichar2 str0 [] = {0}, str1 [6], str2 [] = {0x5E74, 39, 0}, str3 [] = {0xFF21, 0}, str4 [] = {0xFF41, 0};
220 gchar_to_gunichar2 (str1, src1);
223 result = compare_utf8_to_utf16 (str0, src0, 0, 0);
227 result = compare_utf8_to_utf16 (str1, src1, 5, 5);
230 result = compare_utf8_to_utf16 (str2, src2, 4, 2);
233 result = compare_utf8_to_utf16 (str3, src3, 3, 1);
236 result = compare_utf8_to_utf16 (str4, src4, 3, 1);
251 static const char *charsets[] = { "UTF-8", "UTF-16LE", "UTF-16BE", "UTF-32LE", "UTF-32BE" };
252 gsize length, converted_length, n;
253 char *content, *converted, *path;
254 convert_result_t **expected;
261 if (!(srcdir = getenv ("srcdir")) && !(srcdir = getenv ("PWD")))
262 return FAILED ("srcdir not defined!");
264 expected = g_malloc (sizeof (convert_result_t *) * G_N_ELEMENTS (charsets));
266 /* first load all our test samples... */
267 for (i = 0; i < G_N_ELEMENTS (charsets); i++) {
268 path = g_strdup_printf ("%s%c%s.txt", srcdir, G_DIR_SEPARATOR, charsets[i]);
269 loaded = g_file_get_contents (path, &content, &length, &err);
273 for (j = 0; j < i; j++) {
274 g_free (expected[j]->content);
275 g_free (expected[j]);
280 return FAILED ("Failed to load content for %s: %s", charsets[i], err->message);
283 expected[i] = g_malloc (sizeof (convert_result_t));
284 expected[i]->content = content;
285 expected[i]->length = length;
288 /* test conversion from every charset to every other charset */
289 for (i = 0; i < G_N_ELEMENTS (charsets); i++) {
290 for (j = 0; j < G_N_ELEMENTS (charsets); j++) {
291 converted = g_convert (expected[i]->content, expected[i]->length, charsets[j],
292 charsets[i], NULL, &converted_length, NULL);
294 if (converted == NULL) {
295 for (k = 0; k < G_N_ELEMENTS (charsets); k++) {
296 g_free (expected[k]->content);
297 g_free (expected[k]);
302 return FAILED ("Failed to convert from %s to %s: NULL", charsets[i], charsets[j]);
305 if (converted_length != expected[j]->length) {
306 length = expected[j]->length;
308 for (k = 0; k < G_N_ELEMENTS (charsets); k++) {
309 g_free (expected[k]->content);
310 g_free (expected[k]);
316 return FAILED ("Failed to convert from %s to %s: expected %u bytes, got %u",
317 charsets[i], charsets[j], length, converted_length);
320 for (n = 0; n < converted_length; n++) {
321 if (converted[n] != expected[j]->content[n]) {
322 c = expected[j]->content[n];
324 for (k = 0; k < G_N_ELEMENTS (charsets); k++) {
325 g_free (expected[k]->content);
326 g_free (expected[k]);
332 return FAILED ("Failed to convert from %s to %s: expected 0x%x at offset %u, got 0x%x",
333 charsets[i], charsets[j], c, n, converted[n]);
341 for (k = 0; k < G_N_ELEMENTS (charsets); k++) {
342 g_free (expected[k]->content);
343 g_free (expected[k]);
355 static char test_chars[] = {
356 '0', '1', '2', '3', '4',
357 '5', '6', '7', '8', '9',
358 'a', 'b', 'c', 'd', 'e', 'f', 'g',
359 'A', 'B', 'C', 'D', 'E', 'F', 'G'};
360 static gint32 test_values[] = {
363 10, 11, 12, 13, 14, 15, -1,
364 10, 11, 12, 13, 14, 15, -1};
368 for (i = 0; i < sizeof(test_chars); i++)
369 if (g_unichar_xdigit_value ((gunichar)test_chars[i]) != test_values[i])
370 return FAILED("Incorrect value %d at index %d", test_values[i], i);
376 ucs4_to_utf16_check_result (const gunichar2 *result_str, const gunichar2 *expected_str,
377 glong result_items_read, glong expected_items_read,
378 glong result_items_written, glong expected_items_written,
379 GError* result_error, gboolean expect_error)
382 if (result_items_read != expected_items_read)
383 return FAILED("Incorrect number of items read; expected %d, got %d", expected_items_read, result_items_read);
384 if (result_items_written != expected_items_written)
385 return FAILED("Incorrect number of items written; expected %d, got %d", expected_items_written, result_items_written);
386 if (result_error && !expect_error)
387 return FAILED("There should not be an error code.");
388 if (!result_error && expect_error)
389 return FAILED("Unexpected error object.");
390 if (expect_error && result_str)
391 return FAILED("NULL should be returned when an error occurs.");
392 if (!expect_error && !result_str)
393 return FAILED("When no error occurs NULL should not be returned.");
394 for (i=0; i<expected_items_written;i++) {
395 if (result_str [i] != expected_str [i])
396 return FAILED("Incorrect value %d at index %d", result_str [i], i);
398 if (result_str && result_str[expected_items_written] != '\0')
399 return FAILED("Null termination not found at the end of the string.");
405 test_ucs4_to_utf16 ()
407 static gunichar str1[12] = {'H','e','l','l','o',' ','W','o','r','l','d','\0'};
408 static gunichar2 exp1[12] = {'H','e','l','l','o',' ','W','o','r','l','d','\0'};
409 static gunichar str2[3] = {'h',0x80000000,'\0'};
410 static gunichar2 exp2[2] = {'h','\0'};
411 static gunichar str3[3] = {'h',0xDA00,'\0'};
412 static gunichar str4[3] = {'h',0x10FFFF,'\0'};
413 static gunichar2 exp4[4] = {'h',0xdbff,0xdfff,'\0'};
414 static gunichar str5[7] = {0xD7FF,0xD800,0xDFFF,0xE000,0x110000,0x10FFFF,'\0'};
415 static gunichar2 exp5[5] = {0xD7FF,0xE000,0xdbff,0xdfff,'\0'};
416 static gunichar str6[2] = {0x10400, '\0'};
417 static gunichar2 exp6[3] = {0xD801, 0xDC00, '\0'};
418 static glong read_write[12] = {1,1,0,0,0,0,1,1,0,0,1,2};
420 glong items_read, items_written, current_write_index;
425 res = g_ucs4_to_utf16 (str1, 12, &items_read, &items_written, &err);
426 check_result = ucs4_to_utf16_check_result (res, exp1, items_read, 11, items_written, 11, err, FALSE);
427 if (check_result) return check_result;
430 items_read = items_written = 0;
431 res = g_ucs4_to_utf16 (str2, 0, &items_read, &items_written, &err);
432 check_result = ucs4_to_utf16_check_result (res, exp2, items_read, 0, items_written, 0, err, FALSE);
433 if (check_result) return check_result;
436 items_read = items_written = 0;
437 res = g_ucs4_to_utf16 (str2, 1, &items_read, &items_written, &err);
438 check_result = ucs4_to_utf16_check_result (res, exp2, items_read, 1, items_written, 1, err, FALSE);
439 if (check_result) return check_result;
442 items_read = items_written = 0;
443 res = g_ucs4_to_utf16 (str2, 2, &items_read, &items_written, &err);
444 check_result = ucs4_to_utf16_check_result (res, 0, items_read, 1, items_written, 0, err, TRUE);
446 if (check_result) return check_result;
448 items_read = items_written = 0;
450 res = g_ucs4_to_utf16 (str3, 2, &items_read, &items_written, &err);
451 check_result = ucs4_to_utf16_check_result (res, 0, items_read, 1, items_written, 0, err, TRUE);
452 if (check_result) return check_result;
455 items_read = items_written = 0;
457 res = g_ucs4_to_utf16 (str4, 5, &items_read, &items_written, &err);
458 check_result = ucs4_to_utf16_check_result (res, exp4, items_read, 2, items_written, 3, err, FALSE);
459 if (check_result) return check_result;
462 // This loop tests the bounds of the conversion algorithm
463 current_write_index = 0;
465 items_read = items_written = 0;
467 res = g_ucs4_to_utf16 (&str5[i], 1, &items_read, &items_written, &err);
468 check_result = ucs4_to_utf16_check_result (res, &exp5[current_write_index],
469 items_read, read_write[i*2], items_written, read_write[(i*2)+1], err, !read_write[(i*2)+1]);
470 if (check_result) return check_result;
472 current_write_index += items_written;
475 items_read = items_written = 0;
477 res = g_ucs4_to_utf16 (str6, 1, &items_read, &items_written, &err);
478 check_result = ucs4_to_utf16_check_result (res, exp6, items_read, 1, items_written, 2, err, FALSE);
479 if (check_result) return check_result;
486 utf16_to_ucs4_check_result (const gunichar *result_str, const gunichar *expected_str,
487 glong result_items_read, glong expected_items_read,
488 glong result_items_written, glong expected_items_written,
489 GError* result_error, gboolean expect_error)
492 if (result_items_read != expected_items_read)
493 return FAILED("Incorrect number of items read; expected %d, got %d", expected_items_read, result_items_read);
494 if (result_items_written != expected_items_written)
495 return FAILED("Incorrect number of items written; expected %d, got %d", expected_items_written, result_items_written);
496 if (result_error && !expect_error)
497 return FAILED("There should not be an error code.");
498 if (!result_error && expect_error)
499 return FAILED("Unexpected error object.");
500 if (expect_error && result_str)
501 return FAILED("NULL should be returned when an error occurs.");
502 if (!expect_error && !result_str)
503 return FAILED("When no error occurs NULL should not be returned.");
504 for (i=0; i<expected_items_written;i++) {
505 if (result_str [i] != expected_str [i])
506 return FAILED("Incorrect value %d at index %d", result_str [i], i);
508 if (result_str && result_str[expected_items_written] != '\0')
509 return FAILED("Null termination not found at the end of the string.");
515 test_utf16_to_ucs4 ()
517 static gunichar2 str1[12] = {'H','e','l','l','o',' ','W','o','r','l','d','\0'};
518 static gunichar exp1[12] = {'H','e','l','l','o',' ','W','o','r','l','d','\0'};
519 static gunichar2 str2[7] = {'H', 0xD800, 0xDC01,0xD800,0xDBFF,'l','\0'};
520 static gunichar exp2[3] = {'H',0x00010001,'\0'};
521 static gunichar2 str3[4] = {'H', 0xDC00 ,'l','\0'};
522 static gunichar exp3[2] = {'H','\0'};
523 static gunichar2 str4[20] = {0xDC00,0xDFFF,0xDFF,0xD800,0xDBFF,0xD800,0xDC00,0xD800,0xDFFF,
524 0xD800,0xE000,0xDBFF,0xDBFF,0xDBFF,0xDC00,0xDBFF,0xDFFF,0xDBFF,0xE000,'\0'};
525 static gunichar exp4[6] = {0xDFF,0x10000,0x103ff,0x10fc00,0x10FFFF,'\0'};
526 static gunichar2 str5[3] = {0xD801, 0xDC00, 0};
527 static gunichar exp5[2] = {0x10400, 0};
528 static glong read_write[33] = {1,0,0,1,0,0,1,1,1,2,1,0,2,2,1,2,2,1,2,1,0,2,1,0,2,2,1,2,2,1,2,1,0};
530 glong items_read, items_written, current_read_index,current_write_index;
535 res = g_utf16_to_ucs4 (str1, 12, &items_read, &items_written, &err);
536 check_result = utf16_to_ucs4_check_result (res, exp1, items_read, 11, items_written, 11, err, FALSE);
537 if (check_result) return check_result;
540 items_read = items_written = 0;
541 res = g_utf16_to_ucs4 (str2, 0, &items_read, &items_written, &err);
542 check_result = utf16_to_ucs4_check_result (res, exp2, items_read, 0, items_written, 0, err, FALSE);
543 if (check_result) return check_result;
546 items_read = items_written = 0;
547 res = g_utf16_to_ucs4 (str2, 1, &items_read, &items_written, &err);
548 check_result = utf16_to_ucs4_check_result (res, exp2, items_read, 1, items_written, 1, err, FALSE);
549 if (check_result) return check_result;
552 items_read = items_written = 0;
553 res = g_utf16_to_ucs4 (str2, 2, &items_read, &items_written, &err);
554 check_result = utf16_to_ucs4_check_result (res, exp2, items_read, 1, items_written, 1, err, FALSE);
555 if (check_result) return check_result;
558 items_read = items_written = 0;
559 res = g_utf16_to_ucs4 (str2, 3, &items_read, &items_written, &err);
560 check_result = utf16_to_ucs4_check_result (res, exp2, items_read, 3, items_written, 2, err, FALSE);
561 if (check_result) return check_result;
564 items_read = items_written = 0;
565 res = g_utf16_to_ucs4 (str2, 4, &items_read, &items_written, &err);
566 check_result = utf16_to_ucs4_check_result (res, exp2, items_read, 3, items_written, 2, err, FALSE);
567 if (check_result) return check_result;
570 items_read = items_written = 0;
571 res = g_utf16_to_ucs4 (str2, 5, &items_read, &items_written, &err);
572 check_result = utf16_to_ucs4_check_result (res, exp2, items_read, 4, items_written, 0, err, TRUE);
573 if (check_result) return check_result;
576 items_read = items_written = 0;
578 res = g_utf16_to_ucs4 (str3, 5, &items_read, &items_written, &err);
579 check_result = utf16_to_ucs4_check_result (res, exp3, items_read, 1, items_written, 0, err, TRUE);
580 if (check_result) return check_result;
583 // This loop tests the bounds of the conversion algorithm
584 current_read_index = current_write_index = 0;
586 items_read = items_written = 0;
588 res = g_utf16_to_ucs4 (&str4[current_read_index], read_write[i*3], &items_read, &items_written, &err);
589 check_result = utf16_to_ucs4_check_result (res, &exp4[current_write_index], items_read,
590 read_write[(i*3)+1], items_written, read_write[(i*3)+2], err,
591 !read_write[(i*3)+2]);
592 if (check_result) return check_result;
594 current_read_index += read_write[i*3];
595 current_write_index += items_written;
598 items_read = items_written = 0;
600 res = g_utf16_to_ucs4 (str5, 2, &items_read, &items_written, &err);
601 check_result = utf16_to_ucs4_check_result (res, exp5, items_read, 2, items_written, 1, err, FALSE);
602 if (check_result) return check_result;
610 gchar word1 [] = {0xC2, 0x82,0x45,0xE1, 0x81, 0x83,0x58,0xF1, 0x82, 0x82, 0x82,'\0'};//Valid, len = 5
611 gchar word2 [] = {0xF1, 0x82, 0x82, 0x82,0xC2, 0x82,0x45,0xE1, 0x81, 0x83,0x58,'\0'};//Valid, len = 5
612 gchar word3 [] = {'h','e',0xC2, 0x82,0x45,'\0'}; //Valid, len = 4
613 gchar word4 [] = {0x62,0xC2, 0x82,0x45,0xE1, 0x81, 0x83,0x58,'\0'}; //Valid, len = 5
618 len = g_utf8_strlen (word1,-1);
620 return FAILED ("Word1 expected length of 5, but was %i", len);
621 //Do tests with different values for max parameter.
622 len = g_utf8_strlen (word1,1);
624 return FAILED ("Word1, max = 1, expected length of 0, but was %i", len);
625 len = g_utf8_strlen (word1,2);
627 return FAILED ("Word1, max = 1, expected length of 1, but was %i", len);
628 len = g_utf8_strlen (word1,3);
630 return FAILED ("Word1, max = 2, expected length of 2, but was %i", len);
633 len = g_utf8_strlen (word2,-1);
635 return FAILED ("Word2 expected length of 5, but was %i", len);
638 len = g_utf8_strlen (word3,-1);
640 return FAILED ("Word3 expected length of 4, but was %i", len);
643 len = g_utf8_strlen (word4,-1);
645 return FAILED ("Word4 expected length of 5, but was %i", len);
648 len = g_utf8_strlen(NULL,0);
650 return FAILED ("Expected passing null to result in a length of 0");
657 gchar word1 [] = {0xC2, 0x82,0x45,0xE1, 0x81, 0x83,0x58,0xF1, 0x82, 0x82, 0x82,'\0'}; //Valid, len = 5
659 gunichar value = g_utf8_get_char (&word1 [0]);
661 return FAILED ("Expected value of 0x82, but was %x", value);
662 value = g_utf8_get_char (&word1 [2]);
664 return FAILED ("Expected value of 0x45, but was %x", value);
665 value = g_utf8_get_char (&word1 [3]);
666 if (value != 0x1043UL)
667 return FAILED ("Expected value of 0x1043, but was %x", value);
668 value = g_utf8_get_char (&word1 [6]);
670 return FAILED ("Expected value of 0x58, but was %x", value);
671 value = g_utf8_get_char (&word1 [7]);
672 if (value != 0x42082UL)
673 return FAILED ("Expected value of 0x42082, but was %x", value);
679 test_utf8_next_char()
681 gchar word1 [] = {0xC2, 0x82,0x45,0xE1, 0x81, 0x83,0x58,0xF1, 0x82, 0x82, 0x82,'\0'}; //Valid, len = 5
682 gchar word2 [] = {0xF1, 0x82, 0x82, 0x82,0xC2, 0x82,0x45,0xE1, 0x81, 0x83,0x58,'\0'}; //Valid, len = 5
683 gchar word1ExpectedValues [] = {0xC2, 0x45,0xE1, 0x58, 0xF1};
684 gchar word2ExpectedValues [] = {0xF1, 0xC2, 0x45, 0xE1, 0x58};
691 return FAILED ("Word1 has gone past its expected length");
692 if (*ptr != word1ExpectedValues[count])
693 return FAILED ("Word1 has an incorrect next_char at index %i", count);
694 ptr = g_utf8_next_char (ptr);
703 return FAILED ("Word2 has gone past its expected length");
704 if (*ptr != word2ExpectedValues[count])
705 return FAILED ("Word2 has an incorrect next_char at index %i", count);
706 ptr = g_utf8_next_char (ptr);
716 gchar invalidWord1 [] = {0xC3, 0x82, 0xC1,0x90,'\0'}; //Invalid, 1nd oct Can't be 0xC0 or 0xC1
717 gchar invalidWord2 [] = {0xC1, 0x89, 0x60, '\0'}; //Invalid, 1st oct can not be 0xC1
718 gchar invalidWord3 [] = {0xC2, 0x45,0xE1, 0x81, 0x83,0x58,'\0'}; //Invalid, oct after 0xC2 must be > 0x80
720 gchar validWord1 [] = {0xC2, 0x82, 0xC3,0xA0,'\0'}; //Valid
721 gchar validWord2 [] = {0xC2, 0x82,0x45,0xE1, 0x81, 0x83,0x58,0xF1, 0x82, 0x82, 0x82,'\0'}; //Valid
724 gboolean retVal = g_utf8_validate (invalidWord1, -1, &end);
726 return FAILED ("Expected invalidWord1 to be invalid");
727 if (end != &invalidWord1 [2])
728 return FAILED ("Expected end parameter to be pointing to invalidWord1[2]");
731 retVal = g_utf8_validate (invalidWord2, -1, &end);
733 return FAILED ("Expected invalidWord2 to be invalid");
734 if (end != &invalidWord2 [0])
735 return FAILED ("Expected end parameter to be pointing to invalidWord2[0]");
738 retVal = g_utf8_validate (invalidWord3, -1, &end);
740 return FAILED ("Expected invalidWord3 to be invalid");
741 if (end != &invalidWord3 [0])
742 return FAILED ("Expected end parameter to be pointing to invalidWord3[1]");
745 retVal = g_utf8_validate (validWord1, -1, &end);
747 return FAILED ("Expected validWord1 to be valid");
748 if (end != &validWord1 [4])
749 return FAILED ("Expected end parameter to be pointing to validWord1[4]");
752 retVal = g_utf8_validate (validWord2, -1, &end);
754 return FAILED ("Expected validWord2 to be valid");
755 if (end != &validWord2 [11])
756 return FAILED ("Expected end parameter to be pointing to validWord2[11]");
761 utf8_byteslen (const gchar *src)
772 test_utf8_strcase_each (const gchar *src, const gchar *expected, gboolean strup)
778 len = utf8_byteslen (src);
779 tmp = strup ? g_utf8_strup (src, len) : g_utf8_strdown (src, len);
780 len2 = utf8_byteslen (tmp);
781 r = compare_strings_utf8_RESULT (expected, tmp, len < len2 ? len2 : len);
787 test_utf8_strup_each (const gchar *src, const gchar *expected)
789 return test_utf8_strcase_each (src, expected, TRUE);
793 test_utf8_strdown_each (const gchar *src, const gchar *expected)
795 return test_utf8_strcase_each (src, expected, FALSE);
806 if ((r = test_utf8_strup_each ("aBc", "ABC")) != OK)
808 if ((r = test_utf8_strup_each ("x86-64", "X86-64")) != OK)
810 // U+3B1 U+392 -> U+391 U+392
811 if ((r = test_utf8_strup_each ("\xCE\xB1\xCE\x92", "\xCE\x91\xCE\x92")) != OK)
814 if ((r = test_utf8_strup_each ("\xEF\xBC\xA1", "\xEF\xBC\xA1")) != OK)
817 if ((r = test_utf8_strup_each ("\xEF\xBD\x81", "\xEF\xBC\xA1")) != OK)
819 // U+10428 -> U+10400
820 if ((r = test_utf8_strup_each ("\xF0\x90\x90\xA8", "\xF0\x90\x90\x80")) != OK)
834 if ((r = test_utf8_strdown_each ("aBc", "abc")) != OK)
836 if ((r = test_utf8_strdown_each ("X86-64", "x86-64")) != OK)
838 // U+391 U+3B2 -> U+3B1 U+3B2
839 if ((r = test_utf8_strdown_each ("\xCE\x91\xCE\xB2", "\xCE\xB1\xCE\xB2")) != OK)
843 if ((r = test_utf8_strdown_each ("\xEF\xBC\x81", "\xEF\xBC\x81")) != OK)
846 if ((r = test_utf8_strdown_each ("\xEF\xBC\xA1", "\xEF\xBD\x81")) != OK)
848 // U+10400 -> U+10428
849 if ((r = test_utf8_strdown_each ("\xF0\x90\x90\x80", "\xF0\x90\x90\xA8")) != OK)
856 * test initialization
859 static Test utf8_tests [] = {
860 {"g_utf16_to_utf8", test_utf16_to_utf8},
861 {"g_utf8_to_utf16", test_utf8_to_utf16},
862 {"g_utf8_seq", test_utf8_seq},
863 {"g_convert", test_convert },
864 {"g_unichar_xdigit_value", test_xdigit },
865 {"g_ucs4_to_utf16", test_ucs4_to_utf16 },
866 {"g_utf16_to_ucs4", test_utf16_to_ucs4 },
867 {"g_utf8_strlen", test_utf8_strlen },
868 {"g_utf8_get_char", test_utf8_get_char },
869 {"g_utf8_next_char", test_utf8_next_char },
870 {"g_utf8_validate", test_utf8_validate },
871 {"g_utf8_strup", test_utf8_strup},
872 {"g_utf8_strdown", test_utf8_strdown},
876 DEFINE_TEST_GROUP_INIT(utf8_tests_init, utf8_tests)