Add CreateDirectoryA() conformance tests

Francois Gouget fgouget at codeweavers.com
Thu Jun 30 05:32:43 CDT 2005


An application got into an infinite loop because 
CreateDirectoryA("c:\\dotted.\\subdir") failed although "C:\\dotted." 
existed. So I wrote some conformance tests and Alexandre fixed the 
CreateDirectoryA() bug :-)

I also added tests to see what happens when we have two trailing dots 
and found out Win9x and NT behave differently. This discrepancy carries 
out in the tests with one and two trailing spaces.


Changelog:

  * dlls/kernel/tests/directory.c

    Francois Gouget <fgouget at codeweavers.com> for Mandriva
    Test the behavior of CreateDirectory() when it has one or two 
trailing dots or spaces.
    Tweak the previous CreateDirectory() tests so we get more 
information in case of a failure.


-- 
Francois Gouget
fgouget at codeweavers.com

-------------- next part --------------
Index: dlls/kernel/tests/directory.c
===================================================================
RCS file: /var/cvs/wine/dlls/kernel/tests/directory.c,v
retrieving revision 1.15
diff -u -p -r1.15 directory.c
--- dlls/kernel/tests/directory.c	10 Feb 2005 19:19:36 -0000	1.15
+++ dlls/kernel/tests/directory.c	24 Jun 2005 13:36:00 -0000
@@ -156,12 +156,12 @@ static void test_CreateDirectoryA(void)
     ret = CreateDirectoryA(NULL, NULL);
     ok(ret == FALSE && (GetLastError() == ERROR_PATH_NOT_FOUND ||
                         GetLastError() == ERROR_INVALID_PARAMETER),
-       "CreateDirectoryA(NULL,NULL): ret=%d error=%ld\n",ret,GetLastError());
+       "CreateDirectoryA(NULL): ret=%d err=%ld\n", ret, GetLastError());
 
     ret = CreateDirectoryA("", NULL);
     ok(ret == FALSE && (GetLastError() == ERROR_BAD_PATHNAME ||
                         GetLastError() == ERROR_PATH_NOT_FOUND),
-       "CreateDirectoryA(\"\",NULL): ret=%d error=%ld\n",ret,GetLastError());
+       "CreateDirectoryA(%s): ret=%d err=%ld\n", tmpdir, ret, GetLastError());
 
     ret = GetSystemDirectoryA(tmpdir, MAX_PATH);
     ok(ret < MAX_PATH, "System directory should fit into MAX_PATH\n");
@@ -170,52 +170,159 @@ static void test_CreateDirectoryA(void)
     ok(ret == TRUE, "could not chdir to the System directory\n");
 
     ret = CreateDirectoryA(".", NULL);
-    ok(ret == FALSE && GetLastError() == ERROR_ALREADY_EXISTS, "should not create existing path\n");
+    ok(ret == FALSE && GetLastError() == ERROR_ALREADY_EXISTS,
+       "CreateDirectoryA(%s): ret=%d err=%ld\n", tmpdir, ret, GetLastError());
+
 
     ret = CreateDirectoryA("..", NULL);
-    ok(ret == FALSE && GetLastError() == ERROR_ALREADY_EXISTS, "should not create existing path\n");
+    ok(ret == FALSE && GetLastError() == ERROR_ALREADY_EXISTS,
+       "CreateDirectoryA(%s): ret=%d err=%ld\n", tmpdir, ret, GetLastError());
 
     GetTempPathA(MAX_PATH, tmpdir);
     tmpdir[3] = 0; /* truncate the path */
     ret = CreateDirectoryA(tmpdir, NULL);
     ok(ret == FALSE && (GetLastError() == ERROR_ALREADY_EXISTS ||
                         GetLastError() == ERROR_ACCESS_DENIED),
-       "CreateDirectoryA(drive_root): ret=%d error=%ld\n",ret,GetLastError());
+       "CreateDirectoryA(%s): ret=%d err=%ld\n", tmpdir, ret, GetLastError());
 
     GetTempPathA(MAX_PATH, tmpdir);
     lstrcatA(tmpdir, "Please Remove Me");
     ret = CreateDirectoryA(tmpdir, NULL);
