ReactOS  0.4.14-dev-1256-g2125fec
_tfileio.c File Reference
#include <windows.h>
#include <tchar.h>
#include <wchar.h>
#include <stdio.h>
Include dependency graph for _tfileio.c:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define WIN32_LEAN_AND_MEAN
 
#define _tfopen   fopen
 
#define _tunlink   _unlink
 
#define _TEOF   EOF
 
#define _gettchar   getchar
 
#define _puttchar   putchar
 
#define _THEX_FORMAT   "0x%02x "
 
#define TEST_BUFFER_SIZE   200
 
#define TEST_FILE_LINES   4
 
#define TEST_B1_FILE_SIZE   (sizeof(dos_data)-1+TEST_FILE_LINES)
 
#define TEST_B2_FILE_SIZE   (sizeof(dos_data)-1-TEST_FILE_LINES)
 
#define TEST_B3_FILE_SIZE   (sizeof(nix_data)-1+TEST_FILE_LINES)
 
#define TEST_B4_FILE_SIZE   (sizeof(nix_data)-1)
 

Functions

static BOOL test_file_truncate (TCHAR *file_name)
 
static BOOL create_output_file (TCHAR *file_name, TCHAR *file_mode, TCHAR *file_data)
 
static BOOL verify_output_file (TCHAR *file_name, TCHAR *file_mode, TCHAR *file_data)
 
static int create_test_file (TCHAR *file_name, TCHAR *write_mode, TCHAR *read_mode, TCHAR *file_data)
 
static int check_file_size (TCHAR *file_name, TCHAR *file_mode, int expected)
 
static int test_console_io (void)
 
static int test_console_getchar (void)
 
static int test_console_putch (void)
 
static int test_unlink_files (void)
 
static int test_text_fileio (TCHAR *file_name, TCHAR *file_data, int tsize, int bsize)
 
static int test_binary_fileio (TCHAR *file_name, TCHAR *file_data, int tsize, int bsize)
 
static int test_files (int test_num, char *type)
 

Variables

BOOL verbose_flagged
 
BOOL status_flagged
 
static TCHAR test_buffer [TEST_BUFFER_SIZE]
 
static TCHAR dos_data []
 
static TCHAR nix_data []
 

Macro Definition Documentation

◆ _gettchar

#define _gettchar   getchar

Definition at line 41 of file _tfileio.c.

◆ _puttchar

#define _puttchar   putchar

Definition at line 42 of file _tfileio.c.

◆ _TEOF

#define _TEOF   EOF

Definition at line 40 of file _tfileio.c.

◆ _tfopen

#define _tfopen   fopen

Definition at line 38 of file _tfileio.c.

◆ _THEX_FORMAT

#define _THEX_FORMAT   "0x%02x "

Definition at line 43 of file _tfileio.c.

◆ _tunlink

#define _tunlink   _unlink

Definition at line 39 of file _tfileio.c.

◆ TEST_B1_FILE_SIZE

#define TEST_B1_FILE_SIZE   (sizeof(dos_data)-1+TEST_FILE_LINES)

Definition at line 71 of file _tfileio.c.

◆ TEST_B2_FILE_SIZE

#define TEST_B2_FILE_SIZE   (sizeof(dos_data)-1-TEST_FILE_LINES)

Definition at line 72 of file _tfileio.c.

◆ TEST_B3_FILE_SIZE

#define TEST_B3_FILE_SIZE   (sizeof(nix_data)-1+TEST_FILE_LINES)

Definition at line 73 of file _tfileio.c.

◆ TEST_B4_FILE_SIZE

#define TEST_B4_FILE_SIZE   (sizeof(nix_data)-1)

Definition at line 74 of file _tfileio.c.

◆ TEST_BUFFER_SIZE

#define TEST_BUFFER_SIZE   200

Definition at line 47 of file _tfileio.c.

◆ TEST_FILE_LINES

#define TEST_FILE_LINES   4

