Release 1.4.1.
[wine] / dlls / hlink / tests / browse_ctx.c
1 /*
2  * Copyright 2009 Andrew Eikum for CodeWeavers
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17  */
18
19 #define COBJMACROS
20
21 #include <stdio.h>
22
23 #include <hlink.h>
24
25 #include "wine/test.h"
26
27 static void test_SetInitialHlink(void)
28 {
29     IHlinkBrowseContext *bc;
30     IHlink *found_hlink;
31     IMoniker *dummy, *found_moniker;
32     IBindCtx *bindctx;
33     WCHAR one[] = {'1',0};
34     WCHAR five[] = {'5',0};
35     WCHAR *found_name, *exp_name;
36     HRESULT hres;
37
38     hres = CreateBindCtx(0, &bindctx);
39     ok(hres == S_OK, "CreateBindCtx failed: 0x%08x\n", hres);
40
41     hres = CreateItemMoniker(one, five, &dummy);
42     ok(hres == S_OK, "CreateItemMoniker failed: 0x%08x\n", hres);
43
44     hres = IMoniker_GetDisplayName(dummy, bindctx, NULL, &exp_name);
45     ok(hres == S_OK, "GetDisplayName failed: 0x%08x\n", hres);
46
47     hres = HlinkCreateBrowseContext(NULL, &IID_IHlinkBrowseContext, (void**)&bc);
48     ok(hres == S_OK, "HlinkCreateBrowseContext failed: 0x%08x\n", hres);
49
50     hres = IHlinkBrowseContext_SetInitialHlink(bc, dummy, one, NULL);
51     ok(hres == S_OK, "SetInitialHlink failed: 0x%08x\n", hres);
52
53     hres = IHlinkBrowseContext_GetHlink(bc, HLID_CURRENT, &found_hlink);
54     ok(hres == S_OK, "GetHlink failed: 0x%08x\n", hres);
55
56     hres = IHlink_GetMonikerReference(found_hlink, HLINKGETREF_DEFAULT, &found_moniker, NULL);
57     ok(hres == S_OK, "GetMonikerReference failed: 0x%08x\n", hres);
58
59     hres = IMoniker_GetDisplayName(found_moniker, bindctx, NULL, &found_name);
60     ok(hres == S_OK, "GetDisplayName failed: 0x%08x\n", hres);
61     ok(!lstrcmpW(found_name, exp_name), "Found display name should have been %s, was: %s\n", wine_dbgstr_w(exp_name), wine_dbgstr_w(found_name));
62
63     CoTaskMemFree(exp_name);
64     CoTaskMemFree(found_name);
65
66     IBindCtx_Release(bindctx);
67     IMoniker_Release(found_moniker);
68     IHlink_Release(found_hlink);
69     IHlinkBrowseContext_Release(bc);
70     IMoniker_Release(dummy);
71 }
72
73 static void test_BrowseWindowInfo(void)
74 {
75     IHlinkBrowseContext *bc;
76     HLBWINFO bwinfo_set, bwinfo_get;
77     HRESULT hres;
78
79     hres = HlinkCreateBrowseContext(NULL, &IID_IHlinkBrowseContext, (void**)&bc);
80     ok(hres == S_OK, "HlinkCreateBrowseContext failed: 0x%08x\n", hres);
81
82     hres = IHlinkBrowseContext_GetBrowseWindowInfo(bc, NULL);
83     ok(hres == E_INVALIDARG, "GetBrowseWindow failed with wrong code: 0x%08x\n", hres);
84
85     hres = IHlinkBrowseContext_SetBrowseWindowInfo(bc, NULL);
86     ok(hres == E_INVALIDARG, "SetBrowseWindow failed with wrong code: 0x%08x\n", hres);
87
88     memset(&bwinfo_get, -1, sizeof(HLBWINFO));
89
90     hres = IHlinkBrowseContext_GetBrowseWindowInfo(bc, &bwinfo_get);
91     ok(hres == S_OK, "GetBrowseWindowInfo failed: 0x%08x\n", hres);
92     ok(bwinfo_get.cbSize == 0, "Got wrong size: %x\n", bwinfo_get.cbSize);
93
94     bwinfo_set.cbSize = sizeof(HLBWINFO);
95     bwinfo_set.grfHLBWIF = HLBWIF_WEBTOOLBARHIDDEN;
96     bwinfo_set.rcFramePos.left = 1;
97     bwinfo_set.rcFramePos.right = 2;
98     bwinfo_set.rcFramePos.top = 3;
99     bwinfo_set.rcFramePos.bottom = 4;
100     bwinfo_set.rcDocPos.left = 5;
101     bwinfo_set.rcDocPos.right = 6;
102     bwinfo_set.rcDocPos.top = 7;
103     bwinfo_set.rcDocPos.bottom = 8;
104     bwinfo_set.hltbinfo.uDockType = 4321;
105     bwinfo_set.hltbinfo.rcTbPos.left = 9;
106     bwinfo_set.hltbinfo.rcTbPos.right = 10;
107     bwinfo_set.hltbinfo.rcTbPos.top = 11;
108     bwinfo_set.hltbinfo.rcTbPos.bottom = 12;
109     hres = IHlinkBrowseContext_SetBrowseWindowInfo(bc, &bwinfo_set);
110     ok(hres == S_OK, "SetBrowseWindowInfo failed: 0x%08x\n", hres);
111
112     memset(&bwinfo_get, 0, sizeof(HLBWINFO));
113
114     hres = IHlinkBrowseContext_GetBrowseWindowInfo(bc, &bwinfo_get);
115     ok(hres == S_OK, "GetBrowseWindowInfo failed: 0x%08x\n", hres);
116     ok(!memcmp(&bwinfo_set, &bwinfo_get, sizeof(HLBWINFO)), "Set and Get differ\n");
117
118     IHlinkBrowseContext_Release(bc);
119 }
120
121 START_TEST(browse_ctx)
122 {
123     CoInitialize(NULL);
124
125     test_SetInitialHlink();
126     test_BrowseWindowInfo();
127
128     CoUninitialize();
129 }