[KMTESTS:KERNEL32]
[reactos.git] / rostests / kmtests / kernel32 / FileAttributes_user.c
1 /*
2 * PROJECT: ReactOS kernel-mode tests
3 * LICENSE: LGPLv2.1+ - See COPYING.LIB in the top level directory
4 * PURPOSE: Test for GetFileAttributes/SetFileAttributes
5 * PROGRAMMER: Thomas Faber <thomas.faber@reactos.org>
6 */
7
8 #include <kmt_test.h>
9
10 #include "kernel32_test.h"
11
12 START_TEST(FileAttributes)
13 {
14 PCWSTR FileName = L"\\\\.\\Global\\GLOBALROOT\\Device\\Kmtest-kernel32\\Somefile";
15 BOOL Ret;
16 DWORD Attributes;
17
18 KmtLoadDriver(L"kernel32", FALSE);
19 KmtOpenDriver();
20
21 /* Set read-only attribute */
22 KmtSendUlongToDriver(IOCTL_EXPECT_SET_ATTRIBUTES, FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_NORMAL);
23 Ret = SetFileAttributesW(FileName, FILE_ATTRIBUTE_READONLY);
24 ok(Ret == TRUE, "SetFileAttributesW returned %d, error %lu\n", Ret, GetLastError());
25
26 /* Set normal attribute */
27 KmtSendUlongToDriver(IOCTL_EXPECT_SET_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL);
28 Ret = SetFileAttributesW(FileName, FILE_ATTRIBUTE_NORMAL);
29 ok(Ret == TRUE, "SetFileAttributesW returned %d, error %lu\n", Ret, GetLastError());
30
31 /* Set 0 attribute (driver should receive normal) */
32 KmtSendUlongToDriver(IOCTL_EXPECT_SET_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL);
33 Ret = SetFileAttributesW(FileName, 0);
34 ok(Ret == TRUE, "SetFileAttributesW returned %d, error %lu\n", Ret, GetLastError());
35
36 /* Query read-only attribute */
37 KmtSendUlongToDriver(IOCTL_RETURN_QUERY_ATTRIBUTES, FILE_ATTRIBUTE_READONLY);
38 Attributes = GetFileAttributesW(FileName);
39 ok_eq_hex(Attributes, FILE_ATTRIBUTE_READONLY);
40
41 /* Query read-only + normal attribute */
42 KmtSendUlongToDriver(IOCTL_RETURN_QUERY_ATTRIBUTES, FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_NORMAL);
43 Attributes = GetFileAttributesW(FileName);
44 ok_eq_hex(Attributes, FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_NORMAL);
45
46 /* Query normal attribute */
47 KmtSendUlongToDriver(IOCTL_RETURN_QUERY_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL);
48 Attributes = GetFileAttributesW(FileName);
49 ok_eq_hex(Attributes, FILE_ATTRIBUTE_NORMAL);
50
51 /* Query 0 attribute */
52 KmtSendUlongToDriver(IOCTL_RETURN_QUERY_ATTRIBUTES, 0);
53 Attributes = GetFileAttributesW(FileName);
54 ok_eq_hex(Attributes, 0);
55
56 KmtCloseDriver();
57 KmtUnloadDriver();
58 }