Definition at line 48 of file _tfileio.c.

◆ WIN32_LEAN_AND_MEAN

#define WIN32_LEAN_AND_MEAN

Definition at line 23 of file _tfileio.c.

Function Documentation

◆ check_file_size()

static int check_file_size ( TCHAR file_name,
TCHAR file_mode,
int  expected 
)
static

Definition at line 250 of file _tfileio.c.

251 {
252  int count = 0;
253  FILE* file;
254  TCHAR ch;
255  int error_code;
256 
257  if (status_flagged) {
258  //_tprintf(_T("STATUS: (%s) checking for %d bytes in %s mode\n"), file_name, expected, _tcschr(file_mode, _T('b')) ? _T("binary") : _T("text"));
259  _tprintf(_T("STATUS: (%s) checking for %d bytes with mode %s\n"), file_name, expected, file_mode);
260  }
261  file = _tfopen(file_name, file_mode);
262  if (file == NULL) {
263  _tprintf(_T("ERROR: (%s) failed to open file for reading\n"), file_name);
264  return 1;
265  }
266  while ((ch = _fgettc(file)) != _TEOF) {
267  if (verbose_flagged) {
268  _tprintf(_THEX_FORMAT, ch);
269  }
270  ++count;
271  }
273  if (error_code) {
274  _tprintf(_T("ERROR: (%s) ferror returned %d after reading\n"), file_name, error_code);
275  perror("Read error");
276  }
277 
278  if (verbose_flagged) {
279 // _puttc(_T('\n'), stdout);
280  }
281  fclose(file);
282  if (count == expected) {
283  if (status_flagged) {
284  _tprintf(_T("PASSED: (%s) read %d bytes\n"), file_name, count);
285  }
286  } else {
287  _tprintf(_T("FAILED: (%s) read %d bytes but expected %d using mode \"%s\"\n"), file_name, count, expected, file_mode);
288  }
289  return (count == expected) ? 0 : -1;
290 }
#define _tfopen
Definition: _tfileio.c:38
#define _tprintf
Definition: tchar.h:506
_Check_return_ _CRTIMP int __cdecl ferror(_In_ FILE *_File)
BOOL verbose_flagged
Definition: loadlib.c:39
#define _fgettc
Definition: tchar.h:562
GLuint GLuint GLsizei count
Definition: gl.h:1545
_CRTIMP void __cdecl perror(_In_opt_z_ const char *_ErrMsg)
static int error_code[8]
Definition: odbccp32.c:61
smooth NULL
Definition: ftsmooth.c:416
char TCHAR
Definition: xmlstorage.h:189
#define _T(x)
Definition: vfdio.h:22
const char file[]
Definition: icontest.c:11
#define _THEX_FORMAT
Definition: _tfileio.c:43
BOOL status_flagged
Definition: main.c:42
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
static LPCWSTR file_name
Definition: protocol.c:147
#define _TEOF
Definition: _tfileio.c:40
BOOL expected
Definition: store.c:2063
Definition: fci.c:126

Referenced by test_binary_fileio(), and test_text_fileio().

◆ create_output_file()

static BOOL create_output_file ( TCHAR file_name,
TCHAR file_mode,
TCHAR file_data 
)
static

Definition at line 140 of file _tfileio.c.

141 {
142  BOOL result = FALSE;
143  FILE *file = _tfopen(file_name, file_mode);
144  if (file != NULL) {
145  if (_fputts(file_data, file) != _TEOF) {
146  result = TRUE;
147  } else {
148  _tprintf(_T("ERROR: failed to write data to file \"%s\"\n"), file_name);
149  _tprintf(_T("ERROR: ferror returned %d\n"), ferror(file));
150  }
151  fclose(file);
152  } else {
153  _tprintf(_T("ERROR: failed to open/create file \"%s\" for output\n"), file_name);
154  _tprintf(_T("ERROR: ferror returned %d\n"), ferror(file));
155  }
156  return result;
157 }
#define _tfopen
Definition: _tfileio.c:38
#define _tprintf
Definition: tchar.h:506
_Check_return_ _CRTIMP int __cdecl ferror(_In_ FILE *_File)
#define TRUE
Definition: types.h:120
#define _fputts
Definition: tchar.h:569
unsigned int BOOL
Definition: ntddk_ex.h:94
smooth NULL
Definition: ftsmooth.c:416
#define _T(x)
Definition: vfdio.h:22
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
static LPCWSTR file_name
Definition: protocol.c:147
#define _TEOF
Definition: _tfileio.c:40
GLuint64EXT * result
Definition: glext.h:11304
Definition: fci.c:126

