tests for ntdll

Eric Pouech pouech-eric at wanadoo.fr
Sun Apr 6 11:34:00 CDT 2003


this patch adds a few test cases for the ntdll's APIs added in previous 
patch

A+
-- 
Eric Pouech
-------------- next part --------------
Name:          ntdll_tst
ChangeLog:     Added some tests for ntdll DOS path handling APIs
License:       X11
GenDate:       2003/04/06 16:29:14 UTC
ModifiedFiles: dlls/ntdll/tests/Makefile.in
AddedFiles:    dlls/ntdll/tests/dos.c
===================================================================
RCS file: /home/cvs/cvsroot/wine/wine/dlls/ntdll/tests/Makefile.in,v
retrieving revision 1.7
diff -u -u -r1.7 Makefile.in
--- dlls/ntdll/tests/Makefile.in	22 Mar 2003 00:21:35 -0000	1.7
+++ dlls/ntdll/tests/Makefile.in	4 Apr 2003 20:33:41 -0000
@@ -4,8 +4,10 @@
 VPATH     = @srcdir@
 TESTDLL   = ntdll.dll
 IMPORTS   = ntdll
+EXTRALIBS = $(LIBUNICODE)
 
 CTESTS = \
+	dos.c \
 	error.c \
 	generated.c \
 	large_int.c \
