blob: 604078b3852e2a136ae76d6ef1a33a9d07c88e60 [file] [log] [blame]
#include <locale.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "third_party/glibc_locales/common/localeinfo.h"
#include "third_party/glibc_locales/glibc_locales.h"
#include "third_party/glibc_locales/locale_archive.h"
static int validate(const char* input, const char* expected_output) {
const char* archive_data = locale_archive_create()->data;
char* output = google_add_codeset_to_locale_name(archive_data, input);
// Check that we got the expected result.
if (strcmp(output, expected_output) != 0) {
printf("FAIL: For '%s', expected '%s', got '%s'\n", input, expected_output,
output);
free(output);
return 1;
}
// Check that the modified name is usable, if it's not a composite name..
if (!strchr(input, ';')) {
google_locale_t locale;
locale = google_newlocale(LC_ALL_MASK, output, NULL, 0);
int failed_locale = (locale == NULL);
google_freelocale(locale);
if (failed_locale) {
printf("FAIL: Can't make locale for '%s' (from '%s')\n", output, input);
free(output);
return 1;
}
}
free(output);
return 0;
}
static int do_test() {
int res = 0;
// Validate that we just pass through things with codesets and composite
// names.
res += validate("C.utf8", "C.utf8");
res += validate("C.UTF-8", "C.UTF-8");
res += validate("LC_CTYPE=foo;LC_COLLATE=bar", "LC_CTYPE=foo;LC_COLLATE=bar");
// Validate some expected results, including names that we know changed
// between GRTE v4 and GRTE v5.
res += validate("C", "C");
res += validate("POSIX", "POSIX");
res += validate("ca_ES@valencia", "ca_ES.ISO-8859-15@valencia");
res += validate("en_US", "en_US.ISO-8859-1");
res += validate("eo", "eo.ISO-8859-3");
return res;
}
int main() { return do_test(); }