Referenced by create_test_file().

◆ create_test_file()

static int create_test_file ( TCHAR file_name,
TCHAR write_mode,
TCHAR read_mode,
TCHAR file_data 
)
static

Definition at line 226 of file _tfileio.c.

227 {
228  if (status_flagged) {
229  _tprintf(_T("STATUS: Attempting to create output file %s\n"), file_name);
230  }
231  if (create_output_file(file_name, write_mode, file_data)) {
232  if (status_flagged) {
233  _tprintf(_T("STATUS: Attempting to verify output file %s\n"), file_name);
234  }
235  if (verify_output_file(file_name, read_mode, file_data)) {
236  if (status_flagged) {
237  _tprintf(_T("SUCCESS: %s verified ok\n"), file_name);
238  }
239  } else {
240  //_tprintf(_T("ERROR: failed to verify file %s\n"), file_name);
241  return 2;
242  }
243  } else {
244  _tprintf(_T("ERROR: failed to create file %s\n"), file_name);
245  return 1;
246  }
247  return 0;
248 }
#define _tprintf
Definition: tchar.h:506
#define _T(x)
Definition: vfdio.h:22
static BOOL verify_output_file(TCHAR *file_name, TCHAR *file_mode, TCHAR *file_data)
Definition: _tfileio.c:159
static BOOL create_output_file(TCHAR *file_name, TCHAR *file_mode, TCHAR *file_data)
Definition: _tfileio.c:140
BOOL status_flagged
Definition: main.c:42
static LPCWSTR file_name
Definition: protocol.c:147
static ULONG POBJECT_ATTRIBUTES PIO_STATUS_BLOCK ULONG ULONG ULONG ULONG ULONG read_mode
Definition: pipe.c:68

Referenced by test_binary_fileio(), and test_text_fileio().

◆ test_binary_fileio()

static int test_binary_fileio ( TCHAR file_name,
TCHAR file_data,
int  tsize,
int  bsize 
)
static

Definition at line 369 of file _tfileio.c.

370 {
371  int result = 0;
372 
373  result = create_test_file(file_name, _T("wb"), _T("rb"), file_data);
374  result = check_file_size(file_name, _T("r"), tsize);
375  result = check_file_size(file_name, _T("rb"), bsize);
376  return result;
377 }
static int check_file_size(TCHAR *file_name, TCHAR *file_mode, int expected)
Definition: _tfileio.c:250
static int create_test_file(TCHAR *file_name, TCHAR *write_mode, TCHAR *read_mode, TCHAR *file_data)
Definition: _tfileio.c:226
#define _T(x)
Definition: vfdio.h:22
static LPCWSTR file_name
Definition: protocol.c:147
GLuint64EXT * result
Definition: glext.h:11304

Referenced by test_files().

◆ test_console_getchar()

static int test_console_getchar ( void  )
static

Definition at line 313 of file _tfileio.c.

