Change the %e tests to not check for actual string equality, but rather
authorMatthias Clasen <maclas@gmx.de>
Tue, 28 Oct 2003 22:40:51 +0000 (22:40 +0000)
committerMatthias Clasen <matthiasc@src.gnome.org>
Tue, 28 Oct 2003 22:40:51 +0000 (22:40 +0000)
Tue Oct 28 23:38:30 2003  Matthias Clasen  <maclas@gmx.de>

* tests/printf-test.c: Change the %e tests to not check for
actual string equality, but rather equality under g_ascii_strtod(),
since the number of leading digits in the exponent seems to
be not exactly prescribed by SUS.

ChangeLog
ChangeLog.pre-2-10
ChangeLog.pre-2-12
ChangeLog.pre-2-4
ChangeLog.pre-2-6
ChangeLog.pre-2-8
tests/printf-test.c

index 197d810..546eaad 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Tue Oct 28 23:38:30 2003  Matthias Clasen  <maclas@gmx.de>
+
+       * tests/printf-test.c: Change the %e tests to not check for
+       actual string equality, but rather equality under g_ascii_strtod(),
+       since the number of leading digits in the exponent seems to 
+       be not exactly prescribed by SUS.
+
 Fri Oct 24 17:09:04 2003  Owen Taylor  <otaylor@redhat.com>
 
        * === Released 2.3.0 ===
index 197d810..546eaad 100644 (file)
@@ -1,3 +1,10 @@
+Tue Oct 28 23:38:30 2003  Matthias Clasen  <maclas@gmx.de>
+
+       * tests/printf-test.c: Change the %e tests to not check for
+       actual string equality, but rather equality under g_ascii_strtod(),
+       since the number of leading digits in the exponent seems to 
+       be not exactly prescribed by SUS.
+
 Fri Oct 24 17:09:04 2003  Owen Taylor  <otaylor@redhat.com>
 
        * === Released 2.3.0 ===
index 197d810..546eaad 100644 (file)
@@ -1,3 +1,10 @@
+Tue Oct 28 23:38:30 2003  Matthias Clasen  <maclas@gmx.de>
+
+       * tests/printf-test.c: Change the %e tests to not check for
+       actual string equality, but rather equality under g_ascii_strtod(),
+       since the number of leading digits in the exponent seems to 
+       be not exactly prescribed by SUS.
+
 Fri Oct 24 17:09:04 2003  Owen Taylor  <otaylor@redhat.com>
 
        * === Released 2.3.0 ===
index 197d810..546eaad 100644 (file)
@@ -1,3 +1,10 @@
+Tue Oct 28 23:38:30 2003  Matthias Clasen  <maclas@gmx.de>
+
+       * tests/printf-test.c: Change the %e tests to not check for
+       actual string equality, but rather equality under g_ascii_strtod(),
+       since the number of leading digits in the exponent seems to 
+       be not exactly prescribed by SUS.
+
 Fri Oct 24 17:09:04 2003  Owen Taylor  <otaylor@redhat.com>
 
        * === Released 2.3.0 ===
index 197d810..546eaad 100644 (file)
@@ -1,3 +1,10 @@
+Tue Oct 28 23:38:30 2003  Matthias Clasen  <maclas@gmx.de>
+
+       * tests/printf-test.c: Change the %e tests to not check for
+       actual string equality, but rather equality under g_ascii_strtod(),
+       since the number of leading digits in the exponent seems to 
+       be not exactly prescribed by SUS.
+
 Fri Oct 24 17:09:04 2003  Owen Taylor  <otaylor@redhat.com>
 
        * === Released 2.3.0 ===
index 197d810..546eaad 100644 (file)
@@ -1,3 +1,10 @@
+Tue Oct 28 23:38:30 2003  Matthias Clasen  <maclas@gmx.de>
+
+       * tests/printf-test.c: Change the %e tests to not check for
+       actual string equality, but rather equality under g_ascii_strtod(),
+       since the number of leading digits in the exponent seems to 
+       be not exactly prescribed by SUS.
+
 Fri Oct 24 17:09:04 2003  Owen Taylor  <otaylor@redhat.com>
 
        * === Released 2.3.0 ===
