Back to index

glibc  2.9
Functions | Variables
tst-swscanf.c File Reference
#include <locale.h>
#include <stdio.h>
#include <string.h>
#include <wchar.h>

Go to the source code of this file.

Functions

static int do_test (const char *loc)
int main (void)

Variables

struct {
const wchar_t * fmt
const wchar_t * wfmt
const wchar_t * arg
int retval
const char * res
const wchar_t * wres
int only_C_locale
tests []

Function Documentation

static int do_test ( const char *  loc) [static]

Definition at line 46 of file tst-swscanf.c.

{
  size_t n;
  int result = 0;

  if (setlocale (LC_ALL, loc) == NULL)
    {
      printf ("cannot set locale \"%s\": %m\n", loc);
      return 1;
    }

  printf ("\nnew locale: \"%s\"\n", loc);

  for (n = 0; n < sizeof (tests) / sizeof (tests[0]); ++n)
    {
      char buf[100];
      wchar_t wbuf[100];

      if (tests[n].only_C_locale && strcmp (loc, "C") != 0)
       continue;

      if (swscanf (tests[n].arg, tests[n].fmt, buf) != tests[n].retval)
       {
         printf ("swscanf (\"%S\", \"%S\", ...) failed\n",
                tests[n].arg, tests[n].fmt);
         result = 1;
       }
      else if (tests[n].retval != 0 && strcmp (buf, tests[n].res) != 0)
       {
         printf ("swscanf (\"%S\", \"%S\", ...) return \"%s\", expected \"%s\"\n",
                tests[n].arg, tests[n].fmt, buf, tests[n].res);
         result = 1;
       }
      else
       printf ("swscanf (\"%S\", \"%S\", ...) OK\n",
              tests[n].arg, tests[n].fmt);

      if (swscanf (tests[n].arg, tests[n].wfmt, wbuf) != tests[n].retval)
       {
         printf ("swscanf (\"%S\", \"%S\", ...) failed\n",
                tests[n].arg, tests[n].wfmt);
         result = 1;
       }
      else if (tests[n].retval != 0 && wcscmp (wbuf, tests[n].wres) != 0)
       {
         printf ("swscanf (\"%S\", \"%S\", ...) return \"%S\", expected \"%S\"\n",
                tests[n].arg, tests[n].wfmt, wbuf, tests[n].wres);
         result = 1;
       }
      else
       printf ("swscanf (\"%S\", \"%S\", ...) OK\n",
              tests[n].arg, tests[n].wfmt);
    }

  return result;
}

Here is the call graph for this function:

int main ( void  )

Definition at line 11 of file tst-swscanf.c.

{
  int result;

  result = do_test ("C");
  result |= do_test ("de_DE.ISO-8859-1");
  result |= do_test ("de_DE.UTF-8");
  result |= do_test ("ja_JP.EUC-JP");

  return result;
}

Variable Documentation

struct { ... } tests[] [static]