-    ok(ret == TRUE, "CreateDirectoryA should always succeed\n");
+    ok(ret == TRUE,       "CreateDirectoryA(%s) failed err=%ld\n", tmpdir, GetLastError());
 
     ret = CreateDirectoryA(tmpdir, NULL);
-    ok(ret == FALSE && GetLastError() == ERROR_ALREADY_EXISTS, "should not create existing path\n");
+    ok(ret == FALSE && GetLastError() == ERROR_ALREADY_EXISTS,
+       "CreateDirectoryA(%s): ret=%d err=%ld\n", tmpdir, ret, GetLastError());
 
     ret = RemoveDirectoryA(tmpdir);
-    ok(ret == TRUE, "RemoveDirectoryA should always succeed\n");
+    ok(ret == TRUE,
+       "RemoveDirectoryA(%s) failed err=%ld\n", tmpdir, GetLastError());
+
 
     lstrcatA(tmpdir, "?");
     ret = CreateDirectoryA(tmpdir, NULL);
     ok(ret == FALSE && (GetLastError() == ERROR_INVALID_NAME ||
 			GetLastError() == ERROR_PATH_NOT_FOUND),
-       "CreateDirectoryA with ? wildcard name should fail, ret=%s error=%ld\n",
-       ret ? " True" : "False", GetLastError());
-    ret = RemoveDirectoryA(tmpdir);
+       "CreateDirectoryA(%s): ret=%d err=%ld\n", tmpdir, ret, GetLastError());
+    RemoveDirectoryA(tmpdir);
 
     tmpdir[lstrlenA(tmpdir) - 1] = '*';
     ret = CreateDirectoryA(tmpdir, NULL);
     ok(ret == FALSE && (GetLastError() == ERROR_INVALID_NAME ||
 			GetLastError() == ERROR_PATH_NOT_FOUND),
-       "CreateDirectoryA with * wildcard name should fail, ret=%s error=%ld\n",
-       ret ? " True" : "False", GetLastError());
-    ret = RemoveDirectoryA(tmpdir);
-    
+       "CreateDirectoryA(%s): ret=%d err=%ld\n", tmpdir, ret, GetLastError());
+    RemoveDirectoryA(tmpdir);
+
     GetTempPathA(MAX_PATH, tmpdir);
     lstrcatA(tmpdir, "Please Remove Me/Please Remove Me");
     ret = CreateDirectoryA(tmpdir, NULL);
     ok(ret == FALSE && GetLastError() == ERROR_PATH_NOT_FOUND, 
-      "CreateDirectoryA with multiple nonexistent directories in path should fail\n");
+       "CreateDirectoryA(%s): ret=%d err=%ld\n", tmpdir, ret, GetLastError());
+    RemoveDirectoryA(tmpdir);
+
+    /* Test behavior with a trailing dot.
+     * The directory should be created without the dot.
+     */
+    GetTempPathA(MAX_PATH, tmpdir);
+    lstrcatA(tmpdir, "Please Remove Me.");
+    ret = CreateDirectoryA(tmpdir, NULL);
+    ok(ret == TRUE,
+       "CreateDirectoryA(%s) failed err=%ld\n", tmpdir, GetLastError());
+
+    lstrcatA(tmpdir, "/Please Remove Me");
+    ret = CreateDirectoryA(tmpdir, NULL);
+    ok(ret == TRUE,
+       "CreateDirectoryA(%s) failed err=%ld\n", tmpdir, GetLastError());
     ret = RemoveDirectoryA(tmpdir);
