1c2c66affSColin Finck /*
2c2c66affSColin Finck  * PROJECT:     ReactOS kernel-mode tests
3c2c66affSColin Finck  * LICENSE:     LGPL-2.1+ (https://spdx.org/licenses/LGPL-2.1+)
4c2c66affSColin Finck  * PURPOSE:     Test for GetFileAttributes/SetFileAttributes
5c2c66affSColin Finck  * COPYRIGHT:   Copyright 2017 Thomas Faber <thomas.faber@reactos.org>
6c2c66affSColin Finck  *              Copyright 2017 Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
7c2c66affSColin Finck  */
8c2c66affSColin Finck 
9c2c66affSColin Finck #include <kmt_test.h>
10c2c66affSColin Finck 
11c2c66affSColin Finck #include "kernel32_test.h"
12c2c66affSColin Finck 
START_TEST(FileAttributes)13c2c66affSColin Finck START_TEST(FileAttributes)
14c2c66affSColin Finck {
15c2c66affSColin Finck     PCWSTR FileName = L"\\\\.\\Global\\GLOBALROOT\\Device\\Kmtest-kernel32\\Somefile";
16c2c66affSColin Finck     BOOL Ret;
17c2c66affSColin Finck     DWORD Attributes;
18*9e12af56STimo Kreuzer     DWORD Error;
19c2c66affSColin Finck 
20*9e12af56STimo Kreuzer     Error = KmtLoadAndOpenDriver(L"kernel32", FALSE);
21*9e12af56STimo Kreuzer     ok_eq_int(Error, ERROR_SUCCESS);
22*9e12af56STimo Kreuzer     if (Error)
23*9e12af56STimo Kreuzer         return;
24c2c66affSColin Finck 
25c2c66affSColin Finck     /* Set read-only attribute */
26c2c66affSColin Finck     KmtSendUlongToDriver(IOCTL_EXPECT_SET_ATTRIBUTES, FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_NORMAL);
27c2c66affSColin Finck     Ret = SetFileAttributesW(FileName, FILE_ATTRIBUTE_READONLY);
28c2c66affSColin Finck     ok(Ret == TRUE, "SetFileAttributesW returned %d, error %lu\n", Ret, GetLastError());
29c2c66affSColin Finck 
30c2c66affSColin Finck     /* Set normal attribute */
31c2c66affSColin Finck     KmtSendUlongToDriver(IOCTL_EXPECT_SET_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL);
32c2c66affSColin Finck     Ret = SetFileAttributesW(FileName, FILE_ATTRIBUTE_NORMAL);
33c2c66affSColin Finck     ok(Ret == TRUE, "SetFileAttributesW returned %d, error %lu\n", Ret, GetLastError());
34c2c66affSColin Finck 
35c2c66affSColin Finck     /* Set 0 attribute (driver should receive normal) */
36c2c66affSColin Finck     KmtSendUlongToDriver(IOCTL_EXPECT_SET_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL);
37c2c66affSColin Finck     Ret = SetFileAttributesW(FileName, 0);
38c2c66affSColin Finck     ok(Ret == TRUE, "SetFileAttributesW returned %d, error %lu\n", Ret, GetLastError());
39c2c66affSColin Finck 
40c2c66affSColin Finck     /* Set invalid attributes */
41c2c66affSColin Finck     KmtSendUlongToDriver(IOCTL_EXPECT_SET_ATTRIBUTES, FILE_ATTRIBUTE_VALID_SET_FLAGS);
42c2c66affSColin Finck     Ret = SetFileAttributesW(FileName, INVALID_FILE_ATTRIBUTES);
43c2c66affSColin Finck     ok(Ret == TRUE, "SetFileAttributesW returned %d, error %lu\n", Ret, GetLastError());
44c2c66affSColin Finck 
45c2c66affSColin Finck     /* Query read-only attribute */
46c2c66affSColin Finck     KmtSendUlongToDriver(IOCTL_RETURN_QUERY_ATTRIBUTES, FILE_ATTRIBUTE_READONLY);
47c2c66affSColin Finck     Attributes = GetFileAttributesW(FileName);
48c2c66affSColin Finck     ok_eq_hex(Attributes, FILE_ATTRIBUTE_READONLY);
49c2c66affSColin Finck 
50c2c66affSColin Finck     /* Query read-only + normal attribute */
51c2c66affSColin Finck     KmtSendUlongToDriver(IOCTL_RETURN_QUERY_ATTRIBUTES, FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_NORMAL);
52c2c66affSColin Finck     Attributes = GetFileAttributesW(FileName);
53c2c66affSColin Finck     ok_eq_hex(Attributes, FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_NORMAL);
54c2c66affSColin Finck 
55c2c66affSColin Finck     /* Query normal attribute */
56c2c66affSColin Finck     KmtSendUlongToDriver(IOCTL_RETURN_QUERY_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL);
57c2c66affSColin Finck     Attributes = GetFileAttributesW(FileName);
58c2c66affSColin Finck     ok_eq_hex(Attributes, FILE_ATTRIBUTE_NORMAL);
59c2c66affSColin Finck 
60c2c66affSColin Finck     /* Query 0 attribute */
61c2c66affSColin Finck     KmtSendUlongToDriver(IOCTL_RETURN_QUERY_ATTRIBUTES, 0);
62c2c66affSColin Finck     Attributes = GetFileAttributesW(FileName);
63c2c66affSColin Finck     ok_eq_hex(Attributes, 0);
64c2c66affSColin Finck 
65c2c66affSColin Finck     /* Query invalid attributes */
66c2c66affSColin Finck     KmtSendUlongToDriver(IOCTL_RETURN_QUERY_ATTRIBUTES, INVALID_FILE_ATTRIBUTES);
67c2c66affSColin Finck     Attributes = GetFileAttributesW(FileName);
68c2c66affSColin Finck     ok_eq_hex(Attributes, INVALID_FILE_ATTRIBUTES);
69c2c66affSColin Finck 
70c2c66affSColin Finck     /** Directory attribute **/
71c2c66affSColin Finck     /* Set read-only and directory attribute */
72c2c66affSColin Finck     KmtSendUlongToDriver(IOCTL_EXPECT_SET_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_READONLY);
73c2c66affSColin Finck     Ret = SetFileAttributesW(FileName, FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_DIRECTORY);
74c2c66affSColin Finck     ok(Ret == TRUE, "SetFileAttributesW returned %d, error %lu\n", Ret, GetLastError());
75c2c66affSColin Finck 
76c2c66affSColin Finck     /* Set normal and directory attribute */
77c2c66affSColin Finck     KmtSendUlongToDriver(IOCTL_EXPECT_SET_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL);
78c2c66affSColin Finck     Ret = SetFileAttributesW(FileName, FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_DIRECTORY);
79c2c66affSColin Finck     ok(Ret == TRUE, "SetFileAttributesW returned %d, error %lu\n", Ret, GetLastError());
80c2c66affSColin Finck 
81c2c66affSColin Finck     /* Set directory attribute */
82c2c66affSColin Finck     KmtSendUlongToDriver(IOCTL_EXPECT_SET_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL);
83c2c66affSColin Finck     Ret = SetFileAttributesW(FileName, FILE_ATTRIBUTE_DIRECTORY);
84c2c66affSColin Finck     ok(Ret == TRUE, "SetFileAttributesW returned %d, error %lu\n", Ret, GetLastError());
85c2c66affSColin Finck 
86c2c66affSColin Finck     /* Query read-only and directory attribute */
87c2c66affSColin Finck     KmtSendUlongToDriver(IOCTL_RETURN_QUERY_ATTRIBUTES, FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_DIRECTORY);
88c2c66affSColin Finck     Attributes = GetFileAttributesW(FileName);
89c2c66affSColin Finck     ok_eq_hex(Attributes, FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_DIRECTORY);
90c2c66affSColin Finck 
91c2c66affSColin Finck     /* Query read-only + normal + directory attribute */
92c2c66affSColin Finck     KmtSendUlongToDriver(IOCTL_RETURN_QUERY_ATTRIBUTES, FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_DIRECTORY);
93c2c66affSColin Finck     Attributes = GetFileAttributesW(FileName);
94c2c66affSColin Finck     ok_eq_hex(Attributes, FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_DIRECTORY);
95c2c66affSColin Finck 
96c2c66affSColin Finck     /* Query normal and directory attribute */
97c2c66affSColin Finck     KmtSendUlongToDriver(IOCTL_RETURN_QUERY_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_DIRECTORY);
98c2c66affSColin Finck     Attributes = GetFileAttributesW(FileName);
99c2c66affSColin Finck     ok_eq_hex(Attributes, FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_DIRECTORY);
100c2c66affSColin Finck 
101c2c66affSColin Finck     /* Query directory attribute */
102c2c66affSColin Finck     KmtSendUlongToDriver(IOCTL_RETURN_QUERY_ATTRIBUTES, FILE_ATTRIBUTE_DIRECTORY);
103c2c66affSColin Finck     Attributes = GetFileAttributesW(FileName);
104c2c66affSColin Finck     ok_eq_hex(Attributes, FILE_ATTRIBUTE_DIRECTORY);
105c2c66affSColin Finck 
106c2c66affSColin Finck     KmtCloseDriver();
107c2c66affSColin Finck     KmtUnloadDriver();
108c2c66affSColin Finck }
109