ReactOS  0.4.12-dev-918-g6c6e7b8
iofuncs.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS CRT regression tests
3  * LICENSE: GPL - See COPYING in the top level directory
4  * FILE: rostests/regtests/crt/iofuncs.c
5  * PURPOSE: Tests for input/output functions of the CRT
6  * PROGRAMMERS: Gregor Schneider
7  */
8 
9 #include <stdio.h>
10 #include <wine/test.h>
11 
12 #define _CRT_NON_CONFORMING_SWPRINTFS
13 
14 struct _testData
15 {
16  double val;
17  int prec;
18  char* exp;
19  char* exp2;
20 } ECVTTESTDATA[] =
21 {
22  { 45.0, 2, "+4.50E+001", "+4.5000E+001" }, /*0*/
23  { 0.0001, 1, "+1.0E-004", "+1.000E-004" },
24  { 0.0001, -10, "+1.000000E-004", "+1.000000E-004" },
25  { 0.0001, 10, "+1.0000000000E-004", "+1.000000000000E-004" },
26  { -111.0001, 5, "-1.11000E+002", "-1.1100010E+002" },
27  { 111.0001, 5, "+1.11000E+002", "+1.1100010E+002" }, /*5*/
28  { 3333.3, 2, "+3.33E+003", "+3.3333E+003" },
29  { 999999999999.9, 3, "+1.000E+012", "+1.00000E+012" },
30  { 0.0, 5, "+0.00000E+000", "+0.0000000E+000" },
31  { 0.0, 0, "+0E+000", "+0.00E+000" },
32  { 0.0, -1, "+0.000000E+000", "+0.0E+000" }, /*10*/
33  { -123.0001, 0, "-1E+002", "-1.23E+002" },
34  { -123.0001, -1, "-1.230001E+002", "-1.2E+002" },
35  { -123.0001, -2, "-1.230001E+002", "-1E+002" },
36  { -123.0001, -3, "-1.230001E+002", "-1.230001E+002" },
37  { 99.99, 1, "+1.0E+002", "+9.999E+001" }, /*15*/
38  { 0.0063, 2, "+6.30E-003", "+6.3000E-003" },
39  { 0.0063, 3, "+6.300E-003", "+6.30000E-003" },
40  { 0.09999999996, 2, "+1.00E-001", "+1.0000E-001" },
41  { 0.6, 1, "+6.0E-001", "+6.000E-001" },
42  { 0.6, 0, "+6E-001", "+6.00E-001" }, /*20*/
43  { 0.4, 0, "+4E-001", "+4.00E-001" },
44  { 0.49, 0, "+5E-001", "+4.90E-001" },
45  { 0.51, 0, "+5E-001", "+5.10E-001" }
46 };
47 
49 {
50  int i;
51  char* buf = NULL;
52 
53  /* Test exponential format */
54  buf = malloc(30 * sizeof(char));
55  if (buf == NULL)
56  {
57  printf("Memory full, exiting\n");
58  return;
59  }
60  for (i = 0; i < sizeof(ECVTTESTDATA)/sizeof(ECVTTESTDATA[0]); i++)
61  {
62  sprintf(buf, "%-+.*E", ECVTTESTDATA[i].prec, ECVTTESTDATA[i].val);
64  "sprintf exp test %d failed: got %s, expected %s\n",
65  i, buf, ECVTTESTDATA[i].exp);
66  }
67  for (i = 0; i < sizeof(ECVTTESTDATA)/sizeof(ECVTTESTDATA[0]); i++)
68  {
69  sprintf(buf, "%-+.*E", ECVTTESTDATA[i].prec + 2, ECVTTESTDATA[i].val);
71  "sprintf exp +2 prec test %d failed: got %s, expected %s\n",
72  i, buf, ECVTTESTDATA[i].exp2);
73  }
74 
75  /* Test with negative number to be rounded */
76  sprintf(buf, "%-+.*E", ECVTTESTDATA[18].prec + 2, -ECVTTESTDATA[18].val);
77  ok(!strcmp(buf, "-1.0000E-001"), "Negative number sprintf rounding failed: got %s, expected %s\n",
78  buf, "-1.0000E-001");
79  free(buf);
80 }
81 
83 {
84  double var;
85  char cnum[] = "12.3";
86  wchar_t wnum[] = L"12.3";
87 
88  /* Test sscanf behaviour */
89  sscanf(cnum, "%lf", &var);
90  ok(var == 12.3, "sscanf double conversion failed: got %f\n", var);
91  swscanf(wnum, L"%lf", &var);
92  ok(var == 12.3, "swscanf double conversion failed: got %f\n", var);
93 }
94 
95 START_TEST(iofuncs)
96 {
97  Test_ofuncs();
98  Test_ifuncs();
99 }
100 
int prec
Definition: iofuncs.c:17
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define free
Definition: debug_ros.c:5
#define sprintf(buf, format,...)
Definition: sprintf.c:55
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
smooth NULL
Definition: ftsmooth.c:416
char * exp2
Definition: iofuncs.c:19
START_TEST(iofuncs)
Definition: iofuncs.c:95
_Check_return_ _CRTIMP int __cdecl sscanf(_In_z_ const char *_Src, _In_z_ _Scanf_format_string_ const char *_Format,...)
GLuint GLfloat * val
Definition: glext.h:7180
#define ok(value,...)
Definition: CComObject.cpp:34
struct _testData ECVTTESTDATA[]
void Test_ifuncs()
Definition: iofuncs.c:82
void Test_ofuncs()
Definition: iofuncs.c:48
static const WCHAR L[]
Definition: oid.c:1250
char * exp
Definition: iofuncs.c:18
double __cdecl exp2(double)
DWORD exp
Definition: msg.c:15681
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
#define malloc
Definition: debug_ros.c:4
_Check_return_ _CRTIMP int __cdecl swscanf(_In_z_ const wchar_t *_Src, _In_z_ _Scanf_format_string_ const wchar_t *_Format,...)
double val
Definition: iofuncs.c:16
#define printf
Definition: config.h:203