From fd6f68841494ca8f4c907d57d480e803831ade56 Mon Sep 17 00:00:00 2001 From: Thomas Faber Date: Sun, 17 Sep 2017 08:08:39 +0000 Subject: [PATCH] [KMTESTS:KERNEL32] - Add additional file attribute tests. Based on a patch by Katayama Hirofumi MZ. CORE-13495 svn path=/trunk/; revision=75861 --- .../kmtests/kernel32/FileAttributes_user.c | 55 +++++++++++++++++-- rostests/kmtests/kernel32/kernel32_drv.c | 18 ++++-- 2 files changed, 63 insertions(+), 10 deletions(-) diff --git a/rostests/kmtests/kernel32/FileAttributes_user.c b/rostests/kmtests/kernel32/FileAttributes_user.c index a644b999bc2..93f8e756bd0 100644 --- a/rostests/kmtests/kernel32/FileAttributes_user.c +++ b/rostests/kmtests/kernel32/FileAttributes_user.c @@ -1,8 +1,9 @@ /* - * PROJECT: ReactOS kernel-mode tests - * LICENSE: LGPLv2.1+ - See COPYING.LIB in the top level directory - * PURPOSE: Test for GetFileAttributes/SetFileAttributes - * PROGRAMMER: Thomas Faber + * PROJECT: ReactOS kernel-mode tests + * LICENSE: LGPL-2.1+ (https://spdx.org/licenses/LGPL-2.1+) + * PURPOSE: Test for GetFileAttributes/SetFileAttributes + * COPYRIGHT: Copyright 2017 Thomas Faber + * Copyright 2017 Katayama Hirofumi MZ */ #include @@ -33,6 +34,11 @@ START_TEST(FileAttributes) Ret = SetFileAttributesW(FileName, 0); ok(Ret == TRUE, "SetFileAttributesW returned %d, error %lu\n", Ret, GetLastError()); + /* Set invalid attributes */ + KmtSendUlongToDriver(IOCTL_EXPECT_SET_ATTRIBUTES, FILE_ATTRIBUTE_VALID_SET_FLAGS); + Ret = SetFileAttributesW(FileName, 0xFFFFFFFF); + ok(Ret == TRUE, "SetFileAttributesW returned %d, error %lu\n", Ret, GetLastError()); + /* Query read-only attribute */ KmtSendUlongToDriver(IOCTL_RETURN_QUERY_ATTRIBUTES, FILE_ATTRIBUTE_READONLY); Attributes = GetFileAttributesW(FileName); @@ -53,6 +59,47 @@ START_TEST(FileAttributes) Attributes = GetFileAttributesW(FileName); ok_eq_hex(Attributes, 0); + /* Query invalid attributes */ + KmtSendUlongToDriver(IOCTL_RETURN_QUERY_ATTRIBUTES, 0xFFFFFFFF); + Attributes = GetFileAttributesW(FileName); + ok_eq_hex(Attributes, 0xFFFFFFFF); + + /** Directory attribute **/ + /* Set read-only and directory attribute */ + KmtSendUlongToDriver(IOCTL_EXPECT_SET_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_READONLY); + Ret = SetFileAttributesW(FileName, FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_DIRECTORY); + ok(Ret == TRUE, "SetFileAttributesW returned %d, error %lu\n", Ret, GetLastError()); + + /* Set normal and directory attribute */ + KmtSendUlongToDriver(IOCTL_EXPECT_SET_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL); + Ret = SetFileAttributesW(FileName, FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_DIRECTORY); + ok(Ret == TRUE, "SetFileAttributesW returned %d, error %lu\n", Ret, GetLastError()); + + /* Set directory attribute */ + KmtSendUlongToDriver(IOCTL_EXPECT_SET_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL); + Ret = SetFileAttributesW(FileName, FILE_ATTRIBUTE_DIRECTORY); + ok(Ret == TRUE, "SetFileAttributesW returned %d, error %lu\n", Ret, GetLastError()); + + /* Query read-only and directory attribute */ + KmtSendUlongToDriver(IOCTL_RETURN_QUERY_ATTRIBUTES, FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_DIRECTORY); + Attributes = GetFileAttributesW(FileName); + ok_eq_hex(Attributes, FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_DIRECTORY); + + /* Query read-only + normal + directory attribute */ + KmtSendUlongToDriver(IOCTL_RETURN_QUERY_ATTRIBUTES, FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_DIRECTORY); + Attributes = GetFileAttributesW(FileName); + ok_eq_hex(Attributes, FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_DIRECTORY); + + /* Query normal and directory attribute */ + KmtSendUlongToDriver(IOCTL_RETURN_QUERY_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_DIRECTORY); + Attributes = GetFileAttributesW(FileName); + ok_eq_hex(Attributes, FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_DIRECTORY); + + /* Query directory attribute */ + KmtSendUlongToDriver(IOCTL_RETURN_QUERY_ATTRIBUTES, FILE_ATTRIBUTE_DIRECTORY); + Attributes = GetFileAttributesW(FileName); + ok_eq_hex(Attributes, FILE_ATTRIBUTE_DIRECTORY); + KmtCloseDriver(); KmtUnloadDriver(); } diff --git a/rostests/kmtests/kernel32/kernel32_drv.c b/rostests/kmtests/kernel32/kernel32_drv.c index 6432fdf6e70..7ac59c3260d 100644 --- a/rostests/kmtests/kernel32/kernel32_drv.c +++ b/rostests/kmtests/kernel32/kernel32_drv.c @@ -1,8 +1,8 @@ /* - * PROJECT: ReactOS kernel-mode tests - * LICENSE: LGPLv2.1+ - See COPYING.LIB in the top level directory - * PURPOSE: Test driver for kernel32 filesystem tests - * PROGRAMMER: Thomas Faber + * PROJECT: ReactOS kernel-mode tests + * LICENSE: LGPL-2.1+ (https://spdx.org/licenses/LGPL-2.1+) + * PURPOSE: Test driver for kernel32 filesystem tests + * COPYRIGHT: Copyright 2013-2017 Thomas Faber */ #include @@ -19,7 +19,9 @@ static KMT_IRP_HANDLER TestSetInformation; static UNICODE_STRING ExpectedExpression = RTL_CONSTANT_STRING(L""); static WCHAR ExpressionBuffer[MAX_PATH]; +static BOOLEAN ExpectingSetAttributes = FALSE; static ULONG ExpectedSetAttributes = -1; +static BOOLEAN ExpectingQueryAttributes = FALSE; static ULONG ReturnQueryAttributes = -1; NTSTATUS @@ -92,6 +94,7 @@ TestMessageHandler( return STATUS_INVALID_PARAMETER; ReturnQueryAttributes = *(PULONG)Buffer; + ExpectingQueryAttributes = TRUE; DPRINT("IOCTL_RETURN_QUERY_ATTRIBUTES: %lu\n", ReturnQueryAttributes); break; } @@ -102,6 +105,7 @@ TestMessageHandler( return STATUS_INVALID_PARAMETER; ExpectedSetAttributes = *(PULONG)Buffer; + ExpectingSetAttributes = TRUE; DPRINT("IOCTL_EXPECT_SET_ATTRIBUTES: %lu\n", ExpectedSetAttributes); break; } @@ -168,7 +172,7 @@ TestQueryInformation( ok_eq_ulong(IoStackLocation->Parameters.QueryFile.FileInformationClass, FileBasicInformation); if (IoStackLocation->Parameters.QueryFile.FileInformationClass == FileBasicInformation) { - ok(ReturnQueryAttributes != (ULONG)-1, "Unexpected QUERY_INFORMATION call\n"); + ok(ExpectingQueryAttributes, "Unexpected QUERY_INFORMATION call\n"); BasicInfo = Irp->AssociatedIrp.SystemBuffer; BasicInfo->CreationTime.QuadPart = 126011664000000000; BasicInfo->LastAccessTime.QuadPart = 130899112800000000; @@ -176,6 +180,7 @@ TestQueryInformation( BasicInfo->ChangeTime.QuadPart = 130899112800000000; BasicInfo->FileAttributes = ReturnQueryAttributes; ReturnQueryAttributes = -1; + ExpectingQueryAttributes = FALSE; Status = STATUS_SUCCESS; Irp->IoStatus.Information = sizeof(*BasicInfo); } @@ -205,7 +210,7 @@ TestSetInformation( ok_eq_ulong(IoStackLocation->Parameters.SetFile.FileInformationClass, FileBasicInformation); if (IoStackLocation->Parameters.SetFile.FileInformationClass == FileBasicInformation) { - ok(ExpectedSetAttributes != (ULONG)-1, "Unexpected SET_INFORMATION call\n"); + ok(ExpectingSetAttributes, "Unexpected SET_INFORMATION call\n"); BasicInfo = Irp->AssociatedIrp.SystemBuffer; ok_eq_longlong(BasicInfo->CreationTime.QuadPart, 0LL); ok_eq_longlong(BasicInfo->LastAccessTime.QuadPart, 0LL); @@ -213,6 +218,7 @@ TestSetInformation( ok_eq_longlong(BasicInfo->ChangeTime.QuadPart, 0LL); ok_eq_ulong(BasicInfo->FileAttributes, ExpectedSetAttributes); ExpectedSetAttributes = -1; + ExpectingSetAttributes = FALSE; Status = STATUS_SUCCESS; }