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
24 #include "wine/test.h"
27 #define expect(expected, got) ok(expected == got, "expected %d, got %d\n", expected,got)
29 static HWND
create_ipaddress_control (void)
33 handle
= CreateWindowExA(0, WC_IPADDRESSA
, NULL
,
34 WS_BORDER
|WS_VISIBLE
, 0, 0, 0, 0,
35 NULL
, NULL
, NULL
, NULL
);
39 static void test_get_set_text(void)
45 hwnd
= create_ipaddress_control();
48 win_skip("IPAddress control not implemented\n");
52 /* check text just after creation */
53 r
= GetWindowTextA(hwnd
, ip
, ARRAY_SIZE(ip
));
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
));
60 ok(strcmp(ip
, "127.0.0.1") == 0, "Expected 127.0.0.1, got %s\n", ip
);
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 };
77 GetWindowTextA(hwnd
, buff
, ARRAY_SIZE(buff
));
79 ok(index
< 4, "Unexpected index.\n");
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
;
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
);
116 static void test_WM_SETFOCUS(void)
118 struct child_enum child_enum
= {{ 0 }};
119 unsigned int ret
, from
, to
, i
;
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
);
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
);
147 static void test_IPM_CLEARADDRESS(void)
149 struct child_enum child_enum
= {{ 0 }};
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
)
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
);
188 START_TEST(ipaddress
)
196 test_IPM_CLEARADDRESS();
198 if (!load_v6_module(&cookie
, &ctxt
))
204 test_IPM_CLEARADDRESS();
206 unload_v6_module(cookie
, ctxt
);