2 * Unit test suite for comdlg32 API functions: find/replace dialogs
4 * Copyright 2010 by Dylan Smith
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "wine/test.h"
26 static UINT ID_FINDMSGSTRING
;
28 static LRESULT
handle_findmsg(FINDREPLACEA
*fr
)
33 static LRESULT CALLBACK
OwnerWndProc(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
35 if(msg
== ID_FINDMSGSTRING
) {
36 return handle_findmsg((FINDREPLACEA
*)lParam
);
38 return DefWindowProc(hwnd
, msg
, wParam
, lParam
);
41 static void test_param_check(void)
44 char replacebuffer
[64];
45 FINDREPLACEA fr
, *pFr
;
48 ZeroMemory(&wc
, sizeof(wc
));
49 wc
.lpfnWndProc
= OwnerWndProc
;
50 wc
.lpszClassName
= "test_param_check";
53 #define CHECK_FIND_OR_REPLACE(FUNC, FAIL, ERR_CODE) \
55 HWND hwnd = FUNC(pFr); \
56 BOOL is_ok = !!hwnd == !FAIL; \
57 ok(is_ok, "%s should%s fail\n", #FUNC, FAIL ? "" : "n't"); \
58 if (FAIL && is_ok) { \
59 DWORD ext_err = CommDlgExtendedError(); \
60 ok(ext_err == ERR_CODE, "expected err %x got %x\n", \
63 DestroyWindow(hwnd); \
67 #define CHECK_FIND_FAIL(ERR_CODE) \
68 CHECK_FIND_OR_REPLACE(FindTextA, TRUE, ERR_CODE)
70 #define CHECK_FIND_SUCCEED() \
71 CHECK_FIND_OR_REPLACE(FindTextA, FALSE, 0)
73 #define CHECK_REPLACE_FAIL(ERR_CODE) \
74 CHECK_FIND_OR_REPLACE(ReplaceTextA, TRUE, ERR_CODE)
76 #define CHECK_REPLACE_SUCCEED() \
77 CHECK_FIND_OR_REPLACE(ReplaceTextA, FALSE, 0)
79 #define CHECK_FINDREPLACE_FAIL(ERR_CODE) \
81 CHECK_FIND_FAIL(ERR_CODE); \
82 CHECK_REPLACE_FAIL(ERR_CODE); \
86 CHECK_FINDREPLACE_FAIL(CDERR_INITIALIZATION
);
89 ZeroMemory(&fr
, sizeof(fr
));
90 /* invalid lStructSize (0) */
91 CHECK_FINDREPLACE_FAIL(CDERR_STRUCTSIZE
);
92 fr
.lStructSize
= sizeof(fr
);
94 /* invalid hwndOwner (NULL) */
95 CHECK_FINDREPLACE_FAIL(CDERR_DIALOGFAILURE
);
96 fr
.hwndOwner
= CreateWindowA(wc
.lpszClassName
, NULL
, WS_VISIBLE
, 0, 0, 200, 100,
97 NULL
, NULL
, GetModuleHandleA(NULL
), NULL
);
99 /* invalid wFindWhatLen (0) */
100 CHECK_FINDREPLACE_FAIL(FRERR_BUFFERLENGTHZERO
);
101 fr
.wFindWhatLen
= sizeof(findbuffer
);
103 /* invalid lpstrFindWhat (NULL) */
104 CHECK_FINDREPLACE_FAIL(FRERR_BUFFERLENGTHZERO
);
105 fr
.lpstrFindWhat
= findbuffer
;
107 /* invalid lpstrReplaceWith (NULL) for ReplaceText */
108 CHECK_FIND_SUCCEED();
109 CHECK_REPLACE_FAIL(FRERR_BUFFERLENGTHZERO
);
110 fr
.lpstrReplaceWith
= replacebuffer
;
112 /* wReplaceWithLen may be 0, even for ReplaceText */
113 CHECK_FIND_SUCCEED();
114 CHECK_REPLACE_SUCCEED();
115 fr
.wReplaceWithLen
= sizeof(replacebuffer
);
117 /* invalid lpfnHook (NULL) when Flags has FR_ENABLEHOOK */
118 fr
.Flags
= FR_ENABLEHOOK
;
119 CHECK_FINDREPLACE_FAIL(CDERR_NOHOOK
);
121 /* invalid hInstance (NULL)
122 * when Flags has FR_ENABLETEMPLATE or FR_ENABLETEMPLATEHANDLE */
123 fr
.Flags
= FR_ENABLETEMPLATE
;
124 CHECK_FINDREPLACE_FAIL(CDERR_FINDRESFAILURE
);
125 fr
.Flags
= FR_ENABLETEMPLATEHANDLE
;
126 CHECK_FINDREPLACE_FAIL(CDERR_NOHINSTANCE
);
127 fr
.hInstance
= GetModuleHandle(NULL
);
129 /* invalid lpTemplateName (NULL) when Flags has FR_ENABLETEMPLATE */
130 fr
.Flags
= FR_ENABLETEMPLATE
;
131 CHECK_FINDREPLACE_FAIL(CDERR_FINDRESFAILURE
);
134 CHECK_FIND_SUCCEED();
135 CHECK_REPLACE_SUCCEED();
137 DestroyWindow(fr
.hwndOwner
);
142 ID_FINDMSGSTRING
= RegisterWindowMessageA(FINDMSGSTRINGA
);