diff options
Diffstat (limited to 'src/pal/tests/palsuite/file_io/SearchPathA/test1')
3 files changed, 175 insertions, 0 deletions
diff --git a/src/pal/tests/palsuite/file_io/SearchPathA/test1/CMakeLists.txt b/src/pal/tests/palsuite/file_io/SearchPathA/test1/CMakeLists.txt new file mode 100644 index 0000000000..d1ac975d18 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/SearchPathA/test1/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + SearchPathA.c +) + +add_executable(paltest_searchpatha_test1 + ${SOURCES} +) + +add_dependencies(paltest_searchpatha_test1 coreclrpal) + +target_link_libraries(paltest_searchpatha_test1 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/file_io/SearchPathA/test1/SearchPathA.c b/src/pal/tests/palsuite/file_io/SearchPathA/test1/SearchPathA.c new file mode 100644 index 0000000000..ab9eecdebc --- /dev/null +++ b/src/pal/tests/palsuite/file_io/SearchPathA/test1/SearchPathA.c @@ -0,0 +1,144 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +/*===================================================================== +** +** Source: SearchPathA.c +** +** Purpose: Tests the PAL implementation of the SearchFileA function. +** +** +** TODO: Write a test where complete path is passed (say c:\?) +**===================================================================*/ +//SearchPath +// +//The SearchPath function searches for the specified file in the specified path. +// + + +#include <palsuite.h> +char* szDir = "."; + +char* szNoFileName = "333asdf"; +char* szNoFileNameExt = ".x77t"; + +char* szFileNameExists = "searchfile"; +char* szFileNameExtExists = ".txt"; + +char* szFileNameExistsWithExt = "searchfile.txt"; +char fileloc[_MAX_PATH]; + +void removeFileHelper(LPSTR pfile, int location) +{ + FILE *fp; + fp = fopen( pfile, "r"); + + if (fp != NULL) + { + if(fclose(fp)) + { + Fail("ERROR: Failed to close the file [%s], Error Code [%d], location [%d]\n", pfile, GetLastError(), location); + } + + if(!DeleteFileA(pfile)) + { + Fail("ERROR: Failed to delete file [%s], Error Code [%d], location [%d]\n", pfile, GetLastError(), location); + } + } + +} + + +void RemoveAll() +{ + removeFileHelper(fileloc, 1); +} + +int __cdecl main(int argc, char *argv[]) { + + char* lpPath = NULL; + char* lpFileName = NULL; + char* lpExtension = NULL; + DWORD nBufferLength = 0; + char lpBuffer[_MAX_PATH]; + char** lpFilePart = NULL; + DWORD error = 0; + DWORD result = 0; + + HANDLE hsearchfile; + char fname[_MAX_FNAME]; + char ext[_MAX_EXT]; + char fullPath[_MAX_DIR]; + char drive[_MAX_DRIVE]; + char dir[_MAX_DIR]; + + + if(0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + + /* Initalize the buffer. + */ + memset(fullPath, 0, _MAX_DIR); + + /* Get the full path to the library (DLL). + */ + + if ( NULL != _fullpath( fullPath, argv[0], _MAX_DIR )) { + _splitpath(fullPath,drive,dir,fname,ext); + _makepath(fullPath,drive,dir,"",""); + } else { + Fail("ERROR: conversion from relative path \" %s \" to absolute path failed. _fullpath returned NULL\n",argv[0]); + } + + memset(fileloc, 0, _MAX_PATH); + sprintf(fileloc, "%s%s", fullPath, szFileNameExistsWithExt); + + RemoveAll(); + + hsearchfile = CreateFileA(fileloc, GENERIC_WRITE, 0, 0, CREATE_ALWAYS, + FILE_ATTRIBUTE_NORMAL, 0); + + if (hsearchfile == INVALID_HANDLE_VALUE) + { + Trace("ERROR[%ul]: couldn't create %s\n", GetLastError(), fileloc); + return FAIL; + } + + CloseHandle(hsearchfile); + + // + // find a file that doesn't exist + // + ZeroMemory( lpBuffer, sizeof(lpBuffer)); + lpPath = fullPath; + lpFileName = szNoFileName; + lpExtension = NULL; + + if( SearchPathA( lpPath, lpFileName, lpExtension, nBufferLength, lpBuffer, lpFilePart) != 0 ){ + error = GetLastError(); + Fail ("SearchPathA: ERROR1 -> Found invalid file[%s][%s][%s][%d]\n", lpPath, szNoFileName, szNoFileNameExt, error); + } + + // + // find a file that exists, when path is mentioned explicitly + // + ZeroMemory( lpBuffer, sizeof(lpBuffer)); + lpPath = fullPath; + lpFileName = szFileNameExistsWithExt; + lpExtension = NULL; + + result = SearchPathA( lpPath, lpFileName, lpExtension, nBufferLength, lpBuffer, lpFilePart); + + if( result == 0 ){ + error = GetLastError(); + Fail ("SearchPathA: ERROR2 -> Did not Find valid file[%s][%s][%d]\n", lpPath, szFileNameExistsWithExt, error); + } + + RemoveAll(); + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/file_io/SearchPathA/test1/testinfo.dat b/src/pal/tests/palsuite/file_io/SearchPathA/test1/testinfo.dat new file mode 100644 index 0000000000..82401eeeb2 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/SearchPathA/test1/testinfo.dat @@ -0,0 +1,12 @@ +# Licensed to the .NET Foundation under one or more agreements. +# The .NET Foundation licenses this file to you under the MIT license. +# See the LICENSE file in the project root for more information. + +Version = 1.0 +Section = file_io +Function = SearchPathA +Name = Test #1 for SearchPathA +TYPE = DEFAULT +EXE1 = test1 +Description +=Tests the PAL implementation of the SearchFileA function |