[PATCH 3/3] shell32/tests: Add tests for DoEnvironmentSubstA/W
Detlef Riekenberg
wine.dev at web.de
Sat Nov 24 19:54:19 CST 2012
--
By by ... Detlef
---
dlls/shell32/tests/shellpath.c | 138 ++++++++++++++++++++++++++++++++++++++++
1 files changed, 138 insertions(+), 0 deletions(-)
diff --git a/dlls/shell32/tests/shellpath.c b/dlls/shell32/tests/shellpath.c
index 1798ada..3eba018 100644
--- a/dlls/shell32/tests/shellpath.c
+++ b/dlls/shell32/tests/shellpath.c
@@ -2495,6 +2495,143 @@ static void test_knownFolders(void)
CoUninitialize();
}
+
+static void test_DoEnvironmentSubst(void)
+{
+ WCHAR bufferW[MAX_PATH];
+ CHAR bufferA[MAX_PATH];
+ DWORD res;
+ DWORD res2;
+ DWORD len;
+ INT i;
+ static const CHAR does_not_existA[] = "%DOES_NOT_EXIST%";
+ static const CHAR *names[] = {
+ /* interactive apps and services: todo_wine */
+ "%COMPUTERNAME%", "%ProgramData%", "%PUBLIC%",
+ /* interactive apps and services */
+ "%ALLUSERSPROFILE%", "%APPDATA%", ";%COMPUTERNAME%", "%LOCALAPPDATA%",
+ "%NUMBER_OF_PROCESSORS%", "%OS%", "%PROCESSOR_ARCHITECTURE%",
+ "%PROCESSOR_IDENTIFIER%", "%PROCESSOR_LEVEL%", "%PROCESSOR_REVISION%",
+ ";%ProgramData%", "%ProgramFiles%", ";%PUBLIC%", "%SystemDrive%",
+ "%SystemRoot%", "%USERPROFILE%", "%windir%",
+ /* interactive apps */
+ "%HOMEDRIVE%", "%HOMEPATH%", "%LOGONSERVER%", "%USERDOMAIN%", "%USERNAME%",
+ /* replace more than one var is allowed */
+ "%HOMEDRIVE%%HOMEPATH%",
+ "%OS%: %windir%"}; /* always the last entry in the table */
+
+ for (i = 0; i < (sizeof(names)/sizeof(LPSTR)); i++)
+ {
+ memset(bufferA, '#', MAX_PATH - 1);
+ bufferA[MAX_PATH - 1] = 0;
+ lstrcpyA(bufferA, names[i]);
+ MultiByteToWideChar(CP_ACP, 0, bufferA, MAX_PATH, bufferW, sizeof(bufferW)/sizeof(WCHAR));
+
+ res = DoEnvironmentSubstA(bufferA, MAX_PATH);
+ res2 = DoEnvironmentSubstW(bufferW, MAX_PATH);
+
+ /* is the space for the terminating 0 included? */
+ if (!i && HIWORD(res) && (LOWORD(res) == (lstrlenA(bufferA))))
+ {
+ win_skip("DoEnvironmentSubstA/W are broken on NT 4\n");
+ return;
+ }
+
+ /* Not all variables are supported before vista */
+ if (broken(*bufferA == '%'))
+ trace("%d: %s not supported\n", i, bufferA);
+ else
+ {
+ if (i < 3) todo_wine
+ ok(HIWORD(res) && (LOWORD(res) == (lstrlenA(bufferA)+1)) && (*bufferA != '%'),
+ "%d: got %d/%d and %s (len %d)\n",
+ i, HIWORD(res), LOWORD(res), bufferA, lstrlenA(bufferA));
+
+ if (i < 3) todo_wine
+ ok(HIWORD(res2) && (LOWORD(res2) == (lstrlenW(bufferW)+1)) && (*bufferW != '%'),
+ "%d: got %d/%d and %s (len %d)\n",
+ i, HIWORD(res2), LOWORD(res2), wine_dbgstr_w(bufferW), lstrlenW(bufferW));
+ }
+ }
+
+ /* current data in the buffer: "%OS%: %windir%" */
+ ok(!strchr(bufferA, '%'), "got \"%s\" (expected all variable replaced)\n", bufferA);
+
+ i--; /* reuse data in the last table entry */
+ len = LOWORD(res); /* needed length */
+
+ /* one character extra is fine */
+ memset(bufferA, '#', MAX_PATH - 1);
+ bufferA[len + 2] = 0;
+ lstrcpyA(bufferA, names[i]);
+ MultiByteToWideChar(CP_ACP, 0, bufferA, MAX_PATH, bufferW, sizeof(bufferW)/sizeof(WCHAR));
+ res = DoEnvironmentSubstA(bufferA, len + 1);
+ ok(HIWORD(res) && (LOWORD(res) == (lstrlenA(bufferA)+1)) && (*bufferA != '%'),
+ "+1: got %d/%d and %s (len: %d)\n",
+ HIWORD(res), LOWORD(res), bufferA, lstrlenA(bufferA));
+
+ res2 = DoEnvironmentSubstW(bufferW, len + 1);
+ ok(HIWORD(res2) && (LOWORD(res2) == (lstrlenW(bufferW)+1)) && (*bufferW != '%'),
+ "+1: got %d/%d and %s (len: %d)\n",
+ HIWORD(res2), LOWORD(res2), wine_dbgstr_w(bufferW), lstrlenW(bufferW));
+
+ /* minimal buffer length (result string and terminating 0) */
+ memset(bufferA, '#', MAX_PATH - 1);
+ bufferA[len + 2] = 0;
+ lstrcpyA(bufferA, names[i]);
+ MultiByteToWideChar(CP_ACP, 0, bufferA, MAX_PATH, bufferW, sizeof(bufferW)/sizeof(WCHAR));
+ /* ANSI version failed without an extra byte, as documented on msdn */
+ res = DoEnvironmentSubstA(bufferA, len);
+ ok(!HIWORD(res) && (LOWORD(res) == len) && !lstrcmpA(bufferA, names[i]),
+ " 0: got %d/%d and %s (len: %d)\n",
+ HIWORD(res), LOWORD(res), bufferA, lstrlenA(bufferA));
+ /* DoEnvironmentSubstW works as expected */
+ res2 = DoEnvironmentSubstW(bufferW, len);
+ ok(HIWORD(res2) && (LOWORD(res2) == (lstrlenW(bufferW)+1)) && (*bufferW != '%'),
+ " 0: got %d/%d and %s (len: %d)\n",
+ HIWORD(res2), LOWORD(res2), wine_dbgstr_w(bufferW), lstrlenW(bufferW));
+
+ /* buffer to small */
+ /* result: FALSE / provided buffer length / the buffer is untouched */
+ memset(bufferA, '#', MAX_PATH - 1);
+ bufferA[len + 2] = 0;
+ lstrcpyA(bufferA, names[i]);
+ MultiByteToWideChar(CP_ACP, 0, bufferA, MAX_PATH, bufferW, sizeof(bufferW)/sizeof(WCHAR));
+ res = DoEnvironmentSubstA(bufferA, len - 1);
+ ok(!HIWORD(res) && (LOWORD(res) == len-1) && !lstrcmpA(bufferA, names[i]),
+ "-1: got %d/%d and %s (len: %d)\n",
+ HIWORD(res), LOWORD(res), bufferA, lstrlenA(bufferA));
+
+ res2 = DoEnvironmentSubstW(bufferW, len - 1);
+ WideCharToMultiByte(CP_ACP, 0, bufferW, -1, bufferA, sizeof(bufferA), NULL, NULL);
+ ok(!HIWORD(res2) && (LOWORD(res2) == len -1) && !lstrcmpA(bufferA, names[i]),
+ " 0: got %d/%d and %s (len: %d)\n",
+ HIWORD(res2), LOWORD(res2), wine_dbgstr_w(bufferW), lstrlenW(bufferW));
+
+ /* unknown variable */
+ /* result: TRUE / string length including terminating 0 / the buffer is untouched */
+ memset(bufferA, '#', MAX_PATH - 1);
+ lstrcpyA(bufferA, does_not_existA);
+ MultiByteToWideChar(CP_ACP, 0, bufferA, MAX_PATH, bufferW, sizeof(bufferW)/sizeof(WCHAR));
+ res = DoEnvironmentSubstA(bufferA, MAX_PATH);
+ ok(HIWORD(res) && (LOWORD(res) == (lstrlenA(bufferA)+1)) && !lstrcmpA(bufferA, does_not_existA),
+ "does_not_exist: got %d/%d and %s (len: %d)\n",
+ HIWORD(res), LOWORD(res), bufferA, lstrlenA(bufferA));
+
+ res2 = DoEnvironmentSubstW(bufferW, MAX_PATH);
+ WideCharToMultiByte(CP_ACP, 0, bufferW, -1, bufferA, sizeof(bufferA), NULL, NULL);
+ ok(HIWORD(res2) && (LOWORD(res2) == (lstrlenW(bufferW)+1)) && !lstrcmpA(bufferA, does_not_existA),
+ "does_not_exist: got %d/%d and %s (len: %d)\n",
+ HIWORD(res2), LOWORD(res2), wine_dbgstr_w(bufferW), lstrlenW(bufferW));
+
+ if (0)
+ {
+ /* NULL crashes on windows */
+ res = DoEnvironmentSubstA(NULL, MAX_PATH);
+ res2 = DoEnvironmentSubstW(NULL, MAX_PATH);
+ }
+}
+
START_TEST(shellpath)
{
if (!init()) return;
@@ -2522,5 +2659,6 @@ START_TEST(shellpath)
test_NonExistentPath();
test_SHGetFolderPathEx();
test_knownFolders();
+ test_DoEnvironmentSubst();
}
}
--
1.7.5.4
More information about the wine-patches
mailing list