wined3d: Get rid of the user_stream field from wined3d_state.
[wine.git] / dlls / comdlg32 / tests / finddlg.c
blob82a7a46e915f1e115d3289d44fc0eb22001724f3
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 "wine/test.h"
26 static UINT ID_FINDMSGSTRING;
28 static LRESULT handle_findmsg(FINDREPLACEA *fr)
30 return 0;
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)
43 char findbuffer[64];
44 char replacebuffer[64];
45 FINDREPLACEA fr, *pFr;
46 WNDCLASSA wc;
48 ZeroMemory(&wc, sizeof(wc));
49 wc.lpfnWndProc = OwnerWndProc;
50 wc.lpszClassName = "test_param_check";
51 RegisterClassA(&wc);
53 #define CHECK_FIND_OR_REPLACE(FUNC, FAIL, ERR_CODE) \
54 do { \
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", \
61 ERR_CODE, ext_err); \
62 } else { \
63 DestroyWindow(hwnd); \
64 } \
65 } while (0)
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) \
80 do { \
81 CHECK_FIND_FAIL(ERR_CODE); \
82 CHECK_REPLACE_FAIL(ERR_CODE); \
83 } while (0)
85 pFr = NULL;
86 CHECK_FINDREPLACE_FAIL(CDERR_INITIALIZATION);
87 pFr = &fr;
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;
106 strcpy(findbuffer, "abc");
108 /* invalid lpstrReplaceWith (NULL) for ReplaceText */
109 CHECK_FIND_SUCCEED();
110 CHECK_REPLACE_FAIL(FRERR_BUFFERLENGTHZERO);
111 fr.lpstrReplaceWith = replacebuffer;
112 strcpy(replacebuffer, "def");
114 /* wReplaceWithLen may be 0, even for ReplaceText */
115 CHECK_FIND_SUCCEED();
116 CHECK_REPLACE_SUCCEED();
117 fr.wReplaceWithLen = sizeof(replacebuffer);
119 /* invalid lpfnHook (NULL) when Flags has FR_ENABLEHOOK */
120 fr.Flags = FR_ENABLEHOOK;
121 CHECK_FINDREPLACE_FAIL(CDERR_NOHOOK);
123 /* invalid hInstance (NULL)
124 * when Flags has FR_ENABLETEMPLATE or FR_ENABLETEMPLATEHANDLE */
125 fr.Flags = FR_ENABLETEMPLATE;
126 CHECK_FINDREPLACE_FAIL(CDERR_FINDRESFAILURE);
127 fr.Flags = FR_ENABLETEMPLATEHANDLE;
128 CHECK_FINDREPLACE_FAIL(CDERR_NOHINSTANCE);
129 fr.hInstance = GetModuleHandle(NULL);
131 /* invalid lpTemplateName (NULL) when Flags has FR_ENABLETEMPLATE */
132 fr.Flags = FR_ENABLETEMPLATE;
133 CHECK_FINDREPLACE_FAIL(CDERR_FINDRESFAILURE);
134 fr.Flags = 0;
136 CHECK_FIND_SUCCEED();
137 CHECK_REPLACE_SUCCEED();
139 DestroyWindow(fr.hwndOwner);
142 START_TEST(finddlg)
144 ID_FINDMSGSTRING = RegisterWindowMessageA(FINDMSGSTRINGA);
146 test_param_check();