summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBen Pye <ben@debian>2015-02-12 22:42:43 +0000
committerBen Pye <ben@debian>2015-02-12 22:42:43 +0000
commit999a5e35c956ae816b09fc6ce3d21962ceb9ea6c (patch)
tree6072ae03f2e3a0de186a8f00dc1ce7c820e81d83 /src
parentb773640d437c0f5727a099012b6ef88c25ebbee8 (diff)
downloadcoreclr-999a5e35c956ae816b09fc6ce3d21962ceb9ea6c.tar.gz
coreclr-999a5e35c956ae816b09fc6ce3d21962ceb9ea6c.tar.bz2
coreclr-999a5e35c956ae816b09fc6ce3d21962ceb9ea6c.zip
Cleanup GetFileSize test to reduce duplicated code
Diffstat (limited to 'src')
-rw-r--r--src/pal/tests/palsuite/file_io/GetFileSize/test1/GetFileSize.c150
1 files changed, 54 insertions, 96 deletions
diff --git a/src/pal/tests/palsuite/file_io/GetFileSize/test1/GetFileSize.c b/src/pal/tests/palsuite/file_io/GetFileSize/test1/GetFileSize.c
index 0e84b2d752..c22c8619ec 100644
--- a/src/pal/tests/palsuite/file_io/GetFileSize/test1/GetFileSize.c
+++ b/src/pal/tests/palsuite/file_io/GetFileSize/test1/GetFileSize.c
@@ -30,17 +30,46 @@ void CleanUp(HANDLE hFile)
}
}
+void CheckFileSize(HANDLE hFile, DWORD dwOffset, DWORD dwHighOrder)
+{
+ DWORD dwRc = 0;
+ DWORD dwReturnedHighOrder = 0;
+ DWORD dwReturnedOffset = 0;
+
+ dwRc = SetFilePointer(hFile, dwOffset, (PLONG)&dwHighOrder, FILE_BEGIN);
+ if (dwRc == INVALID_SET_FILE_POINTER)
+ {
+ Trace("GetFileSize: ERROR -> Call to SetFilePointer failed with %ld.\n",
+ GetLastError());
+ CleanUp(hFile);
+ Fail("");
+ }
+ else
+ {
+ if (!SetEndOfFile(hFile))
+ {
+ Trace("GetFileSize: ERROR -> Call to SetEndOfFile failed with %ld.\n",
+ GetLastError());
+ CleanUp(hFile);
+ Fail("");
+ }
+ dwReturnedOffset = GetFileSize(hFile, &dwReturnedHighOrder);
+ if ((dwReturnedOffset != dwOffset) ||
+ (dwReturnedHighOrder != dwHighOrder))
+ {
+ CleanUp(hFile);
+ Fail("GetFileSize: ERROR -> File sizes do not match up.\n");
+ }
+ }
+}
+
int __cdecl main(int argc, char *argv[])
{
HANDLE hFile = NULL;
DWORD dwRc = 0;
DWORD dwRc2 = 0;
- DWORD dwError = 0;
DWORD dwHighOrder = 0;
- DWORD dwOffset = 0;
- DWORD dwReturnedHighOrder = 0;
- DWORD dwReturnedOffset = 0;
DWORD lpNumberOfBytesWritten;
char * data = "1234567890";
@@ -55,13 +84,30 @@ int __cdecl main(int argc, char *argv[])
if (dwRc != INVALID_FILE_SIZE)
{
Fail("GetFileSize: ERROR -> A file size was returned for "
- "an invalid handle.\n");
+ "a null handle.\n");
}
+
/* test on a null file handle using the high order option */
dwRc = GetFileSize(hFile, &dwHighOrder);
if (dwRc != INVALID_FILE_SIZE)
{
Fail("GetFileSize: ERROR -> A file size was returned for "
+ "a null handle.\n");
+ }
+
+ /* test on an invalid file handle */
+ dwRc = GetFileSize(INVALID_HANDLE_VALUE, NULL);
+ if (dwRc != INVALID_FILE_SIZE)
+ {
+ Fail("GetFileSize: ERROR -> A file size was returned for "
+ "an invalid handle.\n");
+ }
+
+ /* test on an invalid file handle using the high order option */
+ dwRc = GetFileSize(INVALID_HANDLE_VALUE, &dwHighOrder);
+ if (dwRc != INVALID_FILE_SIZE)
+ {
+ Fail("GetFileSize: ERROR -> A file size was returned for "
"an invalid handle.\n");
}
@@ -82,102 +128,14 @@ int __cdecl main(int argc, char *argv[])
}
/* give the file a size */
- dwOffset = 256;
- dwRc = SetFilePointer(hFile, dwOffset, NULL, FILE_BEGIN);
- if (dwRc == INVALID_SET_FILE_POINTER)
- {
- Trace("GetFileSize: ERROR -> Call to SetFilePointer failed with %ld.\n",
- GetLastError());
- CleanUp(hFile);
- Fail("");
- }
- else
- {
- if (!SetEndOfFile(hFile))
- {
- Trace("GetFileSize: ERROR -> Call to SetEndOfFile failed with %ld.\n",
- GetLastError());
- CleanUp(hFile);
- Fail("");
- }
- dwReturnedOffset = GetFileSize(hFile, &dwReturnedHighOrder);
- if ((dwReturnedOffset != dwOffset) ||
- (dwReturnedHighOrder != dwHighOrder))
- {
- CleanUp(hFile);
- Fail("GetFileSize: ERROR -> File sizes do not match up.\n");
- }
- }
+ CheckFileSize(hFile, 256, 0);
/* make the file large using the high order option */
- dwOffset = 256;
- dwHighOrder = 1;
- dwRc = SetFilePointer(hFile, dwOffset, (PLONG)&dwHighOrder, FILE_BEGIN);
- if (dwRc == INVALID_SET_FILE_POINTER)
- {
- Trace("GetFileSize: ERROR -> Call to SetFilePointer failed with %ld.\n",
- GetLastError());
- CleanUp(hFile);
- Fail("");
- }
- else
- {
- if (!SetEndOfFile(hFile))
- {
- dwError = GetLastError();
- CleanUp(hFile);
- if (dwError == 112)
- {
- Fail("GetFileSize: ERROR -> SetEndOfFile failed due to lack of "
- "disk space\n");
- }
- else
- {
- Fail("GetFileSize: ERROR -> SetEndOfFile call failed "
- "with error %ld\n", dwError);
- }
- }
- else
- {
- dwReturnedOffset = GetFileSize(hFile, &dwReturnedHighOrder);
- if ((dwReturnedOffset != dwOffset) ||
- (dwReturnedHighOrder != dwHighOrder))
- {
- CleanUp(hFile);
- Fail("GetFileSize: ERROR -> File sizes do not match up.\n");
- }
- }
- }
+ CheckFileSize(hFile, 256, 1);
/* set the file size to zero */
- dwOffset = 0;
- dwHighOrder = 0;
- dwRc = SetFilePointer(hFile, dwOffset, NULL, FILE_BEGIN);
- if (dwRc == INVALID_SET_FILE_POINTER)
- {
- Trace("GetFileSize: ERROR -> SetEndOfFile call failed with error %ld\n",
- GetLastError());
- CleanUp(hFile);
- Fail("");
- }
- else
- {
- if (!SetEndOfFile(hFile))
- {
- Trace("GetFileSize: ERROR -> Call to SetEndOfFile failed "
- "with %ld.\n", GetLastError());
- CleanUp(hFile);
- Fail("");
- }
- dwReturnedOffset = GetFileSize(hFile, &dwReturnedHighOrder);
- if ((dwReturnedOffset != dwOffset) ||
- (dwReturnedHighOrder != dwHighOrder))
- {
- CleanUp(hFile);
- Fail("GetFileSize: ERROR -> File sizes do not match up.\n");
- }
- }
+ CheckFileSize(hFile, 0, 0);
/* test if file size changes by writing to it. */
/* get file size */