wined3d: Pass a wined3d_device_context to wined3d_cs_emit_blt_sub_resource().
[wine/zf.git] / dlls / comctl32 / tests / ipaddress.c
blob5c4db5adc8bc8253f8cd2e74491b9d1b3d5e0abf
1 /* Unit test suite for IP Address control.
3 * Copyright 2009 Nikolay Sivov
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <windows.h>
22 #include <commctrl.h>
24 #include "wine/test.h"
25 #include "v6util.h"
27 #define expect(expected, got) ok(expected == got, "expected %d, got %d\n", expected,got)
29 static HWND create_ipaddress_control (void)
31 HWND handle;
33 handle = CreateWindowExA(0, WC_IPADDRESSA, NULL,
34 WS_BORDER|WS_VISIBLE, 0, 0, 0, 0,
35 NULL, NULL, NULL, NULL);
36 return handle;
39 static void test_get_set_text(void)
41 HWND hwnd;
42 CHAR ip[16];
43 INT r;
45 hwnd = create_ipaddress_control();
46 if (!hwnd)
48 win_skip("IPAddress control not implemented\n");
49 return;
52 /* check text just after creation */
53 r = GetWindowTextA(hwnd, ip, ARRAY_SIZE(ip));
54 expect(7, r);
55 ok(strcmp(ip, "0.0.0.0") == 0, "Expected null IP address, got %s\n", ip);
57 SendMessageA(hwnd, IPM_SETADDRESS, 0, MAKEIPADDRESS(127, 0, 0, 1));
58 r = GetWindowTextA(hwnd, ip, ARRAY_SIZE(ip));
59 expect(9, r);
60 ok(strcmp(ip, "127.0.0.1") == 0, "Expected 127.0.0.1, got %s\n", ip);
62 DestroyWindow(hwnd);
65 struct child_enum
67 HWND fields[4];
68 unsigned int count;
71 static BOOL CALLBACK test_child_enum_proc(HWND hwnd, LPARAM param)
73 struct child_enum *child_enum = (struct child_enum *)param;
74 char buff[16] = { 0 };
75 unsigned int index;
77 GetWindowTextA(hwnd, buff, ARRAY_SIZE(buff));
78 index = atoi(buff);
79 ok(index < 4, "Unexpected index.\n");
80 if (index < 4)
81 child_enum->fields[index] = hwnd;
83 return ++child_enum->count < 4;
86 static void test_IPM_SETFOCUS(void)
88 struct child_enum child_enum = {{ 0 }};
89 unsigned int ret, from, to, i;
90 HWND hwnd;
92 hwnd = create_ipaddress_control();
93 ok(!!hwnd, "Failed to create control.\n");
95 ret = SendMessageA(hwnd, IPM_SETADDRESS, 0, MAKEIPADDRESS(0, 1, 2, 3));
96 ok(ret, "Unexpected return value %u.\n", ret);
98 EnumChildWindows(hwnd, test_child_enum_proc, (LPARAM)&child_enum);
99 ok(child_enum.count == 4, "Unexpected child count %u.\n", child_enum.count);
101 for (i = 0; i < 4; ++i)
102 SendMessageA(child_enum.fields[i], EM_SETSEL, -1, 0);
104 SendMessageA(child_enum.fields[0], EM_GETSEL, (WPARAM)&from, (LPARAM)&to);
105 ok(from == 0 && to == 0, "Unexpected selection %u x %u.\n", from, to);
107 ret = SendMessageA(hwnd, IPM_SETFOCUS, 0, 0);
108 ok(ret, "Unexpected return value %u.\n", ret);
110 SendMessageA(child_enum.fields[0], EM_GETSEL, (WPARAM)&from, (LPARAM)&to);
111 ok(from == 0 && to == 1, "Unexpected selection %u x %u.\n", from, to);
113 DestroyWindow(hwnd);
116 static void test_WM_SETFOCUS(void)
118 struct child_enum child_enum = {{ 0 }};
119 unsigned int ret, from, to, i;
120 HWND hwnd;
122 hwnd = create_ipaddress_control();
123 ok(!!hwnd, "Failed to create control.\n");
125 ret = SendMessageA(hwnd, IPM_SETADDRESS, 0, MAKEIPADDRESS(0, 1, 2, 3));
126 ok(ret, "Unexpected return value %u.\n", ret);
128 EnumChildWindows(hwnd, test_child_enum_proc, (LPARAM)&child_enum);
129 ok(child_enum.count == 4, "Unexpected child count %u.\n", child_enum.count);
131 SetFocus(child_enum.fields[3]);
133 for (i = 0; i < 4; ++i)
134 SendMessageA(child_enum.fields[i], EM_SETSEL, -1, 0);
136 SendMessageA(child_enum.fields[0], EM_GETSEL, (WPARAM)&from, (LPARAM)&to);
137 ok(from == 0 && to == 0, "Unexpected selection %u x %u.\n", from, to);
139 SetFocus(hwnd);
141 SendMessageA(child_enum.fields[0], EM_GETSEL, (WPARAM)&from, (LPARAM)&to);
142 ok(from == 0 && to == 1, "Unexpected selection %u x %u.\n", from, to);
144 DestroyWindow(hwnd);
147 static void test_IPM_CLEARADDRESS(void)
149 struct child_enum child_enum = {{ 0 }};
150 char buff[16];
151 int i, ret;
152 HWND hwnd;
154 hwnd = create_ipaddress_control();
155 ok(!!hwnd, "Failed to create control.\n");
157 ret = SendMessageA(hwnd, IPM_SETADDRESS, 0, MAKEIPADDRESS(0, 1, 2, 3));
158 ok(ret == 1, "Unexpected return value %d.\n", ret);
160 EnumChildWindows(hwnd, test_child_enum_proc, (LPARAM)&child_enum);
161 ok(child_enum.count == 4, "Unexpected child count %u.\n", child_enum.count);
163 ret = SendMessageA(hwnd, IPM_SETADDRESS, 0, MAKEIPADDRESS(1, 2, 3, 4));
164 ok(ret == 1, "Unexpected return value %d.\n", ret);
166 ret = GetWindowTextA(hwnd, buff, ARRAY_SIZE(buff));
167 ok(ret == 7, "Unexpected return value %d.\n", ret);
168 ok(!strcmp(buff, "1.2.3.4"), "Unexpected address %s.\n", buff);
170 ret = SendMessageA(hwnd, IPM_CLEARADDRESS, 0, 0);
171 ok(ret, "Unexpected return value %d.\n", ret);
173 ret = GetWindowTextA(hwnd, buff, ARRAY_SIZE(buff));
174 ok(ret == 7, "Unexpected return value %d.\n", ret);
175 ok(!strcmp(buff, "0.0.0.0"), "Unexpected address %s.\n", buff);
177 for (i = 0; i < 4; ++i)
179 buff[0] = 1;
180 ret = GetWindowTextA(child_enum.fields[i], buff, ARRAY_SIZE(buff));
181 ok(ret == 0, "Unexpected return value %d.\n", ret);
182 ok(!*buff, "Unexpected field text %s.\n", buff);
185 DestroyWindow(hwnd);
188 START_TEST(ipaddress)
190 ULONG_PTR cookie;
191 HANDLE ctxt;
193 test_get_set_text();
194 test_IPM_SETFOCUS();
195 test_WM_SETFOCUS();
196 test_IPM_CLEARADDRESS();
198 if (!load_v6_module(&cookie, &ctxt))
199 return;
201 test_get_set_text();
202 test_IPM_SETFOCUS();
203 test_WM_SETFOCUS();
204 test_IPM_CLEARADDRESS();
206 unload_v6_module(cookie, ctxt);