#include <locale.h>
#include <stdio.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/library/current_locale.h"

static int validate_locale(google_locale_t locale, int category, char *name,
                           char *where) {
  if (locale->category_data[category] == NULL) {
    printf("FAIL: current locale data is NULL %s.\n", where);
    return 1;
  } else if (strcmp(locale->category_data[category]->name, name)) {
    printf("FAIL: current locale name is '%s', not '%s', %s.\n",
           locale->category_data[category]->name, name, where);
    return 1;
  }
  return 0;
}

static int do_test() {
  int res = 0;

  // Make sure we have a locale before anything is called.
  google_locale_t locale = google_get_current_locale();
  res +=
      validate_locale(locale, GOOGLE_LC_CTYPE, "C", "ctype before setlocale");
  res += validate_locale(locale, GOOGLE_LC_COLLATE, "C",
                         "collate before setlocale");

  // Set the locale to something that both implementations support
  google_setlocale(LC_ALL, "en_US.UTF-8");
  locale = google_get_current_locale();
  res += validate_locale(locale, GOOGLE_LC_CTYPE, "en_US.UTF-8",
                         "for ctype after setlocale");
  res += validate_locale(locale, GOOGLE_LC_COLLATE, "en_US.UTF-8",
                         "for collate after setlocale");

  // Set only the ctype locale.
  google_setlocale(LC_CTYPE, "C");
  locale = google_get_current_locale();
  res += validate_locale(locale, GOOGLE_LC_CTYPE, "C",
                         "for ctype after setlocale(LC_CTYPE)");
  res += validate_locale(locale, GOOGLE_LC_COLLATE, "en_US.UTF-8",
                         "for collate after setlocale(LC_CTYPE)");

  // Reset the locale.
  google_setlocale(LC_ALL, "en_US.UTF-8");

  // Set only the collate locale.
  google_setlocale(LC_COLLATE, "C");
  locale = google_get_current_locale();
  res += validate_locale(locale, GOOGLE_LC_CTYPE, "en_US.UTF-8",
                         "for ctype after setlocale(LC_COLLATE)");
  res += validate_locale(locale, GOOGLE_LC_COLLATE, "C",
                         "for collate after setlocale(LC_COLLATE)");

  // Reset the locale.
  google_setlocale(LC_ALL, "en_US.UTF-8");

  // Set the locale to something that only glibc_locales supports
  google_setlocale(LC_ALL, "en_GB");
  locale = google_get_current_locale();
  res += validate_locale(locale, GOOGLE_LC_CTYPE, "en_US.UTF-8",
                         "for ctype after bad setlocale");
  res += validate_locale(locale, GOOGLE_LC_COLLATE, "en_US.UTF-8",
                         "for collate after bad setlocale");

  // Finally, set the locale to an empty string.
  if (google_setlocale(LC_ALL, "") == NULL) {
    printf("FAIL: google_setlocale(LC_ALL, "") returned NULL.\n");
    res += 1;
  }

  return res;
}

int main() { return do_test(); }
