Implemented TestFileDeleteFile

This commit is contained in:
Armin Novak 2021-07-29 10:38:41 +02:00 committed by akallabeth
parent af0ce13d8a
commit 04ff6b8824
2 changed files with 88 additions and 45 deletions

View File

@ -1,54 +1,57 @@
set(MODULE_NAME "TestFile")
set(MODULE_PREFIX "TEST_FILE")
if (NOT WIN32)
set(MODULE_NAME "TestFile")
set(MODULE_PREFIX "TEST_FILE")
set(${MODULE_PREFIX}_DRIVER ${MODULE_NAME}.c)
set(${MODULE_PREFIX}_DRIVER ${MODULE_NAME}.c)
set(${MODULE_PREFIX}_TESTS
TestFileCreateFile.c
TestFileDeleteFile.c
TestFileReadFile.c
TestFileWriteFile.c
TestFilePatternMatch.c
TestFileFindFirstFile.c
TestFileFindFirstFileEx.c
TestFileFindNextFile.c
TestFileGetStdHandle.c
)
set(${MODULE_PREFIX}_TESTS
TestFileCreateFile.c
TestFileDeleteFile.c
TestFileReadFile.c
TestFileWriteFile.c
TestFilePatternMatch.c
TestFileFindFirstFile.c
TestFileFindFirstFileEx.c
TestFileFindNextFile.c
TestFileGetStdHandle.c
)
create_test_sourcelist(${MODULE_PREFIX}_SRCS
${${MODULE_PREFIX}_DRIVER}
${${MODULE_PREFIX}_TESTS})
create_test_sourcelist(${MODULE_PREFIX}_SRCS
${${MODULE_PREFIX}_DRIVER}
${${MODULE_PREFIX}_TESTS})
add_executable(${MODULE_NAME} ${${MODULE_PREFIX}_SRCS})
add_executable(${MODULE_NAME} ${${MODULE_PREFIX}_SRCS})
target_link_libraries(${MODULE_NAME} winpr)
target_link_libraries(${MODULE_NAME} winpr)
set_target_properties(${MODULE_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${TESTING_OUTPUT_DIRECTORY}")
set_target_properties(${MODULE_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${TESTING_OUTPUT_DIRECTORY}")
if(NOT MSVC)
set(TEST_AREA "${TESTING_OUTPUT_DIRECTORY}/${MODULE_NAME}Area")
else()
set(TEST_AREA "${TESTING_OUTPUT_DIRECTORY}/${CMAKE_BUILD_TYPE}/${MODULE_NAME}Area")
endif()
file(MAKE_DIRECTORY "${TEST_AREA}")
file(WRITE "${TEST_AREA}/TestFile1" "TestFile1")
file(WRITE "${TEST_AREA}/TestFile2" "TestFile2")
file(WRITE "${TEST_AREA}/TestFile3" "TestFile3")
file(MAKE_DIRECTORY "${TEST_AREA}/TestDirectory1")
file(WRITE "${TEST_AREA}/TestDirectory1/TestDirectory1File1" "TestDirectory1File1")
file(MAKE_DIRECTORY "${TEST_AREA}/TestDirectory2")
file(WRITE "${TEST_AREA}/TestDirectory2/TestDirectory2File1" "TestDirectory2File1")
file(WRITE "${TEST_AREA}/TestDirectory2/TestDirectory2File2" "TestDirectory2File2")
file(MAKE_DIRECTORY "${TEST_AREA}/TestDirectory3")
file(WRITE "${TEST_AREA}/TestDirectory3/TestDirectory3File1" "TestDirectory3File1")
file(WRITE "${TEST_AREA}/TestDirectory3/TestDirectory3File2" "TestDirectory3File2")
file(WRITE "${TEST_AREA}/TestDirectory3/TestDirectory3File3" "TestDirectory3File3")
foreach(test ${${MODULE_PREFIX}_TESTS})
get_filename_component(TestName ${test} NAME_WE)
add_test(${TestName} ${TESTING_OUTPUT_DIRECTORY}/${MODULE_NAME} ${TestName} ${TEST_AREA})
endforeach()
set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "WinPR/Test")
if(NOT MSVC)
set(TEST_AREA "${TESTING_OUTPUT_DIRECTORY}/${MODULE_NAME}Area")
else()
set(TEST_AREA "${TESTING_OUTPUT_DIRECTORY}/${CMAKE_BUILD_TYPE}/${MODULE_NAME}Area")
endif()
file(MAKE_DIRECTORY "${TEST_AREA}")
file(WRITE "${TEST_AREA}/TestFile1" "TestFile1")
file(WRITE "${TEST_AREA}/TestFile2" "TestFile2")
file(WRITE "${TEST_AREA}/TestFile3" "TestFile3")
file(MAKE_DIRECTORY "${TEST_AREA}/TestDirectory1")
file(WRITE "${TEST_AREA}/TestDirectory1/TestDirectory1File1" "TestDirectory1File1")
file(MAKE_DIRECTORY "${TEST_AREA}/TestDirectory2")
file(WRITE "${TEST_AREA}/TestDirectory2/TestDirectory2File1" "TestDirectory2File1")
file(WRITE "${TEST_AREA}/TestDirectory2/TestDirectory2File2" "TestDirectory2File2")
file(MAKE_DIRECTORY "${TEST_AREA}/TestDirectory3")
file(WRITE "${TEST_AREA}/TestDirectory3/TestDirectory3File1" "TestDirectory3File1")
file(WRITE "${TEST_AREA}/TestDirectory3/TestDirectory3File2" "TestDirectory3File2")
file(WRITE "${TEST_AREA}/TestDirectory3/TestDirectory3File3" "TestDirectory3File3")
foreach(test ${${MODULE_PREFIX}_TESTS})
get_filename_component(TestName ${test} NAME_WE)
add_test(${TestName} ${TESTING_OUTPUT_DIRECTORY}/${MODULE_NAME} ${TestName} ${TEST_AREA})
endforeach()
set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "WinPR/Test")

View File

@ -1,10 +1,50 @@
#include <stdio.h>
#include <stdlib.h>
#include <winpr/crt.h>
#include <winpr/file.h>
#include <winpr/windows.h>
int TestFileDeleteFile(int argc, char* argv[])
{
BOOL rc;
int fd;
char validA[] = "/tmp/valid-test-file-XXXXXX";
char validW[] = "/tmp/valid-test-file-XXXXXX";
WCHAR* validWW = NULL;
const char* invalidA = "/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
const WCHAR invalidW[] = { '/', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x',
'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x',
'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x',
'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', '\0' };
WINPR_UNUSED(argc);
WINPR_UNUSED(argv);
rc = DeleteFileA(invalidA);
if (rc)
return -1;
rc = DeleteFileW(invalidW);
if (rc)
return -1;
fd = mkstemp(validA);
if (fd < 0)
return -1;
rc = DeleteFileA(validA);
if (!rc)
return -1;
fd = mkstemp(validW);
if (fd < 0)
return -1;
ConvertToUnicode(CP_UTF8, 0, validW, -1, &validWW, 0);
rc = DeleteFileW(validWW);
free(validWW);
if (!rc)
return -1;
return 0;
}