From: Tarcísio Ladeia de Oliveirawyrquill@gmail.com
Add new variables to be used as function parameters in the tests. They consist on the SHDRAGIMAGE instance, used for initialization, the bitmap it requires, as well as a window (for InitializeFromWindow()), IDragSourceHelper2 pointer, POINT instance, among others.
Release the dynamically allocated variables as soon as possible (as in the case of the device contexts used) or at the end of the test.
Signed-off-by: Tarcísio Ladeia de Oliveira wyrquill@gmail.com --- dlls/shell32/tests/shellole.c | 101 +++++++++++++++++++++++++++++++++- 1 file changed, 99 insertions(+), 2 deletions(-)
diff --git a/dlls/shell32/tests/shellole.c b/dlls/shell32/tests/shellole.c index 316adb5294d..abc63016b76 100644 --- a/dlls/shell32/tests/shellole.c +++ b/dlls/shell32/tests/shellole.c @@ -1181,20 +1181,117 @@ static IDataObject data_object = { &dataobject_vtbl };
static IDataObject data_object_notimpl = { &dataobject_vtbl_notimpl };
+static SHDRAGIMAGE drag_image; + +static LRESULT WINAPI drag_helper_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) +{ + const UINT di_msg = RegisterWindowMessageA(DI_GETDRAGIMAGEA); + + if (msg == di_msg) + { + SHDRAGIMAGE* tmp = (SHDRAGIMAGE*)lparam; + *tmp = drag_image; + return 0; + } + + return DefWindowProcA(hwnd, msg, wparam, lparam); +} + static void test_dragdrophelper(void) { IDragSourceHelper *dragsource; + IDragSourceHelper2 *dragsource2; IDropTargetHelper *target; + WNDCLASSA cls; + POINT pt; + HWND hwnd_target; + HDC dc, comp_dc; + RECT rect; + HBITMAP bitmap, b_old; + HBRUSH brush; + SHDRAGIMAGE di_empty; + DWORD i; HRESULT hr;
+ /* Initialize variables and window */ + + pt.x = 50; + pt.y = 50; + + memset(&cls, 0, sizeof(cls)); + cls.lpfnWndProc = drag_helper_proc; + cls.hInstance = GetModuleHandleA(NULL); + cls.lpszClassName = "drag helper test"; + RegisterClassA(&cls); + + hwnd_target = CreateWindowA("drag helper test", NULL, 0, 0, 200, 200, 0, + NULL, 0, NULL, 0); + ok(hwnd_target != NULL, "CreateWindow failed: %lx\n", GetLastError()); + + dc = GetDC(hwnd_target); + ok(dc != NULL, "Failed to get device context\n"); + + comp_dc = CreateCompatibleDC(dc); + ok(comp_dc != NULL, "Failed to create compatible device context\n"); + + memset(&di_empty, 0, sizeof(di_empty)); + + drag_image.sizeDragImage.cx = 4; + drag_image.sizeDragImage.cy = 4; + drag_image.ptOffset.x = 4; + drag_image.ptOffset.y = 4; + drag_image.crColorKey = 0x00000000; + drag_image.hbmpDragImage = 0; + bitmap = CreateCompatibleBitmap(dc, 4, 4); + ok(bitmap != NULL, "Failed to create bitmap\n"); + + b_old = (HBITMAP)SelectObject(comp_dc, bitmap); + ok(b_old != NULL && b_old != HGDI_ERROR, "Failed to select object: %p\n", b_old); + + brush = CreateSolidBrush(0x00000000); + ok(brush != NULL, "Failed to create black brush: %p", brush); + + rect.left = rect.top = 0; + rect.right = 4; + rect.bottom = 4; + hr = FillRect(comp_dc, &rect, brush); + ok(hr != 0, "Failed to fill black rect."); + + DeleteObject(brush); + rect.right = 2; + rect.bottom = 2; + brush = CreateSolidBrush(0x000000FF); + ok(brush != NULL, "Failed to create red brush: %p", brush); + hr = FillRect(comp_dc, &rect, brush); + ok(hr != 0, "Failed to fill red rect."); + DeleteObject(brush); + + SelectObject(comp_dc, b_old); + + ReleaseDC(hwnd_target, dc); + DeleteDC(comp_dc); + hr = CoCreateInstance(&CLSID_DragDropHelper, NULL, CLSCTX_INPROC_SERVER, &IID_IDropTargetHelper, (void **)&target); - ok(hr == S_OK, "Failed to create IDropTargetHelper, %#lx\n", hr); + ok(hr == S_OK, "Failed to create IDropTargetHelper, 0x%lx\n", hr);
hr = IDropTargetHelper_QueryInterface(target, &IID_IDragSourceHelper, (void **)&dragsource); - ok(hr == S_OK, "QI failed, %#lx\n", hr); + ok(hr == S_OK, "QI failed, 0x%lx\n", hr); + + hr = IDropTargetHelper_QueryInterface(target, &IID_IDragSourceHelper, (void **)&dragsource2); + ok(hr == S_OK, "QI 2 failed, 0x%lx\n", hr); + + /* Clean up */ + + IDragSourceHelper2_Release(dragsource2); + IDragSourceHelper_Release(dragsource);
IDropTargetHelper_Release(target); + + DeleteObject(bitmap); + + DestroyWindow(hwnd_target); + UnregisterClassA("drag helper test", GetModuleHandleA(NULL)); }
START_TEST(shellole)