diff --git a/build/VStudio/testing/winfsp-tests.vcxproj b/build/VStudio/testing/winfsp-tests.vcxproj
index 55cd2848..70850c17 100644
--- a/build/VStudio/testing/winfsp-tests.vcxproj
+++ b/build/VStudio/testing/winfsp-tests.vcxproj
@@ -191,6 +191,7 @@
+
diff --git a/build/VStudio/testing/winfsp-tests.vcxproj.filters b/build/VStudio/testing/winfsp-tests.vcxproj.filters
index d4443b26..5d5ba4c6 100644
--- a/build/VStudio/testing/winfsp-tests.vcxproj.filters
+++ b/build/VStudio/testing/winfsp-tests.vcxproj.filters
@@ -73,6 +73,9 @@
Source
+
+ Source
+
diff --git a/tst/winfsp-tests/oplock-test.c b/tst/winfsp-tests/oplock-test.c
new file mode 100644
index 00000000..dc223535
--- /dev/null
+++ b/tst/winfsp-tests/oplock-test.c
@@ -0,0 +1,92 @@
+/**
+ * @file oplock-test.c
+ *
+ * @copyright 2015-2016 Bill Zissimopoulos
+ */
+/*
+ * This file is part of WinFsp.
+ *
+ * You can redistribute it and/or modify it under the terms of the GNU
+ * General Public License version 3 as published by the Free Software
+ * Foundation.
+ *
+ * Licensees holding a valid commercial license may use this file in
+ * accordance with the commercial license agreement provided with the
+ * software.
+ */
+
+#include
+#include
+#include
+#include "memfs.h"
+
+#include "winfsp-tests.h"
+
+void oplock_not_granted_dotest(ULONG Flags, PWSTR Prefix)
+{
+ void *memfs = memfs_start(Flags);
+
+ HANDLE Handle1, Handle2;
+ BOOLEAN Success;
+ WCHAR FilePath[MAX_PATH];
+ OVERLAPPED Overlapped;
+ DWORD BytesTransferred;
+
+ StringCbPrintfW(FilePath, sizeof FilePath, L"%s%s\\file0",
+ Prefix ? L"" : L"\\\\?\\GLOBALROOT", Prefix ? Prefix : memfs_volumename(memfs));
+
+ Handle1 = CreateFileW(FilePath,
+ GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, 0);
+ ASSERT(INVALID_HANDLE_VALUE != Handle1);
+
+ Handle2 = CreateFileW(FilePath,
+ GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, 0);
+ ASSERT(INVALID_HANDLE_VALUE != Handle2);
+
+ memset(&Overlapped, 0, sizeof Overlapped);
+ Success = DeviceIoControl(Handle2, FSCTL_REQUEST_FILTER_OPLOCK, 0, 0, 0, 0, &BytesTransferred,
+ &Overlapped);
+ ASSERT(!Success);
+ ASSERT(ERROR_OPLOCK_NOT_GRANTED == GetLastError() || ERROR_IO_PENDING == GetLastError());
+ if (ERROR_IO_PENDING == GetLastError())
+ {
+ Success = GetOverlappedResult(Handle2, &Overlapped, &BytesTransferred, TRUE);
+ ASSERT(!Success && ERROR_OPLOCK_NOT_GRANTED == GetLastError());
+ }
+
+ Success = CloseHandle(Handle2);
+ ASSERT(Success);
+
+ Success = CloseHandle(Handle1);
+ ASSERT(Success);
+
+ Success = DeleteFileW(FilePath);
+ ASSERT(Success);
+
+ memfs_stop(memfs);
+}
+
+void oplock_not_granted_test(void)
+{
+ if (OptOplock)
+ return;
+
+ if (NtfsTests)
+ {
+ WCHAR DirBuf[MAX_PATH];
+ GetTestDirectory(DirBuf);
+ oplock_not_granted_dotest(-1, DirBuf);
+ }
+ if (WinFspDiskTests)
+ oplock_not_granted_dotest(MemfsDisk, 0);
+ if (WinFspNetTests)
+ oplock_not_granted_dotest(MemfsNet, L"\\\\memfs\\share");
+}
+
+void oplock_tests(void)
+{
+ if (OptOplock)
+ return;
+
+ TEST(oplock_not_granted_test);
+}
diff --git a/tst/winfsp-tests/winfsp-tests.c b/tst/winfsp-tests/winfsp-tests.c
index 4695c101..012717c4 100644
--- a/tst/winfsp-tests/winfsp-tests.c
+++ b/tst/winfsp-tests/winfsp-tests.c
@@ -194,6 +194,7 @@ int main(int argc, char *argv[])
TESTSUITE(dirctl_tests);
TESTSUITE(reparse_tests);
TESTSUITE(stream_tests);
+ TESTSUITE(oplock_tests);
atexit(exiting);
signal(SIGABRT, abort_handler);