2 * File change notification tests
4 * Copyright 2006 Mike McCormack for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #define WIN32_NO_STATUS
28 #include "wine/test.h"
30 typedef NTSTATUS (WINAPI
*fnNtNotifyChangeDirectoryFile
)(
31 HANDLE
,HANDLE
,PIO_APC_ROUTINE
,PVOID
,
32 PIO_STATUS_BLOCK
,PVOID
,ULONG
,ULONG
,BOOLEAN
);
33 fnNtNotifyChangeDirectoryFile pNtNotifyChangeDirectoryFile
;
35 static void test_ntncdf(void)
37 HMODULE hntdll
= GetModuleHandle("ntdll");
41 DWORD fflags
, filter
= 0;
43 WCHAR path
[MAX_PATH
], subdir
[MAX_PATH
];
44 static const WCHAR szBoo
[] = { '\\','b','o','o',0 };
45 static const WCHAR szHoo
[] = { '\\','h','o','o',0 };
47 pNtNotifyChangeDirectoryFile
= (fnNtNotifyChangeDirectoryFile
)
48 GetProcAddress(hntdll
, "NtNotifyChangeDirectoryFile");
49 if (!pNtNotifyChangeDirectoryFile
)
52 r
= GetTempPathW( MAX_PATH
, path
);
53 ok( r
!= 0, "temp path failed\n");
57 lstrcatW( path
, szBoo
);
58 lstrcpyW( subdir
, path
);
59 lstrcatW( subdir
, szHoo
);
61 RemoveDirectoryW( subdir
);
62 RemoveDirectoryW( path
);
64 r
= CreateDirectoryW(path
, NULL
);
65 ok( r
== TRUE
, "failed to create directory\n");
67 r
= pNtNotifyChangeDirectoryFile(NULL
,NULL
,NULL
,NULL
,NULL
,NULL
,0,0,0);
68 ok(r
==STATUS_ACCESS_VIOLATION
, "should return access violation\n");
70 fflags
= FILE_FLAG_BACKUP_SEMANTICS
| FILE_FLAG_OVERLAPPED
;
71 hdir
= CreateFileW(path
, GENERIC_READ
|SYNCHRONIZE
, FILE_SHARE_READ
, NULL
,
72 OPEN_EXISTING
, fflags
, NULL
);
73 ok( hdir
!= INVALID_HANDLE_VALUE
, "failed to open directory\n");
75 hEvent
= CreateEvent( NULL
, 0, 0, NULL
);
77 r
= pNtNotifyChangeDirectoryFile(hdir
,NULL
,NULL
,NULL
,&iosb
,NULL
,0,0,0);
78 ok(r
==STATUS_INVALID_PARAMETER
, "should return invalid parameter\n");
80 r
= pNtNotifyChangeDirectoryFile(hdir
,hEvent
,NULL
,NULL
,&iosb
,NULL
,0,0,0);
81 ok(r
==STATUS_INVALID_PARAMETER
, "should return invalid parameter\n");
83 filter
= FILE_NOTIFY_CHANGE_FILE_NAME
;
84 filter
|= FILE_NOTIFY_CHANGE_DIR_NAME
;
85 filter
|= FILE_NOTIFY_CHANGE_ATTRIBUTES
;
86 filter
|= FILE_NOTIFY_CHANGE_SIZE
;
87 filter
|= FILE_NOTIFY_CHANGE_LAST_WRITE
;
88 filter
|= FILE_NOTIFY_CHANGE_LAST_ACCESS
;
89 filter
|= FILE_NOTIFY_CHANGE_CREATION
;
90 filter
|= FILE_NOTIFY_CHANGE_SECURITY
;
92 r
= pNtNotifyChangeDirectoryFile(hdir
,hEvent
,NULL
,NULL
,&iosb
,buffer
,sizeof buffer
,filter
,0);
93 ok(r
==STATUS_PENDING
, "should return status pending\n");
95 r
= WaitForSingleObject( hEvent
, 0 );
96 ok( r
== STATUS_TIMEOUT
, "event shouldn't be ready\n" );
98 r
= CreateDirectoryW( subdir
, NULL
);
99 ok( r
== TRUE
, "failed to create directory\n");
101 r
= WaitForSingleObject( hEvent
, 0 );
102 ok( r
== WAIT_OBJECT_0
, "event wasn't ready\n" );
104 r
= pNtNotifyChangeDirectoryFile(hdir
,0,NULL
,NULL
,&iosb
,NULL
,0,filter
,0);
105 ok(r
==STATUS_PENDING
, "should return status pending\n");
107 r
= WaitForSingleObject( hdir
, 0 );
108 ok( r
== STATUS_TIMEOUT
, "event shouldn't be ready\n" );
110 r
= RemoveDirectoryW( subdir
);
111 ok( r
== TRUE
, "failed to remove directory\n");
113 r
= WaitForSingleObject( hdir
, 0 );
114 ok( r
== WAIT_OBJECT_0
, "event wasn't ready\n" );
116 r
= RemoveDirectoryW( path
);
117 ok( r
== FALSE
, "failed to remove directory\n");
121 r
= RemoveDirectoryW( path
);
122 ok( r
== TRUE
, "failed to remove directory\n");