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