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
88 { NULL
, 0, NULL
, 0, 0, NULL
, 0, 0 }
91 static const UINT evVarChLen
= 255;
92 static WCHAR evVar
[evVarChLen
];
96 test_checklinkpath(TestShellLinkDef
* testDef
)
98 HRESULT hr
, expectedHr
;
101 const WCHAR
* expectedPathOut
;
106 hr
= CoCreateInstance(CLSID_ShellLink
,
108 CLSCTX_INPROC_SERVER
,
109 IID_PPV_ARG(IShellLinkW
, &psl
));
110 ok(hr
== S_OK
, "CoCreateInstance, hr = %lx\n", hr
);
113 skip("Could not instantiate CShellLink\n");
117 hr
= psl
->SetPath(testDef
->pathIn
);
118 ok(hr
== testDef
->hrSetPath
, "IShellLink::SetPath, got hr = %lx, expected %lx\n", hr
, testDef
->hrSetPath
);
120 expectedPathOut
= NULL
;
121 for (i1
= 0; i1
<= 1; i1
++ )
125 flags
= testDef
->flags1
;
126 expandPathOut
= testDef
->expandPathOut1
;
127 expectedPathOut
= testDef
->pathOut1
;
128 expectedHr
= testDef
->hrGetPath1
;
132 flags
= testDef
->flags2
;
133 expandPathOut
= testDef
->expandPathOut2
;
134 expectedPathOut
= testDef
->pathOut2
;
135 expectedHr
= testDef
->hrGetPath2
;
138 /* Patch some variables */
139 if (expandPathOut
== TRUE
)
141 ExpandEnvironmentStringsW(expectedPathOut
,evVar
,evVarChLen
);
142 DPRINT("** %S **\n",evVar
);
143 expectedPathOut
= evVar
;
146 hr
= psl
->GetPath(wPathOut
,sizeof(wPathOut
),NULL
,flags
);
148 "IShellLink::GetPath, flags %lx, got hr = %lx, expected %lx\n",
149 flags
, hr
, expectedHr
);
150 ok(wcsicmp(wPathOut
,expectedPathOut
) == 0,
151 "IShellLink::GetPath, flags %lx, in %S, got %S, expected %S\n",
152 flags
,testDef
->pathIn
,wPathOut
,expectedPathOut
);
160 TestDescription(void)
165 PCWSTR testDescription
= L
"This is a test description";
167 /* Test SetDescription */
168 hr
= CoCreateInstance(CLSID_ShellLink
,
170 CLSCTX_INPROC_SERVER
,
171 IID_PPV_ARG(IShellLinkW
, &psl
));
172 ok(hr
== S_OK
, "CoCreateInstance, hr = %lx\n", hr
);
175 skip("Could not instantiate CShellLink\n");
179 memset(buffer
, 0x55, sizeof(buffer
));
180 hr
= psl
->GetDescription(buffer
, RTL_NUMBER_OF(buffer
));
181 ok(hr
== S_OK
, "IShellLink::GetDescription returned hr = %lx\n", hr
);
182 ok(buffer
[0] == 0, "buffer[0] = %x\n", buffer
[0]);
183 ok(buffer
[1] == 0x5555, "buffer[1] = %x\n", buffer
[1]);
185 hr
= psl
->SetDescription(testDescription
);
186 ok(hr
== S_OK
, "IShellLink::SetDescription returned hr = %lx\n", hr
);
188 memset(buffer
, 0x55, sizeof(buffer
));
189 hr
= psl
->GetDescription(buffer
, RTL_NUMBER_OF(buffer
));
190 ok(hr
== S_OK
, "IShellLink::GetDescription returned hr = %lx\n", hr
);
191 ok(buffer
[wcslen(testDescription
)] == 0, "buffer[n] = %x\n", buffer
[wcslen(testDescription
)]);
192 ok(buffer
[wcslen(testDescription
) + 1] == 0x5555, "buffer[n+1] = %x\n", buffer
[wcslen(testDescription
) + 1]);
193 ok(!wcscmp(buffer
, testDescription
), "buffer = '%ls'\n", buffer
);
195 hr
= psl
->SetDescription(NULL
);
196 ok(hr
== S_OK
, "IShellLink::SetDescription returned hr = %lx\n", hr
);
198 memset(buffer
, 0x55, sizeof(buffer
));
199 hr
= psl
->GetDescription(buffer
, RTL_NUMBER_OF(buffer
));
200 ok(hr
== S_OK
, "IShellLink::GetDescription returned hr = %lx\n", hr
);
201 ok(buffer
[0] == 0, "buffer[0] = %x\n", buffer
[0]);
202 ok(buffer
[1] == 0x5555, "buffer[1] = %x\n", buffer
[1]);
209 TestShellLinkDef
*testDef
;
212 /* needed for test */
213 SetEnvironmentVariableW(L
"shell",L
"cmd.exe");
215 testDef
= &linkTestList
[i1
];
216 while (testDef
->pathIn
!= NULL
)
219 DPRINT("IShellLink-Test: %S\n", testDef
->pathIn
);
220 test_checklinkpath(testDef
);
222 testDef
= &linkTestList
[i1
];
225 SetEnvironmentVariableW(L
"shell",NULL
);
230 START_TEST(CShellLink
)
232 CoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);