2 * Unit test suite for rich edit control
4 * Copyright 2006 Google (Thomas Kho)
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.
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.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include <wine/test.h>
26 static HMODULE hmoduleRichEdit;
27 static const char haystack[] = "Think of Wine as a compatibility layer for "
28 "running Windows programs. Wine does not require Microsoft Windows, as it "
29 "is a completely free alternative implementation of the Windows API "
30 "consisting of 100% non-Microsoft code, however Wine can optionally use "
31 "native Windows DLLs if they are available. Wine provides both a "
32 "development toolkit for porting Windows source code to Unix as well as a "
33 "program loader, allowing many unmodified Windows programs to run on "
34 "x86-based Unixes, including Linux, FreeBSD, and Solaris.";
36 static HWND new_window(LPCTSTR lpClassName, DWORD dwStyle, HWND parent) {
38 hwnd = CreateWindow(lpClassName, NULL, dwStyle|WS_POPUP|WS_HSCROLL|WS_VSCROLL
39 |WS_VISIBLE, 0, 0, 200, 50, parent, NULL,
40 hmoduleRichEdit, NULL);
41 ok(hwnd != NULL, "class: %s, error: %d\n", lpClassName, (int) GetLastError());
45 static HWND new_richedit(HWND parent) {
46 return new_window(RICHEDIT_CLASS, ES_MULTILINE, parent);
49 static void check_EM_FINDTEXT(HWND hwnd, int start, int end, char needle[],
50 int flags, int expected_start) {
53 memset(&ft, 0, sizeof(ft));
54 ft.chrg.cpMin = start;
56 ft.lpstrText = needle;
57 findloc = SendMessage(hwnd, EM_FINDTEXT, flags, (LPARAM) &ft);
58 ok(findloc == expected_start,
59 "EM_FINDTEXT '%s' in range (%d,%d), flags %08x, got start at %d\n",
60 needle, start, end, flags, findloc);
63 static void test_EM_FINDTEXT(void)
69 HWND hwndRichEdit = new_richedit(NULL);
71 SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM) haystack);
72 SendMessage(hwndRichEdit, EM_EXGETSEL, 0, (LPARAM)&cr);
73 ok(cr.cpMin == cr.cpMax, "(%ld,%ld)\n", cr.cpMin, cr.cpMax);
75 gtl.flags = GTL_NUMCHARS;
76 gtl.codepage = CP_ACP;
77 size = SendMessage(hwndRichEdit, EM_GETTEXTLENGTHEX, (WPARAM) >l, 0);
78 ok(size == sizeof(haystack) - 1, "size=%d, sizeof haystack=%d\n",
79 size, sizeof(haystack)); /* sizeof counts '\0' */
81 check_EM_FINDTEXT(hwndRichEdit, 0, size, "Wine", FR_DOWN | FR_MATCHCASE, 9);
82 check_EM_FINDTEXT(hwndRichEdit, 10, size, "Wine", FR_DOWN | FR_MATCHCASE, 69);
83 check_EM_FINDTEXT(hwndRichEdit, 298, size, "Wine", FR_DOWN | FR_MATCHCASE,
85 check_EM_FINDTEXT(hwndRichEdit, 0, size, "wine", FR_DOWN | FR_MATCHCASE, -1);
87 check_EM_FINDTEXT(hwndRichEdit, 0, size, "wine", FR_DOWN | FR_WHOLEWORD, 9);
88 check_EM_FINDTEXT(hwndRichEdit, 0, size, "win", FR_DOWN | FR_WHOLEWORD, -1);
91 /* Check the case noted in bug 4479 */
92 SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM) "blahblah");
93 check_EM_FINDTEXT(hwndRichEdit, 0, 8, "blah", FR_DOWN | FR_MATCHCASE, 0);
94 check_EM_FINDTEXT(hwndRichEdit, 4, 8, "blah", FR_DOWN | FR_MATCHCASE, 4);
95 check_EM_FINDTEXT(hwndRichEdit, 4, 9, "blah", FR_DOWN | FR_MATCHCASE, 4);
96 check_EM_FINDTEXT(hwndRichEdit, 0, 8, "blahblah", FR_DOWN | FR_MATCHCASE, 0);
98 DestroyWindow(hwndRichEdit);
101 static void check_EM_FINDTEXTEX(HWND hwnd, int start, int end, char needle[],
102 int flags, int expected_start,
106 memset(&ft, 0, sizeof(ft));
107 ft.chrg.cpMin = start;
109 ft.lpstrText = needle;
110 findloc = SendMessage(hwnd, EM_FINDTEXTEX, flags, (LPARAM) &ft);
111 ok(findloc == expected_start,
112 "EM_FINDTEXTEX '%s' in range (%d,%d), flags %08x, got start at %d\n",
113 needle, start, end, flags, findloc);
115 ok(ft.chrgText.cpMin == expected_start,
116 "EM_FINDTEXTEX '%s' in range (%d,%d), flags %08x, got start at %ld\n",
117 needle, start, end, flags, ft.chrgText.cpMin);
118 ok(ft.chrgText.cpMax == expected_end,
119 "EM_FINDTEXTEX '%s' in range (%d,%d), flags %08x, got end at %ld\n",
120 needle, start, end, flags, ft.chrgText.cpMax);
124 static void test_EM_FINDTEXTEX(void)
130 HWND hwndRichEdit = new_richedit(NULL);
132 SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM) haystack);
133 SendMessage(hwndRichEdit, EM_EXGETSEL, 0, (LPARAM) &cr);
134 ok(cr.cpMin == cr.cpMax, "(%ld,%ld)\n", cr.cpMin, cr.cpMax);
136 gtl.flags = GTL_NUMCHARS;
137 gtl.codepage = CP_ACP;
138 size = SendMessage(hwndRichEdit, EM_GETTEXTLENGTHEX, (WPARAM) >l, 0);
139 ok(size == sizeof(haystack) - 1, "size=%d, sizeof haystack=%d\n", size,
140 sizeof(haystack)); /* sizeof counts '\0' */
142 check_EM_FINDTEXTEX(hwndRichEdit, 0, size, "Wine", FR_DOWN | FR_MATCHCASE,
144 check_EM_FINDTEXTEX(hwndRichEdit, 10, size, "Wine", FR_DOWN | FR_MATCHCASE,
146 check_EM_FINDTEXTEX(hwndRichEdit, 298, size, "Wine", FR_DOWN | FR_MATCHCASE,
148 check_EM_FINDTEXTEX(hwndRichEdit, 0, size, "wine", FR_DOWN | FR_MATCHCASE,
151 check_EM_FINDTEXTEX(hwndRichEdit, 0, size, "wine", FR_DOWN | FR_WHOLEWORD,
153 check_EM_FINDTEXTEX(hwndRichEdit, 0, size, "win", FR_DOWN | FR_WHOLEWORD,
157 DestroyWindow(hwndRichEdit);
165 /* Must explicitly LoadLibrary(). The test has no references to functions in
166 * RICHED20.DLL, so the linker doesn't actually link to it. */
167 hmoduleRichEdit = LoadLibrary("RICHED20.DLL");
168 ok(hmoduleRichEdit != NULL, "error: %d\n", (int) GetLastError());
171 test_EM_FINDTEXTEX();
173 /* Set the environment variable WINETEST_RICHED20 to keep windows
174 * responsive and open for 30 seconds. This is useful for debugging.
176 * The message pump uses PeekMessage() to empty the queue and then sleeps for
177 * 50ms before retrying the queue. */
178 end = time(NULL) + 30;
179 if (getenv( "WINETEST_RICHED20" )) {
180 while (time(NULL) < end) {
181 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
182 TranslateMessage(&msg);
183 DispatchMessage(&msg);
190 ok(FreeLibrary(hmoduleRichEdit) != 0, "error: %d\n", (int) GetLastError());