[GDI32_WINETEST]
[reactos.git] / rostests / winetests / shell32 / progman_dde.c
1 /*
2 * Unit test of the Program Manager DDE Interfaces
3 *
4 * Copyright 2009 Mikey Alexander
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20
21 /* DDE Program Manager Tests
22 * - Covers basic CreateGroup, ShowGroup, DeleteGroup, AddItem, and DeleteItem
23 * functionality
24 * - Todo: Handle CommonGroupFlag
25 * Better AddItem Tests (Lots of parameters to test)
26 * Tests for Invalid Characters in Names / Invalid Parameters
27 */
28
29 #include <stdio.h>
30 #include <wine/test.h>
31 #include <winbase.h>
32 #include "dde.h"
33 #include "ddeml.h"
34 #include "winuser.h"
35 #include "shlobj.h"
36
37 /* Timeout on DdeClientTransaction Call */
38 #define MS_TIMEOUT_VAL 1000
39 /* # of times to poll for window creation */
40 #define PDDE_POLL_NUM 150
41 /* time to sleep between polls */
42 #define PDDE_POLL_TIME 300
43
44 /* Call Info */
45 #define DDE_TEST_MISC 0x00010000
46 #define DDE_TEST_CREATEGROUP 0x00020000
47 #define DDE_TEST_DELETEGROUP 0x00030000
48 #define DDE_TEST_SHOWGROUP 0x00040000
49 #define DDE_TEST_ADDITEM 0x00050000
50 #define DDE_TEST_DELETEITEM 0x00060000
51 #define DDE_TEST_COMPOUND 0x00070000
52 #define DDE_TEST_CALLMASK 0x00ff0000
53
54 #define DDE_TEST_NUMMASK 0x0000ffff
55
56 static HRESULT (WINAPI *pSHGetLocalizedName)(LPCWSTR, LPWSTR, UINT, int *);
57 static BOOL (WINAPI *pSHGetSpecialFolderPathA)(HWND, LPSTR, int, BOOL);
58 static BOOL (WINAPI *pReadCabinetState)(CABINETSTATE *, int);
59
60 static void init_function_pointers(void)
61 {
62 HMODULE hmod;
63
64 hmod = GetModuleHandleA("shell32.dll");
65 pSHGetLocalizedName = (void*)GetProcAddress(hmod, "SHGetLocalizedName");
66 pSHGetSpecialFolderPathA = (void*)GetProcAddress(hmod, "SHGetSpecialFolderPathA");
67 pReadCabinetState = (void*)GetProcAddress(hmod, "ReadCabinetState");
68 if (!pReadCabinetState)
69 pReadCabinetState = (void*)GetProcAddress(hmod, (LPSTR)651);
70 }
71
72 static BOOL use_common(void)
73 {
74 HMODULE hmod;
75 static BOOL (WINAPI *pIsNTAdmin)(DWORD, LPDWORD);
76
77 /* IsNTAdmin() is available on all platforms. */
78 hmod = LoadLibraryA("advpack.dll");
79 pIsNTAdmin = (void*)GetProcAddress(hmod, "IsNTAdmin");
80
81 if (!pIsNTAdmin(0, NULL))
82 {
83 /* We are definitely not an administrator */
84 FreeLibrary(hmod);
85 return FALSE;
86 }
87 FreeLibrary(hmod);
88
89 /* If we end up here we are on NT4+ as Win9x and WinMe don't have the
90 * notion of administrators (as we need it).
91 */
92
93 /* As of Vista we should always use the users directory. Tests with the
94 * real Administrator account on Windows 7 proved this.
95 *
96 * FIXME: We need a better way of identifying Vista+ as currently this check
97 * also covers Wine and we don't know yet which behavior we want to follow.
98 */
99 if (pSHGetLocalizedName)
100 return FALSE;
101
102 return TRUE;
103 }
104
105 static BOOL full_title(void)
106 {
107 CABINETSTATE cs;
108
109 memset(&cs, 0, sizeof(cs));
110 if (pReadCabinetState)
111 {
112 pReadCabinetState(&cs, sizeof(cs));
113 }
114 else
115 {
116 HKEY key;
117 DWORD size;
118
119 win_skip("ReadCabinetState is not available, reading registry directly\n");
120 RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\CabinetState", &key);
121 size = sizeof(cs);
122 RegQueryValueExA(key, "Settings", NULL, NULL, (LPBYTE)&cs, &size);
123 RegCloseKey(key);
124 }
125
126 return (cs.fFullPathTitle == -1);
127 }
128
129 static char ProgramsDir[MAX_PATH];
130
131 static char Group1Title[MAX_PATH] = "Group1";
132 static char Group2Title[MAX_PATH] = "Group2";
133 static char Group3Title[MAX_PATH] = "Group3";
134 static char StartupTitle[MAX_PATH] = "Startup";
135
136 static void init_strings(void)
137 {
138 char startup[MAX_PATH];
139 char commonprograms[MAX_PATH];
140 char programs[MAX_PATH];
141
142 if (pSHGetSpecialFolderPathA)
143 {
144 pSHGetSpecialFolderPathA(NULL, programs, CSIDL_PROGRAMS, FALSE);
145 pSHGetSpecialFolderPathA(NULL, commonprograms, CSIDL_COMMON_PROGRAMS, FALSE);
146 pSHGetSpecialFolderPathA(NULL, startup, CSIDL_STARTUP, FALSE);
147 }
148 else
149 {
150 HKEY key;
151 DWORD size;
152 LONG res;
153
154 /* Older Win9x and NT4 */
155
156 RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders", &key);
157 size = sizeof(programs);
158 RegQueryValueExA(key, "Programs", NULL, NULL, (LPBYTE)&programs, &size);
159 size = sizeof(startup);
160 RegQueryValueExA(key, "Startup", NULL, NULL, (LPBYTE)&startup, &size);
161 RegCloseKey(key);
162
163 RegOpenKeyA(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders", &key);
164 size = sizeof(commonprograms);
165 res = RegQueryValueExA(key, "Common Programs", NULL, NULL, (LPBYTE)&commonprograms, &size);
166 RegCloseKey(key);
167 }
168
169 /* ProgramsDir on Vista+ is always the users one (CSIDL_PROGRAMS). Before Vista
170 * it depends on whether the user is an administrator (CSIDL_COMMON_PROGRAMS) or
171 * not (CSIDL_PROGRAMS).
172 */
173 if (use_common())
174 lstrcpyA(ProgramsDir, commonprograms);
175 else
176 lstrcpyA(ProgramsDir, programs);
177
178 if (full_title())
179 {
180 lstrcpyA(Group1Title, ProgramsDir);
181 lstrcatA(Group1Title, "\\Group1");
182 lstrcpyA(Group2Title, ProgramsDir);
183 lstrcatA(Group2Title, "\\Group2");
184 lstrcpyA(Group3Title, ProgramsDir);
185 lstrcatA(Group3Title, "\\Group3");
186
187 lstrcpyA(StartupTitle, startup);
188 }
189 else
190 {
191 /* Vista has the nice habit of displaying the full path in English
192 * and the short one localized. CSIDL_STARTUP on Vista gives us the
193 * English version so we have to 'translate' this one.
194 *
195 * MSDN claims it should be used for files not folders but this one
196 * suits our purposes just fine.
197 */
198 if (pSHGetLocalizedName)
199 {
200 WCHAR startupW[MAX_PATH];
201 WCHAR module[MAX_PATH];
202 WCHAR module_expanded[MAX_PATH];
203 WCHAR localized[MAX_PATH];
204 int id;
205
206 MultiByteToWideChar(CP_ACP, 0, startup, -1, startupW, sizeof(startupW)/sizeof(WCHAR));
207 pSHGetLocalizedName(startupW, module, MAX_PATH, &id);
208 ExpandEnvironmentStringsW(module, module_expanded, MAX_PATH);
209 LoadStringW(GetModuleHandleW(module_expanded), id, localized, MAX_PATH);
210
211 WideCharToMultiByte(CP_ACP, 0, localized, -1, StartupTitle, sizeof(StartupTitle), NULL, NULL);
212 }
213 else
214 {
215 lstrcpyA(StartupTitle, (strrchr(startup, '\\') + 1));
216 }
217 }
218 }
219
220 static HDDEDATA CALLBACK DdeCallback(UINT type, UINT format, HCONV hConv, HSZ hsz1, HSZ hsz2,
221 HDDEDATA hDDEData, ULONG_PTR data1, ULONG_PTR data2)
222 {
223 trace("Callback: type=%i, format=%i\n", type, format);
224 return NULL;
225 }
226
227 /*
228 * Encoded String for Error Messages so that inner failures can determine
229 * what test is failing. Format is: [Code:TestNum]
230 */
231 static const char * GetStringFromTestParams(int testParams)
232 {
233 int testNum;
234 static char testParamString[64];
235 const char *callId;
236
237 testNum = testParams & DDE_TEST_NUMMASK;
238 switch (testParams & DDE_TEST_CALLMASK)
239 {
240 default:
241 case DDE_TEST_MISC:
242 callId = "MISC";
243 break;
244 case DDE_TEST_CREATEGROUP:
245 callId = "C_G";
246 break;
247 case DDE_TEST_DELETEGROUP:
248 callId = "D_G";
249 break;
250 case DDE_TEST_SHOWGROUP:
251 callId = "S_G";
252 break;
253 case DDE_TEST_ADDITEM:
254 callId = "A_I";
255 break;
256 case DDE_TEST_DELETEITEM:
257 callId = "D_I";
258 break;
259 case DDE_TEST_COMPOUND:
260 callId = "CPD";
261 break;
262 }
263
264 sprintf(testParamString, " [%s:%i]", callId, testNum);
265 return testParamString;
266 }
267
268 /* Transfer DMLERR's into text readable strings for Error Messages */
269 #define DMLERR_TO_STR(x) case x: return#x;
270 static const char * GetStringFromError(UINT err)
271 {
272 switch (err)
273 {
274 DMLERR_TO_STR(DMLERR_NO_ERROR);
275 DMLERR_TO_STR(DMLERR_ADVACKTIMEOUT);
276 DMLERR_TO_STR(DMLERR_BUSY);
277 DMLERR_TO_STR(DMLERR_DATAACKTIMEOUT);
278 DMLERR_TO_STR(DMLERR_DLL_NOT_INITIALIZED);
279 DMLERR_TO_STR(DMLERR_DLL_USAGE);
280 DMLERR_TO_STR(DMLERR_EXECACKTIMEOUT);
281 DMLERR_TO_STR(DMLERR_INVALIDPARAMETER);
282 DMLERR_TO_STR(DMLERR_LOW_MEMORY);
283 DMLERR_TO_STR(DMLERR_MEMORY_ERROR);
284 DMLERR_TO_STR(DMLERR_NOTPROCESSED);
285 DMLERR_TO_STR(DMLERR_NO_CONV_ESTABLISHED);
286 DMLERR_TO_STR(DMLERR_POKEACKTIMEOUT);
287 DMLERR_TO_STR(DMLERR_POSTMSG_FAILED);
288 DMLERR_TO_STR(DMLERR_REENTRANCY);
289 DMLERR_TO_STR(DMLERR_SERVER_DIED);
290 DMLERR_TO_STR(DMLERR_SYS_ERROR);
291 DMLERR_TO_STR(DMLERR_UNADVACKTIMEOUT);
292 DMLERR_TO_STR(DMLERR_UNFOUND_QUEUE_ID);
293 default:
294 return "Unknown DML Error";
295 }
296 }
297
298 /* Helper Function to Transfer DdeGetLastError into a String */
299 static const char * GetDdeLastErrorStr(DWORD instance)
300 {
301 UINT err = DdeGetLastError(instance);
302
303 return GetStringFromError(err);
304 }
305
306 /* Execute a Dde Command and return the error & result */
307 /* Note: Progman DDE always returns a pointer to 0x00000001 on a successful result */
308 static void DdeExecuteCommand(DWORD instance, HCONV hConv, const char *strCmd, HDDEDATA *hData, UINT *err, int testParams)
309 {
310 HDDEDATA command;
311
312 command = DdeCreateDataHandle(instance, (LPBYTE) strCmd, strlen(strCmd)+1, 0, 0L, 0, 0);
313 ok (command != NULL, "DdeCreateDataHandle Error %s.%s\n",
314 GetDdeLastErrorStr(instance), GetStringFromTestParams(testParams));
315 *hData = DdeClientTransaction((void *) command,
316 -1,
317 hConv,
318 0,
319 0,
320 XTYP_EXECUTE,
321 MS_TIMEOUT_VAL,
322 NULL);
323
324 /* hData is technically a pointer, but for Program Manager,
325 * it is NULL (error) or 1 (success)
326 * TODO: Check other versions of Windows to verify 1 is returned.
327 * While it is unlikely that anyone is actually testing that the result is 1
328 * if all versions of windows return 1, Wine should also.
329 */
330 if (*hData == NULL)
331 {
332 *err = DdeGetLastError(instance);
333 }
334 else
335 {
336 *err = DMLERR_NO_ERROR;
337 todo_wine
338 {
339 ok(*hData == (HDDEDATA) 1, "Expected HDDEDATA Handle == 1, actually %p.%s\n",
340 *hData, GetStringFromTestParams(testParams));
341 }
342 }
343 DdeFreeDataHandle(command);
344 }
345
346 /*
347 * Check if Window is onscreen with the appropriate name.
348 *
349 * Windows are not created synchronously. So we do not know
350 * when and if the window will be created/shown on screen.
351 * This function implements a polling mechanism to determine
352 * creation.
353 * A more complicated method would be to use SetWindowsHookEx.
354 * Since polling worked fine in my testing, no reason to implement
355 * the other. Comments about other methods of determining when
356 * window creation happened were not encouraging (not including
357 * SetWindowsHookEx).
358 */
359 static void CheckWindowCreated(const char *winName, int closeWindow, int testParams)
360 {
361 HWND window = NULL;
362 int i;
363
364 /* Poll for Window Creation */
365 for (i = 0; window == NULL && i < PDDE_POLL_NUM; i++)
366 {
367 Sleep(PDDE_POLL_TIME);
368 window = FindWindowA(NULL, winName);
369 }
370 ok (window != NULL, "Window \"%s\" was not created in %i seconds - assumed failure.%s\n",
371 winName, PDDE_POLL_NUM*PDDE_POLL_TIME/1000, GetStringFromTestParams(testParams));
372
373 /* Close Window as desired. */
374 if (window != NULL && closeWindow)
375 {
376 SendMessageA(window, WM_SYSCOMMAND, SC_CLOSE, 0);
377 }
378 }
379
380 /* Check for Existence (or non-existence) of a file or group
381 * When testing for existence of a group, groupName is not needed
382 */
383 static void CheckFileExistsInProgramGroups(const char *nameToCheck, int shouldExist, int isGroup,
384 const char *groupName, int testParams)
385 {
386 char path[MAX_PATH];
387 DWORD attributes;
388 int len;
389
390 lstrcpyA(path, ProgramsDir);
391
392 len = strlen(path) + strlen(nameToCheck)+1;
393 if (groupName != NULL)
394 {
395 len += strlen(groupName)+1;
396 }
397 ok (len <= MAX_PATH, "Path Too Long.%s\n", GetStringFromTestParams(testParams));
398 if (len <= MAX_PATH)
399 {
400 if (groupName != NULL)
401 {
402 strcat(path, "\\");
403 strcat(path, groupName);
404 }
405 strcat(path, "\\");
406 strcat(path, nameToCheck);
407 attributes = GetFileAttributes(path);
408 if (!shouldExist)
409 {
410 ok (attributes == INVALID_FILE_ATTRIBUTES , "File exists and shouldn't %s.%s\n",
411 path, GetStringFromTestParams(testParams));
412 } else {
413 if (attributes == INVALID_FILE_ATTRIBUTES)
414 {
415 ok (FALSE, "Created File %s doesn't exist.%s\n", path, GetStringFromTestParams(testParams));
416 } else if (isGroup) {
417 ok (attributes & FILE_ATTRIBUTE_DIRECTORY, "%s is not a folder (attr=%x).%s\n",
418 path, attributes, GetStringFromTestParams(testParams));
419 } else {
420 ok (attributes & FILE_ATTRIBUTE_ARCHIVE, "Created File %s has wrong attributes (%x).%s\n",
421 path, attributes, GetStringFromTestParams(testParams));
422 }
423 }
424 }
425 }
426
427 /* Create Group Test.
428 * command and expected_result.
429 * if expected_result is DMLERR_NO_ERROR, test
430 * 1. group was created
431 * 2. window is open
432 */
433 static void CreateGroupTest(DWORD instance, HCONV hConv, const char *command, UINT expected_result,
434 const char *groupName, const char *windowTitle, int testParams)
435 {
436 HDDEDATA hData;
437 UINT error;
438
439 /* Execute Command & Check Result */
440 DdeExecuteCommand(instance, hConv, command, &hData, &error, testParams);
441 todo_wine
442 {
443 ok (expected_result == error, "CreateGroup %s: Expected Error %s, received %s.%s\n",
444 groupName, GetStringFromError(expected_result), GetStringFromError(error),
445 GetStringFromTestParams(testParams));
446 }
447
448 /* No Error */
449 if (error == DMLERR_NO_ERROR)
450 {
451
452 /* Check if Group Now Exists */
453 CheckFileExistsInProgramGroups(groupName, TRUE, TRUE, NULL, testParams);
454 /* Check if Window is Open (polling) */
455 CheckWindowCreated(windowTitle, TRUE, testParams);
456 }
457 }
458
459 /* Show Group Test.
460 * DDE command, expected_result, and the group name to check for existence
461 * if expected_result is DMLERR_NO_ERROR, test
462 * 1. window is open
463 */
464 static void ShowGroupTest(DWORD instance, HCONV hConv, const char *command, UINT expected_result,
465 const char *groupName, const char *windowTitle, int closeAfterShowing, int testParams)
466 {
467 HDDEDATA hData;
468 UINT error;
469
470 DdeExecuteCommand(instance, hConv, command, &hData, &error, testParams);
471 /* todo_wine... Is expected to fail, wine stubbed functions DO fail */
472 /* TODO REMOVE THIS CODE!!! */
473 if (expected_result == DMLERR_NOTPROCESSED)
474 {
475 ok (expected_result == error, "ShowGroup %s: Expected Error %s, received %s.%s\n",
476 groupName, GetStringFromError(expected_result), GetStringFromError(error),
477 GetStringFromTestParams(testParams));
478 } else {
479 todo_wine
480 {
481 ok (expected_result == error, "ShowGroup %s: Expected Error %s, received %s.%s\n",
482 groupName, GetStringFromError(expected_result), GetStringFromError(error),
483 GetStringFromTestParams(testParams));
484 }
485 }
486
487 if (error == DMLERR_NO_ERROR)
488 {
489 /* Check if Window is Open (polling) */
490 CheckWindowCreated(windowTitle, closeAfterShowing, testParams);
491 }
492 }
493
494 /* Delete Group Test.
495 * DDE command, expected_result, and the group name to check for existence
496 * if expected_result is DMLERR_NO_ERROR, test
497 * 1. group does not exist
498 */
499 static void DeleteGroupTest(DWORD instance, HCONV hConv, const char *command, UINT expected_result,
500 const char *groupName, int testParams)
501 {
502 HDDEDATA hData;
503 UINT error;
504
505 DdeExecuteCommand(instance, hConv, command, &hData, &error, testParams);
506 todo_wine
507 {
508 ok (expected_result == error, "DeleteGroup %s: Expected Error %s, received %s.%s\n",
509 groupName, GetStringFromError(expected_result), GetStringFromError(error),
510 GetStringFromTestParams(testParams));
511 }
512
513 if (error == DMLERR_NO_ERROR)
514 {
515 /* Check that Group does not exist */
516 CheckFileExistsInProgramGroups(groupName, FALSE, TRUE, NULL, testParams);
517 }
518 }
519
520 /* Add Item Test
521 * DDE command, expected result, and group and file name where it should exist.
522 * checks to make sure error code matches expected error code
523 * checks to make sure item exists if successful
524 */
525 static void AddItemTest(DWORD instance, HCONV hConv, const char *command, UINT expected_result,
526 const char *fileName, const char *groupName, int testParams)
527 {
528 HDDEDATA hData;
529 UINT error;
530
531 DdeExecuteCommand(instance, hConv, command, &hData, &error, testParams);
532 todo_wine
533 {
534 ok (expected_result == error, "AddItem %s: Expected Error %s, received %s.%s\n",
535 fileName, GetStringFromError(expected_result), GetStringFromError(error),
536 GetStringFromTestParams(testParams));
537 }
538
539 if (error == DMLERR_NO_ERROR)
540 {
541 /* Check that File exists */
542 CheckFileExistsInProgramGroups(fileName, TRUE, FALSE, groupName, testParams);
543 }
544 }
545
546 /* Delete Item Test.
547 * DDE command, expected result, and group and file name where it should exist.
548 * checks to make sure error code matches expected error code
549 * checks to make sure item does not exist if successful
550 */
551 static void DeleteItemTest(DWORD instance, HCONV hConv, const char *command, UINT expected_result,
552 const char *fileName, const char *groupName, int testParams)
553 {
554 HDDEDATA hData;
555 UINT error;
556
557 DdeExecuteCommand(instance, hConv, command, &hData, &error, testParams);
558 todo_wine
559 {
560 ok (expected_result == error, "DeleteItem %s: Expected Error %s, received %s.%s\n",
561 fileName, GetStringFromError(expected_result), GetStringFromError(error),
562 GetStringFromTestParams(testParams));
563 }
564
565 if (error == DMLERR_NO_ERROR)
566 {
567 /* Check that File does not exist */
568 CheckFileExistsInProgramGroups(fileName, FALSE, FALSE, groupName, testParams);
569 }
570 }
571
572 /* Compound Command Test.
573 * not really generic, assumes command of the form:
574 * [CreateGroup ...][AddItem ...][AddItem ...]
575 * All samples I've seen using Compound were of this form (CreateGroup,
576 * AddItems) so this covers minimum expected functionality.
577 */
578 static void CompoundCommandTest(DWORD instance, HCONV hConv, const char *command, UINT expected_result,
579 const char *groupName, const char *windowTitle, const char *fileName1,
580 const char *fileName2, int testParams)
581 {
582 HDDEDATA hData;
583 UINT error;
584
585 DdeExecuteCommand(instance, hConv, command, &hData, &error, testParams);
586 todo_wine
587 {
588 ok (expected_result == error, "Compound String %s: Expected Error %s, received %s.%s\n",
589 command, GetStringFromError(expected_result), GetStringFromError(error),
590 GetStringFromTestParams(testParams));
591 }
592
593 if (error == DMLERR_NO_ERROR)
594 {
595 /* Check that File exists */
596 CheckFileExistsInProgramGroups(groupName, TRUE, TRUE, NULL, testParams);
597 CheckWindowCreated(windowTitle, FALSE, testParams);
598 CheckFileExistsInProgramGroups(fileName1, TRUE, FALSE, groupName, testParams);
599 CheckFileExistsInProgramGroups(fileName2, TRUE, FALSE, groupName, testParams);
600 }
601 }
602
603 static void CreateAddItemText(char *itemtext, const char *cmdline, const char *name)
604 {
605 lstrcpyA(itemtext, "[AddItem(");
606 lstrcatA(itemtext, cmdline);
607 lstrcatA(itemtext, ",");
608 lstrcatA(itemtext, name);
609 lstrcatA(itemtext, ")]");
610 }
611
612 /* 1st set of tests */
613 static int DdeTestProgman(DWORD instance, HCONV hConv)
614 {
615 HDDEDATA hData;
616 UINT error;
617 int testnum;
618 char temppath[MAX_PATH];
619 char f1g1[MAX_PATH], f2g1[MAX_PATH], f3g1[MAX_PATH], f1g3[MAX_PATH], f2g3[MAX_PATH];
620 char itemtext[MAX_PATH + 20];
621 char comptext[2 * (MAX_PATH + 20) + 21];
622
623 testnum = 1;
624 /* Invalid Command */
625 DdeExecuteCommand(instance, hConv, "[InvalidCommand()]", &hData, &error, DDE_TEST_MISC|testnum++);
626 ok (error == DMLERR_NOTPROCESSED, "InvalidCommand(), expected error %s, received %s.\n",
627 GetStringFromError(DMLERR_NOTPROCESSED), GetStringFromError(error));
628
629 /* On Vista+ the files have to exist when adding a link */
630 GetTempPathA(MAX_PATH, temppath);
631 GetTempFileNameA(temppath, "dde", 0, f1g1);
632 GetTempFileNameA(temppath, "dde", 0, f2g1);
633 GetTempFileNameA(temppath, "dde", 0, f3g1);
634 GetTempFileNameA(temppath, "dde", 0, f1g3);
635 GetTempFileNameA(temppath, "dde", 0, f2g3);
636
637 /* CreateGroup Tests (including AddItem, DeleteItem) */
638 CreateGroupTest(instance, hConv, "[CreateGroup(Group1)]", DMLERR_NO_ERROR, "Group1", Group1Title, DDE_TEST_CREATEGROUP|testnum++);
639 CreateAddItemText(itemtext, f1g1, "f1g1Name");
640 AddItemTest(instance, hConv, itemtext, DMLERR_NO_ERROR, "f1g1Name.lnk", "Group1", DDE_TEST_ADDITEM|testnum++);
641 CreateAddItemText(itemtext, f2g1, "f2g1Name");
642 AddItemTest(instance, hConv, itemtext, DMLERR_NO_ERROR, "f2g1Name.lnk", "Group1", DDE_TEST_ADDITEM|testnum++);
643 DeleteItemTest(instance, hConv, "[DeleteItem(f2g1Name)]", DMLERR_NO_ERROR, "f2g1Name.lnk", "Group1", DDE_TEST_DELETEITEM|testnum++);
644 CreateAddItemText(itemtext, f3g1, "f3g1Name");
645 AddItemTest(instance, hConv, itemtext, DMLERR_NO_ERROR, "f3g1Name.lnk", "Group1", DDE_TEST_ADDITEM|testnum++);
646 CreateGroupTest(instance, hConv, "[CreateGroup(Group2)]", DMLERR_NO_ERROR, "Group2", Group2Title, DDE_TEST_CREATEGROUP|testnum++);
647 /* Create Group that already exists - same instance */
648 CreateGroupTest(instance, hConv, "[CreateGroup(Group1)]", DMLERR_NO_ERROR, "Group1", Group1Title, DDE_TEST_CREATEGROUP|testnum++);
649
650 /* ShowGroup Tests */
651 ShowGroupTest(instance, hConv, "[ShowGroup(Group1)]", DMLERR_NOTPROCESSED, "Group1", Group1Title, TRUE, DDE_TEST_SHOWGROUP|testnum++);
652 DeleteItemTest(instance, hConv, "[DeleteItem(f3g1Name)]", DMLERR_NO_ERROR, "f3g1Name.lnk", "Group1", DDE_TEST_DELETEITEM|testnum++);
653 ShowGroupTest(instance, hConv, "[ShowGroup(Startup,0)]", DMLERR_NO_ERROR, "Startup", StartupTitle, TRUE, DDE_TEST_SHOWGROUP|testnum++);
654 ShowGroupTest(instance, hConv, "[ShowGroup(Group1,0)]", DMLERR_NO_ERROR, "Group1", Group1Title, FALSE, DDE_TEST_SHOWGROUP|testnum++);
655
656 /* DeleteGroup Test - Note that Window is Open for this test */
657 DeleteGroupTest(instance, hConv, "[DeleteGroup(Group1)]", DMLERR_NO_ERROR, "Group1", DDE_TEST_DELETEGROUP|testnum++);
658
659 /* Compound Execute String Command */
660 lstrcpyA(comptext, "[CreateGroup(Group3)]");
661 CreateAddItemText(itemtext, f1g3, "f1g3Name");
662 lstrcatA(comptext, itemtext);
663 CreateAddItemText(itemtext, f2g3, "f2g3Name");
664 lstrcatA(comptext, itemtext);
665 CompoundCommandTest(instance, hConv, comptext, DMLERR_NO_ERROR, "Group3", Group3Title, "f1g3Name.lnk", "f2g3Name.lnk", DDE_TEST_COMPOUND|testnum++);
666
667 DeleteGroupTest(instance, hConv, "[DeleteGroup(Group3)]", DMLERR_NO_ERROR, "Group3", DDE_TEST_DELETEGROUP|testnum++);
668
669 /* Full Parameters of Add Item */
670 /* AddItem(CmdLine[,Name[,IconPath[,IconIndex[,xPos,yPos[,DefDir[,HotKey[,fMinimize[fSeparateSpace]]]]]]]) */
671
672 DeleteFileA(f1g1);
673 DeleteFileA(f2g1);
674 DeleteFileA(f3g1);
675 DeleteFileA(f1g3);
676 DeleteFileA(f2g3);
677
678 return testnum;
679 }
680
681 /* 2nd set of tests - 2nd connection */
682 static void DdeTestProgman2(DWORD instance, HCONV hConv, int testnum)
683 {
684 /* Create Group that already exists on a separate connection */
685 CreateGroupTest(instance, hConv, "[CreateGroup(Group2)]", DMLERR_NO_ERROR, "Group2", Group2Title, DDE_TEST_CREATEGROUP|testnum++);
686 DeleteGroupTest(instance, hConv, "[DeleteGroup(Group2)]", DMLERR_NO_ERROR, "Group2", DDE_TEST_DELETEGROUP|testnum++);
687 }
688
689 START_TEST(progman_dde)
690 {
691 DWORD instance = 0;
692 UINT err;
693 HSZ hszProgman;
694 HCONV hConv;
695 int testnum;
696
697 init_function_pointers();
698 init_strings();
699
700 /* Initialize DDE Instance */
701 err = DdeInitialize(&instance, DdeCallback, APPCMD_CLIENTONLY, 0);
702 ok (err == DMLERR_NO_ERROR, "DdeInitialize Error %s\n", GetStringFromError(err));
703
704 /* Create Connection */
705 hszProgman = DdeCreateStringHandle(instance, "PROGMAN", CP_WINANSI);
706 ok (hszProgman != NULL, "DdeCreateStringHandle Error %s\n", GetDdeLastErrorStr(instance));
707 hConv = DdeConnect(instance, hszProgman, hszProgman, NULL);
708 ok (DdeFreeStringHandle(instance, hszProgman), "DdeFreeStringHandle failure\n");
709 /* Seeing failures on early versions of Windows Connecting to progman, exit if connection fails */
710 if (hConv == NULL)
711 {
712 ok (DdeUninitialize(instance), "DdeUninitialize failed\n");
713 return;
714 }
715
716 /* Run Tests */
717 testnum = DdeTestProgman(instance, hConv);
718
719 /* Cleanup & Exit */
720 ok (DdeDisconnect(hConv), "DdeDisonnect Error %s\n", GetDdeLastErrorStr(instance));
721 ok (DdeUninitialize(instance), "DdeUninitialize failed\n");
722
723 /* 2nd Instance (Followup Tests) */
724 /* Initialize DDE Instance */
725 instance = 0;
726 err = DdeInitialize(&instance, DdeCallback, APPCMD_CLIENTONLY, 0);
727 ok (err == DMLERR_NO_ERROR, "DdeInitialize Error %s\n", GetStringFromError(err));
728
729 /* Create Connection */
730 hszProgman = DdeCreateStringHandle(instance, "PROGMAN", CP_WINANSI);
731 ok (hszProgman != NULL, "DdeCreateStringHandle Error %s\n", GetDdeLastErrorStr(instance));
732 hConv = DdeConnect(instance, hszProgman, hszProgman, NULL);
733 ok (hConv != NULL, "DdeConnect Error %s\n", GetDdeLastErrorStr(instance));
734 ok (DdeFreeStringHandle(instance, hszProgman), "DdeFreeStringHandle failure\n");
735
736 /* Run Tests */
737 DdeTestProgman2(instance, hConv, testnum);
738
739 /* Cleanup & Exit */
740 ok (DdeDisconnect(hConv), "DdeDisonnect Error %s\n", GetDdeLastErrorStr(instance));
741 ok (DdeUninitialize(instance), "DdeUninitialize failed\n");
742 }