1
/* Copyright (C) 2006-2008 MySQL AB
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; version 2 of the License.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
19
#include "test_file.h"
23
Check that file contance correspond to descriptor
28
file_name Path (and name) of file which is tested
30
buff_size size of buffer which is enought to check the file
31
desc file descriptor to check with
38
int test_file(PAGECACHE_FILE file, char *file_name,
39
off_t size, size_t buff_size, struct file_desc *desc)
41
unsigned char *buffr= my_malloc(buff_size, MYF(0));
49
On Windows, the info returned by stat(), specifically file length
50
is not necessarily current, because this is the behavior of
51
underlying FindFirstFile() function.
53
WIN32_FILE_ATTRIBUTE_DATA file_attr;
55
if(GetFileAttributesEx(file_name, GetFileExInfoStandard, &file_attr) == 0)
57
diag("Can't GetFileAttributesEx %s (errno: %d)\n", file_name,
62
li.HighPart= file_attr.nFileSizeHigh;
63
li.LowPart= file_attr.nFileSizeLow;
64
if(li.QuadPart != size)
66
diag("file %s size is %llu (should be %llu)\n",
67
file_name, (ulonglong)size, (ulonglong)li.QuadPart);
69
/* continue to get more information */
72
MY_STAT stat_buff, *stat;
73
if ((stat= my_stat(file_name, &stat_buff, MYF(0))) == NULL)
75
diag("Can't stat() %s (errno: %d)\n", file_name, errno);
79
if (stat->st_size != size)
81
diag("file %s size is %lu (should be %lu)\n",
82
file_name, (ulong) stat->st_size, (ulong) size);
84
/* continue to get more information */
89
my_seek(file.file, 0, SEEK_SET, MYF(MY_WME));
90
while (desc[step].length != 0)
92
if (my_read(file.file, buffr, desc[step].length, MYF(0)) !=
95
diag("Can't read %u bytes from %s (file: %d errno: %d)\n",
96
(uint)desc[step].length, file_name, file.file, errno);
100
for (byte= 0; byte < desc[step].length; byte++)
102
if (buffr[byte] != desc[step].content)
104
diag("content of %s mismatch 0x%x in position %lu instead of 0x%x\n",
105
file_name, (uint) buffr[byte], (ulong) (pos + byte),
111
pos+= desc[step].length;