2 * PROJECT: ReactOS api tests
3 * LICENSE: LGPLv2.1+ - See COPYING.LIB in the top level directory
4 * PURPOSE: Tests for PathUnExpandEnvStrings
5 * PROGRAMMERS: Hermes Belusca-Maito
12 #define DO_TEST(Res, TestStr, ExpStr) \
14 BOOL ret = PathUnExpandEnvStringsW((TestStr), OutStr, _countof(OutStr)); \
15 ok(ret == (Res), "Tested %s, expected returned value %d, got %d\n", \
16 wine_dbgstr_w((TestStr)), (Res), ret); \
18 ok(_wcsicmp(OutStr, (ExpStr)) == 0, "Tested %s, expected %s, got %s\n", \
19 wine_dbgstr_w((TestStr)), wine_dbgstr_w((ExpStr)), wine_dbgstr_w(OutStr)); \
22 START_TEST(PathUnExpandEnvStrings
)
26 WCHAR TestStr
[MAX_PATH
];
27 WCHAR ExpStr
[MAX_PATH
];
28 WCHAR OutStr
[MAX_PATH
];
31 * We expect here that the following standard environment variables:
32 * %COMPUTERNAME%, %ProgramFiles%, %SystemRoot% and %SystemDrive%
33 * are correctly defined.
36 /* No unexpansion possible */
37 DO_TEST(FALSE
, L
"ZZ:\\foobar\\directory", L
"");
39 /* Contrary to what MSDN says, %COMPUTERNAME% does not seeem to be unexpanded... */
40 ret
= GetEnvironmentVariableW(L
"COMPUTERNAME", TestStr
, _countof(TestStr
));
41 ok(ret
, "got %lu\n", ret
);
42 DO_TEST(FALSE
, TestStr
, L
"%COMPUTERNAME%");
44 StringCchCopyW(TestStr
, _countof(TestStr
), L
"ZZ:\\foobar\\");
45 len
= wcslen(TestStr
);
46 ret
= GetEnvironmentVariableW(L
"COMPUTERNAME", TestStr
+ len
, _countof(TestStr
) - len
);
47 ok(ret
, "got %lu\n", ret
);
48 StringCchCatW(TestStr
, _countof(TestStr
), L
"\\directory");
49 DO_TEST(TRUE
, TestStr
, L
"ZZ:\\foobar\\%COMPUTERNAME%\\directory");
53 * L"%SystemRoot%\\%SystemRoot%" to L"%SystemRoot%\\%SystemRoot%" (no expansion)
55 * This shows that given a path string, if PathUnExpandEnvStrings fails,
56 * the string could have been already unexpanded...
58 DO_TEST(FALSE
, L
"%SystemRoot%\\%SystemRoot%", L
"%SystemRoot%\\%SystemRoot%");
61 * L"<real_SystemRoot><real_SystemRoot>" to L"%SystemRoot%<real_SystemRoot>"
62 * example: L"C:\\WindowsC:\\Windows"
63 * Unexpansion succeeds only on the first path.
65 ret
= GetEnvironmentVariableW(L
"SystemRoot", TestStr
, _countof(TestStr
));
66 ok(ret
, "got %lu\n", ret
);
67 len
= wcslen(TestStr
);
68 ret
= GetEnvironmentVariableW(L
"SystemRoot", TestStr
+ len
, _countof(TestStr
) - len
);
69 ok(ret
, "got %lu\n", ret
);
71 StringCchCopyW(ExpStr
, _countof(ExpStr
), L
"%SystemRoot%");
73 ret
= GetEnvironmentVariableW(L
"SystemRoot", ExpStr
+ len
, _countof(ExpStr
) - len
);
74 ok(ret
, "got %lu\n", ret
);
75 DO_TEST(TRUE
, TestStr
, ExpStr
);
78 * L"%SystemRoot%\\<real_Program_Files>" to L"%SystemRoot%\\%ProgramFiles%"
81 StringCchCopyW(TestStr
, _countof(TestStr
), L
"%SystemRoot%\\");
82 len
= wcslen(TestStr
);
83 ret
= GetEnvironmentVariableW(L
"ProgramFiles", TestStr
+ len
, _countof(TestStr
) - len
);
84 ok(ret
, "got %lu\n", ret
);
85 DO_TEST(FALSE
, TestStr
, L
"%SystemRoot%\\%ProgramFiles%");
88 * L"<real_SystemRoot>\\%ProgramFiles%" to L"%SystemRoot%\\%ProgramFiles%"
89 * Unexpansion succeeds.
91 ret
= GetEnvironmentVariableW(L
"SystemRoot", TestStr
, _countof(TestStr
));
92 ok(ret
, "got %lu\n", ret
);
93 StringCchCatW(TestStr
, _countof(TestStr
), L
"\\%ProgramFiles%");
94 DO_TEST(TRUE
, TestStr
, L
"%SystemRoot%\\%ProgramFiles%");
97 * L"<real_SystemRoot>\\notepad.exe <real_SystemRoot>\\file.txt" to L"%SystemRoot%\\notepad.exe %SystemRoot%\\file.txt"
98 * Unexpansion succeeds only on the first path, therefore the obtained string is not the one naively expected.
100 ret
= GetEnvironmentVariableW(L
"SystemRoot", TestStr
, _countof(TestStr
));
101 ok(ret
, "got %lu\n", ret
);
102 StringCchCatW(TestStr
, _countof(TestStr
), L
"\\notepad.exe ");
103 len
= wcslen(TestStr
);
104 ret
= GetEnvironmentVariableW(L
"SystemRoot", TestStr
+ len
, _countof(TestStr
) - len
);
105 ok(ret
, "got %lu\n", ret
);
106 StringCchCatW(TestStr
, _countof(TestStr
), L
"\\file.txt");
107 // DO_TEST(TRUE, TestStr, L"%SystemRoot%\\notepad.exe %SystemRoot%\\file.txt");
110 * L"<real_SystemRoot>\\notepad.exe <real_SystemRoot>\\file.txt" to L"%SystemRoot%\\notepad.exe <real_SystemRoot>\\file.txt"
111 * Unexpansion succeeds only on the first path.
113 StringCchCopyW(ExpStr
, _countof(ExpStr
), L
"%SystemRoot%\\notepad.exe ");
114 len
= wcslen(ExpStr
);
115 ret
= GetEnvironmentVariableW(L
"SystemRoot", ExpStr
+ len
, _countof(ExpStr
) - len
);
116 ok(ret
, "got %lu\n", ret
);
117 StringCchCatW(ExpStr
, _countof(ExpStr
), L
"\\file.txt");
118 DO_TEST(TRUE
, TestStr
, ExpStr
);