-Add a crt regression test suite, extending the msvcrt winetests
authorGregor Schneider <grschneider@gmail.com>
Wed, 5 Aug 2009 17:13:12 +0000 (17:13 +0000)
committerGregor Schneider <grschneider@gmail.com>
Wed, 5 Aug 2009 17:13:12 +0000 (17:13 +0000)
-iofunc tests were used to verify r42382, added another one that tests swprintf double conversion (roscalc issue)
-time tests crash with the current crt implementation

svn path=/trunk/; revision=42408

rostests/regtests/crt/crt_regtest.rbuild [new file with mode: 0644]
rostests/regtests/crt/iofuncs.c [new file with mode: 0644]
rostests/regtests/crt/testlist.c [new file with mode: 0644]
rostests/regtests/crt/time.c [new file with mode: 0644]
rostests/regtests/directory.rbuild

diff --git a/rostests/regtests/crt/crt_regtest.rbuild b/rostests/regtests/crt/crt_regtest.rbuild
new file mode 100644 (file)
index 0000000..d4956a2
--- /dev/null
@@ -0,0 +1,12 @@
+<?xml version="1.0"?>
+<!DOCTYPE module SYSTEM "../../../tools/rbuild/project.dtd">
+<group>
+<module name="crt_regtest" type="win32cui" installbase="bin" installname="crt_regtest.exe">
+       <include base="crt_regtest">.</include>
+       <library>wine</library>
+       <library>msvcrt</library>
+       <file>iofuncs.c</file>
+       <file>testlist.c</file>
+       <file>time.c</file>
+</module>
+</group>
diff --git a/rostests/regtests/crt/iofuncs.c b/rostests/regtests/crt/iofuncs.c
new file mode 100644 (file)
index 0000000..cc64ac2
--- /dev/null
@@ -0,0 +1,100 @@
+/*
+ * PROJECT:         ReactOS CRT regression tests
+ * LICENSE:         GPL - See COPYING in the top level directory
+ * FILE:            rostests/regtests/crt/iofuncs.c
+ * PURPOSE:         Tests for input/output functions of the CRT
+ * PROGRAMMERS:     Gregor Schneider
+ */
+
+#include <stdio.h>
+#include <wine/test.h>
+
+#define _CRT_NON_CONFORMING_SWPRINTFS
+
+struct _testData
+{
+    double val;
+    int prec;
+    char* exp;
+    char* exp2;
+} ECVTTESTDATA[] =
+{
+    {   45.0,           2,      "+4.50E+001",           "+4.5000E+001"          },  /*0*/
+    {   0.0001,         1,      "+1.0E-004",            "+1.000E-004"           },
+    {   0.0001,         -10,    "+1.000000E-004",       "+1.000000E-004"        },
+    {   0.0001,         10,     "+1.0000000000E-004",   "+1.000000000000E-004"  },
+    {   -111.0001,      5,      "-1.11000E+002",        "-1.1100010E+002"       },
+    {   111.0001,       5,      "+1.11000E+002",        "+1.1100010E+002"       },  /*5*/
+    {   3333.3,         2,      "+3.33E+003",           "+3.3333E+003"          },
+    {   999999999999.9, 3,      "+1.000E+012",          "+1.00000E+012"         },
+    {   0.0,            5,      "+0.00000E+000",        "+0.0000000E+000"       },
+    {   0.0,            0,      "+0E+000",              "+0.00E+000"            },
+    {   0.0,            -1,     "+0.000000E+000",       "+0.0E+000"             },  /*10*/
+    {   -123.0001,      0,      "-1E+002",              "-1.23E+002"            },
+    {   -123.0001,      -1,     "-1.230001E+002",       "-1.2E+002"             },
+    {   -123.0001,      -2,     "-1.230001E+002",       "-1E+002"               },
+    {   -123.0001,      -3,     "-1.230001E+002",       "-1.230001E+002"        },
+    {   99.99,          1,      "+1.0E+002",            "+9.999E+001"           },  /*15*/
+    {   0.0063,         2,      "+6.30E-003",           "+6.3000E-003"          },
+    {   0.0063,         3,      "+6.300E-003",          "+6.30000E-003"         },
+    {   0.09999999996,  2,      "+1.00E-001",           "+1.0000E-001"          },
+    {   0.6,            1,      "+6.0E-001",            "+6.000E-001"           },
+    {   0.6,            0,      "+6E-001",              "+6.00E-001"            },  /*20*/
+    {   0.4,            0,      "+4E-001",              "+4.00E-001"            },
+    {   0.49,           0,      "+5E-001",              "+4.90E-001"            },
+    {   0.51,           0,      "+5E-001",              "+5.10E-001"            }
+};
+
+void Test_ofuncs()
+{
+    int i;    
+    char* buf = NULL;
+
+    /* Test exponential format */
+    buf = malloc(30 * sizeof(char));
+    if (buf == NULL)
+    {
+        printf("Memory full, exiting\n");
+        return;
+    }
+    for (i = 0; i < sizeof(ECVTTESTDATA)/sizeof(ECVTTESTDATA[0]); i++)
+    {
+        sprintf(buf, "%-+.*E", ECVTTESTDATA[i].prec, ECVTTESTDATA[i].val);
+        ok(!strcmp(buf, ECVTTESTDATA[i].exp), 
+            "sprintf exp test %d failed: got %s, expected %s\n", 
+            i, buf, ECVTTESTDATA[i].exp);
+    }
+    for (i = 0; i < sizeof(ECVTTESTDATA)/sizeof(ECVTTESTDATA[0]); i++)
+    {
+        sprintf(buf, "%-+.*E", ECVTTESTDATA[i].prec + 2, ECVTTESTDATA[i].val);
+        ok(!strcmp(buf, ECVTTESTDATA[i].exp2), 
+            "sprintf exp +2 prec test %d failed: got %s, expected %s\n", 
+            i, buf, ECVTTESTDATA[i].exp2);
+    }
+
+    /* Test with negative number to be rounded */
+    sprintf(buf, "%-+.*E", ECVTTESTDATA[18].prec + 2, -ECVTTESTDATA[18].val);
+    ok(!strcmp(buf, "-1.0000E-001"), "Negative number sprintf rounding failed: got %s, expected %s\n",
+        buf, "-1.0000E-001");
+    free(buf);
+}
+
+void Test_ifuncs()
+{
+    double var;
+    char cnum[] = "12.3";
+    wchar_t wnum[] = L"12.3";
+
+    /* Test sscanf behaviour */
+    sscanf(cnum, "%lf", &var);
+    ok(var == 12.3, "sscanf double conversion failed: got %f\n", var);
+    swscanf(wnum, L"%lf", &var);
+    ok(var == 12.3, "swscanf double conversion failed: got %f\n", var);
+}
+
+START_TEST(iofuncs)
+{
+    Test_ofuncs();
+    Test_ifuncs();
+}
+
diff --git a/rostests/regtests/crt/testlist.c b/rostests/regtests/crt/testlist.c
new file mode 100644 (file)
index 0000000..6d720eb
--- /dev/null
@@ -0,0 +1,19 @@
+/* Automatically generated file; DO NOT EDIT!! */
+
+#define WIN32_LEAN_AND_MEAN
+#define __ROS_LONG64__
+#include <windows.h>
+
+#define STANDALONE
+#include "wine/test.h"
+
+extern void func_iofuncs(void);
+extern void func_time(void);
+
+const struct test winetest_testlist[] =
+{
+    { "iofuncs", func_iofuncs },
+    { "time", func_time },
+    { 0, 0 }
+};
+
diff --git a/rostests/regtests/crt/time.c b/rostests/regtests/crt/time.c
new file mode 100644 (file)
index 0000000..e9f4f74
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * PROJECT:         ReactOS CRT regression tests
+ * LICENSE:         GPL - See COPYING in the top level directory
+ * FILE:            rostests/regtests/crt/time.c
+ * PURPOSE:         Tests for time functions of the CRT
+ * PROGRAMMERS:     Gregor Schneider
+ */
+
+#include <stdio.h>
+#include <time.h>
+#include <wine/test.h>
+
+void Test_asctime()
+{
+    /* Test asctime */
+    struct tm time;
+    char* timestr;
+    char explowtime[] = "Mon Jun 04 00:30:20 1909\n"; /* XP's crt returns new line after the string */
+
+    time.tm_hour = 0;
+    time.tm_mday = 4;
+    time.tm_min = 30;
+    time.tm_mon = 5;
+    time.tm_sec = 20;
+    time.tm_wday = 1;
+    time.tm_yday = 200;
+    time.tm_year = 9;
+
+    timestr = asctime(&time);
+    ok(!strcmp(timestr, explowtime), "Wrong time returned, got %s\n", timestr);
+}
+
+void Test_ctime()
+{
+    /* Test border ctime cases */
+    time_t time;
+    time = -15;
+    ok(ctime(&time) == NULL, "ctime doesn't return NULL for invalid parameters\n");
+    time = -5000000;
+    ok(ctime(&time) == NULL,  "ctime doesn't return NULL for invalid parameters\n");
+}
+
+START_TEST(time)
+{
+    Test_asctime();
+    Test_ctime();
+}
+
index d08339a..acbe991 100644 (file)
@@ -4,4 +4,7 @@
        <directory name="gdi">
                <xi:include href="gdi/gdi_regtest.rbuild" />
        </directory>
+       <directory name="crt">
+               <xi:include href="crt/crt_regtest.rbuild" />
+       </directory>
 </group>