index b5ac8b5..b9b061c 100644 (file)
@@ -46,6 +46,17 @@ if (failed) \
 #define TEST_FAILED(message) \
   G_STMT_START { g_print ("Error: "); g_print message; g_print ("\n"); any_failed = TRUE; } G_STMT_END
 
+static gboolean
+same_value (const gchar *actual, 
+            const gchar *expected)
+{
+  gdouble actual_value, expected_value;
+
+  actual_value = g_ascii_strtod (actual, NULL);
+  expected_value = g_ascii_strtod (expected, NULL);
+
+  return actual_value == expected_value;
+}
 
 int
 main (int   argc,
@@ -153,17 +164,23 @@ main (int   argc,
   TEST (NULL, g_snprintf (buf, 128, "%05.2f", G_PI) == 5 && !strcmp (buf, "03.14"));
 
   /* %e, basic formatting */
-  TEST (NULL, g_snprintf (buf, 128, "%e", G_PI) == 12 && !strcmp (buf, "3.141593e+00"));
-  TEST (NULL, g_snprintf (buf, 128, "%.8e", G_PI) == 14 && !strcmp (buf, "3.14159265e+00"));
-  TEST (buf, g_snprintf (buf, 128, "%.0e", G_PI) == 5 && !strcmp (buf, "3e+00"));
-  TEST (buf, g_snprintf (buf, 128, "%.1e", 0.0) == 7 && !strcmp (buf, "0.0e+00"));
-  TEST (buf, g_snprintf (buf, 128, "%.1e", 0.00001) == 7 && !strcmp (buf, "1.0e-05"));
-  TEST (buf, g_snprintf (buf, 128, "%.1e", 10000.0) == 7 && !strcmp (buf, "1.0e+04"));
+  /* for %e we can't expect to reproduce exact strings and lengths, since SUS
+   * only guarantees that the exponent shall always contain at least two 
+   * digits. On Windows, it seems to be at least three digits long.
+   * Therefore, we compare the results of parsing the expected result and the
+   * actual result.
+   */
+  TEST (buf, g_snprintf (buf, 128, "%e", G_PI) >= 12 && same_value (buf, "3.141593e+00"));
+  TEST (buf, g_snprintf (buf, 128, "%.8e", G_PI) >= 14 && same_value (buf, "3.14159265e+00"));
+  TEST (buf, g_snprintf (buf, 128, "%.0e", G_PI) >= 5 && same_value (buf, "3e+00"));
+  TEST (buf, g_snprintf (buf, 128, "%.1e", 0.0) >= 7 && same_value (buf, "0.0e+00"));
+  TEST (buf, g_snprintf (buf, 128, "%.1e", 0.00001) >= 7 && same_value (buf, "1.0e-05"));
+  TEST (buf, g_snprintf (buf, 128, "%.1e", 10000.0) >= 7 && same_value (buf, "1.0e+04"));
   /* %e, flags */
-  TEST (NULL, g_snprintf (buf, 128, "%+e", G_PI) == 13 && !strcmp (buf, "+3.141593e+00"));
-  TEST (NULL, g_snprintf (buf, 128, "% e", G_PI) == 13 && !strcmp (buf, " 3.141593e+00"));
-  TEST (NULL, g_snprintf (buf, 128, "%#.0e", G_PI) == 6 && !strcmp (buf, "3.e+00"));
-  TEST (NULL, g_snprintf (buf, 128, "%09.2e", G_PI) == 9 && !strcmp (buf, "03.14e+00"));
+  TEST (buf, g_snprintf (buf, 128, "%+e", G_PI) >= 13 && same_value (buf, "+3.141593e+00"));
+  TEST (buf, g_snprintf (buf, 128, "% e", G_PI) >= 13 && same_value (buf, " 3.141593e+00"));
+  TEST (buf, g_snprintf (buf, 128, "%#.0e", G_PI) >= 6 && same_value (buf, "3.e+00"));
+  TEST (buf, g_snprintf (buf, 128, "%09.2e", G_PI) >= 9 && same_value (buf, "03.14e+00"));
 
   /* %c */
   TEST (NULL, g_snprintf (buf, 128, "%c", 'a') == 1 && !strcmp (buf, "a"));