--- /dev/null	1970-01-01 01:00:00.000000000 +0100
+++ dlls/ntdll/tests/dos.c	2003-04-06 18:16:35.000000000 +0200
@@ -0,0 +1,284 @@
+/*
+ * Unit tests for Rtl DOS related functions
+ *
+ * Copyright (c) 2003 Eric Pouech
+ *
+ * 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include "wine/test.h"
+
+#include "winbase.h"
+#include "winternl.h"
+#include "wine/unicode.h"
+#include "wine/debug.h"
+
+static char* nil = "--nil--";
+
+static DWORD (WINAPI *pRtlIsDosDeviceName_U)(const WCHAR* device_name);
+static DWORD (WINAPI *pRtlDetermineDosPathNameType_U)(const WCHAR* path);
+static DWORD (WINAPI *pRtlGetFullPathName_U)(const WCHAR*, ULONG, WCHAR*, WCHAR**);
+static BOOLEAN (WINAPI *pRtlDosPathNameToNtPathName_U)(const WCHAR*, UNICODE_STRING*, WCHAR**, void*);
+static BOOLEAN (WINAPI *pRtlIsNameLegalDOS8Dot3)(UNICODE_STRING*, ANSI_STRING*, BOOLEAN*);
+static BOOLEAN (WINAPI *pRtlDosSearchPath_U)(LPCWSTR, LPCWSTR, LPCWSTR, ULONG, LPWSTR, LPWSTR*);
+
+static int prepare_test(void)
+{
+    HMODULE ntdll;
+
+    if (!(ntdll = LoadLibraryA("ntdll.dll"))) return 0;
+    pRtlIsDosDeviceName_U = (void*)GetProcAddress(ntdll, "RtlIsDosDeviceName_U");
+    pRtlDetermineDosPathNameType_U = (void*)GetProcAddress(ntdll, "RtlDetermineDosPathNameType_U");
+    pRtlGetFullPathName_U = (void*)GetProcAddress(ntdll, "RtlGetFullPathName_U");
+    pRtlDosPathNameToNtPathName_U = (void*)GetProcAddress(ntdll, "RtlDosPathNameToNtPathName_U");
+    pRtlIsNameLegalDOS8Dot3 = (void*)GetProcAddress(ntdll, "RtlIsNameLegalDOS8Dot3");
+    pRtlDosSearchPath_U = (void*)GetProcAddress(ntdll, "RtlDosSearchPath_U");
+    return pRtlIsDosDeviceName_U && pRtlDetermineDosPathNameType_U && 
+        pRtlGetFullPathName_U && pRtlDosPathNameToNtPathName_U && 
+        pRtlIsNameLegalDOS8Dot3 && pRtlDosSearchPath_U ? 1 : 0;
+}
+
+static void testDosDevice(void)
+{
+    static      WCHAR a1[] = {'C','O','N',0};
+    static      WCHAR a2[] = {'C','O','N',':',0};
+    static      WCHAR a3[] = {'C','O','N',' ',0};
+    static      WCHAR a4[] = {'\\','C','O','N',0};
+    static      WCHAR a5[] = {'\\','p','\\','C','O','N',0};
+    static      WCHAR a6[] = {'C','O','N','I',0};
+
+    static      WCHAR b1[] = {'C','O','M','4',0};
+    static      WCHAR b2[] = {'C','O','M','4',':',0};
+    static      WCHAR b3[] = {'C','O','M','4',' ',0};
+    static      WCHAR b4[] = {'\\','C','O','M','4',0};
+    static      WCHAR b5[] = {'\\','p','\\','C','O','M','4',0};
+    static      WCHAR b6[] = {'C','O','M','4','1',0};
+
+    DWORD       ret;
+
+#define tok(ws, r, as) ret = pRtlIsDosDeviceName_U(ws); ok(ret == r, "For %s, expected device info as %x, got %lx", as, r, ret)
+    tok(a1, 0x00000006, "'Con'");
+    tok(a2, 0x00000006, "'Con:'");
+    tok(a3, 0x00000006, "'Con '");
+    tok(a4, 0x00020006, "'\\Con'");
+    tok(a5, 0x00060006, "'\\p\\Con'");
+    tok(a6, 0x00000000, "'Coni'");
+
+    tok(b1, 0x00000008, "'Com4'");
+    tok(b2, 0x00000008, "'Com4:'");
+    tok(b3, 0x00000008, "'Com4 '");
+    tok(b4, 0x00020008, "'\\Com4'");
+    tok(b5, 0x00060008, "'\\p\\Com4'");
+    tok(b6, 0x00000000, "'Com41'");
+#undef tok
+}
+
+static void testDosPath(void)
+{
+    static WCHAR        a1_1[] = {'\\','\\','f','o','o',0};
+    static WCHAR        a1_2[] = {'\\','\\',0};
+    static WCHAR        a1_3[] = {'\\','\\','f','o','o','\\','b','a','r',0};
+    static WCHAR        a1_4[] = {'\\','\\','?','\\','f','o','o','\\','b','a','r',0};
+    static WCHAR        a2[] = {'c',':','\\','f','o','o',0};
+    static WCHAR        a3[] = {'c',':','f','o','o',0};
+    static WCHAR        a4[] = {'\\','f','o','o',0};
+    static WCHAR        a5_1[] = {0};
+    static WCHAR        a5_2[] = {'f','o','o',0};
+    static WCHAR        a6[] = {'\\','\\','.','\\','f','o','o',0};
+    static WCHAR        a7[] = {'\\','\\','.',0};
+
+    ok(pRtlDetermineDosPathNameType_U(a1_1) == 1, "NT");
+    ok(pRtlDetermineDosPathNameType_U(a1_2) == 1, "NT");
+    ok(pRtlDetermineDosPathNameType_U(a1_3) == 1, "NT");
+    ok(pRtlDetermineDosPathNameType_U(a1_4) == 1, "NT");
+    ok(pRtlDetermineDosPathNameType_U(a2)   == 2, "DOS drive + absolute");
+    ok(pRtlDetermineDosPathNameType_U(a3)   == 3, "DOS drive + relative");
+    ok(pRtlDetermineDosPathNameType_U(a4)   == 4, "DOS absolute");
+    ok(pRtlDetermineDosPathNameType_U(a5_1) == 5, "DOS relative");
+    ok(pRtlDetermineDosPathNameType_U(a5_2) == 5, "DOS relative");
+    ok(pRtlDetermineDosPathNameType_U(a6)   == 6, "NT device");
+    ok(pRtlDetermineDosPathNameType_U(a7)   == 7, "NT device root");
+}
+
+static void testGetFullPathName(void)
+{
+    static WCHAR        a1_1[] = {'\\','\\','f','o','o',0};
+    static WCHAR        a1_2[] = {'\\','\\',0};
+    static WCHAR        a2[] = {'c',':','\\','f','o','o',0};
+    static WCHAR        a3[] = {'c',':','f','o','o',0};
+    static WCHAR        a4[] = {'\\','f','o','o',0};
+    static WCHAR        a5[] = {'f','o','o',0};
+    static WCHAR        a6[] = {'\\','\\','.','\\','f','o','o',0};
+    static WCHAR        a7[] = {'\\','\\','.',0};
+    static WCHAR        r7[] = {'\\','\\','.','\\',0};
+    static WCHAR        a8[] = {'c',':','\\','f','o','o','\\','C','O','M','3',0};
+    static WCHAR        r8[] = {'\\','\\','.','\\','C','O','M','3',0};
+    static WCHAR        a9[] = {'c',':','\\','f','o','o','\\','.','.','\\','b','a','r',0};
+    static WCHAR        r9[] = {'c',':','\\','b','a','r',0};
+    static WCHAR        a10[] = {'c',':','\\','.','.','\\','b','a','r',0};
+    static WCHAR        a11[] = {'c',':','\\','.','.',0};
+    static WCHAR        r11[] = {'c',':','\\',0};
+
+    WCHAR       buffer[1024], *p;
+    WCHAR       answer[MAX_PATH];
+    DWORD       ret, le;
+
+#define tok(w, r, o)  do { ret = pRtlGetFullPathName_U(w, sizeof(buffer), buffer, &p); \
+le = strlenW(r) * sizeof(WCHAR); \
+ok(ret == le, "For %s, expected length as %lu, got %lu", wine_dbgstr_w(w), le, ret); \
+ok(strcmpiW(buffer, r) == 0, "For %s, expected fullpath as %s, got %s", wine_dbgstr_w(w), wine_dbgstr_w(r), wine_dbgstr_w(buffer)); \
+ok((!p && o == -1) || (p && o != -1 && strcmpiW(p, w + o) == 0), \
+   "For %s, expected file part as %s, got %s", wine_dbgstr_w(w), (o == -1) ? nil : wine_dbgstr_w(w + o), !p ? nil : wine_dbgstr_w(p)); \
+ret = pRtlGetFullPathName_U(w, sizeof(WCHAR), buffer, &p); \
+} while (0)
+
+    /* FIXME: this code should be part of tok macro...
+     * as of today the test itself isn't correct, as well as the returned values (test should be extended with real expected values
+     * but, I'm not even sure all NT versions will return the same length, especially when . and .. are collapsed :-(
+     *
+     * ok(ret == le + sizeof(WCHAR), "For %s, expected length (buffer too short) as %lu, got %lu", wine_dbgstr_w(w), le + sizeof(WCHAR), ret);
+     */
+
+    SetCurrentDirectoryA("C:");
+    tok(a1_1, a1_1, -1);
+    tok(a1_2, a1_2, -1);
+    tok(a2, a2, 3);
+    GetCurrentDirectoryW(sizeof(answer) / sizeof(WCHAR), answer);
+    ret = strlenW(answer); if (answer[ret - 1] != '\\') strcatW(answer, a1_2 + 1);
+    strcatW(answer, a2 + 3);
+    tok(a3, answer, 2);
+    GetCurrentDirectoryW(sizeof(answer) / sizeof(WCHAR), answer);
+    ret = strlenW(answer); if (answer[ret - 1] != '\\') strcatW(answer, a1_2 + 1);
+    strcpyW(answer + 1, a2 + 1);
+    tok(a4, answer, 1);
+    GetCurrentDirectoryW(sizeof(answer) / sizeof(WCHAR), answer);
+    ret = strlenW(answer); if (answer[ret - 1] != '\\') strcatW(answer, a1_2 + 1);
+    strcatW(answer, a4 + 1);
+    tok(a5, answer, 0);
+    tok(a6, a6, 4);
+    tok(a7, r7, -1);
+    tok(a8, r8, -1);
+    tok(a9, r9, 10);
+    tok(a10, r9, 6);
+    tok(a11, r11, -1);
+
+#undef tok
+}
+
+static void testNtToDos(void)
+{
+    static      WCHAR   s1[] = {'C','O','N',0};
+    static      WCHAR   r1[] = {'\\','?','?','\\','C','O','N',0};
+    static      WCHAR   s2[] = {'c',':','t','o','t','o',0};
+    static      WCHAR   r21[] = {'\\','?','?','\\',0};
+    static      WCHAR   s3[] = {'c',':','\\','f','o','o','\\','.','.','\\','b','a','r','\\','t','o','t','o',0};
+    static      WCHAR   r3[] = {'\\','?','?','\\','c',':','\\','b','a','r','\\','t','o','t','o',0};
+    static      WCHAR   s4[] = {'c',':','\\','.','.','\\','b','a','r','\\','t','o','t','o',0};
+    static      WCHAR   s5[] = {'z',':','/','a','/','b','/','c',0};
+    static      WCHAR   r5[] = {'\\','?','?','\\','z',':','\\','a','\\','b','\\','c',0};
+    static      WCHAR   s6[] = {'\\','\\','?','\\','z',':','/','a','/','b','/','c',0};
+    static      WCHAR   r6[] = {'\\','?','?','\\','z',':','/','a','/','b','/','c',0};
+    static      WCHAR   s7[] = {'\\','\\','f','o','o','\\','b','a','r',0};
+    static      WCHAR   r7[] = {'\\','?','?','\\','U','N','C','\\','f','o','o','\\','b','a','r',0};
+
+    UNICODE_STRING      us;
+    WCHAR*              p;
+    ULONG               ret;
+    WCHAR               answer[1024];
+
+/* we don't free the us after each test, it'll be overwritten anyway */
+#define tok(si, so, po) do {ret = pRtlDosPathNameToNtPathName_U(si, &us, &p, NULL); \
+ok(strcmpiW(so, us.Buffer) == 0, "For %s, expected path as %s, got %s", wine_dbgstr_w(si), wine_dbgstr_w(so), wine_dbgstr_w(us.Buffer)); \
+ok((!po && !p) || (po && p && strcmpW(po, p) == 0), "For %s, expected file part as %s, got %s", wine_dbgstr_w(si), po ? wine_dbgstr_w(po) : nil, p ? wine_dbgstr_w(p) : nil); \
+} while (0);
+
+    SetCurrentDirectoryA("c:");
+    tok(s1, r1, NULL);
+    strcpyW(answer, r21);
+    GetCurrentDirectoryW(sizeof(answer) / sizeof(WCHAR) - 4, answer + 4);
+    ret = strlenW(answer); if (answer[ret - 1] != '\\') strcatW(answer, r21 + 3);
+    strcatW(answer, s2 + 2);
+    tok(s2, answer, s2 + 2);
+    tok(s3, r3, s2 + 2);
+    tok(s4, r3, s2 + 2);
+    tok(s5, r5, s5 + 7);
+    todo_wine tok(s6, r6, s6 + 4);
+    tok(s7, r7, s7 + 6);
+#undef tok
+}
+
+static void testLegalDos(void)
+{
+    static WCHAR        a1[] = {'1','2','3','4','5','6','7','8',0};
+    static WCHAR        a2[] = {'1','2','3','4','5','6','7','8','.',0};
+    static WCHAR        a3[] = {'1','2','3','4','5','6','7','8','.','a',0};
+    static WCHAR        a4[] = {'1','2','3','4','5','6','7','8','9','.','a',0};
+    static WCHAR        a5[] = {'1','2','3','4','5','.','a','b','c','d',0};
+    static WCHAR        a6[] = {'.','a','b','c',0};
+    static WCHAR        a7[] = {'1','2','.','a','b','c','.','d',0};
+    static WCHAR        a8[] = {'.',0};
+    static WCHAR        a9[] = {'.','.',0};
+
+    UNICODE_STRING      w;
+    ANSI_STRING         a;
+    BOOLEAN             b, ret;
+
+#define tok(s, tf) w.Length = strlenW(w.Buffer = s) * sizeof(WCHAR); w.MaximumLength = w.Length + sizeof(WCHAR); \
+ret = (pRtlIsNameLegalDOS8Dot3)(&w, &a, &b); ok(ret == tf, "For %s, expected 8.3 legality as %u, got %u", wine_dbgstr_w(s), tf, ret);
+    tok(a1, TRUE);
+    tok(a2, FALSE);
+    tok(a3, TRUE);
+    tok(a4, FALSE);
+    tok(a5, FALSE);
+    tok(a6, FALSE);
+    tok(a7, FALSE);
+    tok(a8, TRUE);
+    tok(a9, TRUE);
+#undef tok
+}
+
+#if 0
+static void testSearch(void)
+{
+    static      WCHAR   foo[] = {'d','i','r','1',';','d','i','r','2','3','4',0};
+    static      WCHAR   f1[] = {'f','o','o',0};
+    static      WCHAR   f2[] = {'f','o','o','.','t',0};
+    static      WCHAR   f3[] = {'\\','f','o','o','.','t',0};
+    static      WCHAR   f4[] = {'c',':','f','o','o','.','t',0};
+    static      WCHAR   ext[] = {'.','e','x','t',0};
+    WCHAR       res[1024];
+    LPWSTR      p;
+
+#define tok(a,f,e) ok(pRtlDosSearchPath_U(a, f, e, sizeof(res), res, &p) == TRUE, "searching %s %s in %s", wine_dbgstr_w(f), e ? wine_dbgstr_w(e) : nil, wine_dbgstr_w(a));
+
+    tok(foo, f1, NULL);
+    tok(foo, f1, ext);
+    tok(foo, f2, ext);
+    tok(foo, f3, ext);
+    tok(foo, f4, ext);
+#undef tok
+}
+#endif
+
+START_TEST(dos)
+{
+    if (!prepare_test()) return;
+    testDosDevice();
+    testDosPath();
+    testGetFullPathName();
+    testNtToDos();
+    testLegalDos();
+    /* testSearch(); */
+}


More information about the wine-patches mailing list