2010-01-20 12:37:15 +01:00
|
|
|
/*
|
|
|
|
* Unit tests for fiber functions
|
|
|
|
*
|
|
|
|
* Copyright (c) 2010 André Hentschel
|
|
|
|
*
|
|
|
|
* 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 "wine/test.h"
|
|
|
|
|
|
|
|
static LPVOID (WINAPI *pCreateFiber)(SIZE_T,LPFIBER_START_ROUTINE,LPVOID);
|
|
|
|
static LPVOID (WINAPI *pConvertThreadToFiber)(LPVOID);
|
|
|
|
static BOOL (WINAPI *pConvertFiberToThread)(void);
|
|
|
|
static void (WINAPI *pSwitchToFiber)(LPVOID);
|
|
|
|
static void (WINAPI *pDeleteFiber)(LPVOID);
|
2010-01-24 16:30:16 +01:00
|
|
|
static LPVOID (WINAPI *pConvertThreadToFiberEx)(LPVOID,DWORD);
|
|
|
|
static LPVOID (WINAPI *pCreateFiberEx)(SIZE_T,SIZE_T,DWORD,LPFIBER_START_ROUTINE,LPVOID);
|
2010-01-24 16:30:36 +01:00
|
|
|
static BOOL (WINAPI *pIsThreadAFiber)(void);
|
2010-01-24 16:30:49 +01:00
|
|
|
static DWORD (WINAPI *pFlsAlloc)(PFLS_CALLBACK_FUNCTION);
|
|
|
|
static BOOL (WINAPI *pFlsFree)(DWORD);
|
|
|
|
static PVOID (WINAPI *pFlsGetValue)(DWORD);
|
|
|
|
static BOOL (WINAPI *pFlsSetValue)(DWORD,PVOID);
|
2010-01-20 12:37:15 +01:00
|
|
|
|
|
|
|
static LPVOID fibers[2];
|
2010-01-24 16:29:30 +01:00
|
|
|
static BYTE testparam = 185;
|
2010-01-24 16:31:02 +01:00
|
|
|
static WORD cbCount;
|
2010-01-20 12:37:15 +01:00
|
|
|
|
2010-01-24 16:29:30 +01:00
|
|
|
static VOID init_funcs(void)
|
2010-01-20 12:37:15 +01:00
|
|
|
{
|
2013-10-21 10:01:46 +02:00
|
|
|
HMODULE hKernel32 = GetModuleHandleA("kernel32.dll");
|
2010-01-20 12:37:15 +01:00
|
|
|
|
2010-01-24 16:29:30 +01:00
|
|
|
#define X(f) p##f = (void*)GetProcAddress(hKernel32, #f);
|
2010-01-20 12:37:15 +01:00
|
|
|
X(CreateFiber);
|
|
|
|
X(ConvertThreadToFiber);
|
|
|
|
X(ConvertFiberToThread);
|
|
|
|
X(SwitchToFiber);
|
|
|
|
X(DeleteFiber);
|
2010-01-24 16:30:16 +01:00
|
|
|
X(ConvertThreadToFiberEx);
|
|
|
|
X(CreateFiberEx);
|
2010-01-24 16:30:36 +01:00
|
|
|
X(IsThreadAFiber);
|
2010-01-24 16:30:49 +01:00
|
|
|
X(FlsAlloc);
|
|
|
|
X(FlsFree);
|
|
|
|
X(FlsGetValue);
|
|
|
|
X(FlsSetValue);
|
2010-01-20 12:37:15 +01:00
|
|
|
#undef X
|
|
|
|
}
|
|
|
|
|
2010-01-24 16:30:49 +01:00
|
|
|
static VOID WINAPI FiberLocalStorageProc(PVOID lpFlsData)
|
|
|
|
{
|
2010-01-24 16:31:02 +01:00
|
|
|
cbCount++;
|
2010-01-24 16:30:49 +01:00
|
|
|
ok(lpFlsData == (PVOID) 1587, "FlsData expected not to be changed\n");
|
|
|
|
}
|
|
|
|
|
2010-01-20 12:37:15 +01:00
|
|
|
static VOID WINAPI FiberMainProc(LPVOID lpFiberParameter)
|
|
|
|
{
|
|
|
|
BYTE *tparam = (BYTE *)lpFiberParameter;
|
2010-01-24 16:31:02 +01:00
|
|
|
cbCount++;
|
2010-01-24 16:29:30 +01:00
|
|
|
ok(*tparam == 185, "Parameterdata expected not to be changed\n");
|
2010-01-20 12:37:15 +01:00
|
|
|
pSwitchToFiber(fibers[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_ConvertThreadToFiber(void)
|
|
|
|
{
|
2010-01-24 16:29:30 +01:00
|
|
|
if (pConvertThreadToFiber)
|
|
|
|
{
|
|
|
|
fibers[0] = pConvertThreadToFiber(&testparam);
|
|
|
|
ok(fibers[0] != 0, "ConvertThreadToFiber failed with error %d\n", GetLastError());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
win_skip( "ConvertThreadToFiber not present\n" );
|
|
|
|
}
|
2010-01-20 12:37:15 +01:00
|
|
|
}
|
|
|
|
|
2010-01-24 16:30:16 +01:00
|
|
|
static void test_ConvertThreadToFiberEx(void)
|
|
|
|
{
|
|
|
|
if (pConvertThreadToFiberEx)
|
|
|
|
{
|
|
|
|
fibers[0] = pConvertThreadToFiberEx(&testparam, 0);
|
|
|
|
ok(fibers[0] != 0, "ConvertThreadToFiberEx failed with error %d\n", GetLastError());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
win_skip( "ConvertThreadToFiberEx not present\n" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-20 12:37:15 +01:00
|
|
|
static void test_ConvertFiberToThread(void)
|
|
|
|
{
|
2010-01-24 16:29:30 +01:00
|
|
|
if (pConvertFiberToThread)
|
|
|
|
{
|
2011-01-11 20:30:00 +01:00
|
|
|
BOOL ret = pConvertFiberToThread();
|
|
|
|
ok(ret, "ConvertFiberToThread failed with error %d\n", GetLastError());
|
2010-01-24 16:29:30 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
win_skip( "ConvertFiberToThread not present\n" );
|
|
|
|
}
|
2010-01-20 12:37:15 +01:00
|
|
|
}
|
|
|
|
|
2010-01-24 16:30:16 +01:00
|
|
|
static void test_FiberHandling(void)
|
2010-01-20 12:37:15 +01:00
|
|
|
{
|
2010-01-24 16:31:02 +01:00
|
|
|
cbCount = 0;
|
2010-01-24 16:30:16 +01:00
|
|
|
fibers[0] = pCreateFiber(0,FiberMainProc,&testparam);
|
|
|
|
ok(fibers[0] != 0, "CreateFiber failed with error %d\n", GetLastError());
|
|
|
|
pDeleteFiber(fibers[0]);
|
|
|
|
|
|
|
|
test_ConvertThreadToFiber();
|
|
|
|
test_ConvertFiberToThread();
|
|
|
|
if (pConvertThreadToFiberEx)
|
|
|
|
test_ConvertThreadToFiberEx();
|
|
|
|
else
|
|
|
|
test_ConvertThreadToFiber();
|
|
|
|
|
|
|
|
|
2010-01-20 12:37:15 +01:00
|
|
|
fibers[1] = pCreateFiber(0,FiberMainProc,&testparam);
|
|
|
|
ok(fibers[1] != 0, "CreateFiber failed with error %d\n", GetLastError());
|
|
|
|
|
|
|
|
pSwitchToFiber(fibers[1]);
|
2010-01-24 16:31:02 +01:00
|
|
|
ok(cbCount == 1, "Wrong callback count: %d\n", cbCount);
|
2010-01-20 12:37:15 +01:00
|
|
|
pDeleteFiber(fibers[1]);
|
2010-01-24 16:30:16 +01:00
|
|
|
|
|
|
|
if (!pCreateFiberEx)
|
|
|
|
{
|
|
|
|
win_skip( "CreateFiberEx not present\n" );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-03-01 17:08:06 +01:00
|
|
|
SetLastError(0xdeadbeef);
|
2010-01-24 16:30:16 +01:00
|
|
|
fibers[1] = pCreateFiberEx(0,0,0,FiberMainProc,&testparam);
|
|
|
|
ok(fibers[1] != 0, "CreateFiberEx failed with error %d\n", GetLastError());
|
|
|
|
|
|
|
|
pSwitchToFiber(fibers[1]);
|
2010-01-24 16:31:02 +01:00
|
|
|
ok(cbCount == 2, "Wrong callback count: %d\n", cbCount);
|
2010-01-24 16:30:16 +01:00
|
|
|
pDeleteFiber(fibers[1]);
|
2010-01-24 16:30:36 +01:00
|
|
|
|
|
|
|
if (!pIsThreadAFiber)
|
|
|
|
{
|
2010-01-24 16:31:19 +01:00
|
|
|
win_skip( "IsThreadAFiber not present\n" );
|
2010-01-24 16:30:36 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ok(pIsThreadAFiber(), "IsThreadAFiber reported FALSE\n");
|
|
|
|
test_ConvertFiberToThread();
|
|
|
|
ok(!pIsThreadAFiber(), "IsThreadAFiber reported TRUE\n");
|
2010-01-20 12:37:15 +01:00
|
|
|
}
|
|
|
|
|
2010-01-24 16:30:49 +01:00
|
|
|
static void test_FiberLocalStorage(PFLS_CALLBACK_FUNCTION cbfunc)
|
|
|
|
{
|
|
|
|
DWORD fls;
|
|
|
|
BOOL ret;
|
|
|
|
PVOID val = (PVOID) 1587;
|
|
|
|
|
|
|
|
if (!pFlsAlloc)
|
|
|
|
{
|
|
|
|
win_skip( "Fiber Local Storage not supported\n" );
|
|
|
|
return;
|
|
|
|
}
|
2010-01-24 16:31:02 +01:00
|
|
|
cbCount = 0;
|
2010-01-24 16:30:49 +01:00
|
|
|
|
|
|
|
fls = pFlsAlloc(cbfunc);
|
|
|
|
ok(fls != FLS_OUT_OF_INDEXES, "FlsAlloc failed with error %d\n", GetLastError());
|
|
|
|
|
|
|
|
ret = pFlsSetValue(fls, val);
|
|
|
|
ok(ret, "FlsSetValue failed\n");
|
|
|
|
ok(val == pFlsGetValue(fls), "FlsGetValue failed\n");
|
|
|
|
|
|
|
|
ret = pFlsFree(fls);
|
|
|
|
ok(ret, "FlsFree failed\n");
|
2010-01-24 16:31:02 +01:00
|
|
|
if (cbfunc)
|
|
|
|
todo_wine ok(cbCount == 1, "Wrong callback count: %d\n", cbCount);
|
2010-01-24 16:30:49 +01:00
|
|
|
}
|
|
|
|
|
2010-01-20 12:37:15 +01:00
|
|
|
START_TEST(fiber)
|
|
|
|
{
|
2010-01-24 16:29:30 +01:00
|
|
|
init_funcs();
|
|
|
|
|
|
|
|
if (!pCreateFiber)
|
2010-01-20 12:37:15 +01:00
|
|
|
{
|
2010-01-24 16:29:30 +01:00
|
|
|
win_skip( "Fibers not supported by win95\n" );
|
2010-01-20 12:37:15 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-01-24 16:30:16 +01:00
|
|
|
test_FiberHandling();
|
2010-01-24 16:30:49 +01:00
|
|
|
test_FiberLocalStorage(NULL);
|
|
|
|
test_FiberLocalStorage(FiberLocalStorageProc);
|
2010-01-20 12:37:15 +01:00
|
|
|
}
|