2003-05-08 03:47:24 +00:00
|
|
|
/*
|
|
|
|
* Unit test suite for ntdll path functions
|
|
|
|
*
|
|
|
|
* Copyright 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
|
2006-05-18 12:49:52 +00:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2003-05-08 03:47:24 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2004-08-14 00:42:12 +00:00
|
|
|
|
|
|
|
#include "ntdll_test.h"
|
2003-05-08 03:47:24 +00:00
|
|
|
|
|
|
|
static NTSTATUS (WINAPI *pRtlMultiByteToUnicodeN)( LPWSTR dst, DWORD dstlen, LPDWORD reslen,
|
|
|
|
LPCSTR src, DWORD srclen );
|
|
|
|
static NTSTATUS (WINAPI *pRtlCreateEnvironment)(BOOLEAN, PWSTR*);
|
|
|
|
static NTSTATUS (WINAPI *pRtlDestroyEnvironment)(PWSTR);
|
|
|
|
static NTSTATUS (WINAPI *pRtlQueryEnvironmentVariable_U)(PWSTR, PUNICODE_STRING, PUNICODE_STRING);
|
|
|
|
static void (WINAPI *pRtlSetCurrentEnvironment)(PWSTR, PWSTR*);
|
|
|
|
static NTSTATUS (WINAPI *pRtlSetEnvironmentVariable)(PWSTR*, PUNICODE_STRING, PUNICODE_STRING);
|
2003-05-13 04:46:05 +00:00
|
|
|
static NTSTATUS (WINAPI *pRtlExpandEnvironmentStrings_U)(LPWSTR, PUNICODE_STRING, PUNICODE_STRING, PULONG);
|
2003-05-08 03:47:24 +00:00
|
|
|
|
|
|
|
static WCHAR small_env[] = {'f','o','o','=','t','o','t','o',0,
|
|
|
|
'f','o','=','t','i','t','i',0,
|
|
|
|
'f','o','o','o','=','t','u','t','u',0,
|
|
|
|
's','r','=','a','n','=','o','u','o',0,
|
|
|
|
'g','=','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a',
|
|
|
|
'a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a',
|
|
|
|
'a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a',
|
|
|
|
'a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a',
|
|
|
|
'a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a',
|
|
|
|
'a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a',
|
|
|
|
'a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a',
|
|
|
|
'a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a',
|
|
|
|
'a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a',
|
|
|
|
'a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a',0,
|
|
|
|
'=','o','O','H','=','I','I','I',0,
|
2003-06-18 03:24:20 +00:00
|
|
|
'n','u','l','=',0,
|
2003-05-08 03:47:24 +00:00
|
|
|
0};
|
|
|
|
|
|
|
|
static void testQuery(void)
|
|
|
|
{
|
|
|
|
struct test
|
|
|
|
{
|
|
|
|
const char *var;
|
|
|
|
int len;
|
|
|
|
NTSTATUS status;
|
|
|
|
const char *val;
|
2008-08-26 09:28:11 +00:00
|
|
|
NTSTATUS alt;
|
2003-05-08 03:47:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const struct test tests[] =
|
|
|
|
{
|
|
|
|
{"foo", 256, STATUS_SUCCESS, "toto"},
|
|
|
|
{"FoO", 256, STATUS_SUCCESS, "toto"},
|
|
|
|
{"foo=", 256, STATUS_VARIABLE_NOT_FOUND, NULL},
|
|
|
|
{"foo ", 256, STATUS_VARIABLE_NOT_FOUND, NULL},
|
|
|
|
{"foo", 1, STATUS_BUFFER_TOO_SMALL, "toto"},
|
|
|
|
{"foo", 3, STATUS_BUFFER_TOO_SMALL, "toto"},
|
2008-08-26 09:28:11 +00:00
|
|
|
{"foo", 4, STATUS_SUCCESS, "toto", STATUS_BUFFER_TOO_SMALL},
|
|
|
|
{"foo", 5, STATUS_SUCCESS, "toto"},
|
2003-05-08 03:47:24 +00:00
|
|
|
{"fooo", 256, STATUS_SUCCESS, "tutu"},
|
|
|
|
{"f", 256, STATUS_VARIABLE_NOT_FOUND, NULL},
|
2004-01-13 04:57:57 +00:00
|
|
|
{"g", 256, STATUS_SUCCESS, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
|
|
|
|
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"},
|
2008-08-26 09:28:11 +00:00
|
|
|
{"sr=an", 256, STATUS_SUCCESS, "ouo", STATUS_VARIABLE_NOT_FOUND},
|
2003-05-08 03:47:24 +00:00
|
|
|
{"sr", 256, STATUS_SUCCESS, "an=ouo"},
|
|
|
|
{"=oOH", 256, STATUS_SUCCESS, "III"},
|
|
|
|
{"", 256, STATUS_VARIABLE_NOT_FOUND, NULL},
|
2003-06-18 03:24:20 +00:00
|
|
|
{"nul", 256, STATUS_SUCCESS, ""},
|
2003-05-08 03:47:24 +00:00
|
|
|
{NULL, 0, 0, NULL}
|
|
|
|
};
|
|
|
|
|
2003-05-13 04:46:05 +00:00
|
|
|
WCHAR bn[257];
|
|
|
|
WCHAR bv[257];
|
2003-05-08 03:47:24 +00:00
|
|
|
UNICODE_STRING name;
|
|
|
|
UNICODE_STRING value;
|
|
|
|
NTSTATUS nts;
|
2009-01-08 12:02:23 +00:00
|
|
|
unsigned int i;
|
2003-05-08 03:47:24 +00:00
|
|
|
|
2009-01-08 12:02:23 +00:00
|
|
|
for (i = 0; tests[i].var; i++)
|
2003-05-08 03:47:24 +00:00
|
|
|
{
|
2009-01-08 12:02:23 +00:00
|
|
|
const struct test *test = &tests[i];
|
2003-05-08 03:47:24 +00:00
|
|
|
name.Length = strlen(test->var) * 2;
|
|
|
|
name.MaximumLength = name.Length + 2;
|
|
|
|
name.Buffer = bn;
|
|
|
|
value.Length = 0;
|
|
|
|
value.MaximumLength = test->len * 2;
|
|
|
|
value.Buffer = bv;
|
2003-05-13 04:46:05 +00:00
|
|
|
bv[test->len] = '@';
|
2003-05-08 03:47:24 +00:00
|
|
|
|
|
|
|
pRtlMultiByteToUnicodeN( bn, sizeof(bn), NULL, test->var, strlen(test->var)+1 );
|
|
|
|
nts = pRtlQueryEnvironmentVariable_U(small_env, &name, &value);
|
2008-08-26 09:28:11 +00:00
|
|
|
ok( nts == test->status || (test->alt && nts == test->alt),
|
|
|
|
"[%d]: Wrong status for '%s', expecting %x got %x\n",
|
2009-01-08 12:02:23 +00:00
|
|
|
i, test->var, test->status, nts );
|
2003-05-08 03:47:24 +00:00
|
|
|
if (nts == test->status) switch (nts)
|
|
|
|
{
|
|
|
|
case STATUS_SUCCESS:
|
|
|
|
pRtlMultiByteToUnicodeN( bn, sizeof(bn), NULL, test->val, strlen(test->val)+1 );
|
2006-06-13 12:03:19 +00:00
|
|
|
ok( value.Length == strlen(test->val) * sizeof(WCHAR), "Wrong length %d for %s\n",
|
|
|
|
value.Length, test->var );
|
2006-05-24 16:05:09 +00:00
|
|
|
ok((value.Length == strlen(test->val) * sizeof(WCHAR) && memcmp(bv, bn, test->len*sizeof(WCHAR)) == 0) ||
|
|
|
|
lstrcmpW(bv, bn) == 0,
|
2004-02-07 01:03:17 +00:00
|
|
|
"Wrong result for %s/%d\n", test->var, test->len);
|
|
|
|
ok(bv[test->len] == '@', "Writing too far away in the buffer for %s/%d\n", test->var, test->len);
|
2003-05-08 03:47:24 +00:00
|
|
|
break;
|
|
|
|
case STATUS_BUFFER_TOO_SMALL:
|
|
|
|
ok( value.Length == strlen(test->val) * sizeof(WCHAR),
|
2006-06-13 12:03:19 +00:00
|
|
|
"Wrong returned length %d (too small buffer) for %s\n", value.Length, test->var );
|
2003-05-08 03:47:24 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-26 09:28:11 +00:00
|
|
|
static void testSetHelper(LPWSTR* env, const char* var, const char* val, NTSTATUS ret, NTSTATUS alt)
|
2003-05-08 03:47:24 +00:00
|
|
|
{
|
|
|
|
WCHAR bvar[256], bval1[256], bval2[256];
|
|
|
|
UNICODE_STRING uvar;
|
|
|
|
UNICODE_STRING uval;
|
|
|
|
NTSTATUS nts;
|
|
|
|
|
|
|
|
uvar.Length = strlen(var) * sizeof(WCHAR);
|
|
|
|
uvar.MaximumLength = uvar.Length + sizeof(WCHAR);
|
|
|
|
uvar.Buffer = bvar;
|
|
|
|
pRtlMultiByteToUnicodeN( bvar, sizeof(bvar), NULL, var, strlen(var)+1 );
|
|
|
|
if (val)
|
|
|
|
{
|
|
|
|
uval.Length = strlen(val) * sizeof(WCHAR);
|
|
|
|
uval.MaximumLength = uval.Length + sizeof(WCHAR);
|
|
|
|
uval.Buffer = bval1;
|
|
|
|
pRtlMultiByteToUnicodeN( bval1, sizeof(bval1), NULL, val, strlen(val)+1 );
|
|
|
|
}
|
|
|
|
nts = pRtlSetEnvironmentVariable(env, &uvar, val ? &uval : NULL);
|
2008-08-26 09:28:11 +00:00
|
|
|
ok(nts == ret || (alt && nts == alt), "Setting var %s=%s (%x/%x)\n", var, val, nts, ret);
|
2003-05-08 03:47:24 +00:00
|
|
|
if (nts == STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
uval.Length = 0;
|
|
|
|
uval.MaximumLength = sizeof(bval2);
|
|
|
|
uval.Buffer = bval2;
|
|
|
|
nts = pRtlQueryEnvironmentVariable_U(*env, &uvar, &uval);
|
|
|
|
switch (nts)
|
|
|
|
{
|
|
|
|
case STATUS_SUCCESS:
|
2006-05-24 16:05:09 +00:00
|
|
|
ok(lstrcmpW(bval1, bval2) == 0, "Cannot get value written to environment\n");
|
2003-05-08 03:47:24 +00:00
|
|
|
break;
|
|
|
|
case STATUS_VARIABLE_NOT_FOUND:
|
2008-08-26 18:43:33 +00:00
|
|
|
ok(val == NULL ||
|
|
|
|
broken(strchr(var,'=') != NULL), /* variable containing '=' may be set but not found again on NT4 */
|
|
|
|
"Couldn't find variable, but didn't delete it. val = %s\n", val);
|
2003-05-08 03:47:24 +00:00
|
|
|
break;
|
|
|
|
default:
|
2006-10-13 21:33:02 +00:00
|
|
|
ok(0, "Wrong ret %u for %s\n", nts, var);
|
2003-05-08 03:47:24 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void testSet(void)
|
|
|
|
{
|
|
|
|
LPWSTR env;
|
|
|
|
char tmp[16];
|
|
|
|
int i;
|
|
|
|
|
2004-02-07 01:03:17 +00:00
|
|
|
ok(pRtlCreateEnvironment(FALSE, &env) == STATUS_SUCCESS, "Creating environment\n");
|
2003-05-08 03:47:24 +00:00
|
|
|
|
2008-08-26 09:28:11 +00:00
|
|
|
testSetHelper(&env, "cat", "dog", STATUS_SUCCESS, 0);
|
|
|
|
testSetHelper(&env, "cat", "horse", STATUS_SUCCESS, 0);
|
|
|
|
testSetHelper(&env, "cat", "zz", STATUS_SUCCESS, 0);
|
|
|
|
testSetHelper(&env, "cat", NULL, STATUS_SUCCESS, 0);
|
|
|
|
testSetHelper(&env, "cat", NULL, STATUS_SUCCESS, STATUS_VARIABLE_NOT_FOUND);
|
|
|
|
testSetHelper(&env, "foo", "meouw", STATUS_SUCCESS, 0);
|
2008-08-26 18:43:33 +00:00
|
|
|
testSetHelper(&env, "me=too", "also", STATUS_SUCCESS, STATUS_INVALID_PARAMETER);
|
2008-08-26 09:28:11 +00:00
|
|
|
testSetHelper(&env, "me", "too=also", STATUS_SUCCESS, 0);
|
|
|
|
testSetHelper(&env, "=too", "also", STATUS_SUCCESS, 0);
|
|
|
|
testSetHelper(&env, "=", "also", STATUS_SUCCESS, 0);
|
2003-05-08 03:47:24 +00:00
|
|
|
|
|
|
|
for (i = 0; i < 128; i++)
|
|
|
|
{
|
|
|
|
sprintf(tmp, "zork%03d", i);
|
2008-08-26 09:28:11 +00:00
|
|
|
testSetHelper(&env, tmp, "is alive", STATUS_SUCCESS, 0);
|
2003-05-08 03:47:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < 128; i++)
|
|
|
|
{
|
|
|
|
sprintf(tmp, "zork%03d", i);
|
2008-08-26 09:28:11 +00:00
|
|
|
testSetHelper(&env, tmp, NULL, STATUS_SUCCESS, 0);
|
2003-05-08 03:47:24 +00:00
|
|
|
}
|
2008-08-26 09:28:11 +00:00
|
|
|
testSetHelper(&env, "fOo", NULL, STATUS_SUCCESS, 0);
|
2003-05-08 03:47:24 +00:00
|
|
|
|
2004-02-07 01:03:17 +00:00
|
|
|
ok(pRtlDestroyEnvironment(env) == STATUS_SUCCESS, "Destroying environment\n");
|
2003-05-08 03:47:24 +00:00
|
|
|
}
|
|
|
|
|
2003-05-13 04:46:05 +00:00
|
|
|
static void testExpand(void)
|
|
|
|
{
|
|
|
|
static const struct test
|
|
|
|
{
|
|
|
|
const char *src;
|
|
|
|
const char *dst;
|
|
|
|
} tests[] =
|
|
|
|
{
|
|
|
|
{"hello%foo%world", "hellototoworld"},
|
|
|
|
{"hello%=oOH%world", "helloIIIworld"},
|
|
|
|
{"hello%foo", "hello%foo"},
|
|
|
|
{"hello%bar%world", "hello%bar%world"},
|
|
|
|
/*
|
|
|
|
* {"hello%foo%world%=oOH%eeck", "hellototoworldIIIeeck"},
|
|
|
|
* Interestingly enough, with a 8 WCHAR buffers, we get on 2k:
|
|
|
|
* helloIII
|
|
|
|
* so it seems like strings overflowing the buffer are written
|
2008-04-08 21:22:43 +00:00
|
|
|
* (truncated) but the write cursor is not advanced :-/
|
2003-05-13 04:46:05 +00:00
|
|
|
*/
|
|
|
|
{NULL, NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
const struct test* test;
|
|
|
|
NTSTATUS nts;
|
|
|
|
UNICODE_STRING us_src, us_dst;
|
|
|
|
WCHAR src[256], dst[256], rst[256];
|
|
|
|
ULONG ul;
|
|
|
|
|
|
|
|
for (test = tests; test->src; test++)
|
|
|
|
{
|
|
|
|
pRtlMultiByteToUnicodeN(src, sizeof(src), NULL, test->src, strlen(test->src)+1);
|
|
|
|
pRtlMultiByteToUnicodeN(rst, sizeof(rst), NULL, test->dst, strlen(test->dst)+1);
|
|
|
|
|
|
|
|
us_src.Length = strlen(test->src) * sizeof(WCHAR);
|
|
|
|
us_src.MaximumLength = us_src.Length + 2;
|
|
|
|
us_src.Buffer = src;
|
|
|
|
|
|
|
|
us_dst.Length = 0;
|
|
|
|
us_dst.MaximumLength = 0;
|
|
|
|
us_dst.Buffer = NULL;
|
|
|
|
|
|
|
|
nts = pRtlExpandEnvironmentStrings_U(small_env, &us_src, &us_dst, &ul);
|
|
|
|
ok(ul == strlen(test->dst) * sizeof(WCHAR) + sizeof(WCHAR),
|
2006-10-13 21:33:02 +00:00
|
|
|
"Wrong returned length for %s: %u\n", test->src, ul );
|
2003-05-13 04:46:05 +00:00
|
|
|
|
|
|
|
us_dst.Length = 0;
|
|
|
|
us_dst.MaximumLength = sizeof(dst);
|
|
|
|
us_dst.Buffer = dst;
|
|
|
|
|
|
|
|
nts = pRtlExpandEnvironmentStrings_U(small_env, &us_src, &us_dst, &ul);
|
2006-10-13 21:33:02 +00:00
|
|
|
ok(nts == STATUS_SUCCESS, "Call failed (%u)\n", nts);
|
2003-05-13 04:46:05 +00:00
|
|
|
ok(ul == us_dst.Length + sizeof(WCHAR),
|
2006-10-13 21:33:02 +00:00
|
|
|
"Wrong returned length for %s: %u\n", test->src, ul);
|
2003-05-13 04:46:05 +00:00
|
|
|
ok(ul == strlen(test->dst) * sizeof(WCHAR) + sizeof(WCHAR),
|
2006-10-13 21:33:02 +00:00
|
|
|
"Wrong returned length for %s: %u\n", test->src, ul);
|
2006-05-24 16:05:09 +00:00
|
|
|
ok(lstrcmpW(dst, rst) == 0, "Wrong result for %s: expecting %s\n",
|
2003-05-13 04:46:05 +00:00
|
|
|
test->src, test->dst);
|
|
|
|
|
|
|
|
us_dst.Length = 0;
|
|
|
|
us_dst.MaximumLength = 8 * sizeof(WCHAR);
|
|
|
|
us_dst.Buffer = dst;
|
|
|
|
dst[8] = '-';
|
|
|
|
nts = pRtlExpandEnvironmentStrings_U(small_env, &us_src, &us_dst, &ul);
|
2006-10-13 21:33:02 +00:00
|
|
|
ok(nts == STATUS_BUFFER_TOO_SMALL, "Call failed (%u)\n", nts);
|
2003-05-13 04:46:05 +00:00
|
|
|
ok(ul == strlen(test->dst) * sizeof(WCHAR) + sizeof(WCHAR),
|
2006-10-13 21:33:02 +00:00
|
|
|
"Wrong returned length for %s (with buffer too small): %u\n", test->src, ul);
|
2004-02-07 01:03:17 +00:00
|
|
|
ok(dst[8] == '-', "Writing too far in buffer (got %c/%d)\n", dst[8], dst[8]);
|
2003-05-13 04:46:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2003-05-08 03:47:24 +00:00
|
|
|
START_TEST(env)
|
|
|
|
{
|
|
|
|
HMODULE mod = GetModuleHandleA("ntdll.dll");
|
2008-09-21 18:17:16 +00:00
|
|
|
if (!mod)
|
|
|
|
{
|
|
|
|
win_skip("Not running on NT, skipping tests\n");
|
|
|
|
return;
|
|
|
|
}
|
2003-05-08 03:47:24 +00:00
|
|
|
|
|
|
|
pRtlMultiByteToUnicodeN = (void *)GetProcAddress(mod,"RtlMultiByteToUnicodeN");
|
|
|
|
pRtlCreateEnvironment = (void*)GetProcAddress(mod, "RtlCreateEnvironment");
|
|
|
|
pRtlDestroyEnvironment = (void*)GetProcAddress(mod, "RtlDestroyEnvironment");
|
|
|
|
pRtlQueryEnvironmentVariable_U = (void*)GetProcAddress(mod, "RtlQueryEnvironmentVariable_U");
|
|
|
|
pRtlSetCurrentEnvironment = (void*)GetProcAddress(mod, "RtlSetCurrentEnvironment");
|
|
|
|
pRtlSetEnvironmentVariable = (void*)GetProcAddress(mod, "RtlSetEnvironmentVariable");
|
2003-05-13 04:46:05 +00:00
|
|
|
pRtlExpandEnvironmentStrings_U = (void*)GetProcAddress(mod, "RtlExpandEnvironmentStrings_U");
|
2003-05-08 03:47:24 +00:00
|
|
|
|
2003-12-15 20:18:50 +00:00
|
|
|
if (pRtlQueryEnvironmentVariable_U)
|
|
|
|
testQuery();
|
|
|
|
if (pRtlSetEnvironmentVariable)
|
|
|
|
testSet();
|
|
|
|
if (pRtlExpandEnvironmentStrings_U)
|
|
|
|
testExpand();
|
2003-05-08 03:47:24 +00:00
|
|
|
}
|