/* Copyright (C) 1999-2014 Free Software Foundation, Inc.
   This file is part of the GNU C Library.

   The GNU C Library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2.1 of the License, or (at your option) any later version.

   The GNU C Library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public
   License along with the GNU C Library; if not, see
   <http://www.gnu.org/licenses/>.  */

#include <stdio.h>
#include <stdlib.h>

#include "third_party/glibc_locales/glibc_locales.h"

#define FAIL(str, args...)             \
  {                                    \
    printf("FAIL: " str "\n", ##args); \
    ++errors;                          \
  }

int main(int argc, char *argv[]) {
  int errors = 0;

  for (int c = 0; c < 128; ++c) {
    if (google_iswlower(c)) {
      /* Get corresponding upper case character.  */
      int up = google_towupper(c);
      /* This should have no effect.  */
      int low = google_towlower(c);

      if ((c != low) || (up == c) || (up == low))
        FAIL("iswlower/towupper/towlower for character \\%x wrong\n", c);
    }
    if (google_iswupper(c)) {
      /* Get corresponding lower case character.  */
      int low = google_towlower(c);
      /* This should have no effect.  */
      int up = google_towupper(c);

      if ((c != up) || (low == c) || (up == low))
        FAIL("iswupper/towlower/towupper for character \\%x wrong\n", c);
    }
  }

  /* Finally some specific tests.  */
  if (!google_iswupper(L'A') || google_iswlower(L'A'))
    FAIL("!iswupper/iswlower (L'A') wrong\n");
  if (google_iswupper(L'a') || !google_iswlower(L'a'))
    FAIL("iswupper/!iswlower (L'a') wrong\n");
  if (google_towlower(L'A') != L'a') FAIL("towlower(L'A') wrong\n");
  if (google_towupper(L'a') != L'A') FAIL("towupper(L'a') wrong\n");

  if (errors != 0) {
    printf("Result: %d error%s\n", errors, errors == 1 ? "" : "s");
    return 1;
  }
  printf("PASS: No errors\n");
  return 0;
}
