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