animate.c 4.99 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
/* Unit tests for the animate control.
 *
 * Copyright 2016 Bruno Jesus
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 */

#include <stdarg.h>

#include "windef.h"
#include "winbase.h"
#include "wingdi.h"
#include "winuser.h"
#include "commctrl.h"

#include "wine/test.h"

#define SEARCHING_AVI_INDEX 151 /* From shell32 resource library */
#define INVALID_AVI_INDEX 0xffff

static HWND hAnimateParentWnd, hAnimateWnd;
static const char animateTestClass[] = "AnimateTestClass";
static WNDPROC animate_wndproc;
static HANDLE shell32;

/* try to make sure pending X events have been processed before continuing */
static void flush_events(void)
{
    MSG msg;
    int diff = 100;
    DWORD time = GetTickCount() + diff;

    while (diff > 0)
    {
        if (MsgWaitForMultipleObjects( 0, NULL, FALSE, min(10,diff), QS_ALLINPUT ) == WAIT_TIMEOUT) break;
        while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessageA( &msg );
        diff = time - GetTickCount();
    }
}

static LRESULT CALLBACK animate_test_wnd_proc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    switch(msg)
    {
        case WM_DESTROY:
            PostQuitMessage(0);
            break;

        default:
            return DefWindowProcA(hWnd, msg, wParam, lParam);
    }
    return 0L;
}

static void update_window(HWND hWnd)
{
    UpdateWindow(hWnd);
    ok(!GetUpdateRect(hWnd, NULL, FALSE), "GetUpdateRect must return zero after UpdateWindow\n");
}

static void create_animate(DWORD parent_style, DWORD animate_style)
{
    WNDCLASSA wc;
    RECT rect;
    BOOL ret;

    wc.style = CS_HREDRAW | CS_VREDRAW;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hInstance = GetModuleHandleA(NULL);
    wc.hIcon = NULL;
    wc.hCursor = LoadCursorA(NULL, (LPCSTR)IDC_ARROW);
    wc.hbrBackground = GetSysColorBrush(COLOR_WINDOW);
    wc.lpszMenuName = NULL;
    wc.lpszClassName = animateTestClass;
    wc.lpfnWndProc = animate_test_wnd_proc;
    RegisterClassA(&wc);

91
    SetRect(&rect, 0, 0, 200, 200);
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
    ret = AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW, FALSE);
    ok(ret, "got %d\n", ret);

    hAnimateParentWnd = CreateWindowExA(0, animateTestClass, "Animate Test", WS_OVERLAPPEDWINDOW | parent_style,
      CW_USEDEFAULT, CW_USEDEFAULT, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, GetModuleHandleA(NULL), 0);
    ok(hAnimateParentWnd != NULL, "failed to create parent wnd\n");

    GetClientRect(hAnimateParentWnd, &rect);
    hAnimateWnd = CreateWindowExA(0, ANIMATE_CLASSA, NULL, WS_CHILD | WS_VISIBLE | animate_style,
      0, 0, rect.right, rect.bottom, hAnimateParentWnd, NULL, shell32, 0);
    ok(hAnimateWnd != NULL, "failed to create parent wnd\n");
    animate_wndproc = (WNDPROC)SetWindowLongPtrA(hAnimateWnd, GWLP_WNDPROC, 0);

    ShowWindow(hAnimateParentWnd, SW_SHOWNORMAL);
    ok(GetUpdateRect(hAnimateParentWnd, NULL, FALSE), "GetUpdateRect: There should be a region that needs to be updated\n");
    flush_events();
    update_window(hAnimateParentWnd);
}

static void destroy_animate(void)
{
    MSG msg;

    PostMessageA(hAnimateParentWnd, WM_CLOSE, 0, 0);
    while (GetMessageA(&msg,0,0,0))
    {
        TranslateMessage(&msg);
        DispatchMessageA(&msg);
    }
    hAnimateParentWnd = NULL;
}

static void cleanup(void)
{
    UnregisterClassA(animateTestClass, GetModuleHandleA(NULL));
}

static void test_play(void)
{
    LONG res;
    DWORD err;

    create_animate(0, 0);
    SetLastError(0xdeadbeef);
    res = SendMessageA(hAnimateWnd, ACM_OPENA,(WPARAM)shell32, MAKEINTRESOURCE(INVALID_AVI_INDEX));
    err = GetLastError();
    ok(res == 0, "Invalid video should have failed\n");
    ok(err == ERROR_RESOURCE_NAME_NOT_FOUND, "Expected 1814, got %u\n", err);

    SetLastError(0xdeadbeef);
    res = SendMessageA(hAnimateWnd, ACM_PLAY, (WPARAM) -1, MAKELONG(0, -1));
143
    err = GetLastError();
144
    ok(res == 0, "Play should have failed\n");
145
    ok(err == 0xdeadbeef, "Expected 0xdeadbeef, got %u\n", err);
146 147 148 149 150 151 152 153 154 155 156 157
    destroy_animate();

    create_animate(0, 0);
    res = SendMessageA(hAnimateWnd, ACM_OPENA,(WPARAM)shell32, MAKEINTRESOURCE(SEARCHING_AVI_INDEX));
    ok(res != 0, "Load AVI resource failed\n");
    res = SendMessageA(hAnimateWnd, ACM_PLAY, (WPARAM) -1, MAKELONG(0, -1));
    ok(res != 0, "Play should have worked\n");
    destroy_animate();
}

START_TEST(animate)
{
158
    shell32 = LoadLibraryA("Shell32.dll");
159 160 161 162 163

    test_play();

    cleanup();
}