treewide: Replace <name>_cnt by n_<name>s and <name>_cap by allocated_<name>.
[pspp] / tests / data / datasheet-test.c
index 532b883faa1980f0671e249a27a9b1d71c5728ee..09dc3d8e759f952973ca5fcd3cbcb7b74abd9176 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPP - a program for statistical analysis.
-   Copyright (C) 2007, 2009, 2010 Free Software Foundation, Inc.
+   Copyright (C) 2007, 2009, 2010, 2014 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -19,6 +19,7 @@
 #include <data/datasheet.h>
 
 #include <ctype.h>
+#include <float.h>
 #include <stdlib.h>
 #include <stdint.h>
 #include <string.h>
@@ -41,7 +42,6 @@
 #include "error.h"
 #include "minmax.h"
 #include "progname.h"
-#include "xalloc.h"
 
 /* lazy_casereader callback function to instantiate a casereader
    from the datasheet. */
@@ -117,15 +117,15 @@ check_datasheet_casereader (struct mc *mc, struct casereader *reader,
   if (!check_caseproto (mc, proto, casereader_get_proto (reader),
                         "casereader"))
     return;
-  else if (casereader_get_case_cnt (reader) != n_rows)
+  else if (casereader_get_n_cases (reader) != n_rows)
     {
-      if (casereader_get_case_cnt (reader) == CASENUMBER_MAX
+      if (casereader_get_n_cases (reader) == CASENUMBER_MAX
           && casereader_count_cases (reader) == n_rows)
         mc_error (mc, "datasheet casereader has unknown case count");
       else
         mc_error (mc, "casereader row count (%lu) does not match "
                   "expected (%zu)",
-                  (unsigned long int) casereader_get_case_cnt (reader),
+                  (unsigned long int) casereader_get_n_cases (reader),
                   n_rows);
     }
   else
@@ -153,15 +153,16 @@ check_datasheet_casereader (struct mc *mc, struct casereader *reader,
                 {
                   if (width == 0)
                     mc_error (mc, "element %zu,%zu (of %zu,%zu) differs: "
-                              "%g != %g",
+                              "%.*g != %.*g",
                               row, col, n_rows, n_columns,
-                              case_num_idx (c, col), array[row][col].f);
+                              DBL_DIG + 1, case_num_idx (c, col),
+                              DBL_DIG + 1, array[row][col].f);
                   else
                     mc_error (mc, "element %zu,%zu (of %zu,%zu) differs: "
                               "'%.*s' != '%.*s'",
                               row, col, n_rows, n_columns,
                               width, case_str_idx (c, col),
-                              width, value_str (&array[row][col], width));
+                              width, array[row][col].s);
                 }
             }
 
@@ -217,14 +218,14 @@ check_datasheet (struct mc *mc, struct datasheet *ds,
               {
                 if (width == 0)
                   mc_error (mc, "element %zu,%zu (of %zu,%zu) differs: "
-                            "%g != %g", row, col, n_rows, n_columns,
-                            v.f, av->f);
+                            "%.*g != %.*g", row, col, n_rows, n_columns,
+                            DBL_DIG + 1, v.f, DBL_DIG + 1, av->f);
                 else
                   mc_error (mc, "element %zu,%zu (of %zu,%zu) differs: "
                             "'%.*s' != '%.*s'",
                             row, col, n_rows, n_columns,
-                            width, value_str (&v, width),
-                            width, value_str (av, width));
+                            width, v.s,
+                            width, v.s);
                 difference = true;
               }
             value_destroy (&v, width);
@@ -247,7 +248,7 @@ check_datasheet (struct mc *mc, struct datasheet *ds,
                   if (width == 0)
                     ds_put_format (&s, " %g", v->f);
                   else
-                    ds_put_format (&s, " '%.*s'", width, value_str (v, width));
+                    ds_put_format (&s, " '%.*s'", width, v->s);
                 }
               mc_error (mc, "%s", ds_cstr (&s));
             }
@@ -268,8 +269,7 @@ check_datasheet (struct mc *mc, struct datasheet *ds,
                   if (width == 0)
                     ds_put_format (&s, " %g", v.f);
                   else
-                    ds_put_format (&s, " '%.*s'",
-                                   width, value_str (&v, width));
+                    ds_put_format (&s, " '%.*s'", width, v.s);
                 }
               mc_error (mc, "%s", ds_cstr (&s));
             }
@@ -405,12 +405,11 @@ value_from_param (union value *value, int width, unsigned int idx)
   else
     {
       unsigned int hash = hash_int (idx, 0);
-      uint8_t *string = value_str_rw (value, width);
       int offset;
 
       assert (width < 32);
       for (offset = 0; offset < width; offset++)
-        string[offset] = "ABCDEFGHIJ"[(hash >> offset) % 10];
+        value->s[offset] = "ABCDEFGHIJ"[(hash >> offset) % 10];
     }
 }
 
@@ -856,10 +855,9 @@ usage (void)
           "                       other values are string widths (0,1,11)\n",
           program_name, program_name);
   mc_options_usage ();
-  fputs ("\nOther options:\n"
-         "  --help               Display this help message\n"
-         "\nReport bugs to <bug-gnu-pspp@gnu.org>\n",
-         stdout);
+  printf ("\nOther options:\n"
+          "  --help               Display this help message\n"
+          "\nReport bugs to <%s>\n", PACKAGE_BUGREPORT);
   exit (0);
 }
 
@@ -893,7 +891,7 @@ main (int argc, char *argv[])
   params.n_widths = 3;
   params.next_value = 1;
 
-  /* Parse comand line. */
+  /* Parse command line. */
   parser = argv_parser_create ();
   options = mc_options_create ();
   mc_options_register_argv_parser (options, parser);