| /* Branched from glibc's string/tst-strxfrm2.c. */ |
| |
| #include <locale.h> |
| #include <stdio.h> |
| #include <string.h> |
| |
| #include "third_party/glibc_locales/glibc_locales.h" |
| |
| static int do_test(void) { |
| google_locale_t loc = google_newlocale(LC_ALL_MASK, "POSIX", NULL, 0); |
| if (loc == NULL) { |
| puts("google_newlocale POSIX failed"); |
| return 1; |
| } |
| |
| int res = 0; |
| |
| char buf[20]; |
| size_t l1 = google_strxfrm_l(NULL, "ab", 0, loc); |
| size_t l2 = google_strxfrm_l(buf, "ab", 1, loc); |
| size_t l3 = google_strxfrm_l(buf, "ab", sizeof(buf), loc); |
| if (l3 < sizeof(buf) && strlen(buf) != l3) { |
| puts("C locale l3 test failed"); |
| res = 1; |
| } |
| |
| size_t l4 = google_strxfrm_l(buf, "ab", l1 + 1, loc); |
| if (l4 < l1 + 1 && strlen(buf) != l4) { |
| puts("C locale l4 test failed"); |
| res = 1; |
| } |
| |
| buf[l1] = 'Z'; |
| size_t l5 = google_strxfrm_l(buf, "ab", l1, loc); |
| if (buf[l1] != 'Z') { |
| puts("C locale l5 test failed"); |
| res = 1; |
| } |
| |
| if (l1 != l2 || l1 != l3 || l1 != l4 || l1 != l5) { |
| puts("C locale retval test failed"); |
| res = 1; |
| } |
| |
| loc = google_newlocale(LC_ALL_MASK, "de_DE.UTF-8", NULL, 0); |
| if (loc == NULL) { |
| puts("google_setlocale failed"); |
| res = 1; |
| } else { |
| l1 = google_strxfrm_l(NULL, "ab", 0, loc); |
| l2 = google_strxfrm_l(buf, "ab", 1, loc); |
| l3 = google_strxfrm_l(buf, "ab", sizeof(buf), loc); |
| if (l3 < sizeof(buf) && strlen(buf) != l3) { |
| puts("UTF-8 locale l3 test failed"); |
| res = 1; |
| } |
| |
| l4 = google_strxfrm_l(buf, "ab", l1 + 1, loc); |
| if (l4 < l1 + 1 && strlen(buf) != l4) { |
| puts("UTF-8 locale l4 test failed"); |
| res = 1; |
| } |
| |
| buf[l1] = 'Z'; |
| l5 = google_strxfrm_l(buf, "ab", l1, loc); |
| if (buf[l1] != 'Z') { |
| puts("UTF-8 locale l5 test failed"); |
| res = 1; |
| } |
| |
| if (l1 != l2 || l1 != l3 || l1 != l4 || l1 != l5) { |
| puts("UTF-8 locale retval test failed"); |
| res = 1; |
| } |
| } |
| |
| return res; |
| } |
| |
| int main() { return do_test(); } |