imagehlp: Use the IMAGE_FIRST_SECTION helper macro.
[wine.git] / dlls / comdlg32 / tests / finddlg.c
blob6a67b2f6d3a0bde739cf4f6d5174a7c089ead67e
1 /*
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
22 #include "windows.h"
23 #include "commdlg.h"
24 #include "cderr.h"
25 #include "wine/test.h"
27 static UINT ID_FINDMSGSTRING;
29 static LRESULT handle_findmsg(FINDREPLACEA *fr)
31 return 0;
34 static LRESULT CALLBACK OwnerWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
36 if(msg == ID_FINDMSGSTRING) {
37 return handle_findmsg((FINDREPLACEA*)lParam);
39 return DefWindowProcA(hwnd, msg, wParam, lParam);
42 static void test_param_check(void)
44 char findbuffer[64];
45 char replacebuffer[64];
46 FINDREPLACEA fr, *pFr;
47 WNDCLASSA wc;
49 ZeroMemory(&wc, sizeof(wc));
50 wc.lpfnWndProc = OwnerWndProc;
51 wc.lpszClassName = "test_param_check";
52 RegisterClassA(&wc);
54 #define CHECK_FIND_OR_REPLACE(FUNC, FAIL, ERR_CODE) \
55 do { \
56 HWND hwnd = FUNC(pFr); \
57 BOOL is_ok = !!hwnd == !FAIL; \
58 ok(is_ok, "%s should%s fail\n", #FUNC, FAIL ? "" : "n't"); \
59 if (FAIL && is_ok) { \
60 DWORD ext_err = CommDlgExtendedError(); \
61 ok(ext_err == ERR_CODE, "expected err %x got %lx\n", \
62 ERR_CODE, ext_err); \
63 } else { \
64 DestroyWindow(hwnd); \
65 } \
66 } while (0)
68 #define CHECK_FIND_FAIL(ERR_CODE) \
69 CHECK_FIND_OR_REPLACE(FindTextA, TRUE, ERR_CODE)
71 #define CHECK_FIND_SUCCEED() \
72 CHECK_FIND_OR_REPLACE(FindTextA, FALSE, 0)
74 #define CHECK_REPLACE_FAIL(ERR_CODE) \
75 CHECK_FIND_OR_REPLACE(ReplaceTextA, TRUE, ERR_CODE)
77 #define CHECK_REPLACE_SUCCEED() \
78 CHECK_FIND_OR_REPLACE(ReplaceTextA, FALSE, 0)
80 #define CHECK_FINDREPLACE_FAIL(ERR_CODE) \
81 do { \
82 CHECK_FIND_FAIL(ERR_CODE); \
83 CHECK_REPLACE_FAIL(ERR_CODE); \
84 } while (0)
86 pFr = NULL;
87 CHECK_FINDREPLACE_FAIL(CDERR_INITIALIZATION);
88 pFr = &fr;
90 ZeroMemory(&fr, sizeof(fr));
91 /* invalid lStructSize (0) */
92 CHECK_FINDREPLACE_FAIL(CDERR_STRUCTSIZE);
93 fr.lStructSize = sizeof(fr);
95 /* invalid hwndOwner (NULL) */
96 CHECK_FINDREPLACE_FAIL(CDERR_DIALOGFAILURE);
97 fr.hwndOwner = CreateWindowA(wc.lpszClassName, NULL, WS_VISIBLE, 0, 0, 200, 100,
98 NULL, NULL, GetModuleHandleA(NULL), NULL);
100 /* invalid wFindWhatLen (0) */
101 CHECK_FINDREPLACE_FAIL(FRERR_BUFFERLENGTHZERO);
102 fr.wFindWhatLen = sizeof(findbuffer);
104 /* invalid lpstrFindWhat (NULL) */
105 CHECK_FINDREPLACE_FAIL(FRERR_BUFFERLENGTHZERO);
106 fr.lpstrFindWhat = findbuffer;
107 strcpy(findbuffer, "abc");
109 /* invalid lpstrReplaceWith (NULL) for ReplaceText */
110 CHECK_FIND_SUCCEED();
111 CHECK_REPLACE_FAIL(FRERR_BUFFERLENGTHZERO);
112 fr.lpstrReplaceWith = replacebuffer;
113 strcpy(replacebuffer, "def");
115 /* wReplaceWithLen may be 0, even for ReplaceText */
116 CHECK_FIND_SUCCEED();
117 CHECK_REPLACE_SUCCEED();
118 fr.wReplaceWithLen = sizeof(replacebuffer);
120 /* invalid lpfnHook (NULL) when Flags has FR_ENABLEHOOK */
121 fr.Flags = FR_ENABLEHOOK;
122 CHECK_FINDREPLACE_FAIL(CDERR_NOHOOK);
124 /* invalid hInstance (NULL)
125 * when Flags has FR_ENABLETEMPLATE or FR_ENABLETEMPLATEHANDLE */
126 fr.Flags = FR_ENABLETEMPLATE;
127 CHECK_FINDREPLACE_FAIL(CDERR_FINDRESFAILURE);
128 fr.Flags = FR_ENABLETEMPLATEHANDLE;
129 CHECK_FINDREPLACE_FAIL(CDERR_NOHINSTANCE);
130 fr.hInstance = GetModuleHandleA(NULL);
132 /* invalid lpTemplateName (NULL) when Flags has FR_ENABLETEMPLATE */
133 fr.Flags = FR_ENABLETEMPLATE;
134 CHECK_FINDREPLACE_FAIL(CDERR_FINDRESFAILURE);
135 fr.Flags = 0;
137 CHECK_FIND_SUCCEED();
138 CHECK_REPLACE_SUCCEED();
140 DestroyWindow(fr.hwndOwner);
143 START_TEST(finddlg)
145 ID_FINDMSGSTRING = RegisterWindowMessageA(FINDMSGSTRINGA);
147 test_param_check();