timer.c 2.27 KB
Newer Older
Mike McCormack's avatar
Mike McCormack committed
1
/*
2
 * Unit test suite for timer functions
Mike McCormack's avatar
Mike McCormack committed
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
 *
 * Copyright 2004 Mike McCormack
 *
 * 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
18
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
Mike McCormack's avatar
Mike McCormack committed
19 20
 */

21 22
#define _WIN32_WINNT 0x0501

Mike McCormack's avatar
Mike McCormack committed
23 24 25 26
#include "wine/test.h"
#include "winbase.h"


27
static void test_timer(void)
Mike McCormack's avatar
Mike McCormack committed
28
{
29 30
    HANDLE (WINAPI *pCreateWaitableTimerA)( SECURITY_ATTRIBUTES*, BOOL, LPSTR );
    BOOL (WINAPI *pSetWaitableTimer)(HANDLE, LARGE_INTEGER*, LONG, PTIMERAPCROUTINE, LPVOID, BOOL);
Mike McCormack's avatar
Mike McCormack committed
31 32 33 34 35
    HMODULE hker = GetModuleHandle("kernel32");
    HANDLE handle;
    BOOL r;
    LARGE_INTEGER due;

36
    pCreateWaitableTimerA = (void*)GetProcAddress( hker, "CreateWaitableTimerA");
Mike McCormack's avatar
Mike McCormack committed
37
    if( !pCreateWaitableTimerA )
38
    {
39
        win_skip("CreateWaitableTimerA is not available\n");
Mike McCormack's avatar
Mike McCormack committed
40
        return;
41
    }
Mike McCormack's avatar
Mike McCormack committed
42

43
    pSetWaitableTimer = (void*)GetProcAddress( hker, "SetWaitableTimer");
Mike McCormack's avatar
Mike McCormack committed
44
    if( !pSetWaitableTimer )
45
    {
46
        win_skip("SetWaitableTimer is not available\n");
Mike McCormack's avatar
Mike McCormack committed
47
        return;
48
    }
Mike McCormack's avatar
Mike McCormack committed
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
       
    /* try once with a positive number */
    handle = pCreateWaitableTimerA( NULL, 0, NULL );
    ok( handle != NULL, "failed to create waitable timer with no name\n" );

    due.QuadPart = 10000;
    r = pSetWaitableTimer( handle, &due, 0x1f4, NULL, NULL, FALSE ); 
    ok( r, "failed to set timer\n");

    CloseHandle( handle );

    /* try once with a negative number */
    handle = pCreateWaitableTimerA( NULL, 0, NULL );
    ok( handle != NULL, "failed to create waitable timer with no name\n" );

    due.QuadPart = -10000;
    r = pSetWaitableTimer( handle, &due, 0x1f4, NULL, NULL, FALSE ); 
    ok( r, "failed to set timer\n");

    CloseHandle( handle );
}

START_TEST(timer)
{
    test_timer();
}