diff options
author | dotnet-bot <dotnet-bot@microsoft.com> | 2015-01-30 14:14:42 -0800 |
---|---|---|
committer | dotnet-bot <dotnet-bot@microsoft.com> | 2015-01-30 14:14:42 -0800 |
commit | ef1e2ab328087c61a6878c1e84f4fc5d710aebce (patch) | |
tree | dee1bbb89e9d722e16b0d1485e3cdd1b6c8e2cfa /src/pal/tests/palsuite/file_io/CreateFileW/test1 | |
download | coreclr-ef1e2ab328087c61a6878c1e84f4fc5d710aebce.tar.gz coreclr-ef1e2ab328087c61a6878c1e84f4fc5d710aebce.tar.bz2 coreclr-ef1e2ab328087c61a6878c1e84f4fc5d710aebce.zip |
Initial commit to populate CoreCLR repo
[tfs-changeset: 1407945]
Diffstat (limited to 'src/pal/tests/palsuite/file_io/CreateFileW/test1')
4 files changed, 187 insertions, 0 deletions
diff --git a/src/pal/tests/palsuite/file_io/CreateFileW/test1/CMakeLists.txt b/src/pal/tests/palsuite/file_io/CreateFileW/test1/CMakeLists.txt new file mode 100644 index 0000000000..6bde4fadd3 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/CreateFileW/test1/CMakeLists.txt @@ -0,0 +1,20 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + CreateFileW.c +) + +add_executable(paltest_createfilew_test1 + ${SOURCES} +) + +add_dependencies(paltest_createfilew_test1 CoreClrPal) + +target_link_libraries(paltest_createfilew_test1 + pthread + rt + m + CoreClrPal +) diff --git a/src/pal/tests/palsuite/file_io/CreateFileW/test1/CreateFileW.c b/src/pal/tests/palsuite/file_io/CreateFileW/test1/CreateFileW.c new file mode 100644 index 0000000000..ff941fdd62 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/CreateFileW/test1/CreateFileW.c @@ -0,0 +1,153 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +/*===================================================================== +** +** Source: CreateFileW.c +** +** Purpose: Test the PAL implementation of the CreateFileW function +** +** +**===================================================================*/ + +#include <palsuite.h> + +BOOL Cleanup(void) +{ + char FileName[20]; + int i; + BOOL bRet = TRUE; // assume success + + // loop through all accesses, modes, dispositions and flags + for (i=0; i<4*8*4*5; ++i) { + sprintf(FileName, "test%03d.txt", i); + if (DeleteFileA(FileName) == FALSE) { + if (GetLastError() != ERROR_FILE_NOT_FOUND) { + bRet = FALSE; + } + } + } + return bRet; +} + + +int __cdecl main(int argc, char *argv[]) +{ + BOOL bSuccess = TRUE; + int nCounter = 0; + HANDLE hFile = NULL; + WCHAR *lpFileName = NULL; + char* pTemp = NULL; + char string[40]; + FILE *outFile = NULL; + char results[1024]; + int i, j, k, l; + DWORD dwDesiredAccess[4] = {0, // 0 + GENERIC_READ, // 1 + GENERIC_WRITE, // 2 + GENERIC_READ | GENERIC_WRITE}; // 3 + DWORD dwShareMode[8] = {0, // 0 + FILE_SHARE_READ, // 1 + FILE_SHARE_WRITE, // 2 + FILE_SHARE_DELETE, // 3 + FILE_SHARE_READ | FILE_SHARE_WRITE, // 4 + FILE_SHARE_READ | FILE_SHARE_DELETE, // 5 + FILE_SHARE_WRITE | FILE_SHARE_DELETE, // 6 + FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE}; // 7 + LPSECURITY_ATTRIBUTES lpAttr = NULL; + DWORD dwCreationDisp[4] = {CREATE_NEW, // 0 + CREATE_ALWAYS, // 1 + OPEN_EXISTING, // 2 + OPEN_ALWAYS}; // 3 + DWORD dwFlagsAttrib[5] = {FILE_ATTRIBUTE_NORMAL, // 0 + FILE_FLAG_SEQUENTIAL_SCAN, // 1 + FILE_FLAG_WRITE_THROUGH, // 2 + FILE_FLAG_NO_BUFFERING, // 3 + FILE_FLAG_RANDOM_ACCESS}; // 4 + HANDLE hTemplate = NULL; + + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + if (!Cleanup()) { + Trace("Pre-test Cleanup() failed. LastError=%d\n", GetLastError()); + return FAIL; + } + + /* open the file to read the expected results */ + outFile = fopen("winoutput", "r"); + memset (results, 0, 1024); + + fgets(results, 1024, outFile); + fclose(outFile); + + nCounter = 0; + + // desired access loop + for (i = 0; i < 4; i++) + { + // share mode loop + for (j = 0; j < 8; j++) + { + // security attributes loop + for (k = 0; k < 4; k++) + { + // creation disp loop + for (l = 0; l < 5; l++) + { + sprintf(string, "test%03d.txt", nCounter); + lpFileName = convert(string); + hFile = CreateFileW(lpFileName, + dwDesiredAccess[i], + dwShareMode[j], + lpAttr, + dwCreationDisp[k], + dwFlagsAttrib[l], + hTemplate); + free(lpFileName); + if (hFile == INVALID_HANDLE_VALUE) + { + if (results[nCounter] == '1') + { + pTemp = convertC(lpFileName); + Trace("CreateFile: ERROR: Failed when expected " + "to pass %s [%d][%d][%d][%d]\n", + pTemp, i, j, k, l); + free(pTemp); + bSuccess = FALSE; + } + } + else + { + CloseHandle(hFile); + if (results[nCounter] == '0') + { + pTemp = convertC(lpFileName); + Trace("CreateFile: ERROR: Passed when expected " + "to fail %s [%d][%d][%d][%d]\n", + pTemp, i, j, k, l); + free(pTemp); + bSuccess = FALSE; + } + } + nCounter ++; + } + } + } + } + + if (!Cleanup()) + { + Trace("Post-test Cleanup() failed. LastError=%d\n", GetLastError()); + return FAIL; + } + + int exitCode = bSuccess ? PASS : FAIL; + PAL_TerminateEx(exitCode); + return exitCode; +} diff --git a/src/pal/tests/palsuite/file_io/CreateFileW/test1/testinfo.dat b/src/pal/tests/palsuite/file_io/CreateFileW/test1/testinfo.dat new file mode 100644 index 0000000000..8195b65f86 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/CreateFileW/test1/testinfo.dat @@ -0,0 +1,13 @@ +# +# Copyright (c) Microsoft Corporation. All rights reserved. +# + +Version = 1.0 +Section = file_io +Function = CreateFileW +Name = test for CreateFileW +Type = DEFAULT +EXE1 = createfilew +Description += Attempts to create files based on all combinations of += options of CreateFileW diff --git a/src/pal/tests/palsuite/file_io/CreateFileW/test1/winoutput b/src/pal/tests/palsuite/file_io/CreateFileW/test1/winoutput new file mode 100644 index 0000000000..3913b99427 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/CreateFileW/test1/winoutput @@ -0,0 +1 @@ +1111111111000001111111111111110000011111111111111100000111111111111111000001111111111111110000011111111111111100000111111111111111000001111111111111110000011111111111111100000111111111111111000001111111111111110000011111111111111100000111111111111111000001111111111111110000011111111111111100000111111111111111000001111111111111110000011111111111111100000111111111111111000001111111111111110000011111111111111100000111111111111111000001111111111111110000011111111111111100000111111111111111000001111111111111110000011111111111111100000111111111111111000001111111111111110000011111111111111100000111111111111111000001111111111111110000011111
\ No newline at end of file |