314 {
315  int result = 0;
316  TCHAR ch;
317 
318  _tprintf(_T("Enter lines for dumping or <ctrl-z><nl> to finish:\n"));
319 
320  //while ((ch = _gettchar()) != _TEOF) {
321  while ((ch = _gettc(stdin)) != _TEOF) {
322  _tprintf(_THEX_FORMAT, ch);
323  //printf("0x%04x ", ch);
324  }
325  return result;
326 }
#define _gettc
Definition: tchar.h:571
#define _tprintf
Definition: tchar.h:506
FILE * stdin
char TCHAR
Definition: xmlstorage.h:189
#define _T(x)
Definition: vfdio.h:22
#define _THEX_FORMAT
Definition: _tfileio.c:43
#define _TEOF
Definition: _tfileio.c:40
GLuint64EXT * result
Definition: glext.h:11304

Referenced by test_files().

◆ test_console_io()

static int test_console_io ( void  )
static

Definition at line 292 of file _tfileio.c.

293 {
294  TCHAR buffer[81];
295  TCHAR ch;
296  int i, j;
297 
298  _tprintf(_T("Enter a line for echoing:\n"));
299 
300  //for (i = 0; (i < 80) && ((ch = _gettchar()) != _TEOF) && (ch != _T('\n')); i++) {
301  for (i = 0; (i < 80) && ((ch = _gettc(stdin)) != _TEOF) && (ch != _T('\n')); i++) {
302  buffer[i] = (TCHAR)ch;
303  }
304  buffer[i] = _T('\0');
305  for (j = 0; j < i; j++) {
306  _puttc(buffer[j], stdout);
307  }
308  _puttc(_T('\n'), stdout);
309  _tprintf(_T("%s\n"), buffer);
310  return 0;
311 }
#define _gettc
Definition: tchar.h:571
#define _tprintf
Definition: tchar.h:506
#define _puttc
Definition: tchar.h:581
GLuint buffer
Definition: glext.h:5915
FILE * stdin
FILE * stdout
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
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 GLint GLint j
Definition: glfuncs.h:250
char TCHAR
Definition: xmlstorage.h:189
#define _T(x)
Definition: vfdio.h:22
#define _TEOF
Definition: _tfileio.c:40

Referenced by test_files().

◆ test_console_putch()

static int test_console_putch ( void  )
static

Definition at line 328 of file _tfileio.c.

329 {
330  int result = 0;
331 
332  _putch('1');
333  _putch('@');
334  _putch('3');
335  _putch(':');
336  _putch('\n');
337  _putch('a');
338  _putch('B');
339  _putch('c');
340  _putch(':');
341  _putch('\n');
342  return result;
343 }
_CRTIMP int __cdecl _putch(_In_ int _Ch)
GLuint64EXT * result
Definition: glext.h:11304

Referenced by test_files().

◆ test_file_truncate()

static BOOL test_file_truncate ( TCHAR file_name)
static

Definition at line 80 of file _tfileio.c.

