This is the mail archive of the libc-alpha@sources.redhat.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: New test for LC_NUMERIC


[Ulrich Drepper]
> How large is the patch?

The difference between tst-fmon.c and tst-numeric.c is not very large:

--- tst-fmon.c  Fri Jul  6 06:55:34 2001
+++ tst-numeric.c       Wed Apr 16 20:27:17 2003
@@ -1,7 +1,9 @@
-/* Testing the implementation of strfmon(3).
-   Copyright (C) 1996, 1997, 2000 Free Software Foundation, Inc.
+/* Testing the implementation of LC_NUMERIC.
+   Copyright (C) 2003 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
-   Contributed by Jochen Hein <jochen dot hein at delphi dot central dot de>, 1997.
+   Contributed by Petter Reinholdtsen <pere at hungry dot com>, 2003
+
+   Based on tst-fmon.c by Jochen Hein <jochen dot hein at delphi dot central dot de>, 1997.

    The GNU C Library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
@@ -20,42 +22,43 @@

 #include <stdio.h>
 #include <locale.h>
-#include <monetary.h>
 #include <string.h>
 #include <stdlib.h>

 /*
-  test-strfmon gets called with three parameters:
+  test-numeric gets called with three parameters:
    - the locale
    - the format-string to be used
    - the actual number to be formatted
    - the expected string
-   If the test passes, test-strfmon terminates with returncode 0,
+   If the test passes, test-numeric terminates with returncode 0,
    otherwise with 1
 */
 #define EXIT_SUCCESS 0
 #define EXIT_FAILURE 1
 #define EXIT_SETLOCALE 2
-#define EXIT_STRFMON 3
+#define EXIT_SNPRINTF 3

 int
 main (int argc, char *argv[])
 {
   char *s = malloc (201);
-  double monval;
+  double val;
+
+  /* Make sure to read the value before setting of the locale, as
+     strtod() is locale-dependent. */
+  val = strtod (argv[3], NULL);

-  if (setlocale (LC_MONETARY, argv[1]) == NULL)
+  if (setlocale (LC_NUMERIC, argv[1]) == NULL)
     {
       perror ("setlocale");
       exit (EXIT_SETLOCALE);
     }
-  /* This is locale-dependent! see setlocale(3) for details */
-  monval = strtod (argv[3], NULL);

-  if (strfmon (s, 200, argv[2], (double) atof (argv[3])) == -1)
+  if (snprintf (s, 200, argv[2], val) == -1)
     {
-      perror ("strfmon");
-      exit (EXIT_STRFMON);
+      perror ("snprintf");
+      exit (EXIT_SNPRINTF);
     }

   if (strcmp (s, argv[4]) != 0)

I'll send a proper patch using -N as Roland suggested.

> Don't just set LC_NUMERIC, always use LC_ALL.

Why is this?  tst-fmon.c only sets LC_MONETARY.  Is this wrong?

> As for the name or putting it in an existing file, it doesn't really
> matter.

Oh, I think it need a separate file, but that it might be easier to
copy the existing files and patch them

[Roland McGrath]
> If what you are testing is really the LC_NUMERIC locale info, then
> tst-numeric (and putting it in locale or localedata) is a reasonable
> enough name.  Something called tst-snprintf would test a lot of
> different formats like the existing tst-printf does.

Well, it only reads and prints doubles, so I guess tst-numeric is the
best name.

> Since you will need a patch for a Makefile as well as the new files,
> that is the simplest thing for us to use.

OK. 

> Just send it, and make sure your FSF copyright papers are in order.

I knew there was something I needed to do.  I'll get it fixed as soon
as possible.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]