[PATCH 2 of 3] shell32: add test for SHPathPrepareForWrite

Vincent Povirk madewokherd at gmail.com
Sun Sep 2 02:10:14 CDT 2007


---
 dlls/shell32/tests/Makefile.in  |    1 +
 dlls/shell32/tests/shpathprep.c |  147 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 148 insertions(+), 0 deletions(-)
 create mode 100644 dlls/shell32/tests/shpathprep.c

diff --git a/dlls/shell32/tests/Makefile.in b/dlls/shell32/tests/Makefile.in
index f66b34d..335940e 100644
--- a/dlls/shell32/tests/Makefile.in
+++ b/dlls/shell32/tests/Makefile.in
@@ -13,6 +13,7 @@ CTESTS = \
 	shlexec.c \
 	shlfileop.c \
 	shlfolder.c \
+	shpathprep.c \
 	string.c \
 	systray.c
 
diff --git a/dlls/shell32/tests/shpathprep.c b/dlls/shell32/tests/shpathprep.c
new file mode 100644
index 0000000..4e018b0
--- /dev/null
+++ b/dlls/shell32/tests/shpathprep.c
@@ -0,0 +1,147 @@
+/*
+ * Unit test of the SHPathPrepareForWrite functions.
+ *
+ * Copyright 2007 Vincent Povirk
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include <wine/test.h>
+#include <winbase.h>
+
+#include "shlobj.h"
+
+/* creates a file with the specified name for tests */
+static void CreateTestFile(const CHAR *name)
+{
+    HANDLE file;
+    DWORD written;
+
+    file = CreateFileA(name, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
+    if (file != INVALID_HANDLE_VALUE)
+    {
+        WriteFile(file, name, strlen(name), &written, NULL);
+        WriteFile(file, "\n", strlen("\n"), &written, NULL);
+        CloseHandle(file);
+    }
+}
+
+
+/* initializes the tests */
+static void CreateFilesFolders(void)
+{
+    CreateDirectoryA("c:\\testdir", NULL);
+    CreateTestFile  ("c:\\testdir\\test1.txt ");
+    CreateDirectoryA(".\\testdir", NULL);
+}
+
+/* cleans after tests */
+static void Cleanup(void)
+{
+    DeleteFileA("c:\\testdir\\test1.txt");
+    RemoveDirectoryA("c:\\testdir\\createdir\\subdir\\somefile");
+    RemoveDirectoryA("c:\\testdir\\createdir\\subdir");
+    RemoveDirectoryA("c:\\testdir\\createdir");
+    RemoveDirectoryA("c:\\testdir\\createdir2\\subdir");
+    RemoveDirectoryA("c:\\testdir\\createdir2");
+    RemoveDirectoryA("c:\\testdir\\nonexistent\\somefile");
+    RemoveDirectoryA("c:\\testdir\\nonexistent");
+    RemoveDirectoryA("c:\\testdir");
+    RemoveDirectoryA(".\\testdir\\nonexistent");
+    RemoveDirectoryA(".\\testdir");
+}
+
+/* checks if a path exists */
+static int Exists(const CHAR *name)
+{
+    DWORD res;
+    res = GetFileAttributesA(name);
+    return (res != INVALID_FILE_ATTRIBUTES) && (res & FILE_ATTRIBUTE_DIRECTORY);
+}
+
+START_TEST(shpathprep)
+{
+    HRESULT res;
+    int ex;
+
+    CreateFilesFolders();
+
+    res = SHPathPrepareForWriteA(0, 0, "c:\\testdir", SHPPFW_NONE);
+    ok(res == S_OK, "res == 0x%08x\n", res);
+
+    res = SHPathPrepareForWriteA(0, 0, "c:\\testdir\\nonexistent", SHPPFW_NONE);
+    todo_wine ok(res == 0x80070003, "res == 0x%08x\n", res);
+
+    res = SHPathPrepareForWriteA(0, 0, "c:\\testdir\\test1.txt", SHPPFW_NONE);
+    todo_wine ok(res == 0x8007010b, "res == 0x%08x\n", res);
+
+    res = SHPathPrepareForWriteA(0, 0, "c:\\testdir\\test1.txt", SHPPFW_DIRCREATE);
+    todo_wine ok(res == 0x8007010b, "res == 0x%08x\n", res);
+
+    res = SHPathPrepareForWriteA(0, 0, "c:\\testdir\\test1.txt\\", SHPPFW_NONE);
+    todo_wine ok(res == 0x8007010b, "res == 0x%08x\n", res);
+
+    res = SHPathPrepareForWriteA(0, 0, "c:\\testdir\\nonexistent", SHPPFW_IGNOREFILENAME);
+    ok(res == S_OK, "res == 0x%08x\n", res);
+
+    res = SHPathPrepareForWriteA(0, 0, "c:\\testdir\\nonexistent\\", SHPPFW_IGNOREFILENAME);
+    todo_wine ok(res == 0x80070003, "res == 0x%08x\n", res);
+    ex = Exists("c:\\testdir\\nonexistent\\");
+    ok(!ex, "c:\\testdir\\nonexistent\\ exists but shouldn't\n");
+
+    res = SHPathPrepareForWriteA(0, 0, "c:\\testdir\\nonexistent\\somefile", SHPPFW_IGNOREFILENAME);
+    todo_wine ok(res == 0x80070003, "res == 0x%08x\n", res);
+    ex = Exists("c:\\testdir\\nonexistent\\");
+    ok(!ex, "c:\\testdir\\nonexistent\\ exists but shouldn't\n");
+
+    res = SHPathPrepareForWriteA(0, 0, "c:\\testdir", SHPPFW_DIRCREATE);
+    ok(res == S_OK, "res == 0x%08x\n", res);
+
+    res = SHPathPrepareForWriteA(0, 0, "c:\\testdir\\nonexistent", SHPPFW_IGNOREFILENAME|SHPPFW_DIRCREATE);
+    ok(res == S_OK, "res == 0x%08x\n", res);
+    ex = Exists("c:\\testdir\\nonexistent\\");
+    ok(!ex, "c:\\testdir\\nonexistent\\ exists but shouldn't\n");
+
+    /* using a relative path on Windows tests for access but does not create the directory */
+    res = SHPathPrepareForWriteA(0, 0, ".\\testdir", SHPPFW_DIRCREATE);
+    ok(res == S_OK, "res == 0x%08x\n", res);
+
+    res = SHPathPrepareForWriteA(0, 0, ".\\testdir\\nonexistent", SHPPFW_DIRCREATE);
+    todo_wine ok(res == 0x80070003, "res == 0x%08x\n", res);
+    ex = Exists(".\\testdir\\nonexistent\\");
+    ok(!ex, ".\\testdir\\nonexistent\\ exists but shouldn't\n");
+
+    res = SHPathPrepareForWriteA(0, 0, "c:\\testdir\\createdir", SHPPFW_DIRCREATE);
+    ok(res == S_OK, "res == 0x%08x\n", res);
+    ex = Exists("c:\\testdir\\createdir\\");
+    todo_wine ok(ex, "c:\\testdir\\createdir\\ doesn't exist but should\n");
+
+    res = SHPathPrepareForWriteA(0, 0, "c:\\testdir\\createdir\\subdir\\somefile", SHPPFW_IGNOREFILENAME|SHPPFW_DIRCREATE);
+    ok(res == S_OK, "res == 0x%08x\n", res);
+    ex = Exists("c:\\testdir\\createdir\\subdir");
+    todo_wine ok(ex, "c:\\testdir\\createdir\\subdir doesn't exist but should\n");
+    ex = Exists("c:\\testdir\\createdir\\subdir\\somefile");
+    ok(!ex, "c:\\testdir\\createdir\\subdir\\somefile exists but shouldn't\n");
+
+    res = SHPathPrepareForWriteA(0, 0, "c:\\testdir\\createdir2\\subdir\\", SHPPFW_IGNOREFILENAME|SHPPFW_DIRCREATE);
+    ok(res == S_OK, "res == 0x%08x\n", res);
+    ex = Exists("c:\\testdir\\createdir2\\subdir");
+    todo_wine ok(ex, "c:\\testdir\\createdir2\\subdir doesn't exist but should\n");
+
+    /* SHPPFW_ASKDIRCREATE, SHPPFW_NOWRITECHECK, and SHPPFW_MEDIACHECKONLY are untested */
+
+    Cleanup();
+}
+
-- 
1.5.2.5

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.winehq.org/pipermail/wine-patches/attachments/20070902/aa6c0830/attachment.html


More information about the wine-patches mailing list