winex11: Add support for byte swapping in GetImage.
[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 /* Win9x and WinMe don't have lstrcmpW */
28 static int strcmp_ww(const WCHAR *str1, const WCHAR *str2)
29 {
30     DWORD len1 = lstrlenW(str1);
31     DWORD len2 = lstrlenW(str2);
32
33     if (len1 != len2) return 1;
34     return memcmp(str1, str2, len1 * sizeof(WCHAR));
35 }
36
37 static void test_SetInitialHlink(void)
38 {
39     IHlinkBrowseContext *bc;
40     IHlink *found_hlink;
41     IMoniker *dummy, *found_moniker;
42     IBindCtx *bindctx;
43     WCHAR one[] = {'1',0};
44     WCHAR five[] = {'5',0};
45     WCHAR *found_name, *exp_name;
46     HRESULT hres;
47
48     hres = CreateBindCtx(0, &bindctx);
49     ok(hres == S_OK, "CreateBindCtx failed: 0x%08x\n", hres);
50
51     hres = CreateItemMoniker(one, five, &dummy);
52     ok(hres == S_OK, "CreateItemMoniker failed: 0x%08x\n", hres);
53
54     hres = IMoniker_GetDisplayName(dummy, bindctx, NULL, &exp_name);
55     ok(hres == S_OK, "GetDisplayName failed: 0x%08x\n", hres);
56
57     hres = HlinkCreateBrowseContext(NULL, &IID_IHlinkBrowseContext, (void**)&bc);
58     ok(hres == S_OK, "HlinkCreateBrowseContext failed: 0x%08x\n", hres);
59
60     hres = IHlinkBrowseContext_SetInitialHlink(bc, dummy, one, NULL);
61     ok(hres == S_OK, "SetInitialHlink failed: 0x%08x\n", hres);
62
63     hres = IHlinkBrowseContext_GetHlink(bc, HLID_CURRENT, &found_hlink);
64     ok(hres == S_OK, "GetHlink failed: 0x%08x\n", hres);
65
66     hres = IHlink_GetMonikerReference(found_hlink, HLINKGETREF_DEFAULT, &found_moniker, NULL);
67     ok(hres == S_OK, "GetMonikerReference failed: 0x%08x\n", hres);
68
69     hres = IMoniker_GetDisplayName(found_moniker, bindctx, NULL, &found_name);
70     ok(hres == S_OK, "GetDisplayName failed: 0x%08x\n", hres);
71     ok(!strcmp_ww(found_name, exp_name), "Found display name should have been %s, was: %s\n", wine_dbgstr_w(exp_name), wine_dbgstr_w(found_name));
72
73     CoTaskMemFree(exp_name);
74     CoTaskMemFree(found_name);
75
76     IBindCtx_Release(bindctx);
77     IMoniker_Release(found_moniker);
78     IHlink_Release(found_hlink);
79     IHlinkBrowseContext_Release(bc);
80     IMoniker_Release(dummy);
81 }
82
83 static void test_BrowseWindowInfo(void)
84 {
85     IHlinkBrowseContext *bc;
86     HLBWINFO bwinfo_set, bwinfo_get;
87     HRESULT hres;
88
89     hres = HlinkCreateBrowseContext(NULL, &IID_IHlinkBrowseContext, (void**)&bc);
90     ok(hres == S_OK, "HlinkCreateBrowseContext failed: 0x%08x\n", hres);
91
92     hres = IHlinkBrowseContext_GetBrowseWindowInfo(bc, NULL);
93     ok(hres == E_INVALIDARG, "GetBrowseWindow failed with wrong code: 0x%08x\n", hres);
94
95     hres = IHlinkBrowseContext_SetBrowseWindowInfo(bc, NULL);
96     ok(hres == E_INVALIDARG, "SetBrowseWindow failed with wrong code: 0x%08x\n", hres);
97
98     memset(&bwinfo_get, -1, sizeof(HLBWINFO));
99
100     hres = IHlinkBrowseContext_GetBrowseWindowInfo(bc, &bwinfo_get);
101     ok(hres == S_OK, "GetBrowseWindowInfo failed: 0x%08x\n", hres);
102     ok(bwinfo_get.cbSize == 0, "Got wrong size: %x\n", bwinfo_get.cbSize);
103
104     bwinfo_set.cbSize = sizeof(HLBWINFO);
105     bwinfo_set.grfHLBWIF = HLBWIF_WEBTOOLBARHIDDEN;
106     bwinfo_set.rcFramePos.left = 1;
107     bwinfo_set.rcFramePos.right = 2;
108     bwinfo_set.rcFramePos.top = 3;
109     bwinfo_set.rcFramePos.bottom = 4;
110     bwinfo_set.rcDocPos.left = 5;
111     bwinfo_set.rcDocPos.right = 6;
112     bwinfo_set.rcDocPos.top = 7;
113     bwinfo_set.rcDocPos.bottom = 8;
114     bwinfo_set.hltbinfo.uDockType = 4321;
115     bwinfo_set.hltbinfo.rcTbPos.left = 9;
116     bwinfo_set.hltbinfo.rcTbPos.right = 10;
117     bwinfo_set.hltbinfo.rcTbPos.top = 11;
118     bwinfo_set.hltbinfo.rcTbPos.bottom = 12;
119     hres = IHlinkBrowseContext_SetBrowseWindowInfo(bc, &bwinfo_set);
120     ok(hres == S_OK, "SetBrowseWindowInfo failed: 0x%08x\n", hres);
121
122     memset(&bwinfo_get, 0, sizeof(HLBWINFO));
123
124     hres = IHlinkBrowseContext_GetBrowseWindowInfo(bc, &bwinfo_get);
125     ok(hres == S_OK, "GetBrowseWindowInfo failed: 0x%08x\n", hres);
126     ok(!memcmp(&bwinfo_set, &bwinfo_get, sizeof(HLBWINFO)), "Set and Get differ\n");
127
128     IHlinkBrowseContext_Release(bc);
129 }
130
131 START_TEST(browse_ctx)
132 {
133     CoInitialize(NULL);
134
135     test_SetInitialHlink();
136     test_BrowseWindowInfo();
137
138     CoUninitialize();
139 }