2 * PROJECT: ReactOS api tests
3 * LICENSE: LGPLv2.1+ - See COPYING.LIB in the top level directory
4 * PURPOSE: Test for CShellLink
5 * PROGRAMMER: Andreas Maier
12 #include <ndk/rtlfuncs.h>
16 #include <shellutils.h>
19 struct _TestShellLinkDef
23 /* Test 1 - hrGetPathX = IShellLink::GetPath(pathOutX, ... , flagsX); */
24 const WCHAR
* pathOut1
;
29 const WCHAR
* pathOut2
;
35 /* Test IShellLink::SetPath with environment-variables, existing, non-existing, ...*/
36 static struct _TestShellLinkDef linkTestList
[] =
40 L
"%comspec%", SLGP_SHORTPATH
, S_OK
, TRUE
,
41 L
"%comspec%", SLGP_RAWPATH
, S_OK
, FALSE
44 L
"%anyvar%", E_INVALIDARG
,
45 L
"", SLGP_SHORTPATH
, ERROR_INVALID_FUNCTION
, FALSE
,
46 L
"", SLGP_RAWPATH
, ERROR_INVALID_FUNCTION
, FALSE
49 L
"%anyvar%%comspec%", S_OK
,
50 L
"c:\\%anyvar%%comspec%", SLGP_SHORTPATH
, S_OK
, TRUE
,
51 L
"%anyvar%%comspec%", SLGP_RAWPATH
, S_OK
, FALSE
55 L
"%temp%", SLGP_SHORTPATH
, S_OK
, TRUE
,
56 L
"%temp%", SLGP_RAWPATH
, S_OK
, FALSE
60 L
"%systemroot%\\system32\\%shell%", SLGP_SHORTPATH
, S_OK
, TRUE
,
61 L
"%shell%", SLGP_RAWPATH
, S_OK
, FALSE
64 L
"u:\\anypath\\%anyvar%", S_OK
,
65 L
"u:\\anypath\\%anyvar%", SLGP_SHORTPATH
, S_OK
, TRUE
,
66 L
"u:\\anypath\\%anyvar%", SLGP_RAWPATH
, S_OK
, FALSE
70 L
"c:\\temp", SLGP_SHORTPATH
, S_OK
, FALSE
,
71 L
"c:\\temp", SLGP_RAWPATH
, S_OK
, FALSE
75 L
"%comspec%", SLGP_SHORTPATH
, S_OK
, TRUE
,
76 L
"%comspec%", SLGP_RAWPATH
, S_OK
, TRUE
79 L
"c:\\non-existent-path\\non-existent-file", S_OK
,
80 L
"c:\\non-existent-path\\non-existent-file", SLGP_SHORTPATH
, S_OK
, FALSE
,
81 L
"c:\\non-existent-path\\non-existent-file", SLGP_RAWPATH
, S_OK
, FALSE
84 L
"non-existent-file", E_INVALIDARG
,
85 L
"", SLGP_SHORTPATH
, ERROR_INVALID_FUNCTION
, FALSE
,
86 L
"", SLGP_RAWPATH
, ERROR_INVALID_FUNCTION
, FALSE
92 test_checklinkpath(UINT i
, TestShellLinkDef
* testDef
)
94 static WCHAR evVar
[MAX_PATH
];
96 HRESULT hr
, expectedHr
;
97 WCHAR wPathOut
[MAX_PATH
];
99 const WCHAR
* expectedPathOut
;
104 hr
= CoCreateInstance(CLSID_ShellLink
,
106 CLSCTX_INPROC_SERVER
,
107 IID_PPV_ARG(IShellLinkW
, &psl
));
108 ok(hr
== S_OK
, "CoCreateInstance, hr = %lx\n", hr
);
111 skip("Could not instantiate CShellLink\n");
115 hr
= psl
->SetPath(testDef
->pathIn
);
116 ok(hr
== testDef
->hrSetPath
, "IShellLink::SetPath(%lu), got hr = %lx, expected %lx\n", i
, hr
, testDef
->hrSetPath
);
118 expectedPathOut
= NULL
;
119 for (i1
= 0; i1
<= 1; i1
++ )
123 flags
= testDef
->flags1
;
124 expandPathOut
= testDef
->expandPathOut1
;
125 expectedPathOut
= testDef
->pathOut1
;
126 expectedHr
= testDef
->hrGetPath1
;
130 flags
= testDef
->flags2
;
131 expandPathOut
= testDef
->expandPathOut2
;
132 expectedPathOut
= testDef
->pathOut2
;
133 expectedHr
= testDef
->hrGetPath2
;
136 /* Patch some variables */
137 if (expandPathOut
== TRUE
)
139 ExpandEnvironmentStringsW(expectedPathOut
, evVar
, _countof(evVar
));
140 DPRINT("** %S **\n",evVar
);
141 expectedPathOut
= evVar
;
144 hr
= psl
->GetPath(wPathOut
, _countof(wPathOut
), NULL
, flags
);
146 "IShellLink::GetPath(%lu), flags %lx, got hr = %lx, expected %lx\n",
147 i
, flags
, hr
, expectedHr
);
148 ok(wcsicmp(wPathOut
, expectedPathOut
) == 0,
149 "IShellLink::GetPath(%lu), flags %lx, in %S, got %S, expected %S\n",
150 i
, flags
, testDef
->pathIn
, wPathOut
, expectedPathOut
);
158 TestDescription(void)
163 PCWSTR testDescription
= L
"This is a test description";
165 /* Test SetDescription */
166 hr
= CoCreateInstance(CLSID_ShellLink
,
168 CLSCTX_INPROC_SERVER
,
169 IID_PPV_ARG(IShellLinkW
, &psl
));
170 ok(hr
== S_OK
, "CoCreateInstance, hr = %lx\n", hr
);
173 skip("Could not instantiate CShellLink\n");
177 memset(buffer
, 0x55, sizeof(buffer
));
178 hr
= psl
->GetDescription(buffer
, RTL_NUMBER_OF(buffer
));
179 ok(hr
== S_OK
, "IShellLink::GetDescription returned hr = %lx\n", hr
);
180 ok(buffer
[0] == 0, "buffer[0] = %x\n", buffer
[0]);
181 ok(buffer
[1] == 0x5555, "buffer[1] = %x\n", buffer
[1]);
183 hr
= psl
->SetDescription(testDescription
);
184 ok(hr
== S_OK
, "IShellLink::SetDescription returned hr = %lx\n", hr
);
186 memset(buffer
, 0x55, sizeof(buffer
));
187 hr
= psl
->GetDescription(buffer
, RTL_NUMBER_OF(buffer
));
188 ok(hr
== S_OK
, "IShellLink::GetDescription returned hr = %lx\n", hr
);
189 ok(buffer
[wcslen(testDescription
)] == 0, "buffer[n] = %x\n", buffer
[wcslen(testDescription
)]);
190 ok(buffer
[wcslen(testDescription
) + 1] == 0x5555, "buffer[n+1] = %x\n", buffer
[wcslen(testDescription
) + 1]);
191 ok(!wcscmp(buffer
, testDescription
), "buffer = '%ls'\n", buffer
);
193 hr
= psl
->SetDescription(NULL
);
194 ok(hr
== S_OK
, "IShellLink::SetDescription returned hr = %lx\n", hr
);
196 memset(buffer
, 0x55, sizeof(buffer
));
197 hr
= psl
->GetDescription(buffer
, RTL_NUMBER_OF(buffer
));
198 ok(hr
== S_OK
, "IShellLink::GetDescription returned hr = %lx\n", hr
);
199 ok(buffer
[0] == 0, "buffer[0] = %x\n", buffer
[0]);
200 ok(buffer
[1] == 0x5555, "buffer[1] = %x\n", buffer
[1]);
211 /* Needed for test */
212 SetEnvironmentVariableW(L
"shell", L
"cmd.exe");
214 for (i
= 0; i
< ARRAYSIZE(linkTestList
); ++i
)
216 DPRINT("IShellLink-Test(%lu): %S\n", i
, linkTestList
[i
].pathIn
);
217 test_checklinkpath(i
, &linkTestList
[i
]);
220 SetEnvironmentVariableW(L
"shell",NULL
);
223 START_TEST(CShellLink
)
225 CoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);