-    
+    ok(ret == TRUE,
+       "RemoveDirectoryA(%s) failed err=%ld\n", tmpdir, GetLastError());
+
+    GetTempPathA(MAX_PATH, tmpdir);
+    lstrcatA(tmpdir, "Please Remove Me");
+    ret = RemoveDirectoryA(tmpdir);
+    ok(ret == TRUE,
+       "RemoveDirectoryA(%s) failed err=%ld\n", tmpdir, GetLastError());
+
+    /* Test behavior with two trailing dots.
+     * The directory should be created without the trailing dots.
+     */
+    GetTempPathA(MAX_PATH, tmpdir);
+    lstrcatA(tmpdir, "Please Remove Me..");
+    ret = CreateDirectoryA(tmpdir, NULL);
+    ok(ret == TRUE,
+       "CreateDirectoryA(%s) failed err=%ld\n", tmpdir, GetLastError());
+
+    lstrcatA(tmpdir, "/Please Remove Me");
+    ret = CreateDirectoryA(tmpdir, NULL);
+    ok(ret == TRUE || /* On Win98 */
+       (ret == FALSE && GetLastError() == ERROR_PATH_NOT_FOUND), /* On NT! */
+       "CreateDirectoryA(%s): ret=%d err=%ld\n", tmpdir, ret, GetLastError());
+    if (ret == TRUE)
+    {
+        ret = RemoveDirectoryA(tmpdir);
+        ok(ret == TRUE,
+           "RemoveDirectoryA(%s) failed err=%ld\n", tmpdir, GetLastError());
+    }
+
+    GetTempPathA(MAX_PATH, tmpdir);
+    lstrcatA(tmpdir, "Please Remove Me");
+    ret = RemoveDirectoryA(tmpdir);
+    ok(ret == TRUE,
+       "RemoveDirectoryA(%s) failed err=%ld\n", tmpdir, GetLastError());
+
+    /* Test behavior with a trailing space.
+     * The directory should be created without the trailing space.
+     */
+    GetTempPathA(MAX_PATH, tmpdir);
+    lstrcatA(tmpdir, "Please Remove Me ");
+    ret = CreateDirectoryA(tmpdir, NULL);
+    ok(ret == TRUE,
+       "CreateDirectoryA(%s) failed err=%ld\n", tmpdir, GetLastError());
+
+    lstrcatA(tmpdir, "/Please Remove Me");
+    ret = CreateDirectoryA(tmpdir, NULL);
+    ok(ret == TRUE || /* On Win98 */
+       (ret == FALSE && GetLastError() == ERROR_PATH_NOT_FOUND), /* On NT! */
+       "CreateDirectoryA(%s): ret=%d err=%ld\n", tmpdir, ret, GetLastError());
+    if (ret == TRUE)
+    {
+        ret = RemoveDirectoryA(tmpdir);
+        ok(ret == TRUE,
+           "RemoveDirectoryA(%s) failed err=%ld\n", tmpdir, GetLastError());
+    }
+
+    GetTempPathA(MAX_PATH, tmpdir);
+    lstrcatA(tmpdir, "Please Remove Me");
+    ret = RemoveDirectoryA(tmpdir);
+    ok(ret == TRUE,
+       "RemoveDirectoryA(%s) failed err=%ld\n", tmpdir, GetLastError());
+
+    /* Test behavior with a trailing space.
+     * The directory should be created without the trailing spaces.
+     */
+    GetTempPathA(MAX_PATH, tmpdir);
+    lstrcatA(tmpdir, "Please Remove Me  ");
+    ret = CreateDirectoryA(tmpdir, NULL);
+    ok(ret == TRUE,
+       "CreateDirectoryA(%s) failed err=%ld\n", tmpdir, GetLastError());
+
+    lstrcatA(tmpdir, "/Please Remove Me");
+    ret = CreateDirectoryA(tmpdir, NULL);
+    ok(ret == TRUE || /* On Win98 */
+       (ret == FALSE && GetLastError() == ERROR_PATH_NOT_FOUND), /* On NT! */
+       "CreateDirectoryA(%s): ret=%d err=%ld\n", tmpdir, ret, GetLastError());
+    if (ret == TRUE)
+    {
+        ret = RemoveDirectoryA(tmpdir);
+        ok(ret == TRUE,
+           "RemoveDirectoryA(%s) failed err=%ld\n", tmpdir, GetLastError());
+    }
+
+    GetTempPathA(MAX_PATH, tmpdir);
+    lstrcatA(tmpdir, "Please Remove Me");
+    ret = RemoveDirectoryA(tmpdir);
+    ok(ret == TRUE,
+       "RemoveDirectoryA(%s) failed err=%ld\n", tmpdir, GetLastError());
 }
 
 static void test_CreateDirectoryW(void)


More information about the wine-patches mailing list