81 {
82  BOOL result = FALSE;
83  int count = -1;
84  int error_code;
85  TCHAR ch;
86  TCHAR* file_data = _T("this file should have been truncated to zero bytes...");
87  FILE *file = _tfopen(file_name, _T("wb"));
88 
89  if (verbose_flagged) {
90  _tprintf(_T("test_file_truncate(\"%s\")\n"), file_name);
91  }
92 
93  if (file != NULL) {
94  if (_fputts(file_data, file) != _TEOF) {
95  } else {
96  _tprintf(_T("ERROR: failed to write data to file \"%s\"\n"), file_name);
97  _tprintf(_T("ERROR: ferror returned %d\n"), ferror(file));
98  }
99  fclose(file);
100  } else {
101  _tprintf(_T("ERROR: failed to open/create file \"%s\" for output\n"), file_name);
102  _tprintf(_T("ERROR: ferror returned %d\n"), ferror(file));
103  }
104 
105  file = _tfopen(file_name, _T("wb"));
106  if (file != NULL) {
108  if (error_code) {
109  _tprintf(_T("ERROR: (%s) ferror returned %d\n"), file_name, error_code);
110  }
111  fclose(file);
112  } else {
113  _tprintf(_T("ERROR: (%s) failed to open file for truncating\n"), file_name);
114  }
115 
116  file = _tfopen(file_name, _T("rb"));
117  if (file != NULL) {
118  count = 0;
119  while ((ch = _fgettc(file)) != _TEOF) {
120  if (verbose_flagged) {
121  _tprintf(_THEX_FORMAT, ch);
122  }
123  ++count;
124  }
126  if (error_code) {
127  _tprintf(_T("ERROR: (%s) ferror returned %d after reading\n"), file_name, error_code);
128  perror("Read error");
129  }
130  fclose(file);
131  } else {
132  _tprintf(_T("ERROR: (%s) failed to open file for reading\n"), file_name);
133  }
134  if (count) {
135  result = TRUE;
136  }
137  return result;
138 }
#define _tfopen
Definition: _tfileio.c:38
#define _tprintf
Definition: tchar.h:506
_Check_return_ _CRTIMP int __cdecl ferror(_In_ FILE *_File)
#define TRUE
Definition: types.h:120
BOOL verbose_flagged
Definition: loadlib.c:39
#define _fgettc
Definition: tchar.h:562
GLuint GLuint GLsizei count
Definition: gl.h:1545
#define _fputts
Definition: tchar.h:569
_CRTIMP void __cdecl perror(_In_opt_z_ const char *_ErrMsg)
unsigned int BOOL
Definition: ntddk_ex.h:94
static int error_code[8]
Definition: odbccp32.c:61
smooth NULL
Definition: ftsmooth.c:416
char TCHAR
Definition: xmlstorage.h:189
#define _T(x)
Definition: vfdio.h:22
#define _THEX_FORMAT
Definition: _tfileio.c:43
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
static LPCWSTR file_name
Definition: protocol.c:147
#define _TEOF
Definition: _tfileio.c:40
GLuint64EXT * result
Definition: glext.h:11304
Definition: fci.c:126

Referenced by test_files().

◆ test_files()

static int test_files ( int  test_num,
char type 
)
static

Definition at line 379 of file _tfileio.c.

380 {
381  int result = 0;
382 
383  printf("performing test: %d (%s)\n", test_num, type);
384 
385 
386  if (test_file_truncate(_T("zerosize.foo"))) {
387  printf("System unable to truncate files yet, unlinking:\n");
389  }
390 
391  switch (test_num) {
392  case 1:
393  result = test_text_fileio(_T("text.dos"), dos_data, 166, TEST_B1_FILE_SIZE);
394  break;
395  case 2:
396  result = test_binary_fileio(_T("binary.dos"), dos_data, TEST_B2_FILE_SIZE, 166);
397  break;
398  case 3:
399  result = test_text_fileio(_T("text.nix"), nix_data, 162, TEST_B3_FILE_SIZE);
400  break;
401  case 4:
402  result = test_binary_fileio(_T("binary.nix"), nix_data, TEST_B4_FILE_SIZE, 162);
403  break;
404  case 5:
406  break;
407  case 6:
409  break;
410  case 7:
412  break;
413  case -1:
415  break;
416  default:
417  _tprintf(_T("no test number selected\n"));
418  break;
419  }
420  return result;
421 }
#define _tprintf
Definition: tchar.h:506
#define TEST_B4_FILE_SIZE
Definition: _tfileio.c:74
static BOOL test_file_truncate(TCHAR *file_name)
Definition: _tfileio.c:80
#define TEST_B1_FILE_SIZE
Definition: _tfileio.c:71
static int test_unlink_files(void)
Definition: _tfileio.c:345
static TCHAR nix_data[]
Definition: _tfileio.c:60
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
#define TEST_B3_FILE_SIZE
Definition: _tfileio.c:73
static int test_text_fileio(TCHAR *file_name, TCHAR *file_data, int tsize, int bsize)
Definition: _tfileio.c:359
static int test_binary_fileio(TCHAR *file_name, TCHAR *file_data, int tsize, int bsize)
Definition: _tfileio.c:369
#define _T(x)
Definition: vfdio.h:22
static int test_console_getchar(void)
Definition: _tfileio.c:313
static int test_console_io(void)
Definition: _tfileio.c:292
GLuint64EXT * result
Definition: glext.h:11304
static int test_console_putch(void)
Definition: _tfileio.c:328
static TCHAR dos_data[]
Definition: _tfileio.c:55
#define TEST_B2_FILE_SIZE
Definition: _tfileio.c:72
#define printf
Definition: config.h:203

