Blame wcsmbs/tst-c16c32-1.c

Packit Service 82fcde
#include <inttypes.h>
Packit Service 82fcde
#include <locale.h>
Packit Service 82fcde
#include <stdio.h>
Packit Service 82fcde
#include <uchar.h>
Packit Service 82fcde
#include <stdint.h>
Packit Service 82fcde
Packit Service 82fcde
static int
Packit Service 82fcde
do_test (void)
Packit Service 82fcde
{
Packit Service 82fcde
  if (setlocale (LC_ALL, "de_DE.UTF-8") == NULL)
Packit Service 82fcde
    {
Packit Service 82fcde
      puts ("cannot set locale");
Packit Service 82fcde
      return 1;
Packit Service 82fcde
    }
Packit Service 82fcde
Packit Service 82fcde
  int result = 0;
Packit Service 82fcde
Packit Service 82fcde
  char32_t c32 = 48;
Packit Service 82fcde
  do
Packit Service 82fcde
    {
Packit Service 82fcde
      if (c32 >= 0xd800 && c32 <= 0xe000)
Packit Service 82fcde
	continue;
Packit Service 82fcde
Packit Service 82fcde
      char buf[20];
Packit Service 82fcde
      size_t n1 = c32rtomb (buf, c32, NULL);
Packit Service 82fcde
      if (n1 <= 0)
Packit Service 82fcde
	{
Packit Service 82fcde
	  printf ("c32rtomb for U'\\x%" PRIx32 "' failed\n", (uint32_t) c32);
Packit Service 82fcde
	  result = 1;
Packit Service 82fcde
	  continue;
Packit Service 82fcde
	}
Packit Service 82fcde
Packit Service 82fcde
      char32_t c32out;
Packit Service 82fcde
      size_t n2 = mbrtoc32 (&c32out, buf, n1, NULL);
Packit Service 82fcde
      if ((ssize_t) n2 < 0)
Packit Service 82fcde
	{
Packit Service 82fcde
	  printf ("mbrtoc32 for U'\\x%" PRIx32 "' failed\n", (uint32_t) c32);
Packit Service 82fcde
	  result = 1;
Packit Service 82fcde
	  continue;
Packit Service 82fcde
	}
Packit Service 82fcde
      if (n2 != n1)
Packit Service 82fcde
	{
Packit Service 82fcde
	  printf ("mbrtoc32 for U'\\x%" PRIx32 "' consumed %zu bytes, not %zu\n",
Packit Service 82fcde
		  (uint32_t) c32, n2, n1);
Packit Service 82fcde
	  result = 1;
Packit Service 82fcde
	}
Packit Service 82fcde
      else if (c32out != c32)
Packit Service 82fcde
	{
Packit Service 82fcde
	  printf ("mbrtoc32 for U'\\x%" PRIx32 "' produced U'\\x%" PRIx32 "\n",
Packit Service 82fcde
		  (uint32_t) c32, (uint32_t) c32out);
Packit Service 82fcde
	  result = 1;
Packit Service 82fcde
	}
Packit Service 82fcde
Packit Service 82fcde
      char16_t c16;
Packit Service 82fcde
      size_t n3 = mbrtoc16 (&c16, buf, n1, NULL);
Packit Service 82fcde
      if (n3 != n1)
Packit Service 82fcde
	{
Packit Service 82fcde
	  printf ("mbrtoc16 for U'\\x%" PRIx32 "' did not consume all bytes\n",
Packit Service 82fcde
		  (uint32_t) c32);
Packit Service 82fcde
	  result = 1;
Packit Service 82fcde
	  continue;
Packit Service 82fcde
	}
Packit Service 82fcde
      if (c32 < 0x10000)
Packit Service 82fcde
	{
Packit Service 82fcde
	  if (c16 != c32)
Packit Service 82fcde
	    {
Packit Service 82fcde
	      printf ("mbrtoc16 for U'\\x%" PRIx32 "' produce u'\\x%" PRIx16 "'\n",
Packit Service 82fcde
		      (uint32_t) c32, (uint16_t) c16);
Packit Service 82fcde
	      result = 1;
Packit Service 82fcde
	      continue;
Packit Service 82fcde
	    }
Packit Service 82fcde
	}
Packit Service 82fcde
      else
Packit Service 82fcde
	{
Packit Service 82fcde
	  buf[0] = '1';
Packit Service 82fcde
	  char16_t c16_2;
Packit Service 82fcde
	  size_t n4 = mbrtoc16 (&c16_2, buf, 1, NULL);
Packit Service 82fcde
	  if (n4 != (size_t) -3)
Packit Service 82fcde
	    {
Packit Service 82fcde
	      printf ("second mbrtoc16 for U'\\x%" PRIx32 "' did not return -3\n",
Packit Service 82fcde
		      (uint32_t) c32);
Packit Service 82fcde
	      result = 1;
Packit Service 82fcde
	      continue;
Packit Service 82fcde
	    }
Packit Service 82fcde
Packit Service 82fcde
	  if (c32 != (((uint32_t) (c16 - 0xd7c0)) << 10) + (c16_2 - 0xdc00))
Packit Service 82fcde
	    {
Packit Service 82fcde
	      printf ("mbrtoc16 for U'\\x%" PRIx32 "' returns U'\\x%" PRIx32 "\n",
Packit Service 82fcde
		      (uint32_t) c32,
Packit Service 82fcde
		      (((uint32_t) (c16 - 0xd7c0)) << 10) + (c16_2 - 0xdc00));
Packit Service 82fcde
	      result = 1;
Packit Service 82fcde
	      continue;
Packit Service 82fcde
	    }
Packit Service 82fcde
	}
Packit Service 82fcde
Packit Service 82fcde
      buf[0] = '\0';
Packit Service 82fcde
      char16_t c16_nul;
Packit Service 82fcde
      n3 = mbrtoc16 (&c16_nul, buf, n1, NULL);
Packit Service 82fcde
      if (n3 != 0)
Packit Service 82fcde
	{
Packit Service 82fcde
	  printf ("mbrtoc16 for '\\0' returns %zd\n", n3);
Packit Service 82fcde
	  result = 1;
Packit Service 82fcde
	  continue;
Packit Service 82fcde
	}
Packit Service 82fcde
Packit Service 82fcde
      if (c32 < 0x10000)
Packit Service 82fcde
	{
Packit Service 82fcde
	  size_t n5 = c16rtomb (buf, c16, NULL);
Packit Service 82fcde
	  if ((ssize_t) n5 < 0)
Packit Service 82fcde
	    {
Packit Service 82fcde
	      printf ("c16rtomb for U'\\x%" PRIx32 "' failed with %zd\n",
Packit Service 82fcde
		      (uint32_t) c32, n5);
Packit Service 82fcde
	      result = 1;
Packit Service 82fcde
	      continue;
Packit Service 82fcde
	    }
Packit Service 82fcde
	  if (n5 != n1)
Packit Service 82fcde
	    {
Packit Service 82fcde
	      printf ("c16rtomb for U'\\x%" PRIx32 "' produced %zu bytes instead of %zu bytes\n",
Packit Service 82fcde
		      (uint32_t) c32, n5, n1);
Packit Service 82fcde
	      result = 1;
Packit Service 82fcde
	      continue;
Packit Service 82fcde
	    }
Packit Service 82fcde
	}
Packit Service 82fcde
    }
Packit Service 82fcde
  while ((c32 += 0x1111) <= U'\x12000');
Packit Service 82fcde
Packit Service 82fcde
  return result;
Packit Service 82fcde
}
Packit Service 82fcde
Packit Service 82fcde
#define TEST_FUNCTION do_test ()
Packit Service 82fcde
#include "../test-skeleton.c"