Referenced by run_ansi_tests(), and run_unicode_tests().

◆ test_text_fileio()

static int test_text_fileio ( TCHAR file_name,
TCHAR file_data,
int  tsize,
int  bsize 
)
static

Definition at line 359 of file _tfileio.c.

360 {
361  int result = 0;
362 
363  result = create_test_file(file_name, _T("w"), _T("r"), file_data);
364  result = check_file_size(file_name, _T("r"), tsize);
365  result = check_file_size(file_name, _T("rb"), bsize);
366  return result;
367 }
static int check_file_size(TCHAR *file_name, TCHAR *file_mode, int expected)
Definition: _tfileio.c:250
static int create_test_file(TCHAR *file_name, TCHAR *write_mode, TCHAR *read_mode, TCHAR *file_data)
Definition: _tfileio.c:226
#define _T(x)
Definition: vfdio.h:22
static LPCWSTR file_name
Definition: protocol.c:147
GLuint64EXT * result
Definition: glext.h:11304

Referenced by test_files().

◆ test_unlink_files()

static int test_unlink_files ( void  )
static

Definition at line 345 of file _tfileio.c.

346 {
347  int result = 0;
348 
349  //printf("sizeof dos_data: %d\n", sizeof(dos_data));
350  //printf("sizeof nix_data: %d\n", sizeof(nix_data));
351 
352  result |= _tunlink(_T("binary.dos"));
353  result |= _tunlink(_T("binary.nix"));
354  result |= _tunlink(_T("text.dos"));
355  result |= _tunlink(_T("text.nix"));
356  return result;
357 }
#define _tunlink
Definition: _tfileio.c:39
#define _T(x)
Definition: vfdio.h:22
GLuint64EXT * result
Definition: glext.h:11304

Referenced by test_files().

◆ verify_output_file()

static BOOL verify_output_file ( TCHAR file_name,
TCHAR file_mode,
TCHAR file_data 
)
static

Definition at line 159 of file _tfileio.c.

160 {
161  int error_code;
162  int offset = 0;
163  int line_num = 0;
164  BOOL result = FALSE;
165  BOOL error_flagged = FALSE;
166  FILE* file = _tfopen(file_name, file_mode);
167  if (file == NULL) {
168  _tprintf(_T("ERROR: (%s) Can't open file for reading\n"), file_name);
169  _tprintf(_T("ERROR: ferror returned %d\n"), ferror(file));
170  return FALSE;
171  } else if (status_flagged) {
172  _tprintf(_T("STATUS: (%s) opened file for reading\n"), file_name);
173  }
175  int length = _tcslen(test_buffer);
176  int req_len = _tcschr(file_data+offset, _T('\n')) - (file_data+offset) + 1;
177 
178  ++line_num;
179  if (length > req_len) {
180  _tprintf(_T("ERROR: read excess bytes from line %d, length %d, but expected %d\n"), line_num, length, req_len);
181  error_flagged = TRUE;
182  break;
183  }
184  if (length < req_len) {
185  _tprintf(_T("ERROR: read to few bytes from line %d, length %d, but expected %d\n"), line_num, length, req_len);
186  error_flagged = TRUE;
187  break;
188  }
189  if (status_flagged) {
190  _tprintf(_T("STATUS: Verifying %d bytes read from line %d\n"), length, line_num);
191  }
192  if (_tcsncmp(test_buffer, file_data+offset, length - 1) == 0) {
193  result = TRUE;
194  } else {
195  if (status_flagged) {
196  int i;
197  _tprintf(_T("WARNING: (%s) failed to verify file\n"), file_name);
198  for (i = 0; i < length; i++) {
199  if (file_data[offset+i] != test_buffer[i]) {
200  _tprintf(_T("line %d, offset %d expected: 0x%04x found: 0x%04x\n"), line_num, i, (int)file_data[offset+i], (int)test_buffer[i]);
201  }
202  }
203  _tprintf(_T("\n"));
204  } else {
205  error_flagged = TRUE;
206  }
207  }
208  offset += length;
209  }
211  if (error_code) {
212  _tprintf(_T("ERROR: (%s) ferror returned %d after reading\n"), file_name, error_code);
213  perror("Read error");
214  }
215  if (!line_num) {
216  _tprintf(_T("ERROR: (%s) failed to read from file\n"), file_name);
217  }
218  if (error_flagged == TRUE) {
219  _tprintf(_T("ERROR: (%s) failed to verify file\n"), file_name);
220  result = FALSE;
221  }
222  fclose(file);
223  return result;
224 }
#define _tfopen
Definition: _tfileio.c:38
#define _tprintf
Definition: tchar.h:506
_Check_return_ _CRTIMP int __cdecl ferror(_In_ FILE *_File)
#define TRUE
Definition: types.h:120
#define _fgetts
Definition: tchar.h:565
GLintptr offset
Definition: glext.h:5920
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
_CRTIMP void __cdecl perror(_In_opt_z_ const char *_ErrMsg)
unsigned int BOOL
Definition: ntddk_ex.h:94
static int error_code[8]
Definition: odbccp32.c:61
size_t __cdecl _tcslen(const _TCHAR *str)
Definition: tcslen.h:9
smooth NULL
Definition: ftsmooth.c:416
_TCHAR * _tcschr(const _TCHAR *s, _XINT c)
Definition: tcschr.h:4
#define _T(x)
Definition: vfdio.h:22
GLenum GLuint GLenum GLsizei length
Definition: glext.h:5579
BOOL status_flagged
Definition: main.c:42
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
static TCHAR test_buffer[TEST_BUFFER_SIZE]
Definition: _tfileio.c:53
#define TEST_BUFFER_SIZE
Definition: _tfileio.c:47
static LPCWSTR file_name
Definition: protocol.c:147
GLuint64EXT * result
Definition: glext.h:11304
int _tcsncmp(const _TCHAR *s1, const _TCHAR *s2, size_t n)
Definition: tcsncmp.h:9
Definition: fci.c:126

Referenced by create_test_file().

Variable Documentation

◆ dos_data

TCHAR dos_data[]
static
Initial value:
= _T("line1: this is a bunch of readable text.\r\n")
_T("line2: some more printable text and punctuation !@#$%^&*()\r\n")
_T("line3: followed up with some numerals 1234567890\r\n")
_T("line4: done.\r\n")
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
const WCHAR * text
Definition: package.c:1827
GLdouble n
Definition: glext.h:7729
#define _T(x)
Definition: vfdio.h:22

Definition at line 55 of file _tfileio.c.

Referenced by test_files().

◆ nix_data

TCHAR nix_data[]
static
Initial value:
= _T("line1: this is a bunch of readable text.\n")
_T("line2: some more printable text and punctuation !@#$%^&*()\n")
_T("line3: followed up with some numerals 1234567890\n")
_T("line4: done.\n")
const WCHAR * text
Definition: package.c:1827
GLdouble n
Definition: glext.h:7729
#define _T(x)
Definition: vfdio.h:22

Definition at line 60 of file _tfileio.c.

Referenced by test_files().

◆ status_flagged

BOOL status_flagged

Definition at line 42 of file main.c.

Referenced by check_file_size(), create_test_file(), main(), and verify_output_file().

◆ test_buffer

◆ verbose_flagged

BOOL verbose_flagged

Definition at line 39 of file loadlib.c.

Referenced by check_file_size(), main(), and test_file_truncate().