[KERNEL32_WINETEST]

* Sync with Wine 1.7.1.

svn path=/trunk/; revision=60032
This commit is contained in:
Amine Khaldi 2013-09-11 11:32:57 +00:00
parent 5424614ddc
commit c6cea14cef
17 changed files with 3061 additions and 345 deletions

View file

@ -16,7 +16,7 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include "wine/test.h"
#include <wine/test.h>
#include <winbase.h>
#include <windef.h>
#include <winnt.h>
@ -24,6 +24,9 @@
#include <winnls.h>
#include <stdio.h>
#include <oaidl.h>
#include <initguid.h>
static BOOL (WINAPI *pActivateActCtx)(HANDLE,ULONG_PTR*);
static HANDLE (WINAPI *pCreateActCtxW)(PCACTCTXW);
static BOOL (WINAPI *pDeactivateActCtx)(DWORD,ULONG_PTR);
@ -32,6 +35,7 @@ static BOOL (WINAPI *pGetCurrentActCtx)(HANDLE *);
static BOOL (WINAPI *pIsDebuggerPresent)(void);
static BOOL (WINAPI *pQueryActCtxW)(DWORD,HANDLE,PVOID,ULONG,PVOID,SIZE_T,SIZE_T*);
static VOID (WINAPI *pReleaseActCtx)(HANDLE);
static BOOL (WINAPI *pFindActCtxSectionGuid)(DWORD,const GUID*,ULONG,const GUID*,PACTCTX_SECTION_KEYED_DATA);
static const char* strw(LPCWSTR x)
{
@ -43,6 +47,18 @@ static const char* strw(LPCWSTR x)
return buffer;
}
static const char *debugstr_guid(REFIID riid)
{
static char buf[50];
sprintf(buf, "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
riid->Data1, riid->Data2, riid->Data3, riid->Data4[0],
riid->Data4[1], riid->Data4[2], riid->Data4[3], riid->Data4[4],
riid->Data4[5], riid->Data4[6], riid->Data4[7]);
return buf;
}
#ifdef __i386__
#define ARCH "x86"
#elif defined __x86_64__
@ -68,15 +84,72 @@ static const char manifest2[] =
"</dependency>"
"</assembly>";
DEFINE_GUID(IID_CoTest, 0x12345678, 0x1234, 0x5678, 0x12, 0x34, 0x11, 0x11, 0x22, 0x22, 0x33, 0x33);
DEFINE_GUID(IID_TlibTest, 0x99999999, 0x8888, 0x7777, 0x66, 0x66, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55);
DEFINE_GUID(IID_TlibTest2, 0x99999999, 0x8888, 0x7777, 0x66, 0x66, 0x55, 0x55, 0x55, 0x55, 0x55, 0x56);
DEFINE_GUID(IID_TlibTest3, 0x99999999, 0x8888, 0x7777, 0x66, 0x66, 0x55, 0x55, 0x55, 0x55, 0x55, 0x57);
DEFINE_GUID(IID_TlibTest4, 0x99999999, 0x8888, 0x7777, 0x66, 0x66, 0x55, 0x55, 0x55, 0x55, 0x55, 0x58);
static const char manifest3[] =
"<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
"<assemblyIdentity version=\"1.2.3.4\" name=\"Wine.Test\" type=\"win32\""
" publicKeyToken=\"6595b6414666f1df\" />"
"<file name=\"testlib.dll\">"
"<windowClass>wndClass</windowClass>"
" <comClass description=\"Test com class\""
" clsid=\"{12345678-1234-5678-1234-111122223333}\""
" tlbid=\"{99999999-8888-7777-6666-555555555555}\""
" threadingModel=\"Neutral\""
" progid=\"ProgId.ProgId\""
" miscStatus=\"cantlinkinside\""
" miscStatusIcon=\"recomposeonresize\""
" miscStatusContent=\"insideout\""
" miscStatusThumbnail=\"alignable\""
" miscStatusDocPrint=\"simpleframe,setclientsitefirst\""
" />"
"</file>"
"</assembly>";
static const char manifest_wndcls1[] =
"<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
"<assemblyIdentity version=\"1.2.3.4\" name=\"testdep1\" type=\"win32\" processorArchitecture=\"" ARCH "\"/>"
"<file name=\"testlib1.dll\">"
"<windowClass versioned=\"yes\">wndClass1</windowClass>"
"<windowClass>wndClass2</windowClass>"
" <typelib tlbid=\"{99999999-8888-7777-6666-555555555558}\" version=\"1.0\" helpdir=\"\" />"
"</file>"
"<file name=\"testlib1_2.dll\" />"
"</assembly>";
static const char manifest_wndcls2[] =
"<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
"<assemblyIdentity version=\"4.3.2.1\" name=\"testdep2\" type=\"win32\" processorArchitecture=\"" ARCH "\" />"
"<file name=\"testlib2.dll\">"
" <windowClass versioned=\"no\">wndClass3</windowClass>"
" <windowClass>wndClass4</windowClass>"
" <typelib tlbid=\"{99999999-8888-7777-6666-555555555555}\" version=\"1.0\" helpdir=\"help\" resourceid=\"409\""
" flags=\"HIDDEN,CONTROL,RESTRICTED\" />"
" <typelib tlbid=\"{99999999-8888-7777-6666-555555555556}\" version=\"1.0\" helpdir=\"help1\" resourceid=\"409\" />"
" <typelib tlbid=\"{99999999-8888-7777-6666-555555555557}\" version=\"1.0\" helpdir=\"\" />"
"</file>"
"<file name=\"testlib2_2.dll\" />"
"</assembly>";
static const char manifest_wndcls_main[] =
"<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
"<assemblyIdentity version=\"1.2.3.4\" name=\"Wine.Test\" type=\"win32\" />"
"<dependency>"
" <dependentAssembly>"
" <assemblyIdentity type=\"win32\" name=\"testdep1\" version=\"1.2.3.4\" processorArchitecture=\"" ARCH "\" />"
" </dependentAssembly>"
"</dependency>"
"<dependency>"
" <dependentAssembly>"
" <assemblyIdentity type=\"win32\" name=\"testdep2\" version=\"4.3.2.1\" processorArchitecture=\"" ARCH "\" />"
" </dependentAssembly>"
"</dependency>"
"</assembly>";
static const char manifest4[] =
"<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
"<assemblyIdentity version=\"1.2.3.4\" name=\"Wine.Test\" type=\"win32\">"
@ -167,8 +240,12 @@ static const WCHAR testlib2_dll[] =
{'t','e','s','t','l','i','b','2','.','d','l','l',0};
static const WCHAR wndClassW[] =
{'w','n','d','C','l','a','s','s',0};
static const WCHAR wndClass1W[] =
{'w','n','d','C','l','a','s','s','1',0};
static const WCHAR wndClass2W[] =
{'w','n','d','C','l','a','s','s','2',0};
static const WCHAR wndClass3W[] =
{'w','n','d','C','l','a','s','s','3',0};
static const WCHAR acr_manifest[] =
{'a','c','r','.','m','a','n','i','f','e','s','t',0};
@ -576,7 +653,7 @@ static void test_file_info(HANDLE handle, ULONG assid, ULONG fileid, LPCWSTR fil
HeapFree(GetProcessHeap(), 0, info);
}
static HANDLE test_create(const char *file, const char *manifest)
static HANDLE test_create(const char *file)
{
ACTCTXW actctx;
HANDLE handle;
@ -693,10 +770,80 @@ static void test_create_fail(void)
test_create_and_fail(manifest2, wrong_depmanifest1, 0 );
}
struct strsection_header
{
DWORD magic;
ULONG size;
DWORD unk1[3];
ULONG count;
ULONG index_offset;
DWORD unk2[4];
};
struct string_index
{
ULONG hash;
ULONG name_offset;
ULONG name_len;
ULONG data_offset;
ULONG data_len;
ULONG rosterindex;
};
struct guidsection_header
{
DWORD magic;
ULONG size;
DWORD unk[3];
ULONG count;
ULONG index_offset;
DWORD unk2;
ULONG names_offset;
ULONG names_len;
};
struct guid_index
{
GUID guid;
ULONG data_offset;
ULONG data_len;
ULONG rosterindex;
};
struct wndclass_redirect_data
{
ULONG size;
DWORD res;
ULONG name_len;
ULONG name_offset; /* versioned name offset */
ULONG module_len;
ULONG module_offset;/* container name offset */
};
struct dllredirect_data
{
ULONG size;
ULONG unk;
DWORD res[3];
};
struct tlibredirect_data
{
ULONG size;
DWORD res;
ULONG name_len;
ULONG name_offset;
LANGID langid;
WORD flags;
ULONG help_len;
ULONG help_offset;
WORD major_version;
WORD minor_version;
};
static void test_find_dll_redirection(HANDLE handle, LPCWSTR libname, ULONG exid, int line)
{
ACTCTX_SECTION_KEYED_DATA data;
DWORD *p;
BOOL ret;
memset(&data, 0xfe, sizeof(data));
@ -706,29 +853,29 @@ static void test_find_dll_redirection(HANDLE handle, LPCWSTR libname, ULONG exid
ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION,
libname, &data);
ok_(__FILE__, line)(ret, "FindActCtxSectionStringW failed: %u\n", GetLastError());
if(!ret)
{
skip("couldn't find %s\n",strw(libname));
return;
}
if (!ret) return;
ok_(__FILE__, line)(data.cbSize == sizeof(data), "data.cbSize=%u\n", data.cbSize);
ok_(__FILE__, line)(data.ulDataFormatVersion == 1, "data.ulDataFormatVersion=%u\n", data.ulDataFormatVersion);
ok_(__FILE__, line)(data.lpData != NULL, "data.lpData == NULL\n");
ok_(__FILE__, line)(data.ulLength == 20, "data.ulLength=%u\n", data.ulLength);
p = data.lpData;
if(ret && p) todo_wine {
ok_(__FILE__, line)(p[0] == 20 && p[1] == 2 && p[2] == 0 && p[3] == 0 && p[4] == 0,
"wrong data %u,%u,%u,%u,%u\n",p[0], p[1], p[2], p[3], p[4]);
if (data.lpData)
{
struct dllredirect_data *dlldata = (struct dllredirect_data*)data.lpData;
ok_(__FILE__, line)(dlldata->size == data.ulLength, "got wrong size %d\n", dlldata->size);
ok_(__FILE__, line)(dlldata->unk == 2, "got wrong field value %d\n", dlldata->unk);
ok_(__FILE__, line)(dlldata->res[0] == 0, "got wrong res[0] value %d\n", dlldata->res[0]);
ok_(__FILE__, line)(dlldata->res[1] == 0, "got wrong res[1] value %d\n", dlldata->res[1]);
ok_(__FILE__, line)(dlldata->res[2] == 0, "got wrong res[2] value %d\n", dlldata->res[2]);
}
ok_(__FILE__, line)(data.lpSectionGlobalData == NULL, "data.lpSectionGlobalData != NULL\n");
ok_(__FILE__, line)(data.ulSectionGlobalDataLength == 0, "data.ulSectionGlobalDataLength=%u\n",
data.ulSectionGlobalDataLength);
ok_(__FILE__, line)(data.lpSectionBase != NULL, "data.lpSectionBase == NULL\n");
/* ok_(__FILE__, line)(data.ulSectionTotalLength == ??, "data.ulSectionTotalLength=%u\n",
data.ulSectionTotalLength); */
ok_(__FILE__, line)(data.ulSectionTotalLength > 0, "data.ulSectionTotalLength=%u\n",
data.ulSectionTotalLength);
ok_(__FILE__, line)(data.hActCtx == NULL, "data.hActCtx=%p\n", data.hActCtx);
ok_(__FILE__, line)(data.ulAssemblyRosterIndex == exid, "data.ulAssemblyRosterIndex=%u, expected %u\n",
data.ulAssemblyRosterIndex, exid);
@ -740,11 +887,7 @@ static void test_find_dll_redirection(HANDLE handle, LPCWSTR libname, ULONG exid
ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION,
libname, &data);
ok_(__FILE__, line)(ret, "FindActCtxSectionStringW failed: %u\n", GetLastError());
if(!ret)
{
skip("couldn't find\n");
return;
}
if (!ret) return;
ok_(__FILE__, line)(data.cbSize == sizeof(data), "data.cbSize=%u\n", data.cbSize);
ok_(__FILE__, line)(data.ulDataFormatVersion == 1, "data.ulDataFormatVersion=%u\n", data.ulDataFormatVersion);
@ -754,8 +897,8 @@ static void test_find_dll_redirection(HANDLE handle, LPCWSTR libname, ULONG exid
ok_(__FILE__, line)(data.ulSectionGlobalDataLength == 0, "data.ulSectionGlobalDataLength=%u\n",
data.ulSectionGlobalDataLength);
ok_(__FILE__, line)(data.lpSectionBase != NULL, "data.lpSectionBase == NULL\n");
/* ok_(__FILE__, line)(data.ulSectionTotalLength == ?? , "data.ulSectionTotalLength=%u\n",
data.ulSectionTotalLength); */
ok_(__FILE__, line)(data.ulSectionTotalLength > 0, "data.ulSectionTotalLength=%u\n",
data.ulSectionTotalLength);
ok_(__FILE__, line)(data.hActCtx == handle, "data.hActCtx=%p\n", data.hActCtx);
ok_(__FILE__, line)(data.ulAssemblyRosterIndex == exid, "data.ulAssemblyRosterIndex=%u, expected %u\n",
data.ulAssemblyRosterIndex, exid);
@ -765,6 +908,8 @@ static void test_find_dll_redirection(HANDLE handle, LPCWSTR libname, ULONG exid
static void test_find_window_class(HANDLE handle, LPCWSTR clsname, ULONG exid, int line)
{
struct wndclass_redirect_data *wnddata;
struct strsection_header *header;
ACTCTX_SECTION_KEYED_DATA data;
BOOL ret;
@ -774,23 +919,60 @@ static void test_find_window_class(HANDLE handle, LPCWSTR clsname, ULONG exid, i
ret = pFindActCtxSectionStringW(0, NULL,
ACTIVATION_CONTEXT_SECTION_WINDOW_CLASS_REDIRECTION,
clsname, &data);
ok_(__FILE__, line)(ret, "FindActCtxSectionStringW failed: %u\n", GetLastError());
if(!ret)
{
skip("couldn't find\n");
return;
}
ok_(__FILE__, line)(ret, "FindActCtxSectionStringW failed: %u, class %s\n", GetLastError(),
wine_dbgstr_w(clsname));
if (!ret) return;
header = (struct strsection_header*)data.lpSectionBase;
wnddata = (struct wndclass_redirect_data*)data.lpData;
ok_(__FILE__, line)(header->magic == 0x64487353, "got wrong magic 0x%08x\n", header->magic);
ok_(__FILE__, line)(header->count > 0, "got count %d\n", header->count);
ok_(__FILE__, line)(data.cbSize == sizeof(data), "data.cbSize=%u\n", data.cbSize);
ok_(__FILE__, line)(data.ulDataFormatVersion == 1, "data.ulDataFormatVersion=%u\n", data.ulDataFormatVersion);
ok_(__FILE__, line)(data.lpData != NULL, "data.lpData == NULL\n");
/* ok_(__FILE__, line)(data.ulLength == ??, "data.ulLength=%u\n", data.ulLength); */
ok_(__FILE__, line)(wnddata->size == sizeof(*wnddata), "got %d for header size\n", wnddata->size);
if (data.lpData && wnddata->size == sizeof(*wnddata))
{
static const WCHAR verW[] = {'6','.','5','.','4','.','3','!',0};
WCHAR buff[50];
WCHAR *ptr;
ULONG len;
ok_(__FILE__, line)(wnddata->res == 0, "got reserved as %d\n", wnddata->res);
/* redirect class name (versioned or not) is stored just after header data */
ok_(__FILE__, line)(wnddata->name_offset == wnddata->size, "got name offset as %d\n", wnddata->name_offset);
ok_(__FILE__, line)(wnddata->module_len > 0, "got module name length as %d\n", wnddata->module_len);
/* expected versioned name */
lstrcpyW(buff, verW);
lstrcatW(buff, clsname);
ptr = (WCHAR*)((BYTE*)wnddata + wnddata->name_offset);
ok_(__FILE__, line)(!lstrcmpW(ptr, buff), "got wrong class name %s, expected %s\n", wine_dbgstr_w(ptr), wine_dbgstr_w(buff));
ok_(__FILE__, line)(lstrlenW(ptr)*sizeof(WCHAR) == wnddata->name_len,
"got wrong class name length %d, expected %d\n", wnddata->name_len, lstrlenW(ptr));
/* data length is simply header length + string data length including nulls */
len = wnddata->size + wnddata->name_len + wnddata->module_len + 2*sizeof(WCHAR);
ok_(__FILE__, line)(data.ulLength == len, "got wrong data length %d, expected %d\n", data.ulLength, len);
if (data.ulSectionTotalLength > wnddata->module_offset)
{
WCHAR *modulename, *sectionptr;
/* just compare pointers */
modulename = (WCHAR*)((BYTE*)wnddata + wnddata->size + wnddata->name_len + sizeof(WCHAR));
sectionptr = (WCHAR*)((BYTE*)data.lpSectionBase + wnddata->module_offset);
ok_(__FILE__, line)(modulename == sectionptr, "got wrong name offset %p, expected %p\n", sectionptr, modulename);
}
}
ok_(__FILE__, line)(data.lpSectionGlobalData == NULL, "data.lpSectionGlobalData != NULL\n");
ok_(__FILE__, line)(data.ulSectionGlobalDataLength == 0, "data.ulSectionGlobalDataLength=%u\n",
data.ulSectionGlobalDataLength);
ok_(__FILE__, line)(data.lpSectionBase != NULL, "data.lpSectionBase == NULL\n");
/* ok_(__FILE__, line)(data.ulSectionTotalLength == 0, "data.ulSectionTotalLength=%u\n",
data.ulSectionTotalLength); FIXME */
ok_(__FILE__, line)(data.ulSectionTotalLength > 0, "data.ulSectionTotalLength=%u\n",
data.ulSectionTotalLength);
ok_(__FILE__, line)(data.hActCtx == NULL, "data.hActCtx=%p\n", data.hActCtx);
ok_(__FILE__, line)(data.ulAssemblyRosterIndex == exid, "data.ulAssemblyRosterIndex=%u, expected %u\n",
data.ulAssemblyRosterIndex, exid);
@ -801,23 +983,19 @@ static void test_find_window_class(HANDLE handle, LPCWSTR clsname, ULONG exid, i
ret = pFindActCtxSectionStringW(FIND_ACTCTX_SECTION_KEY_RETURN_HACTCTX, NULL,
ACTIVATION_CONTEXT_SECTION_WINDOW_CLASS_REDIRECTION,
clsname, &data);
ok_(__FILE__, line)(ret, "FindActCtxSectionStringW failed: %u\n", GetLastError());
if(!ret)
{
skip("couldn't find\n");
return;
}
ok_(__FILE__, line)(ret, "FindActCtxSectionStringW failed: %u, class %s\n", GetLastError(),
wine_dbgstr_w(clsname));
if (!ret) return;
ok_(__FILE__, line)(data.cbSize == sizeof(data), "data.cbSize=%u\n", data.cbSize);
ok_(__FILE__, line)(data.ulDataFormatVersion == 1, "data.ulDataFormatVersion=%u\n", data.ulDataFormatVersion);
ok_(__FILE__, line)(data.lpData != NULL, "data.lpData == NULL\n");
/* ok_(__FILE__, line)(data.ulLength == ??, "data.ulLength=%u\n", data.ulLength); FIXME */
ok_(__FILE__, line)(data.ulLength > 0, "data.ulLength=%u\n", data.ulLength);
ok_(__FILE__, line)(data.lpSectionGlobalData == NULL, "data.lpSectionGlobalData != NULL\n");
ok_(__FILE__, line)(data.ulSectionGlobalDataLength == 0, "data.ulSectionGlobalDataLength=%u\n",
data.ulSectionGlobalDataLength);
ok_(__FILE__, line)(data.lpSectionBase != NULL, "data.lpSectionBase == NULL\n");
/* ok_(__FILE__, line)(data.ulSectionTotalLength == 0, "data.ulSectionTotalLength=%u\n",
data.ulSectionTotalLength); FIXME */
ok_(__FILE__, line)(data.ulSectionTotalLength > 0, "data.ulSectionTotalLength=%u\n", data.ulSectionTotalLength);
ok_(__FILE__, line)(data.hActCtx == handle, "data.hActCtx=%p\n", data.hActCtx);
ok_(__FILE__, line)(data.ulAssemblyRosterIndex == exid, "data.ulAssemblyRosterIndex=%u, expected %u\n",
data.ulAssemblyRosterIndex, exid);
@ -899,6 +1077,311 @@ static void test_basic_info(HANDLE handle, int line)
}
}
enum comclass_threadingmodel {
ThreadingModel_Apartment = 1,
ThreadingModel_Free = 2,
ThreadingModel_No = 3,
ThreadingModel_Both = 4,
ThreadingModel_Neutral = 5
};
enum comclass_miscfields {
MiscStatus = 1,
MiscStatusIcon = 2,
MiscStatusContent = 4,
MiscStatusThumbnail = 8,
MiscStatusDocPrint = 16
};
struct comclassredirect_data {
ULONG size;
BYTE res;
BYTE miscmask;
BYTE res1[2];
DWORD model;
GUID clsid;
GUID alias;
GUID clsid2;
GUID tlid;
ULONG name_len;
ULONG name_offset;
ULONG progid_len;
ULONG progid_offset;
DWORD res2[2];
DWORD miscstatus;
DWORD miscstatuscontent;
DWORD miscstatusthumbnail;
DWORD miscstatusicon;
DWORD miscstatusdocprint;
};
static void test_find_com_redirection(HANDLE handle, const GUID *clsid, const GUID *tlid, ULONG exid, int line)
{
struct comclassredirect_data *comclass, *comclass2;
ACTCTX_SECTION_KEYED_DATA data, data2;
BOOL ret;
memset(&data, 0xfe, sizeof(data));
data.cbSize = sizeof(data);
ret = pFindActCtxSectionGuid(0, NULL,
ACTIVATION_CONTEXT_SECTION_COM_SERVER_REDIRECTION,
clsid, &data);
ok_(__FILE__, line)(ret, "FindActCtxSectionGuid failed: %u\n", GetLastError());
comclass = (struct comclassredirect_data*)data.lpData;
ok_(__FILE__, line)(data.cbSize == sizeof(data), "data.cbSize=%u\n", data.cbSize);
ok_(__FILE__, line)(data.ulDataFormatVersion == 1, "data.ulDataFormatVersion=%u\n", data.ulDataFormatVersion);
ok_(__FILE__, line)(data.lpData != NULL, "data.lpData == NULL\n");
ok_(__FILE__, line)(comclass->size == sizeof(*comclass), "got %d for header size\n", comclass->size);
if (data.lpData && comclass->size == sizeof(*comclass))
{
static const WCHAR progid[] = {'P','r','o','g','I','d','.','P','r','o','g','I','d',0};
WCHAR *ptr;
ULONG len;
ok_(__FILE__, line)(comclass->res == 0, "got res as %d\n", comclass->res);
ok_(__FILE__, line)(comclass->res1[0] == 0, "got res1[0] as %02x\n", comclass->res1[0]);
ok_(__FILE__, line)(comclass->res1[1] == 0, "got res1[1] as %02x\n", comclass->res1[1]);
ok_(__FILE__, line)(comclass->model == ThreadingModel_Neutral, "got model %d\n", comclass->model);
ok_(__FILE__, line)(IsEqualGUID(&comclass->clsid, clsid), "got wrong clsid %s\n", debugstr_guid(&comclass->clsid));
ok_(__FILE__, line)(IsEqualGUID(&comclass->clsid2, clsid), "got wrong clsid2 %s\n", debugstr_guid(&comclass->clsid2));
ok_(__FILE__, line)(IsEqualGUID(&comclass->tlid, tlid), "got wrong tlid %s\n", debugstr_guid(&comclass->tlid));
ok_(__FILE__, line)(comclass->name_len > 0, "got modulename len %d\n", comclass->name_len);
ok_(__FILE__, line)(comclass->progid_offset == comclass->size, "got progid offset %d\n", comclass->progid_offset);
ptr = (WCHAR*)((BYTE*)comclass + comclass->size);
ok_(__FILE__, line)(!lstrcmpW(ptr, progid), "got wrong progid %s, expected %s\n", wine_dbgstr_w(ptr), wine_dbgstr_w(progid));
ok_(__FILE__, line)(lstrlenW(ptr)*sizeof(WCHAR) == comclass->progid_len,
"got progid name length %d, expected %d\n", comclass->progid_len, lstrlenW(ptr));
/* data length is simply header length + string data length including nulls */
len = comclass->size + comclass->progid_len + sizeof(WCHAR);
ok_(__FILE__, line)(data.ulLength == len, "got wrong data length %d, expected %d\n", data.ulLength, len);
/* keyed data structure doesn't include module name, it's available from section data */
ok_(__FILE__, line)(data.ulSectionTotalLength > comclass->name_offset, "got wrong offset %d\n", comclass->name_offset);
/* check misc fields are set */
if (comclass->miscmask)
{
if (comclass->miscmask & MiscStatus)
ok_(__FILE__, line)(comclass->miscstatus != 0, "got miscstatus 0x%08x\n", comclass->miscstatus);
if (comclass->miscmask & MiscStatusIcon)
ok_(__FILE__, line)(comclass->miscstatusicon != 0, "got miscstatusicon 0x%08x\n", comclass->miscstatusicon);
if (comclass->miscmask & MiscStatusContent)
ok_(__FILE__, line)(comclass->miscstatuscontent != 0, "got miscstatuscontent 0x%08x\n", comclass->miscstatuscontent);
if (comclass->miscmask & MiscStatusThumbnail)
ok_(__FILE__, line)(comclass->miscstatusthumbnail != 0, "got miscstatusthumbnail 0x%08x\n", comclass->miscstatusthumbnail);
if (comclass->miscmask & MiscStatusDocPrint)
ok_(__FILE__, line)(comclass->miscstatusdocprint != 0, "got miscstatusdocprint 0x%08x\n", comclass->miscstatusdocprint);
}
}
todo_wine {
ok_(__FILE__, line)(data.lpSectionGlobalData != NULL, "data.lpSectionGlobalData == NULL\n");
ok_(__FILE__, line)(data.ulSectionGlobalDataLength > 0, "data.ulSectionGlobalDataLength=%u\n",
data.ulSectionGlobalDataLength);
}
ok_(__FILE__, line)(data.lpSectionBase != NULL, "data.lpSectionBase == NULL\n");
ok_(__FILE__, line)(data.ulSectionTotalLength > 0, "data.ulSectionTotalLength=%u\n",
data.ulSectionTotalLength);
ok_(__FILE__, line)(data.hActCtx == NULL, "data.hActCtx=%p\n", data.hActCtx);
ok_(__FILE__, line)(data.ulAssemblyRosterIndex == exid, "data.ulAssemblyRosterIndex=%u, expected %u\n",
data.ulAssemblyRosterIndex, exid);
/* generated guid for this class works as key guid in search */
memset(&data2, 0xfe, sizeof(data2));
data2.cbSize = sizeof(data2);
ret = pFindActCtxSectionGuid(0, NULL,
ACTIVATION_CONTEXT_SECTION_COM_SERVER_REDIRECTION,
&comclass->alias, &data2);
ok_(__FILE__, line)(ret, "FindActCtxSectionGuid failed: %u\n", GetLastError());
comclass2 = (struct comclassredirect_data*)data2.lpData;
ok_(__FILE__, line)(comclass->size == comclass2->size, "got wrong data length %d, expected %d\n", comclass2->size, comclass->size);
ok_(__FILE__, line)(!memcmp(comclass, comclass2, comclass->size), "got wrong data\n");
}
static void test_wndclass_section(void)
{
static const WCHAR cls1W[] = {'1','.','2','.','3','.','4','!','w','n','d','C','l','a','s','s','1',0};
ACTCTX_SECTION_KEYED_DATA data, data2;
struct wndclass_redirect_data *classdata;
struct strsection_header *section;
ULONG_PTR cookie;
HANDLE handle;
WCHAR *ptrW;
BOOL ret;
/* use two dependent manifests, each defines 2 window class redirects */
create_manifest_file("testdep1.manifest", manifest_wndcls1, -1, NULL, NULL);
create_manifest_file("testdep2.manifest", manifest_wndcls2, -1, NULL, NULL);
create_manifest_file("main_wndcls.manifest", manifest_wndcls_main, -1, NULL, NULL);
handle = test_create("main_wndcls.manifest");
DeleteFileA("testdep1.manifest");
DeleteFileA("testdep2.manifest");
DeleteFileA("main_wndcls.manifest");
ret = pActivateActCtx(handle, &cookie);
ok(ret, "ActivateActCtx failed: %u\n", GetLastError());
memset(&data, 0, sizeof(data));
memset(&data2, 0, sizeof(data2));
data.cbSize = sizeof(data);
data2.cbSize = sizeof(data2);
/* get data for two classes from different assemblies */
ret = pFindActCtxSectionStringW(0, NULL,
ACTIVATION_CONTEXT_SECTION_WINDOW_CLASS_REDIRECTION,
wndClass1W, &data);
ok(ret, "got %d\n", ret);
ret = pFindActCtxSectionStringW(0, NULL,
ACTIVATION_CONTEXT_SECTION_WINDOW_CLASS_REDIRECTION,
wndClass3W, &data2);
ok(ret, "got %d\n", ret);
section = (struct strsection_header*)data.lpSectionBase;
ok(section->count == 4, "got %d\n", section->count);
ok(section->size == sizeof(*section), "got %d\n", section->size);
/* For both string same section is returned, meaning it's one wndclass section per context */
ok(data.lpSectionBase == data2.lpSectionBase, "got %p, %p\n", data.lpSectionBase, data2.lpSectionBase);
ok(data.ulSectionTotalLength == data2.ulSectionTotalLength, "got %u, %u\n", data.ulSectionTotalLength,
data2.ulSectionTotalLength);
/* wndClass1 is versioned, wndClass3 is not */
classdata = (struct wndclass_redirect_data*)data.lpData;
ptrW = (WCHAR*)((BYTE*)data.lpData + classdata->name_offset);
ok(!lstrcmpW(ptrW, cls1W), "got %s\n", wine_dbgstr_w(ptrW));
classdata = (struct wndclass_redirect_data*)data2.lpData;
ptrW = (WCHAR*)((BYTE*)data2.lpData + classdata->name_offset);
ok(!lstrcmpW(ptrW, wndClass3W), "got %s\n", wine_dbgstr_w(ptrW));
ret = pDeactivateActCtx(0, cookie);
ok(ret, "DeactivateActCtx failed: %u\n", GetLastError());
pReleaseActCtx(handle);
}
static void test_dllredirect_section(void)
{
static const WCHAR testlib1W[] = {'t','e','s','t','l','i','b','1','.','d','l','l',0};
static const WCHAR testlib2W[] = {'t','e','s','t','l','i','b','2','.','d','l','l',0};
ACTCTX_SECTION_KEYED_DATA data, data2;
struct strsection_header *section;
ULONG_PTR cookie;
HANDLE handle;
BOOL ret;
/* use two dependent manifests, 4 'files' total */
create_manifest_file("testdep1.manifest", manifest_wndcls1, -1, NULL, NULL);
create_manifest_file("testdep2.manifest", manifest_wndcls2, -1, NULL, NULL);
create_manifest_file("main_wndcls.manifest", manifest_wndcls_main, -1, NULL, NULL);
handle = test_create("main_wndcls.manifest");
DeleteFileA("testdep1.manifest");
DeleteFileA("testdep2.manifest");
DeleteFileA("main_wndcls.manifest");
ret = pActivateActCtx(handle, &cookie);
ok(ret, "ActivateActCtx failed: %u\n", GetLastError());
memset(&data, 0, sizeof(data));
memset(&data2, 0, sizeof(data2));
data.cbSize = sizeof(data);
data2.cbSize = sizeof(data2);
/* get data for two files from different assemblies */
ret = pFindActCtxSectionStringW(0, NULL,
ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION,
testlib1W, &data);
ok(ret, "got %d\n", ret);
ret = pFindActCtxSectionStringW(0, NULL,
ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION,
testlib2W, &data2);
ok(ret, "got %d\n", ret);
section = (struct strsection_header*)data.lpSectionBase;
ok(section->count == 4, "got %d\n", section->count);
ok(section->size == sizeof(*section), "got %d\n", section->size);
/* For both string same section is returned, meaning it's one dll redirect section per context */
ok(data.lpSectionBase == data2.lpSectionBase, "got %p, %p\n", data.lpSectionBase, data2.lpSectionBase);
ok(data.ulSectionTotalLength == data2.ulSectionTotalLength, "got %u, %u\n", data.ulSectionTotalLength,
data2.ulSectionTotalLength);
ret = pDeactivateActCtx(0, cookie);
ok(ret, "DeactivateActCtx failed: %u\n", GetLastError());
pReleaseActCtx(handle);
}
static void test_typelib_section(void)
{
static const WCHAR helpW[] = {'h','e','l','p'};
ACTCTX_SECTION_KEYED_DATA data, data2;
struct guidsection_header *section;
struct tlibredirect_data *tlib;
ULONG_PTR cookie;
HANDLE handle;
BOOL ret;
/* use two dependent manifests, 4 'files' total */
create_manifest_file("testdep1.manifest", manifest_wndcls1, -1, NULL, NULL);
create_manifest_file("testdep2.manifest", manifest_wndcls2, -1, NULL, NULL);
create_manifest_file("main_wndcls.manifest", manifest_wndcls_main, -1, NULL, NULL);
handle = test_create("main_wndcls.manifest");
DeleteFileA("testdep1.manifest");
DeleteFileA("testdep2.manifest");
DeleteFileA("main_wndcls.manifest");
ret = pActivateActCtx(handle, &cookie);
ok(ret, "ActivateActCtx failed: %u\n", GetLastError());
memset(&data, 0, sizeof(data));
memset(&data2, 0, sizeof(data2));
data.cbSize = sizeof(data);
data2.cbSize = sizeof(data2);
/* get data for two typelibs from different assemblies */
ret = pFindActCtxSectionGuid(0, NULL,
ACTIVATION_CONTEXT_SECTION_COM_TYPE_LIBRARY_REDIRECTION,
&IID_TlibTest, &data);
ok(ret, "got %d\n", ret);
ret = pFindActCtxSectionGuid(0, NULL,
ACTIVATION_CONTEXT_SECTION_COM_TYPE_LIBRARY_REDIRECTION,
&IID_TlibTest4, &data2);
ok(ret, "got %d\n", ret);
section = (struct guidsection_header*)data.lpSectionBase;
ok(section->count == 4, "got %d\n", section->count);
ok(section->size == sizeof(*section), "got %d\n", section->size);
/* For both GUIDs same section is returned */
ok(data.lpSectionBase == data2.lpSectionBase, "got %p, %p\n", data.lpSectionBase, data2.lpSectionBase);
ok(data.ulSectionTotalLength == data2.ulSectionTotalLength, "got %u, %u\n", data.ulSectionTotalLength,
data2.ulSectionTotalLength);
/* test some actual data */
tlib = (struct tlibredirect_data*)data.lpData;
ok(tlib->size == sizeof(*tlib), "got %d\n", tlib->size);
ok(tlib->major_version == 1, "got %d\n", tlib->major_version);
ok(tlib->minor_version == 0, "got %d\n", tlib->minor_version);
ok(tlib->help_offset > 0, "got %d\n", tlib->help_offset);
ok(tlib->help_len == sizeof(helpW), "got %d\n", tlib->help_len);
ok(tlib->flags == (LIBFLAG_FHIDDEN|LIBFLAG_FCONTROL|LIBFLAG_FRESTRICTED), "got %x\n", tlib->flags);
ret = pDeactivateActCtx(0, cookie);
ok(ret, "DeactivateActCtx failed: %u\n", GetLastError());
pReleaseActCtx(handle);
}
static void test_actctx(void)
{
ULONG_PTR cookie;
@ -925,7 +1408,7 @@ static void test_actctx(void)
trace("manifest1\n");
handle = test_create("test1.manifest", manifest1);
handle = test_create("test1.manifest");
DeleteFileA("test1.manifest");
if(handle != INVALID_HANDLE_VALUE) {
test_basic_info(handle, __LINE__);
@ -950,7 +1433,7 @@ static void test_actctx(void)
trace("manifest2 depmanifest1\n");
handle = test_create("test2.manifest", manifest2);
handle = test_create("test2.manifest");
DeleteFileA("test2.manifest");
DeleteFileA("testdep.manifest");
if(handle != INVALID_HANDLE_VALUE) {
@ -968,7 +1451,7 @@ static void test_actctx(void)
trace("manifest2 depmanifest2\n");
handle = test_create("test2-2.manifest", manifest2);
handle = test_create("test2-2.manifest");
DeleteFileA("test2-2.manifest");
DeleteFileA("testdep.manifest");
if(handle != INVALID_HANDLE_VALUE) {
@ -996,7 +1479,7 @@ static void test_actctx(void)
return;
}
handle = test_create("test2-3.manifest", manifest2);
handle = test_create("test2-3.manifest");
DeleteFileA("test2-3.manifest");
DeleteFileA("testdep.manifest");
if(handle != INVALID_HANDLE_VALUE) {
@ -1026,7 +1509,7 @@ static void test_actctx(void)
return;
}
handle = test_create("test3.manifest", manifest3);
handle = test_create("test3.manifest");
DeleteFileA("test3.manifest");
if(handle != INVALID_HANDLE_VALUE) {
test_basic_info(handle, __LINE__);
@ -1038,6 +1521,7 @@ static void test_actctx(void)
ok(b, "ActivateActCtx failed: %u\n", GetLastError());
test_find_dll_redirection(handle, testlib_dll, 1, __LINE__);
test_find_dll_redirection(handle, testlib_dll, 1, __LINE__);
test_find_com_redirection(handle, &IID_CoTest, &IID_TlibTest, 1, __LINE__);
test_find_string_fail();
b = pDeactivateActCtx(0, cookie);
ok(b, "DeactivateActCtx failed: %u\n", GetLastError());
@ -1052,7 +1536,7 @@ static void test_actctx(void)
return;
}
handle = test_create("test4.manifest", manifest4);
handle = test_create("test4.manifest");
DeleteFileA("test4.manifest");
DeleteFileA("testdep.manifest");
if(handle != INVALID_HANDLE_VALUE) {
@ -1072,7 +1556,7 @@ static void test_actctx(void)
skip("Could not create manifest file\n");
return;
}
handle = test_create("..\\test1.manifest", manifest1);
handle = test_create("..\\test1.manifest");
DeleteFileA("..\\test1.manifest");
if(handle != INVALID_HANDLE_VALUE) {
test_basic_info(handle, __LINE__);
@ -1092,7 +1576,7 @@ static void test_actctx(void)
return;
}
handle = test_create("test1.manifest", manifest1);
handle = test_create("test1.manifest");
DeleteFileA("test1.manifest");
if (handle != INVALID_HANDLE_VALUE) {
test_basic_info(handle, __LINE__);
@ -1107,7 +1591,7 @@ static void test_actctx(void)
return;
}
handle = test_create("test1.manifest", manifest1);
handle = test_create("test1.manifest");
DeleteFileA("test1.manifest");
if (handle != INVALID_HANDLE_VALUE) {
test_basic_info(handle, __LINE__);
@ -1116,6 +1600,9 @@ static void test_actctx(void)
pReleaseActCtx(handle);
}
test_wndclass_section();
test_dllredirect_section();
test_typelib_section();
}
static void test_app_manifest(void)
@ -1212,6 +1699,7 @@ static BOOL init_funcs(void)
X(IsDebuggerPresent);
X(QueryActCtxW);
X(ReleaseActCtx);
X(FindActCtxSectionGuid);
#undef X
return TRUE;

View file

@ -285,7 +285,7 @@ static void test_string_conversion(LPBOOL bUsedDefaultChar)
SetLastError(0xdeadbeef);
ret = WideCharToMultiByte(1252, 0, &wc1, 1, &mbc, 1, NULL, bUsedDefaultChar);
ok(ret == 1, "ret is %d\n", ret);
ok(mbc == -28, "mbc is %d\n", mbc);
ok(mbc == '\xe4', "mbc is %d\n", mbc);
if(bUsedDefaultChar) ok(*bUsedDefaultChar == FALSE, "bUsedDefaultChar is %d\n", *bUsedDefaultChar);
ok(GetLastError() == 0xdeadbeef, "GetLastError() is %u\n", GetLastError());
@ -301,7 +301,7 @@ static void test_string_conversion(LPBOOL bUsedDefaultChar)
SetLastError(0xdeadbeef);
ret = WideCharToMultiByte(1251, 0, &wc2, 1, &mbc, 1, NULL, bUsedDefaultChar);
ok(ret == 1, "ret is %d\n", ret);
ok(mbc == -16, "mbc is %d\n", mbc);
ok(mbc == '\xf0', "mbc is %d\n", mbc);
if(bUsedDefaultChar) ok(*bUsedDefaultChar == FALSE, "bUsedDefaultChar is %d\n", *bUsedDefaultChar);
ok(GetLastError() == 0xdeadbeef ||
broken(GetLastError() == 0), /* win95 */

View file

@ -41,6 +41,12 @@
* available. For the 8250 this is equivalent to TXD->RXD, OUT2->DCD,
* OUT1->RI, RTS->CTS and DTR->DSR
*/
/* use variables and not #define to compile the code */
static BOOL loopback_txd_rxd = LOOPBACK_TXD_RXD;
static BOOL loopback_rts_cts = LOOPBACK_CTS_RTS;
static BOOL loopback_dtr_dsr = LOOPBACK_DTR_DSR;
static BOOL loopback_dtr_ring = LOOPBACK_DTR_RING;
static BOOL loopback_dtr_dcd = LOOPBACK_DTR_DCD;
typedef struct
{
@ -51,7 +57,7 @@ typedef struct
COMMTIMEOUTS timeouts1, timeouts2;
} TEST;
static TEST test[] =
static const TEST test[] =
{
{
"baud=9600 parity=e data=5 stop=1 xon=on odsr=off octs=off dtr=on rts=on idsr=on",
@ -428,7 +434,7 @@ static TEST test[] =
pdcb->wReserved1 & 0xffff );
} */
static void check_result(const char *function, TEST *ptest, int initial_value, BOOL result)
static void check_result(const char *function, const TEST *ptest, int initial_value, BOOL result)
{
DWORD LastError = GetLastError();
DWORD CorrectError = (ptest->result ? 0xdeadbeef : ERROR_INVALID_PARAMETER);
@ -440,7 +446,7 @@ static void check_result(const char *function, TEST *ptest, int initial_value, B
#define check_dcb_member(a,b) ok(pdcb1->a == pdcb2->a, "%s(\"%s\"), 0x%02x: "#a" is "b", should be "b"\n", function, ptest->string, initial_value, pdcb1->a, pdcb2->a)
#define check_dcb_member2(a,c,b) if(pdcb2->a == c) { check_dcb_member(a,b); } else { ok(pdcb1->a == pdcb2->a || pdcb1->a == c, "%s(\"%s\"), 0x%02x: "#a" is "b", should be "b" or "b"\n", function, ptest->string, initial_value, pdcb1->a, pdcb2->a, c); }
static void check_dcb(const char *function, TEST *ptest, int initial_value, DCB *pdcb1, DCB *pdcb2)
static void check_dcb(const char *function, const TEST *ptest, int initial_value, const DCB *pdcb1, const DCB *pdcb2)
{
/* DCBlength is a special case since Win 9x sets it but NT does not.
We will accept either as correct. */
@ -512,7 +518,7 @@ static void check_dcb(const char *function, TEST *ptest, int initial_value, DCB
#define check_timeouts_member(a) ok(ptimeouts1->a == ptimeouts2->a, "%s(\"%s\"), 0x%02x: "#a" is %u, should be %u\n", function, ptest->string, initial_value, ptimeouts1->a, ptimeouts2->a);
static void check_timeouts(const char *function, TEST *ptest, int initial_value, COMMTIMEOUTS *ptimeouts1, COMMTIMEOUTS *ptimeouts2)
static void check_timeouts(const char *function, const TEST *ptest, int initial_value, const COMMTIMEOUTS *ptimeouts1, const COMMTIMEOUTS *ptimeouts2)
{
check_timeouts_member(ReadIntervalTimeout);
check_timeouts_member(ReadTotalTimeoutMultiplier);
@ -521,7 +527,7 @@ static void check_timeouts(const char *function, TEST *ptest, int initial_value,
check_timeouts_member(WriteTotalTimeoutConstant);
}
static void test_BuildCommDCBA(TEST *ptest, int initial_value, DCB *pexpected_dcb)
static void test_BuildCommDCBA(const char *string, const TEST *ptest, int initial_value, const DCB *pexpected_dcb)
{
BOOL result;
DCB dcb;
@ -530,14 +536,14 @@ static void test_BuildCommDCBA(TEST *ptest, int initial_value, DCB *pexpected_dc
memset(&dcb, initial_value, sizeof(DCB));
SetLastError(0xdeadbeef);
result = BuildCommDCBA(ptest->string, &dcb);
result = BuildCommDCBA(string, &dcb);
/* check results */
check_result("BuildCommDCBA", ptest, initial_value, result);
check_dcb("BuildCommDCBA", ptest, initial_value, &dcb, pexpected_dcb);
}
static void test_BuildCommDCBAndTimeoutsA(TEST *ptest, int initial_value, DCB *pexpected_dcb, COMMTIMEOUTS *pexpected_timeouts)
static void test_BuildCommDCBAndTimeoutsA(const char *string, const TEST *ptest, int initial_value, const DCB *pexpected_dcb, const COMMTIMEOUTS *pexpected_timeouts)
{
BOOL result;
DCB dcb;
@ -548,7 +554,7 @@ static void test_BuildCommDCBAndTimeoutsA(TEST *ptest, int initial_value, DCB *p
memset(&timeouts, initial_value, sizeof(COMMTIMEOUTS));
SetLastError(0xdeadbeef);
result = BuildCommDCBAndTimeoutsA(ptest->string, &dcb, &timeouts);
result = BuildCommDCBAndTimeoutsA(string, &dcb, &timeouts);
/* check results */
check_result("BuildCommDCBAndTimeoutsA", ptest, initial_value, result);
@ -556,14 +562,14 @@ static void test_BuildCommDCBAndTimeoutsA(TEST *ptest, int initial_value, DCB *p
check_timeouts("BuildCommDCBAndTimeoutsA", ptest, initial_value, &timeouts, pexpected_timeouts);
}
static void test_BuildCommDCBW(TEST *ptest, int initial_value, DCB *pexpected_dcb)
static void test_BuildCommDCBW(const char *string, const TEST *ptest, int initial_value, const DCB *pexpected_dcb)
{
BOOL result;
DCB dcb;
WCHAR wide_string[sizeof(ptest->string)];
static int reportedDCBW = 0;
MultiByteToWideChar(CP_ACP, 0, ptest->string, -1, wide_string, sizeof(wide_string) / sizeof(WCHAR));
MultiByteToWideChar(CP_ACP, 0, string, -1, wide_string, sizeof(wide_string) / sizeof(WCHAR));
/* set initial conditions */
memset(&dcb, initial_value, sizeof(DCB));
@ -583,7 +589,7 @@ static void test_BuildCommDCBW(TEST *ptest, int initial_value, DCB *pexpected_dc
check_dcb("BuildCommDCBW", ptest, initial_value, &dcb, pexpected_dcb);
}
static void test_BuildCommDCBAndTimeoutsW(TEST *ptest, int initial_value, DCB *pexpected_dcb, COMMTIMEOUTS *pexpected_timeouts)
static void test_BuildCommDCBAndTimeoutsW(const char *string, const TEST *ptest, int initial_value, const DCB *pexpected_dcb, const COMMTIMEOUTS *pexpected_timeouts)
{
BOOL result;
DCB dcb;
@ -591,7 +597,7 @@ static void test_BuildCommDCBAndTimeoutsW(TEST *ptest, int initial_value, DCB *p
WCHAR wide_string[sizeof(ptest->string)];
static int reportedDCBAndTW = 0;
MultiByteToWideChar(CP_ACP, 0, ptest->string, -1, wide_string, sizeof(wide_string) / sizeof(WCHAR));
MultiByteToWideChar(CP_ACP, 0, string, -1, wide_string, sizeof(wide_string) / sizeof(WCHAR));
/* set initial conditions */
memset(&dcb, initial_value, sizeof(DCB));
@ -639,8 +645,12 @@ static void test_BuildCommDCB(void)
for(i = 0; i < TEST_COUNT; i++)
{
char string[sizeof(test[i].string)];
strcpy(string, test[i].string);
/* Check if this test case needs a valid COM port. */
ptr = strstr(test[i].string, "COMx");
ptr = strstr(string, "COMx");
/* If required, substitute valid port number into device control string. */
if(ptr)
@ -651,15 +661,15 @@ static void test_BuildCommDCB(void)
continue;
}
test_BuildCommDCBA(&test[i], 0x00, &test[i].dcb1);
test_BuildCommDCBA(&test[i], 0xff, &test[i].dcb2);
test_BuildCommDCBAndTimeoutsA(&test[i], 0x00, &test[i].dcb1, &test[i].timeouts1);
test_BuildCommDCBAndTimeoutsA(&test[i], 0xff, &test[i].dcb2, &test[i].timeouts2);
test_BuildCommDCBA(string, &test[i], 0x00, &test[i].dcb1);
test_BuildCommDCBA(string, &test[i], 0xff, &test[i].dcb2);
test_BuildCommDCBAndTimeoutsA(string, &test[i], 0x00, &test[i].dcb1, &test[i].timeouts1);
test_BuildCommDCBAndTimeoutsA(string, &test[i], 0xff, &test[i].dcb2, &test[i].timeouts2);
test_BuildCommDCBW(&test[i], 0x00, &test[i].dcb1);
test_BuildCommDCBW(&test[i], 0xff, &test[i].dcb2);
test_BuildCommDCBAndTimeoutsW(&test[i], 0x00, &test[i].dcb1, &test[i].timeouts1);
test_BuildCommDCBAndTimeoutsW(&test[i], 0xff, &test[i].dcb2, &test[i].timeouts2);
test_BuildCommDCBW(string, &test[i], 0x00, &test[i].dcb1);
test_BuildCommDCBW(string, &test[i], 0xff, &test[i].dcb2);
test_BuildCommDCBAndTimeoutsW(string, &test[i], 0x00, &test[i].dcb1, &test[i].timeouts1);
test_BuildCommDCBAndTimeoutsW(string, &test[i], 0xff, &test[i].dcb2, &test[i].timeouts2);
}
}
@ -682,7 +692,7 @@ static HANDLE test_OpenComm(BOOL doOverlap)
if(!shown)
{
if (hcom == INVALID_HANDLE_VALUE)
trace("Could not find a valid COM port. Skipping test_ReadTimeOut\n");
trace("Could not find a valid COM port.\n");
else
trace("Found Com port %s. Connected devices may disturb results\n", port_name);
/*shown = TRUE; */
@ -723,14 +733,20 @@ static void test_GetModemStatus(HANDLE hcom)
}
/* When we don't write anything, Read should time out even on a loopbacked port */
static void test_ReadTimeOut(HANDLE hcom)
static void test_ReadTimeOut(void)
{
HANDLE hcom;
DCB dcb;
COMMTIMEOUTS timeouts;
char rbuf[32];
DWORD before, after, read, timediff, LastError;
BOOL res;
hcom = test_OpenComm(FALSE);
if (hcom == INVALID_HANDLE_VALUE) return;
test_GetModemStatus(hcom);
ok(GetCommState(hcom, &dcb), "GetCommState failed\n");
dcb.BaudRate = FASTBAUD;
dcb.ByteSize = 8;
@ -754,94 +770,153 @@ static void test_ReadTimeOut(HANDLE hcom)
timediff = after - before;
ok( timediff > TIMEOUT>>2 && timediff < TIMEOUT *2,
"Unexpected TimeOut %d, expected %d\n", timediff, TIMEOUT);
CloseHandle(hcom);
}
static void test_waittxempty(HANDLE hcom)
static void test_waittxempty(void)
{
HANDLE hcom;
DCB dcb;
COMMTIMEOUTS timeouts;
char tbuf[]="test_waittxempty";
DWORD before, after, written, timediff, evtmask = 0;
BOOL res_write, res;
DWORD before, after, bytes, timediff, evtmask;
BOOL res;
DWORD baud = SLOWBAUD;
OVERLAPPED ovl_write, ovl_wait;
hcom = test_OpenComm(TRUE);
if (hcom == INVALID_HANDLE_VALUE) return;
trace("test_waittxempty\n");
/* set a low baud rate to have ample time*/
ok(GetCommState(hcom, &dcb), "GetCommState failed\n");
res = GetCommState(hcom, &dcb);
ok(res, "GetCommState error %d\n", GetLastError());
dcb.BaudRate = baud;
dcb.ByteSize = 8;
dcb.Parity = NOPARITY;
dcb.fRtsControl=RTS_CONTROL_ENABLE;
dcb.fDtrControl=DTR_CONTROL_ENABLE;
dcb.StopBits = ONESTOPBIT;
ok(SetCommState(hcom, &dcb), "SetCommState failed\n");
res = SetCommState(hcom, &dcb);
ok(res, "SetCommState error %d\n", GetLastError());
ZeroMemory( &timeouts, sizeof(timeouts));
timeouts.ReadTotalTimeoutConstant = TIMEOUT;
ok(SetCommTimeouts(hcom, &timeouts),"SetCommTimeouts failed\n");
res = SetCommTimeouts(hcom, &timeouts);
ok(res,"SetCommTimeouts error %d\n", GetLastError());
ok(SetupComm(hcom,1024,1024),"SetUpComm failed\n");
ok(SetCommMask(hcom, EV_TXEMPTY), "SetCommMask failed\n");
res = SetupComm(hcom, 1024, 1024);
ok(res, "SetUpComm error %d\n", GetLastError());
/* calling SetCommMask after WriteFile leads to WaitCommEvent failures
* due to timeout (no events) under testbot VMs and VirtualBox
*/
res = SetCommMask(hcom, EV_TXEMPTY);
ok(res, "SetCommMask error %d\n", GetLastError());
SetLastError(0xdeadbeef);
res = WriteFile(hcom, tbuf, sizeof(tbuf), &bytes, NULL);
todo_wine
ok(!res, "WriteFile on an overlapped handle without ovl structure should fail\n");
todo_wine
ok(GetLastError() == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
S(U(ovl_write)).Offset = 0;
S(U(ovl_write)).OffsetHigh = 0;
ovl_write.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
before = GetTickCount();
res_write=WriteFile(hcom, tbuf, sizeof(tbuf), &written, NULL);
SetLastError(0xdeadbeef);
res = WriteFile(hcom, tbuf, sizeof(tbuf), &bytes, &ovl_write);
after = GetTickCount();
ok(res_write == TRUE, "WriteFile failed\n");
ok(written == sizeof(tbuf),
"WriteFile: Unexpected write_size %d\n", written);
trace("WriteFile succeeded, took %d ms to write %d Bytes at %d Baud\n",
after - before, written, baud);
todo_wine
ok(!res && GetLastError() == ERROR_IO_PENDING, "WriteFile returned %d, error %d\n", res, GetLastError());
todo_wine
ok(!bytes, "expected 0, got %u\n", bytes);
ok(after - before < 30, "WriteFile took %d ms to write %d Bytes at %d Baud\n",
after - before, bytes, baud);
/* don't wait for WriteFile completion */
S(U(ovl_wait)).Offset = 0;
S(U(ovl_wait)).OffsetHigh = 0;
ovl_wait.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
evtmask = 0;
before = GetTickCount();
res = WaitCommEvent(hcom, &evtmask, NULL);
SetLastError(0xdeadbeef);
res = WaitCommEvent(hcom, &evtmask, &ovl_wait);
ok(!res && GetLastError() == ERROR_IO_PENDING, "WaitCommEvent error %d\n", GetLastError());
res = WaitForSingleObject(ovl_wait.hEvent, TIMEOUT);
todo_wine
ok(res == WAIT_OBJECT_0, "WaitCommEvent failed with a timeout\n");
if (res == WAIT_OBJECT_0)
{
res = GetOverlappedResult(hcom, &ovl_wait, &bytes, FALSE);
ok(res, "GetOverlappedResult reported error %d\n", GetLastError());
todo_wine
ok(bytes == sizeof(evtmask), "expected %u, written %u\n", (UINT)sizeof(evtmask), bytes);
res = TRUE;
}
else res = FALSE;
after = GetTickCount();
ok(res == TRUE, "WaitCommEvent failed\n");
ok((evtmask & EV_TXEMPTY),
"WaitCommEvent: Unexpected EvtMask 0x%08x, expected 0x%08x\n",
evtmask, EV_TXEMPTY);
todo_wine
ok(res, "WaitCommEvent error %d\n", GetLastError());
todo_wine
ok(evtmask & EV_TXEMPTY, "WaitCommEvent: expected EV_TXEMPTY, got %#x\n", evtmask);
CloseHandle(ovl_wait.hEvent);
timediff = after - before;
trace("WaitCommEvent for EV_TXEMPTY took %d ms (timeout %d)\n", timediff, TIMEOUT);
todo_wine
ok(timediff < 900, "WaitCommEvent used %d ms for waiting\n", timediff);
trace("WaitCommEvent for EV_TXEMPTY took %d ms\n", timediff);
/* 050604: This shows a difference between XP (tested with mingw compiled crosstest):
XP returns Writefile only after everything went out of the Serial port,
while wine returns immediately.
Thus on XP, WaintCommEvent after setting the CommMask for EV_TXEMPTY
nearly return immediate,
while on wine the most time is spent here
*/
res = WaitForSingleObject(ovl_write.hEvent, 0);
ok(res == WAIT_OBJECT_0, "WriteFile failed with a timeout\n");
res = GetOverlappedResult(hcom, &ovl_write, &bytes, FALSE);
ok(res, "GetOverlappedResult reported error %d\n", GetLastError());
ok(bytes == sizeof(tbuf), "expected %u, written %u\n", (UINT)sizeof(tbuf), bytes);
CloseHandle(ovl_write.hEvent);
CloseHandle(hcom);
}
/* A new open handle should not return error or have bytes in the Queues */
static void test_ClearCommErrors(HANDLE hcom)
static void test_ClearCommError(void)
{
DWORD errors;
HANDLE hcom;
DWORD errors;
COMSTAT lpStat;
hcom = test_OpenComm(FALSE);
if (hcom == INVALID_HANDLE_VALUE) return;
ok(ClearCommError(hcom, &errors, &lpStat), "ClearCommError failed\n");
ok(lpStat.cbInQue == 0, "Unexpected %d chars in InQueue\n", lpStat.cbInQue);
ok(lpStat.cbOutQue == 0, "Unexpected %d chars in OutQueue\n", lpStat.cbOutQue);
ok(errors == 0, "ClearCommErrors: Unexpected error 0x%08x\n", errors);
trace("test_ClearCommErrors done\n");
CloseHandle(hcom);
}
static void test_non_pending_errors(HANDLE hcom)
static void test_non_pending_errors(void)
{
HANDLE hcom;
DCB dcb;
DWORD err;
hcom = test_OpenComm(FALSE);
if (hcom == INVALID_HANDLE_VALUE) return;
ok(GetCommState(hcom, &dcb), "GetCommState failed\n");
dcb.ByteSize = 255; /* likely bogus */
ok(!SetCommState(hcom, &dcb), "SetCommState should have failed\n");
ok(ClearCommError(hcom, &err, NULL), "ClearCommError should succeed\n");
ok(!(err & CE_MODE), "ClearCommError shouldn't set CE_MODE byte in this case (%x)\n", err);
CloseHandle(hcom);
}
/**/
static void test_LoopbackRead(HANDLE hcom)
static void test_LoopbackRead(void)
{
HANDLE hcom;
DCB dcb;
COMMTIMEOUTS timeouts;
char rbuf[32];
@ -849,6 +924,11 @@ static void test_LoopbackRead(HANDLE hcom)
BOOL res;
char tbuf[]="test_LoopbackRead";
if (!loopback_txd_rxd) return;
hcom = test_OpenComm(FALSE);
if (hcom == INVALID_HANDLE_VALUE) return;
trace("Starting test_LoopbackRead\n");
ok(GetCommState(hcom, &dcb), "GetCommState failed\n");
dcb.BaudRate = FASTBAUD;
@ -936,18 +1016,27 @@ static void test_LoopbackRead(HANDLE hcom)
after = GetTickCount();
ok( read == sizeof(tbuf),"ReadFile read %d bytes\n", read);
trace("Plain Read for %d char at %d baud took %d ms\n", read, SLOWBAUD, after-before);
CloseHandle(hcom);
}
static void test_LoopbackCtsRts(HANDLE hcom)
static void test_LoopbackCtsRts(void)
{
HANDLE hcom;
DWORD ModemStat = 0, defaultStat = 0;
DCB dcb;
if (!loopback_rts_cts) return;
hcom = test_OpenComm(FALSE);
if (hcom == INVALID_HANDLE_VALUE) return;
memset (&dcb, 0, sizeof (dcb));
ok(GetCommState(hcom, &dcb), "GetCommState failed\n");
if (dcb.fRtsControl == RTS_CONTROL_HANDSHAKE)
{
trace("RTS_CONTROL_HANDSHAKE is set, so don't manipulate RTS\n");
CloseHandle(hcom);
return;
}
ok(GetCommModemStatus(hcom, &defaultStat), "GetCommModemStatus failed\n");
@ -976,17 +1065,26 @@ static void test_LoopbackCtsRts(HANDLE hcom)
ok (ModemStat == defaultStat, "Failed to restore CTS: 0x%04x, expected 0x%04x\n",
ModemStat, defaultStat);
}
CloseHandle(hcom);
}
static void test_LoopbackDtrDcd(HANDLE hcom)
static void test_LoopbackDtrDcd(void)
{
HANDLE hcom;
DWORD ModemStat = 0, defaultStat = 0;
DCB dcb;
if (!loopback_dtr_dcd) return;
hcom = test_OpenComm(FALSE);
if (hcom == INVALID_HANDLE_VALUE) return;
ok(GetCommState(hcom, &dcb), "GetCommState failed\n");
if (dcb.fDtrControl == DTR_CONTROL_HANDSHAKE)
{
trace("DTR_CONTROL_HANDSHAKE is set, so don't manipulate DTR\n");
CloseHandle(hcom);
return;
}
ok(GetCommModemStatus(hcom, &defaultStat), "GetCommModemStatus failed\n");
@ -1015,17 +1113,26 @@ static void test_LoopbackDtrDcd(HANDLE hcom)
ok (ModemStat == defaultStat, "Failed to restore RLSD: 0x%04x, expected 0x%04x\n",
ModemStat, defaultStat);
}
CloseHandle(hcom);
}
static void test_LoopbackDtrDsr(HANDLE hcom)
static void test_LoopbackDtrDsr(void)
{
HANDLE hcom;
DWORD ModemStat = 0, defaultStat = 0;
DCB dcb;
if (!loopback_dtr_dsr) return;
hcom = test_OpenComm(FALSE);
if (hcom == INVALID_HANDLE_VALUE) return;
ok(GetCommState(hcom, &dcb), "GetCommState failed\n");
if (dcb.fDtrControl == DTR_CONTROL_DISABLE)
{
trace("DTR_CONTROL_HANDSHAKE is set, so don't manipulate DTR\n");
CloseHandle(hcom);
return;
}
ok(GetCommModemStatus(hcom, &defaultStat), "GetCommModemStatus failed\n");
@ -1054,13 +1161,21 @@ static void test_LoopbackDtrDsr(HANDLE hcom)
ok (ModemStat == defaultStat, "Failed to restore DSR: 0x%04x, expected 0x%04x\n",
ModemStat, defaultStat);
}
CloseHandle(hcom);
}
static void test_LoopbackDtrRing(HANDLE hcom)
static void test_LoopbackDtrRing(void)
{
HANDLE hcom;
DWORD ModemStat = 0, defaultStat = 0;
DCB dcb;
if (!loopback_dtr_ring) return;
hcom = test_OpenComm(FALSE);
if (hcom == INVALID_HANDLE_VALUE) return;
ok(GetCommState(hcom, &dcb), "GetCommState failed\n");
if (dcb.fDtrControl == DTR_CONTROL_HANDSHAKE)
{
@ -1093,6 +1208,8 @@ static void test_LoopbackDtrRing(HANDLE hcom)
ok (ModemStat == defaultStat, "Failed to restore RING: 0x%04x, expected 0x%04x\n",
ModemStat, defaultStat);
}
CloseHandle(hcom);
}
/*
@ -1102,13 +1219,18 @@ static void test_LoopbackDtrRing(HANDLE hcom)
* Need Loopback TX->RX
*/
static void test_WaitRx(HANDLE hcom)
static void test_WaitRx(void)
{
OVERLAPPED overlapped, overlapped_w;
HANDLE hComPortEvent, hComWriteEvent;
HANDLE hcom, hComPortEvent, hComWriteEvent;
DWORD before, after, after1, diff, success_wait = FALSE, success_write;
DWORD err_wait, err_write, written, evtmask=0;
if (!loopback_txd_rxd) return;
hcom = test_OpenComm(TRUE);
if (hcom == INVALID_HANDLE_VALUE) return;
ok(SetCommMask(hcom, EV_RXCHAR), "SetCommMask failed\n");
hComPortEvent = CreateEvent( NULL, TRUE, FALSE, NULL );
ok(hComPortEvent != 0, "CreateEvent failed\n");
@ -1121,12 +1243,12 @@ static void test_WaitRx(HANDLE hcom)
overlapped_w.hEvent = hComWriteEvent;
before = GetTickCount();
{success_wait = WaitCommEvent(hcom, &evtmask, &overlapped);}
success_wait = WaitCommEvent(hcom, &evtmask, &overlapped);
err_wait = GetLastError();
after = GetTickCount();
trace("Success 0x%08x err %d evtmask 0x%08x\n", success_wait, err_wait, evtmask);
ok(success_wait || err_wait == ERROR_IO_PENDING, "overlapped WaitCommEvent failed\n");
trace("overlapped WriteCommEvent returned.\n");
trace("overlapped WaitCommEvent returned.\n");
success_write= WriteFile(hcom, "X", 1, &written, &overlapped_w);
err_write = GetLastError();
@ -1166,9 +1288,10 @@ static void test_WaitRx(HANDLE hcom)
ok ((diff > (TIMEOUT>>1) -TIMEDELTA) && (diff < (TIMEOUT>>1) + TIMEDELTA),
"Unexpected time %d, expected around %d\n", diff, TIMEOUT>>1);
CloseHandle(hcom);
}
/* Change the controling line after the given timeout to the given state
/* Change the controlling line after the given timeout to the given state
By the loopback, this should trigger the WaitCommEvent
*/
static DWORD CALLBACK toggle_ctlLine(LPVOID arg)
@ -1195,15 +1318,19 @@ static DWORD CALLBACK toggle_ctlLine(LPVOID arg)
* Wait for a change in CTS
* Needs Loopback from DTR to CTS
*/
static void test_WaitCts(HANDLE hcom)
static void test_WaitCts(void)
{
DCB dcb;
OVERLAPPED overlapped;
HANDLE hComPortEvent;
HANDLE alarmThread;
HANDLE hcom, hComPortEvent, alarmThread;
DWORD_PTR args[4];
DWORD alarmThreadId, before, after, after1, diff, success, err, written, evtmask=0, defaultStat = 0;
if (!loopback_rts_cts) return;
hcom = test_OpenComm(TRUE);
if (hcom == INVALID_HANDLE_VALUE) return;
ok(GetCommState(hcom, &dcb), "GetCommState failed\n");
dcb.fRtsControl=RTS_CONTROL_ENABLE;
dcb.fDtrControl=DTR_CONTROL_ENABLE;
@ -1211,6 +1338,7 @@ static void test_WaitCts(HANDLE hcom)
if (dcb.fDtrControl == RTS_CONTROL_DISABLE)
{
trace("RTS_CONTROL_HANDSHAKE is set, so don't manipulate DTR\n");
CloseHandle(hcom);
return;
}
args[0]= TIMEOUT >>1;
@ -1242,7 +1370,7 @@ static void test_WaitCts(HANDLE hcom)
trace("Success 0x%08x err %d evtmask 0x%08x\n", success, err, evtmask);
ok(success || err == ERROR_IO_PENDING, "overlapped WaitCommEvent failed\n");
trace("overlapped WriteCommEvent returned.\n");
trace("overlapped WaitCommEvent returned.\n");
if (!success && (err == ERROR_IO_PENDING))
ok(WaitForSingleObjectEx(hComPortEvent, TIMEOUT, TRUE) == 0,
"WaitCts hComPortEvent failed\n");
@ -1269,6 +1397,8 @@ static void test_WaitCts(HANDLE hcom)
args[1] = SETRTS;
else
args[1] = CLRRTS;
CloseHandle(hcom);
}
/* Change the Comm Mask while a Wait is going on
@ -1292,19 +1422,22 @@ static DWORD CALLBACK reset_CommMask(LPVOID arg)
reset the CommMask and expect the wait to return with a mask of 0
No special port connections needed
*/
static void test_AbortWaitCts(HANDLE hcom)
static void test_AbortWaitCts(void)
{
DCB dcb;
OVERLAPPED overlapped;
HANDLE hComPortEvent;
HANDLE alarmThread;
HANDLE hcom, hComPortEvent, alarmThread;
DWORD_PTR args[2];
DWORD alarmThreadId, before, after, after1, diff, success, err, written, evtmask=0;
hcom = test_OpenComm(TRUE);
if (hcom == INVALID_HANDLE_VALUE) return;
ok(GetCommState(hcom, &dcb), "GetCommState failed\n");
if (dcb.fDtrControl == RTS_CONTROL_DISABLE)
{
trace("RTS_CONTROL_HANDSHAKE is set, so don't manipulate DTR\n");
CloseHandle(hcom);
return;
}
args[0]= TIMEOUT >>1;
@ -1330,7 +1463,7 @@ static void test_AbortWaitCts(HANDLE hcom)
trace("Success 0x%08x err %d evtmask 0x%08x\n", success, err, evtmask);
ok(success || err == ERROR_IO_PENDING, "overlapped WaitCommEvent failed\n");
trace("overlapped WriteCommEvent returned.\n");
trace("overlapped WaitCommEvent returned.\n");
if (!success && (err == ERROR_IO_PENDING))
ok(WaitForSingleObjectEx(hComPortEvent, TIMEOUT, TRUE) == 0,
"AbortWaitCts hComPortEvent failed\n");
@ -1347,25 +1480,31 @@ static void test_AbortWaitCts(HANDLE hcom)
ok ((diff > (TIMEOUT>>1) -TIMEDELTA) && (diff < (TIMEOUT>>1) + TIMEDELTA),
"Unexpected time %d, expected around %d\n", diff, TIMEOUT>>1);
CloseHandle(hcom);
}
/*
* Wait for a change in DSR
* Needs Loopback from DTR to DSR
*/
static void test_WaitDsr(HANDLE hcom)
static void test_WaitDsr(void)
{
DCB dcb;
OVERLAPPED overlapped;
HANDLE hComPortEvent;
HANDLE alarmThread;
HANDLE hcom, hComPortEvent, alarmThread;
DWORD_PTR args[3];
DWORD alarmThreadId, before, after, after1, diff, success, err, written, evtmask=0, defaultStat = 0;
if (!loopback_dtr_dsr) return;
hcom = test_OpenComm(TRUE);
if (hcom == INVALID_HANDLE_VALUE) return;
ok(GetCommState(hcom, &dcb), "GetCommState failed\n");
if (dcb.fDtrControl == DTR_CONTROL_DISABLE)
{
trace("DTR_CONTROL_HANDSHAKE is set, so don't manipulate DTR\n");
CloseHandle(hcom);
return;
}
args[0]= TIMEOUT >>1;
@ -1393,7 +1532,7 @@ static void test_WaitDsr(HANDLE hcom)
trace("Success 0x%08x err %d evtmask 0x%08x\n", success, err, evtmask);
ok(success || err == ERROR_IO_PENDING, "overlapped WaitCommEvent failed\n");
trace("overlapped WriteCommEvent returned.\n");
trace("overlapped WaitCommEvent returned.\n");
if (!success && (err == ERROR_IO_PENDING))
ok(WaitForSingleObjectEx(hComPortEvent, TIMEOUT, TRUE) == 0,
"wait hComPortEvent failed\n");
@ -1420,26 +1559,33 @@ static void test_WaitDsr(HANDLE hcom)
args[1] = SETDTR;
else
args[1] = CLRDTR;
CloseHandle(hcom);
}
/*
* Wait for a Ring
* Needs Loopback from DTR to RING
*/
static void test_WaitRing(HANDLE hcom)
static void test_WaitRing(void)
{
DCB dcb;
OVERLAPPED overlapped;
HANDLE hComPortEvent;
HANDLE alarmThread;
HANDLE hcom, hComPortEvent, alarmThread;
DWORD_PTR args[3];
DWORD alarmThreadId, before, after, after1, diff, success, err, written, evtmask=0, defaultStat;
BOOL ret;
if (!loopback_dtr_ring) return;
hcom = test_OpenComm(TRUE);
if (hcom == INVALID_HANDLE_VALUE) return;
ok(GetCommState(hcom, &dcb), "GetCommState failed\n");
if (dcb.fDtrControl == DTR_CONTROL_DISABLE)
{
trace("DTR_CONTROL_HANDSHAKE is set, so don't manipulate DTR\n");
CloseHandle(hcom);
return;
}
args[0]= TIMEOUT >>1;
@ -1471,7 +1617,7 @@ static void test_WaitRing(HANDLE hcom)
trace("Success 0x%08x err %d evtmask 0x%08x\n", success, err, evtmask);
ok(success || err == ERROR_IO_PENDING, "overlapped WaitCommEvent failed\n");
trace("overlapped WriteCommEvent returned.\n");
trace("overlapped WaitCommEvent returned.\n");
if (!success && (err == ERROR_IO_PENDING))
ok(WaitForSingleObjectEx(hComPortEvent, TIMEOUT, TRUE) == 0,
"wait hComPortEvent failed\n");
@ -1482,7 +1628,7 @@ static void test_WaitRing(HANDLE hcom)
success, err, evtmask, after-before, after1-before);
ok(evtmask & EV_RING, "Failed to detect EV_RING: 0x%08x, expected 0x%08x\n",
evtmask, EV_CTS);
evtmask, EV_RING);
ok(GetCommModemStatus(hcom, &evtmask), "GetCommModemStatus failed\n");
if(defaultStat & MS_RING_ON)
ok((evtmask & MS_RING_ON) == 0,"DTR didn't change state!\n");
@ -1498,24 +1644,31 @@ static void test_WaitRing(HANDLE hcom)
args[1] = SETDTR;
else
args[1] = CLRDTR;
CloseHandle(hcom);
}
/*
* Wait for a change in DCD
* Needs Loopback from DTR to DCD
*/
static void test_WaitDcd(HANDLE hcom)
static void test_WaitDcd(void)
{
DCB dcb;
OVERLAPPED overlapped;
HANDLE hComPortEvent;
HANDLE alarmThread;
HANDLE hcom, hComPortEvent, alarmThread;
DWORD_PTR args[3];
DWORD alarmThreadId, before, after, after1, diff, success, err, written, evtmask=0, defaultStat = 0;
if (!loopback_dtr_dcd) return;
hcom = test_OpenComm(TRUE);
if (hcom == INVALID_HANDLE_VALUE) return;
ok(GetCommState(hcom, &dcb), "GetCommState failed\n");
if (dcb.fDtrControl == DTR_CONTROL_DISABLE)
{
trace("DTR_CONTROL_HANDSHAKE is set, so don't manipulate DTR\n");
CloseHandle(hcom);
return;
}
args[0]= TIMEOUT >>1;
@ -1543,7 +1696,7 @@ static void test_WaitDcd(HANDLE hcom)
trace("Success 0x%08x err %d evtmask 0x%08x\n", success, err, evtmask);
ok(success || err == ERROR_IO_PENDING, "overlapped WaitCommEvent failed\n");
trace("overlapped WriteCommEvent returned.\n");
trace("overlapped WaitCommEvent returned.\n");
if (!success && (err == ERROR_IO_PENDING))
ok(WaitForSingleObjectEx(hComPortEvent, TIMEOUT, TRUE) == 0,
"wait hComPortEvent failed\n");
@ -1554,7 +1707,7 @@ static void test_WaitDcd(HANDLE hcom)
success, err, evtmask, after-before, after1-before);
ok(evtmask & EV_RLSD, "Failed to detect EV_RLSD: 0x%08x, expected 0x%08x\n",
evtmask, EV_CTS);
evtmask, EV_RLSD);
ok(GetCommModemStatus(hcom, &evtmask), "GetCommModemStatus failed\n");
if(defaultStat & MS_RLSD_ON)
ok((evtmask & MS_RLSD_ON) == 0,"DTR didn't change state!\n");
@ -1570,6 +1723,8 @@ static void test_WaitDcd(HANDLE hcom)
args[1] = SETDTR;
else
args[1] = CLRDTR;
CloseHandle(hcom);
}
/*
@ -1593,14 +1748,18 @@ static DWORD CALLBACK set_CommBreak(LPVOID arg)
Wait for the Break condition (TX resp. RX active)
Needs Loopback TX-RX
*/
static void test_WaitBreak(HANDLE hcom)
static void test_WaitBreak(void)
{
OVERLAPPED overlapped;
HANDLE hComPortEvent;
HANDLE alarmThread;
HANDLE hcom, hComPortEvent, alarmThread;
DWORD_PTR args[2];
DWORD alarmThreadId, before, after, after1, diff, success, err, written, evtmask=0;
if (!loopback_txd_rxd) return;
hcom = test_OpenComm(TRUE);
if (hcom == INVALID_HANDLE_VALUE) return;
ok(SetCommMask(hcom, EV_BREAK), "SetCommMask failed\n");
hComPortEvent = CreateEvent( NULL, TRUE, FALSE, NULL );
ok(hComPortEvent != 0, "CreateEvent failed\n");
@ -1623,7 +1782,7 @@ static void test_WaitBreak(HANDLE hcom)
trace("Success 0x%08x err %d evtmask 0x%08x\n", success, err, evtmask);
ok(success || err == ERROR_IO_PENDING, "overlapped WaitCommEvent failed\n");
trace("overlapped WriteCommEvent returned.\n");
trace("overlapped WaitCommEvent returned.\n");
if (!success && (err == ERROR_IO_PENDING))
{
@ -1645,6 +1804,8 @@ static void test_WaitBreak(HANDLE hcom)
"Unexpected time %d, expected around %d\n", diff, TIMEOUT>>1);
ok(ClearCommBreak(hcom), "ClearCommBreak failed\n");
CloseHandle(hcom);
}
static void test_stdio(void)
@ -1657,97 +1818,112 @@ static void test_stdio(void)
"got error %u\n", GetLastError() );
}
START_TEST(comm)
static void test_WaitCommEvent(void)
{
HANDLE hcom;
/* use variables and not #define to compile the code */
BOOL loopback_txd_rxd = LOOPBACK_TXD_RXD;
BOOL loopback_rts_cts = LOOPBACK_CTS_RTS;
BOOL loopback_dtr_dsr = LOOPBACK_DTR_DSR;
BOOL loopback_dtr_ring = LOOPBACK_DTR_RING;
BOOL loopback_dtr_dcd = LOOPBACK_DTR_DCD;
DWORD evtmask, ret, bytes, before, after, last_event_time;
OVERLAPPED ovl_wait;
test_BuildCommDCB();
hcom = test_OpenComm(FALSE);
if (hcom != INVALID_HANDLE_VALUE)
hcom = test_OpenComm(TRUE);
if (hcom == INVALID_HANDLE_VALUE) return;
test_GetModemStatus(hcom);
ret = SetCommMask(hcom, 0x1fff);
ok(ret, "SetCommMask error %d\n", GetLastError());
S(U(ovl_wait)).Offset = 0;
S(U(ovl_wait)).OffsetHigh = 0;
ovl_wait.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
trace("waiting 10 secs for com port events (turn on/off the device)...\n");
last_event_time = 0;
before = GetTickCount();
do
{
test_GetModemStatus(hcom);
test_ReadTimeOut(hcom);
test_waittxempty(hcom);
CloseHandle(hcom);
}
hcom = test_OpenComm(FALSE);
if (hcom != INVALID_HANDLE_VALUE)
{
Sleep(200); /* Give the laster character of test_waittxempty to drop into the receiver */
test_ClearCommErrors(hcom);
CloseHandle(hcom);
}
hcom = test_OpenComm(FALSE);
if (hcom != INVALID_HANDLE_VALUE)
{
test_non_pending_errors(hcom);
CloseHandle(hcom);
}
if((loopback_txd_rxd) && ((hcom = test_OpenComm(FALSE))!=INVALID_HANDLE_VALUE))
{
test_LoopbackRead(hcom);
CloseHandle(hcom);
}
if((loopback_rts_cts) && ((hcom = test_OpenComm(FALSE))!=INVALID_HANDLE_VALUE))
{
test_LoopbackCtsRts(hcom);
CloseHandle(hcom);
}
if((loopback_dtr_dsr) && ((hcom = test_OpenComm(FALSE))!=INVALID_HANDLE_VALUE))
{
test_LoopbackDtrDsr(hcom);
CloseHandle(hcom);
}
if((loopback_dtr_ring) && ((hcom = test_OpenComm(FALSE))!=INVALID_HANDLE_VALUE))
{
test_LoopbackDtrRing(hcom);
CloseHandle(hcom);
}
if((loopback_dtr_dcd) && ((hcom = test_OpenComm(FALSE))!=INVALID_HANDLE_VALUE))
{
test_LoopbackDtrDcd(hcom);
CloseHandle(hcom);
}
if((loopback_txd_rxd) && ((hcom = test_OpenComm(TRUE))!=INVALID_HANDLE_VALUE))
{
test_WaitRx(hcom);
CloseHandle(hcom);
}
if((loopback_rts_cts) && ((hcom = test_OpenComm(TRUE))!=INVALID_HANDLE_VALUE))
{
test_WaitCts(hcom);
CloseHandle(hcom);
}
if((hcom = test_OpenComm(TRUE))!=INVALID_HANDLE_VALUE)
{
test_AbortWaitCts(hcom);
CloseHandle(hcom);
}
if((loopback_dtr_dsr) && ((hcom = test_OpenComm(TRUE))!=INVALID_HANDLE_VALUE))
{
test_WaitDsr(hcom);
CloseHandle(hcom);
}
if((loopback_dtr_ring) && ((hcom = test_OpenComm(TRUE))!=INVALID_HANDLE_VALUE))
{
test_WaitRing(hcom);
CloseHandle(hcom);
}
if((loopback_dtr_dcd) && ((hcom = test_OpenComm(TRUE))!=INVALID_HANDLE_VALUE))
{
test_WaitDcd(hcom);
CloseHandle(hcom);
}
if(loopback_txd_rxd && (hcom = test_OpenComm(TRUE))!=INVALID_HANDLE_VALUE)
{
test_WaitBreak(hcom);
CloseHandle(hcom);
}
test_stdio();
evtmask = 0;
SetLastError(0xdeadbeef);
ret = WaitCommEvent(hcom, &evtmask, &ovl_wait);
ok(!ret && GetLastError() == ERROR_IO_PENDING, "WaitCommEvent returned %d, error %d\n", ret, GetLastError());
if (GetLastError() != ERROR_IO_PENDING) goto done; /* no point in further testing */
for (;;)
{
ret = WaitForSingleObject(ovl_wait.hEvent, 500);
after = GetTickCount();
if (ret == WAIT_OBJECT_0)
{
last_event_time = after;
ret = GetOverlappedResult(hcom, &ovl_wait, &bytes, FALSE);
ok(ret, "GetOverlappedResult reported error %d\n", GetLastError());
ok(bytes == sizeof(evtmask), "expected %u, written %u\n", (UINT)sizeof(evtmask), bytes);
trace("WaitCommEvent: got events %#x\n", evtmask);
test_GetModemStatus(hcom);
break;
}
else
{
if (last_event_time || after - before >= 10000) goto done;
}
}
} while (after - before < 10000);
done:
CloseHandle(ovl_wait.hEvent);
CloseHandle(hcom);
}
static void test_FlushFileBuffers(void)
{
HANDLE hcom;
DWORD ret, bytes, errors;
COMSTAT stat;
hcom = test_OpenComm(FALSE);
if (hcom == INVALID_HANDLE_VALUE) return;
ret = WriteFile(hcom, "\0\0\0\0\0\0\0", 7, &bytes, NULL);
ok(ret, "WriteFile error %d\n", GetLastError());
ok(bytes == 7, "expected 7, got %u\n", bytes);
ret = FlushFileBuffers(hcom);
ok(ret, "FlushFileBuffers error %d\n", GetLastError());
ret = ClearCommError(hcom, &errors, &stat);
ok(ret, "ClearCommError error %d\n", GetLastError());
ok(stat.cbInQue == 0, "expected 0, got %d bytes in InQueue\n", stat.cbInQue);
ok(stat.cbOutQue == 0, "expected 0, got %d bytes in OutQueue\n", stat.cbOutQue);
ok(errors == 0, "expected errors 0, got %#x\n", errors);
CloseHandle(hcom);
}
START_TEST(comm)
{
test_ClearCommError(); /* keep it the very first test */
test_FlushFileBuffers();
test_BuildCommDCB();
test_ReadTimeOut();
test_waittxempty();
test_non_pending_errors();
test_LoopbackRead();
test_LoopbackCtsRts();
test_LoopbackDtrDsr();
test_LoopbackDtrRing();
test_LoopbackDtrDcd();
test_WaitRx();
test_WaitCts();
test_AbortWaitCts();
test_WaitDsr();
test_WaitRing();
test_WaitDcd();
test_WaitBreak();
test_stdio();
if (!winetest_interactive)
{
skip("interactive tests (set WINETEST_INTERACTIVE=1)\n");
return;
}
test_WaitCommEvent();
}

View file

@ -2608,6 +2608,18 @@ START_TEST(console)
ok(ret, "Getting sb info\n");
if (!ret) return;
/* Reduce the size of the buffer to the visible area plus 3 lines to speed
* up the tests.
*/
trace("Visible area: %dx%d - %dx%d Buffer size: %dx%d\n", sbi.srWindow.Left, sbi.srWindow.Top, sbi.srWindow.Right, sbi.srWindow.Bottom, sbi.dwSize.X, sbi.dwSize.Y);
sbi.dwSize.Y = size = (sbi.srWindow.Bottom + 1) + 3;
ret = SetConsoleScreenBufferSize(hConOut, sbi.dwSize);
ok(ret, "Setting sb info\n");
ret = GetConsoleScreenBufferInfo(hConOut, &sbi);
ok(ret, "Getting sb info\n");
ok(sbi.dwSize.Y == size, "Unexpected buffer size: %d instead of %d\n", sbi.dwSize.Y, size);
if (!ret) return;
/* Non interactive tests */
testCursor(hConOut, sbi.dwSize);
/* test parameters (FIXME: test functionality) */

View file

@ -666,6 +666,150 @@ static void test_debug_loop(int argc, char **argv)
ok(ret, "DeleteFileA failed, last error %#x.\n", GetLastError());
}
static void doChildren(int argc, char **argv)
{
const char *arguments = "debugger children last";
struct child_blackbox blackbox;
const char *blackbox_file, *p;
char event_name[MAX_PATH];
PROCESS_INFORMATION pi;
STARTUPINFOA si;
HANDLE event;
char *cmd;
BOOL ret;
if (!strcmp(argv[3], "last")) return;
blackbox_file = argv[3];
p = strrchr(blackbox_file, '\\');
p = p ? p+1 : blackbox_file;
strcpy(event_name, p);
strcat(event_name, "_init");
event = OpenEvent(EVENT_ALL_ACCESS, FALSE, event_name);
child_ok(event != NULL, "OpenEvent failed, last error %d.\n", GetLastError());
SetEvent(event);
CloseHandle(event);
p = strrchr(blackbox_file, '\\');
p = p ? p+1 : blackbox_file;
strcpy(event_name, p);
strcat(event_name, "_attach");
event = OpenEvent(EVENT_ALL_ACCESS, FALSE, event_name);
child_ok(event != NULL, "OpenEvent failed, last error %d.\n", GetLastError());
WaitForSingleObject(event, INFINITE);
CloseHandle(event);
cmd = HeapAlloc(GetProcessHeap(), 0, strlen(argv[0]) + strlen(arguments) + 2);
sprintf(cmd, "%s %s", argv[0], arguments);
memset(&si, 0, sizeof(si));
si.cb = sizeof(si);
ret = CreateProcessA(NULL, cmd, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
child_ok(ret, "CreateProcess failed, last error %d.\n", GetLastError());
child_ok(WaitForSingleObject(pi.hProcess, 10000) == WAIT_OBJECT_0,
"Timed out waiting for the child to exit\n");
ret = CloseHandle(pi.hThread);
child_ok(ret, "CloseHandle failed, last error %d.\n", GetLastError());
ret = CloseHandle(pi.hProcess);
child_ok(ret, "CloseHandle failed, last error %d.\n", GetLastError());
blackbox.failures = child_failures;
save_blackbox(blackbox_file, &blackbox, sizeof(blackbox));
}
static void test_debug_children(char *name, DWORD flag, BOOL debug_child)
{
const char *arguments = "debugger children";
struct child_blackbox blackbox;
char blackbox_file[MAX_PATH], *p;
char event_name[MAX_PATH];
PROCESS_INFORMATION pi;
STARTUPINFOA si;
HANDLE event_init, event_attach;
char *cmd;
BOOL debug, ret;
BOOL got_child_event = FALSE;
if (!pDebugActiveProcessStop || !pCheckRemoteDebuggerPresent)
{
win_skip("DebugActiveProcessStop or CheckRemoteDebuggerPresent not available, skipping test.\n");
return;
}
get_file_name(blackbox_file);
cmd = HeapAlloc(GetProcessHeap(), 0, strlen(name) + strlen(arguments) + strlen(blackbox_file) + 5);
sprintf(cmd, "%s %s \"%s\"", name, arguments, blackbox_file);
p = strrchr(blackbox_file, '\\');
p = p ? p+1 : blackbox_file;
strcpy(event_name, p);
strcat(event_name, "_init");
event_init = CreateEvent(NULL, FALSE, FALSE, event_name);
ok(event_init != NULL, "OpenEvent failed, last error %d.\n", GetLastError());
p = strrchr(blackbox_file, '\\');
p = p ? p+1 : blackbox_file;
strcpy(event_name, p);
strcat(event_name, "_attach");
event_attach = CreateEvent(NULL, FALSE, flag!=0, event_name);
ok(event_attach != NULL, "CreateEvent failed, last error %d.\n", GetLastError());
memset(&si, 0, sizeof(si));
si.cb = sizeof(si);
ret = CreateProcessA(NULL, cmd, NULL, NULL, FALSE, flag, NULL, NULL, &si, &pi);
ok(ret, "CreateProcess failed, last error %d.\n", GetLastError());
HeapFree(GetProcessHeap(), 0, cmd);
if (!flag)
{
WaitForSingleObject(event_init, INFINITE);
ret = DebugActiveProcess(pi.dwProcessId);
ok(ret, "DebugActiveProcess failed, last error %d.\n", GetLastError());
ret = SetEvent(event_attach);
ok(ret, "SetEvent failed, last error %d.\n", GetLastError());
}
ret = pCheckRemoteDebuggerPresent(pi.hProcess, &debug);
ok(ret, "CheckRemoteDebuggerPresent failed, last error %d.\n", GetLastError());
ok(debug, "Expected debug != 0, got %x.\n", debug);
for (;;)
{
DEBUG_EVENT ev;
ret = WaitForDebugEvent(&ev, INFINITE);
ok(ret, "WaitForDebugEvent failed, last error %d.\n", GetLastError());
if (!ret) break;
if (ev.dwDebugEventCode==EXIT_PROCESS_DEBUG_EVENT && ev.dwProcessId==pi.dwProcessId) break;
else if (ev.dwProcessId != pi.dwProcessId) got_child_event = TRUE;
ret = ContinueDebugEvent(ev.dwProcessId, ev.dwThreadId, DBG_CONTINUE);
ok(ret, "ContinueDebugEvent failed, last error %d.\n", GetLastError());
if (!ret) break;
}
if(debug_child)
ok(got_child_event, "didn't get any child events (flag: %x).\n", flag);
else
ok(!got_child_event, "got child event (flag: %x).\n", flag);
CloseHandle(event_init);
CloseHandle(event_attach);
ret = CloseHandle(pi.hThread);
ok(ret, "CloseHandle failed, last error %d.\n", GetLastError());
ret = CloseHandle(pi.hProcess);
ok(ret, "CloseHandle failed, last error %d.\n", GetLastError());
load_blackbox(blackbox_file, &blackbox, sizeof(blackbox));
ok(!blackbox.failures, "Got %d failures from child process.\n", blackbox.failures);
ret = DeleteFileA(blackbox_file);
ok(ret, "DeleteFileA failed, last error %d.\n", GetLastError());
}
START_TEST(debugger)
{
HMODULE hdll;
@ -691,10 +835,17 @@ START_TEST(debugger)
{
doChild(myARGC, myARGV);
}
else if (myARGC >= 4 && !strcmp(myARGV[2], "children"))
{
doChildren(myARGC, myARGV);
}
else
{
test_ExitCode();
test_RemoteDebugger();
test_debug_loop(myARGC, myARGV);
test_debug_children(myARGV[0], DEBUG_PROCESS, TRUE);
test_debug_children(myARGV[0], DEBUG_ONLY_THIS_PROCESS, FALSE);
test_debug_children(myARGV[0], 0, FALSE);
}
}

View file

@ -114,18 +114,14 @@ static void test_GetDiskFreeSpaceA(void)
drive, ret, GetLastError());
else
{
ok(ret ||
GetLastError() == ERROR_NOT_READY ||
GetLastError() == ERROR_INVALID_FUNCTION ||
GetLastError() == ERROR_INVALID_DRIVE ||
GetLastError() == ERROR_PATH_NOT_FOUND ||
GetLastError() == ERROR_REQUEST_ABORTED ||
GetLastError() == ERROR_NETNAME_DELETED ||
GetLastError() == ERROR_UNRECOGNIZED_VOLUME,
"GetDiskFreeSpaceA(%s): ret=%d GetLastError=%d\n",
drive, ret, GetLastError());
if (!ret)
/* GetDiskFreeSpaceA() should succeed, but it can fail with too many
different GetLastError() results to be usable for a ok() */
trace("GetDiskFreeSpaceA(%s) failed with %d\n", drive, GetLastError());
if( GetVersion() & 0x80000000)
/* win3.0 thru winME */
/* win3.0 through winME */
ok( total_clusters <= 65535,
"total clusters is %d > 65535\n", total_clusters);
else if (pGetDiskFreeSpaceExA) {
@ -135,14 +131,12 @@ static void test_GetDiskFreeSpaceA(void)
tot.QuadPart = sectors_per_cluster;
tot.QuadPart = (tot.QuadPart * bytes_per_sector) * total_clusters;
ret = pGetDiskFreeSpaceExA( drive, &d, &totEx, NULL);
ok( ret ||
GetLastError() == ERROR_NOT_READY ||
GetLastError() == ERROR_INVALID_FUNCTION ||
GetLastError() == ERROR_PATH_NOT_FOUND ||
GetLastError() == ERROR_REQUEST_ABORTED ||
GetLastError() == ERROR_NETNAME_DELETED ||
GetLastError() == ERROR_UNRECOGNIZED_VOLUME,
"GetDiskFreeSpaceExA( %s ) failed. GetLastError=%d\n", drive, GetLastError());
if (!ret)
/* GetDiskFreeSpaceExA() should succeed, but it can fail with too many
different GetLastError() results to be usable for a ok() */
trace("GetDiskFreeSpaceExA(%s) failed with %d\n", drive, GetLastError());
ok( bytes_per_sector == 0 || /* empty cd rom drive */
totEx.QuadPart <= tot.QuadPart,
"GetDiskFreeSpaceA should report at least as much bytes on disk %s as GetDiskFreeSpaceExA\n", drive);
@ -196,15 +190,10 @@ static void test_GetDiskFreeSpaceW(void)
ok(!ret && GetLastError() == ERROR_PATH_NOT_FOUND,
"GetDiskFreeSpaceW(%c): ret=%d GetLastError=%d\n",
drive[0], ret, GetLastError());
else
ok( ret ||
GetLastError() == ERROR_NOT_READY ||
GetLastError() == ERROR_INVALID_FUNCTION ||
GetLastError() == ERROR_PATH_NOT_FOUND ||
GetLastError() == ERROR_REQUEST_ABORTED ||
GetLastError() == ERROR_UNRECOGNIZED_VOLUME,
"GetDiskFreeSpaceW(%c): ret=%d GetLastError=%d\n",
drive[0], ret, GetLastError());
else if (!ret)
/* GetDiskFreeSpaceW() should succeed, but it can fail with too many
different GetLastError() results to be usable for a ok() */
trace("GetDiskFreeSpaceW(%c) failed with %d\n", drive[0], GetLastError());
}
logical_drives >>= 1;
}

View file

@ -652,11 +652,11 @@ static void test_CopyFileA(void)
"copying from an r+w opened and r shared file failed (ret=%d, err=%d)\n", retok, GetLastError());
CloseHandle(hfile);
/* copying from a delete-locked source is unreliable */
/* copying from a delete-locked source mostly succeeds */
hfile = CreateFileA(source, DELETE, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0);
ok(hfile != INVALID_HANDLE_VALUE, "failed to open source file, error %d\n", GetLastError());
retok = CopyFileA(source, dest, FALSE);
ok((!retok && GetLastError() == ERROR_SHARING_VIOLATION) || broken(retok) /* 98, Vista, 2k8, 7 */,
ok(retok || broken(!retok && GetLastError() == ERROR_SHARING_VIOLATION) /* NT, 2000, XP */,
"copying from a delete-locked file failed (ret=%d, err=%d)\n", retok, GetLastError());
CloseHandle(hfile);
@ -1783,10 +1783,10 @@ static BOOL create_fake_dll( LPCSTR filename )
nt->FileHeader.Machine = IMAGE_FILE_MACHINE_AMD64;
#elif defined __powerpc__
nt->FileHeader.Machine = IMAGE_FILE_MACHINE_POWERPC;
#elif defined __sparc__
nt->FileHeader.Machine = IMAGE_FILE_MACHINE_SPARC;
#elif defined __arm__
nt->FileHeader.Machine = IMAGE_FILE_MACHINE_ARMNT;
#elif defined __aarch64__
nt->FileHeader.Machine = IMAGE_FILE_MACHINE_ARM64;
#else
# error You must specify the machine type
#endif
@ -3296,7 +3296,8 @@ static void test_GetFileInformationByHandleEx(void)
/* ensure the existence of a file in the temp folder */
ret2 = GetTempFileNameA(tempPath, "abc", 0, tempFileName);
ok(ret2, "GetFileInformationByHandleEx: GetTempFileNameA failed, got error %u.\n", GetLastError());
ok(GetFileAttributesA(tempFileName) != INVALID_FILE_ATTRIBUTES, "GetFileInformationByHandleEx: "
ret2 = GetFileAttributesA(tempFileName);
ok(ret2 != INVALID_FILE_ATTRIBUTES, "GetFileInformationByHandleEx: "
"GetFileAttributesA failed to find the temp file, got error %u.\n", GetLastError());
directory = CreateFileA(tempPath, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
@ -3359,7 +3360,8 @@ static void test_OpenFileById(void)
/* ensure the existence of a file in the temp folder */
ret2 = GetTempFileNameA(tempPath, "abc", 0, tempFileName);
ok(ret2, "OpenFileById: GetTempFileNameA failed, got error %u.\n", GetLastError());
ok(GetFileAttributesA(tempFileName) != INVALID_FILE_ATTRIBUTES,
ret2 = GetFileAttributesA(tempFileName);
ok(ret2 != INVALID_FILE_ATTRIBUTES,
"OpenFileById: GetFileAttributesA failed to find the temp file, got error %u\n", GetLastError());
ret2 = MultiByteToWideChar(CP_ACP, 0, tempFileName + strlen(tempPath), -1, tempFileNameW, sizeof(tempFileNameW)/sizeof(tempFileNameW[0]));
@ -3502,7 +3504,8 @@ static void test_SetFileValidData(void)
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &token) ||
!LookupPrivilegeValue(NULL, SE_MANAGE_VOLUME_NAME, &privs.Privileges[0].Luid) ||
!AdjustTokenPrivileges(token, FALSE, &privs, sizeof(privs), NULL, NULL))
!AdjustTokenPrivileges(token, FALSE, &privs, sizeof(privs), NULL, NULL) ||
GetLastError() == ERROR_NOT_ALL_ASSIGNED)
{
win_skip("cannot enable SE_MANAGE_VOLUME_NAME privilege\n");
CloseHandle(token);

View file

@ -86,6 +86,7 @@ static void test_heap(void)
HGLOBAL gbl;
HGLOBAL hsecond;
SIZE_T size, size2;
const SIZE_T max_size = 1024, init_size = 10;
/* Heap*() functions */
mem = HeapAlloc(GetProcessHeap(), 0, 0);
@ -245,6 +246,28 @@ static void test_heap(void)
"Expected ERROR_INVALID_HANDLE or ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
}
/* GMEM_FIXED block expands in place only without flags */
for (size = 1; size <= max_size; size <<= 1) {
gbl = GlobalAlloc(GMEM_FIXED, init_size);
SetLastError(MAGIC_DEAD);
hsecond = GlobalReAlloc(gbl, size + init_size, 0);
ok(hsecond == gbl || (hsecond == NULL && GetLastError() == ERROR_NOT_ENOUGH_MEMORY),
"got %p with %x (expected %p or NULL) @%ld\n", hsecond, GetLastError(), gbl, size);
GlobalFree(gbl);
}
/* GMEM_FIXED block can be relocated with GMEM_MOVEABLE */
for (size = 1; size <= max_size; size <<= 1) {
gbl = GlobalAlloc(GMEM_FIXED, init_size);
SetLastError(MAGIC_DEAD);
hsecond = GlobalReAlloc(gbl, size + init_size, GMEM_MOVEABLE);
ok(hsecond != NULL,
"got %p with %x (expected non-NULL) @%ld\n", hsecond, GetLastError(), size);
mem = GlobalLock(hsecond);
ok(mem == hsecond, "got %p (expected %p) @%ld\n", mem, hsecond, size);
GlobalFree(hsecond);
}
gbl = GlobalAlloc(GMEM_DDESHARE, 100);
res = GlobalUnlock(gbl);
@ -382,6 +405,28 @@ static void test_heap(void)
"returned %d with %d (expected '0' with ERROR_INVALID_HANDLE)\n",
res, GetLastError());
/* LMEM_FIXED block expands in place only without flags */
for (size = 1; size <= max_size; size <<= 1) {
gbl = LocalAlloc(LMEM_FIXED, init_size);
SetLastError(MAGIC_DEAD);
hsecond = LocalReAlloc(gbl, size + init_size, 0);
ok(hsecond == gbl || (hsecond == NULL && GetLastError() == ERROR_NOT_ENOUGH_MEMORY),
"got %p with %x (expected %p or NULL) @%ld\n", hsecond, GetLastError(), gbl, size);
LocalFree(gbl);
}
/* LMEM_FIXED memory can be relocated with LMEM_MOVEABLE */
for (size = 1; size <= max_size; size <<= 1) {
gbl = LocalAlloc(LMEM_FIXED, init_size);
SetLastError(MAGIC_DEAD);
hsecond = LocalReAlloc(gbl, size + init_size, LMEM_MOVEABLE);
ok(hsecond != NULL,
"got %p with %x (expected non-NULL) @%ld\n", hsecond, GetLastError(), size);
mem = LocalLock(hsecond);
ok(mem == hsecond, "got %p (expected %p) @%ld\n", mem, hsecond, size);
LocalFree(hsecond);
}
/* trying to unlock pointer from LocalAlloc */
gbl = LocalAlloc(LMEM_FIXED, 100);
SetLastError(0xdeadbeef);

File diff suppressed because it is too large Load diff

View file

@ -283,11 +283,23 @@ static void test_GetLocaleInfoW(void)
ret = GetLocaleInfoW(lcid_en_neut, LOCALE_SCOUNTRY, bufferW, COUNTOF(bufferW));
ok(ret, "got %d\n", ret);
ok(!lstrcmpW(statesW, bufferW), "got wrong name %s\n", wine_dbgstr_w(bufferW));
if ((PRIMARYLANGID(LANGIDFROMLCID(GetSystemDefaultLCID())) != LANG_ENGLISH) ||
(PRIMARYLANGID(LANGIDFROMLCID(GetThreadLocale())) != LANG_ENGLISH))
{
skip("Non-English locale\n");
}
else
ok(!lstrcmpW(statesW, bufferW), "got wrong name %s\n", wine_dbgstr_w(bufferW));
ret = GetLocaleInfoW(lcid_en_neut, LOCALE_SLANGUAGE, bufferW, COUNTOF(bufferW));
ok(ret, "got %d\n", ret);
ok(!lstrcmpW(slangW, bufferW), "got wrong name %s\n", wine_dbgstr_w(bufferW));
if ((PRIMARYLANGID(LANGIDFROMLCID(GetSystemDefaultLCID())) != LANG_ENGLISH) ||
(PRIMARYLANGID(LANGIDFROMLCID(GetThreadLocale())) != LANG_ENGLISH))
{
skip("Non-English locale\n");
}
else
ok(!lstrcmpW(slangW, bufferW), "got wrong name %s\n", wine_dbgstr_w(bufferW));
while (*ptr->name)
{
@ -1319,6 +1331,7 @@ static const struct comparestringa_entry comparestringa_data[] = {
static void test_CompareStringA(void)
{
int ret, i;
char a[256];
LCID lcid = MAKELCID(MAKELANGID(LANG_FRENCH, SUBLANG_DEFAULT), SORT_DEFAULT);
for (i = 0; i < sizeof(comparestringa_data)/sizeof(struct comparestringa_entry); i++)
@ -1452,6 +1465,12 @@ static void test_CompareStringA(void)
todo_wine ok(ret == CSTR_LESS_THAN, "\'\\xB9\' character should be greater than \'a\'\n");
ret = CompareStringA(lcid, 0, "\xB9", 1, "b", 1);
ok(ret == CSTR_LESS_THAN, "\'\\xB9\' character should be smaller than \'b\'\n");
memset(a, 'a', sizeof(a));
SetLastError(0xdeadbeef);
ret = CompareStringA(lcid, 0, a, sizeof(a), a, sizeof(a));
ok (GetLastError() == 0xdeadbeef && ret == CSTR_EQUAL,
"ret %d, error %d, expected value %d\n", ret, GetLastError(), CSTR_EQUAL);
}
static void test_LCMapStringA(void)
@ -1847,7 +1866,7 @@ static const struct neutralsublang_name_t neutralsublang_names[] = {
{ {'d','e',0}, MAKELCID(MAKELANGID(LANG_GERMAN, SUBLANG_GERMAN), SORT_DEFAULT) },
{ {'e','n',0}, MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT) },
{ {'e','s',0}, MAKELCID(MAKELANGID(LANG_SPANISH, SUBLANG_SPANISH_MODERN), SORT_DEFAULT), 1 },
{ {'g','a',0}, MAKELCID(MAKELANGID(LANG_IRISH, SUBLANG_IRISH_IRELAND), SORT_DEFAULT), 1 },
{ {'g','a',0}, MAKELCID(MAKELANGID(LANG_IRISH, SUBLANG_IRISH_IRELAND), SORT_DEFAULT) },
{ {'i','t',0}, MAKELCID(MAKELANGID(LANG_ITALIAN, SUBLANG_ITALIAN), SORT_DEFAULT) },
{ {'m','s',0}, MAKELCID(MAKELANGID(LANG_MALAY, SUBLANG_MALAY_MALAYSIA), SORT_DEFAULT) },
{ {'n','l',0}, MAKELCID(MAKELANGID(LANG_DUTCH, SUBLANG_DUTCH), SORT_DEFAULT) },
@ -2661,7 +2680,7 @@ static BOOL CALLBACK lgrplocale_procA(LGRPID lgrpid, LCID lcid, LPSTR lpszNum,
ok(pIsValidLanguageGroup(lgrpid, LGRPID_SUPPORTED) == TRUE,
"Enumerated grp %d not valid\n", lgrpid);
ok(IsValidLocale(lcid, LCID_SUPPORTED) == TRUE,
"Enumerated grp locale %d not valid\n", lcid);
"Enumerated grp locale %04x not valid\n", lcid);
return TRUE;
}
@ -2979,7 +2998,7 @@ static void test_GetStringTypeW(void)
C1_SPACE | C1_BLANK,
C1_SPACE | C1_BLANK};
static const WCHAR undefined[] = {0x378, 0x379, 0x604, 0xfff8, 0xfffe};
static const WCHAR undefined[] = {0x378, 0x379, 0x5ff, 0xfff8, 0xfffe};
/* Lu, Ll, Lt */
static const WCHAR alpha[] = {0x47, 0x67, 0x1c5};
@ -3377,6 +3396,10 @@ static void test_IdnToUnicode(void)
for (i=0; i<sizeof(test_data)/sizeof(*test_data); i++)
{
ret = pIdnToUnicode(test_data[i].flags, test_data[i].in,
test_data[i].in_len, NULL, 0);
ok(ret == test_data[i].ret, "%d) ret = %d\n", i, ret);
SetLastError(0xdeadbeef);
ret = pIdnToUnicode(test_data[i].flags, test_data[i].in,
test_data[i].in_len, buf, sizeof(buf));
@ -3437,7 +3460,13 @@ static void test_GetLocaleInfoEx(void)
ret = pGetLocaleInfoEx(enW, LOCALE_SCOUNTRY, bufferW, sizeof(bufferW)/sizeof(WCHAR));
ok(ret == lstrlenW(bufferW)+1, "got %d\n", ret);
ok(!lstrcmpW(bufferW, statesW), "got %s\n", wine_dbgstr_w(bufferW));
if ((PRIMARYLANGID(LANGIDFROMLCID(GetSystemDefaultLCID())) != LANG_ENGLISH) ||
(PRIMARYLANGID(LANGIDFROMLCID(GetThreadLocale())) != LANG_ENGLISH))
{
skip("Non-English locale\n");
}
else
ok(!lstrcmpW(bufferW, statesW), "got %s\n", wine_dbgstr_w(bufferW));
bufferW[0] = 0;
SetLastError(0xdeadbeef);

View file

@ -21,6 +21,7 @@
#include <stdarg.h>
#include <stdio.h>
#include <assert.h>
#include "wine/test.h"
#include "windef.h"
#include "winbase.h"
@ -558,9 +559,10 @@ static void test_ShortPathCase(const char *tmpdir, const char *dirname,
{
char buf[MAX_PATH], shortbuf[MAX_PATH];
HANDLE hndl;
int i;
size_t i;
snprintf(buf,sizeof(buf),"%s\\%s\\%s",tmpdir,dirname,filename);
assert(strlen(tmpdir) + strlen(dirname) + strlen(filename) + 2 < sizeof(buf));
sprintf(buf,"%s\\%s\\%s",tmpdir,dirname,filename);
GetShortPathNameA(buf,shortbuf,sizeof(shortbuf));
hndl = CreateFileA(shortbuf,GENERIC_READ|GENERIC_WRITE,0,NULL,OPEN_EXISTING,0,NULL);
ok(hndl!=INVALID_HANDLE_VALUE,"CreateFileA failed (%d)\n",GetLastError());
@ -1273,7 +1275,15 @@ static void test_GetShortPathNameW(void)
ok( length, "GetShortPathNameW returned 0.\n" );
ret = GetShortPathNameW( path, short_path, length );
ok( ret, "GetShortPathNameW returned 0.\n" );
lstrcatW( short_path, name );
/* GetShortPathName for a non-existent short file name should fail */
SetLastError(0xdeadbeef);
length = GetShortPathNameW( short_path, path, 0 );
ok(!length, "GetShortPathNameW should fail\n");
ok(GetLastError() == ERROR_FILE_NOT_FOUND, "expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
file = CreateFileW( short_path, GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
ok( file != INVALID_HANDLE_VALUE, "File was not created.\n" );

View file

@ -1612,8 +1612,8 @@ static void test_GetProcessVersion(void)
si.cb = sizeof(si);
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = SW_HIDE;
ret = CreateProcessA(NULL, cmdline, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
SetLastError(0xdeadbeef);
ret = CreateProcessA(NULL, cmdline, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
ok(ret, "CreateProcess error %u\n", GetLastError());
SetLastError(0xdeadbeef);
@ -1926,6 +1926,140 @@ static void test_RegistryQuota(void)
"Expected GetSystemRegistryQuota to return TRUE, got %d\n", ret);
}
static void test_TerminateProcess(void)
{
static char cmdline[] = "winver.exe";
PROCESS_INFORMATION pi;
STARTUPINFO si;
DWORD ret;
HANDLE dummy, thread;
memset(&si, 0, sizeof(si));
si.cb = sizeof(si);
SetLastError(0xdeadbeef);
ret = CreateProcess(NULL, cmdline, NULL, NULL, FALSE, CREATE_SUSPENDED, NULL, NULL, &si, &pi);
ok(ret, "CreateProcess error %u\n", GetLastError());
SetLastError(0xdeadbeef);
thread = CreateRemoteThread(pi.hProcess, NULL, 0, (void *)0xdeadbeef, NULL, CREATE_SUSPENDED, &ret);
ok(thread != 0, "CreateRemoteThread error %d\n", GetLastError());
/* create a not closed thread handle duplicate in the target process */
SetLastError(0xdeadbeef);
ret = DuplicateHandle(GetCurrentProcess(), thread, pi.hProcess, &dummy,
0, FALSE, DUPLICATE_SAME_ACCESS);
ok(ret, "DuplicateHandle error %u\n", GetLastError());
SetLastError(0xdeadbeef);
ret = TerminateThread(thread, 0);
ok(ret, "TerminateThread error %u\n", GetLastError());
CloseHandle(thread);
SetLastError(0xdeadbeef);
ret = TerminateProcess(pi.hProcess, 0);
ok(ret, "TerminateProcess error %u\n", GetLastError());
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
}
static void test_DuplicateHandle(void)
{
char path[MAX_PATH], file_name[MAX_PATH];
HANDLE f, fmin, out;
DWORD info;
BOOL r;
r = DuplicateHandle(GetCurrentProcess(), GetCurrentProcess(),
GetCurrentProcess(), &out, 0, FALSE,
DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE);
ok(r, "DuplicateHandle error %u\n", GetLastError());
r = GetHandleInformation(out, &info);
ok(r, "GetHandleInformation error %u\n", GetLastError());
ok(info == 0, "info = %x\n", info);
ok(out != GetCurrentProcess(), "out = GetCurrentProcess()\n");
CloseHandle(out);
r = DuplicateHandle(GetCurrentProcess(), GetCurrentProcess(),
GetCurrentProcess(), &out, 0, TRUE,
DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE);
ok(r, "DuplicateHandle error %u\n", GetLastError());
r = GetHandleInformation(out, &info);
ok(r, "GetHandleInformation error %u\n", GetLastError());
ok(info == HANDLE_FLAG_INHERIT, "info = %x\n", info);
ok(out != GetCurrentProcess(), "out = GetCurrentProcess()\n");
CloseHandle(out);
GetTempPath(MAX_PATH, path);
GetTempFileName(path, "wt", 0, file_name);
f = CreateFile(file_name, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0);
if (f == INVALID_HANDLE_VALUE)
{
ok(0, "could not create %s\n", file_name);
return;
}
r = DuplicateHandle(GetCurrentProcess(), f, GetCurrentProcess(), &out,
0, FALSE, DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE);
ok(r, "DuplicateHandle error %u\n", GetLastError());
ok(f == out, "f != out\n");
r = GetHandleInformation(out, &info);
ok(r, "GetHandleInformation error %u\n", GetLastError());
ok(info == 0, "info = %x\n", info);
r = DuplicateHandle(GetCurrentProcess(), f, GetCurrentProcess(), &out,
0, TRUE, DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE);
ok(r, "DuplicateHandle error %u\n", GetLastError());
ok(f == out, "f != out\n");
r = GetHandleInformation(out, &info);
ok(r, "GetHandleInformation error %u\n", GetLastError());
ok(info == HANDLE_FLAG_INHERIT, "info = %x\n", info);
r = SetHandleInformation(f, HANDLE_FLAG_PROTECT_FROM_CLOSE, HANDLE_FLAG_PROTECT_FROM_CLOSE);
ok(r, "SetHandleInformation error %u\n", GetLastError());
r = DuplicateHandle(GetCurrentProcess(), f, GetCurrentProcess(), &out,
0, TRUE, DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE);
ok(r, "DuplicateHandle error %u\n", GetLastError());
ok(f != out, "f == out\n");
r = GetHandleInformation(out, &info);
ok(r, "GetHandleInformation error %u\n", GetLastError());
ok(info == HANDLE_FLAG_INHERIT, "info = %x\n", info);
r = SetHandleInformation(f, HANDLE_FLAG_PROTECT_FROM_CLOSE, 0);
ok(r, "SetHandleInformation error %u\n", GetLastError());
/* Test if DuplicateHandle allocates first free handle */
if (f > out)
{
fmin = out;
}
else
{
fmin = f;
f = out;
}
CloseHandle(fmin);
r = DuplicateHandle(GetCurrentProcess(), f, GetCurrentProcess(), &out,
0, TRUE, DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE);
ok(r, "DuplicateHandle error %u\n", GetLastError());
ok(f == out, "f != out\n");
CloseHandle(out);
DeleteFile(file_name);
f = CreateFile("CONIN$", GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, 0);
if (!is_console(f))
{
skip("DuplicateHandle on console handle\n");
CloseHandle(f);
return;
}
r = DuplicateHandle(GetCurrentProcess(), f, GetCurrentProcess(), &out,
0, FALSE, DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE);
ok(r, "DuplicateHandle error %u\n", GetLastError());
todo_wine ok(f != out, "f == out\n");
CloseHandle(out);
}
START_TEST(process)
{
int b = init();
@ -1937,6 +2071,7 @@ START_TEST(process)
doChild(myARGV[2], (myARGC == 3) ? NULL : myARGV[3]);
return;
}
test_TerminateProcess();
test_Startup();
test_CommandLine();
test_Directory();
@ -1953,6 +2088,7 @@ START_TEST(process)
test_Handles();
test_SystemInfo();
test_RegistryQuota();
test_DuplicateHandle();
/* things that can be tested:
* lookup: check the way program to be executed is searched
* handles: check the handle inheritance stuff (+sec options)

View file

@ -1164,7 +1164,7 @@ static void test_initonce(void)
if (!pInitOnceInitialize || !pInitOnceExecuteOnce)
{
skip("one-time initialization API not supported\n");
win_skip("one-time initialization API not supported\n");
return;
}
@ -1177,7 +1177,7 @@ static void test_initonce(void)
g_initcallback_ret = TRUE;
g_initctxt = NULL;
ret = pInitOnceExecuteOnce(&initonce, initonce_callback, (void*)0xdeadbeef, &g_initctxt);
ok(ret, "got wrong ret value %d\n", ret);
ok(ret, "wrong ret %d err %u\n", ret, GetLastError());
ok(initonce.Ptr == (void*)0x2, "got %p\n", initonce.Ptr);
ok(g_initctxt == NULL, "got %p\n", g_initctxt);
ok(g_initcallback_called, "got %d\n", g_initcallback_called);
@ -1186,7 +1186,7 @@ static void test_initonce(void)
g_initctxt = NULL;
g_initcallback_called = FALSE;
ret = pInitOnceExecuteOnce(&initonce, initonce_callback, (void*)0xdeadbeef, &g_initctxt);
ok(ret, "got wrong ret value %d\n", ret);
ok(ret, "wrong ret %d err %u\n", ret, GetLastError());
ok(initonce.Ptr == (void*)0x2, "got %p\n", initonce.Ptr);
ok(g_initctxt == NULL, "got %p\n", g_initctxt);
ok(!g_initcallback_called, "got %d\n", g_initcallback_called);
@ -1196,7 +1196,7 @@ static void test_initonce(void)
/* 2 lower order bits should never be used, you'll get a crash in result */
g_initctxt = (void*)0xFFFFFFF0;
ret = pInitOnceExecuteOnce(&initonce, initonce_callback, (void*)0xdeadbeef, &g_initctxt);
ok(ret, "got wrong ret value %d\n", ret);
ok(ret, "wrong ret %d err %u\n", ret, GetLastError());
ok(initonce.Ptr == (void*)0xFFFFFFF2, "got %p\n", initonce.Ptr);
ok(g_initctxt == (void*)0xFFFFFFF0, "got %p\n", g_initctxt);
ok(g_initcallback_called, "got %d\n", g_initcallback_called);
@ -1206,18 +1206,19 @@ static void test_initonce(void)
g_initcallback_called = FALSE;
g_initctxt = NULL;
pInitOnceInitialize(&initonce);
SetLastError( 0xdeadbeef );
ret = pInitOnceExecuteOnce(&initonce, initonce_callback, (void*)0xdeadbeef, &g_initctxt);
ok(!ret, "got wrong ret value %d\n", ret);
ok(!ret && GetLastError() == 0xdeadbeef, "got wrong ret value %d err %u\n", ret, GetLastError());
ok(initonce.Ptr == NULL, "got %p\n", initonce.Ptr);
ok(g_initctxt == NULL, "got %p\n", g_initctxt);
ok(g_initcallback_called, "got %d\n", g_initcallback_called);
/* blocking initialzation without a callback */
/* blocking initialization without a callback */
pInitOnceInitialize(&initonce);
g_initctxt = NULL;
pending = FALSE;
ret = pInitOnceBeginInitialize(&initonce, 0, &pending, &g_initctxt);
ok(ret, "got wrong ret value %d\n", ret);
ok(ret, "wrong ret %d err %u\n", ret, GetLastError());
ok(pending, "got %d\n", pending);
ok(initonce.Ptr == (void*)1, "got %p\n", initonce.Ptr);
ok(g_initctxt == NULL, "got %p\n", g_initctxt);
@ -1225,41 +1226,192 @@ static void test_initonce(void)
g_initctxt = NULL;
pending = 0xf;
SetLastError( 0xdeadbeef );
ret = pInitOnceBeginInitialize(&initonce, INIT_ONCE_CHECK_ONLY, &pending, &g_initctxt);
ok(!ret, "got wrong ret value %d\n", ret);
ok(!ret && GetLastError() == ERROR_GEN_FAILURE, "wrong ret %d err %u\n", ret, GetLastError());
ok(pending == 0xf, "got %d\n", pending);
ok(initonce.Ptr == (void*)1, "got %p\n", initonce.Ptr);
ok(g_initctxt == NULL, "got %p\n", g_initctxt);
g_initctxt = (void*)0xdeadbee0;
SetLastError( 0xdeadbeef );
ret = pInitOnceComplete(&initonce, INIT_ONCE_INIT_FAILED, g_initctxt);
ok(!ret, "got wrong ret value %d\n", ret);
ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER, "wrong ret %d err %u\n", ret, GetLastError());
ok(initonce.Ptr == (void*)1, "got %p\n", initonce.Ptr);
/* once failed already */
g_initctxt = (void*)0xdeadbee0;
ret = pInitOnceComplete(&initonce, 0, g_initctxt);
ok(ret, "got wrong ret value %d\n", ret);
ok(ret, "wrong ret %d err %u\n", ret, GetLastError());
ok(initonce.Ptr == (void*)0xdeadbee2, "got %p\n", initonce.Ptr);
pInitOnceInitialize(&initonce);
SetLastError( 0xdeadbeef );
ret = pInitOnceComplete(&initonce, INIT_ONCE_INIT_FAILED, NULL);
ok(!ret && GetLastError() == ERROR_GEN_FAILURE, "wrong ret %d err %u\n", ret, GetLastError());
ok(initonce.Ptr == NULL, "got %p\n", initonce.Ptr);
SetLastError( 0xdeadbeef );
ret = pInitOnceComplete(&initonce, INIT_ONCE_INIT_FAILED | INIT_ONCE_ASYNC, NULL);
ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER, "wrong ret %d err %u\n", ret, GetLastError());
ok(initonce.Ptr == NULL, "got %p\n", initonce.Ptr);
ret = pInitOnceBeginInitialize(&initonce, 0, &pending, &g_initctxt);
ok(ret, "wrong ret %d err %u\n", ret, GetLastError());
ok(pending, "got %d\n", pending);
ok(initonce.Ptr == (void*)1, "got %p\n", initonce.Ptr);
SetLastError( 0xdeadbeef );
ret = pInitOnceBeginInitialize(&initonce, INIT_ONCE_ASYNC, &pending, &g_initctxt);
ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER, "wrong ret %d err %u\n", ret, GetLastError());
SetLastError( 0xdeadbeef );
ret = pInitOnceComplete(&initonce, INIT_ONCE_INIT_FAILED | INIT_ONCE_ASYNC, NULL);
ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER, "wrong ret %d err %u\n", ret, GetLastError());
ok(initonce.Ptr == (void*)1, "got %p\n", initonce.Ptr);
SetLastError( 0xdeadbeef );
ret = pInitOnceComplete(&initonce, 0, (void *)0xdeadbeef);
ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER, "wrong ret %d err %u\n", ret, GetLastError());
ok(initonce.Ptr == (void*)1, "got %p\n", initonce.Ptr);
ret = pInitOnceComplete(&initonce, INIT_ONCE_INIT_FAILED, NULL);
ok(ret, "wrong ret %d err %u\n", ret, GetLastError());
ok(initonce.Ptr == NULL, "got %p\n", initonce.Ptr);
pInitOnceInitialize(&initonce);
ret = pInitOnceBeginInitialize(&initonce, INIT_ONCE_ASYNC, &pending, &g_initctxt);
ok(ret, "wrong ret %d err %u\n", ret, GetLastError());
ok(pending, "got %d\n", pending);
ok(initonce.Ptr == (void*)3, "got %p\n", initonce.Ptr);
SetLastError( 0xdeadbeef );
ret = pInitOnceBeginInitialize(&initonce, 0, &pending, &g_initctxt);
ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER, "wrong ret %d err %u\n", ret, GetLastError());
ret = pInitOnceBeginInitialize(&initonce, INIT_ONCE_ASYNC, &pending, &g_initctxt);
ok(ret, "wrong ret %d err %u\n", ret, GetLastError());
ok(pending, "got %d\n", pending);
ok(initonce.Ptr == (void*)3, "got %p\n", initonce.Ptr);
SetLastError( 0xdeadbeef );
ret = pInitOnceComplete(&initonce, INIT_ONCE_INIT_FAILED, NULL);
ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER, "wrong ret %d err %u\n", ret, GetLastError());
ok(initonce.Ptr == (void*)3, "got %p\n", initonce.Ptr);
SetLastError( 0xdeadbeef );
ret = pInitOnceComplete(&initonce, INIT_ONCE_INIT_FAILED | INIT_ONCE_ASYNC, NULL);
ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER, "wrong ret %d err %u\n", ret, GetLastError());
ok(initonce.Ptr == (void*)3, "got %p\n", initonce.Ptr);
SetLastError( 0xdeadbeef );
ret = pInitOnceComplete(&initonce, INIT_ONCE_ASYNC, (void *)0xdeadbeef);
ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER, "wrong ret %d err %u\n", ret, GetLastError());
ok(initonce.Ptr == (void*)3, "got %p\n", initonce.Ptr);
ret = pInitOnceComplete(&initonce, INIT_ONCE_ASYNC, (void *)0xdeadbee0);
ok(ret, "wrong ret %d err %u\n", ret, GetLastError());
ok(initonce.Ptr == (void*)0xdeadbee2, "got %p\n", initonce.Ptr);
SetLastError( 0xdeadbeef );
ret = pInitOnceComplete(&initonce, INIT_ONCE_INIT_FAILED | INIT_ONCE_ASYNC, NULL);
ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER, "wrong ret %d err %u\n", ret, GetLastError());
ok(initonce.Ptr == (void*)0xdeadbee2, "got %p\n", initonce.Ptr);
pInitOnceInitialize(&initonce);
ret = pInitOnceBeginInitialize(&initonce, 0, &pending, &g_initctxt);
ok(ret, "wrong ret %d err %u\n", ret, GetLastError());
ok(pending, "got %d\n", pending);
ok(initonce.Ptr == (void*)1, "got %p\n", initonce.Ptr);
/* test INIT_ONCE_CHECK_ONLY */
pInitOnceInitialize(&initonce);
SetLastError( 0xdeadbeef );
ret = pInitOnceBeginInitialize(&initonce, INIT_ONCE_CHECK_ONLY, &pending, &g_initctxt);
ok(!ret && GetLastError() == ERROR_GEN_FAILURE, "wrong ret %d err %u\n", ret, GetLastError());
SetLastError( 0xdeadbeef );
ret = pInitOnceBeginInitialize(&initonce, INIT_ONCE_CHECK_ONLY|INIT_ONCE_ASYNC, &pending, &g_initctxt);
ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER, "wrong ret %d err %u\n", ret, GetLastError());
ret = pInitOnceBeginInitialize(&initonce, 0, &pending, &g_initctxt);
ok(ret, "wrong ret %d err %u\n", ret, GetLastError());
ok(pending, "got %d\n", pending);
ok(initonce.Ptr == (void*)1, "got %p\n", initonce.Ptr);
SetLastError( 0xdeadbeef );
ret = pInitOnceBeginInitialize(&initonce, INIT_ONCE_CHECK_ONLY, &pending, &g_initctxt);
ok(!ret && GetLastError() == ERROR_GEN_FAILURE, "wrong ret %d err %u\n", ret, GetLastError());
SetLastError( 0xdeadbeef );
ret = pInitOnceBeginInitialize(&initonce, INIT_ONCE_CHECK_ONLY|INIT_ONCE_ASYNC, &pending, &g_initctxt);
ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER, "wrong ret %d err %u\n", ret, GetLastError());
ret = pInitOnceComplete(&initonce, 0, (void *)0xdeadbee0);
ok(ret, "wrong ret %d err %u\n", ret, GetLastError());
ok(initonce.Ptr == (void*)0xdeadbee2, "got %p\n", initonce.Ptr);
ret = pInitOnceBeginInitialize(&initonce, INIT_ONCE_CHECK_ONLY, &pending, &g_initctxt);
ok(ret, "got wrong ret value %d err %u\n", ret, GetLastError());
ok(!pending, "got %d\n", pending);
ok(initonce.Ptr == (void*)0xdeadbee2, "got %p\n", initonce.Ptr);
ok(g_initctxt == (void*)0xdeadbee0, "got %p\n", initonce.Ptr);
SetLastError( 0xdeadbeef );
ret = pInitOnceBeginInitialize(&initonce, INIT_ONCE_CHECK_ONLY|INIT_ONCE_ASYNC, &pending, &g_initctxt);
ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER, "wrong ret %d err %u\n", ret, GetLastError());
pInitOnceInitialize(&initonce);
ret = pInitOnceBeginInitialize(&initonce, INIT_ONCE_ASYNC, &pending, &g_initctxt);
ok(ret, "wrong ret %d err %u\n", ret, GetLastError());
ok(pending, "got %d\n", pending);
ok(initonce.Ptr == (void*)3, "got %p\n", initonce.Ptr);
SetLastError( 0xdeadbeef );
ret = pInitOnceBeginInitialize(&initonce, INIT_ONCE_CHECK_ONLY, &pending, &g_initctxt);
ok(!ret && GetLastError() == ERROR_GEN_FAILURE, "wrong ret %d err %u\n", ret, GetLastError());
SetLastError( 0xdeadbeef );
ret = pInitOnceBeginInitialize(&initonce, INIT_ONCE_CHECK_ONLY|INIT_ONCE_ASYNC, &pending, &g_initctxt);
ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER, "wrong ret %d err %u\n", ret, GetLastError());
ret = pInitOnceComplete(&initonce, INIT_ONCE_ASYNC, (void *)0xdeadbee0);
ok(ret, "wrong ret %d err %u\n", ret, GetLastError());
ok(initonce.Ptr == (void*)0xdeadbee2, "got %p\n", initonce.Ptr);
ret = pInitOnceBeginInitialize(&initonce, INIT_ONCE_CHECK_ONLY, &pending, &g_initctxt);
ok(ret, "got wrong ret value %d err %u\n", ret, GetLastError());
ok(!pending, "got %d\n", pending);
ok(initonce.Ptr == (void*)0xdeadbee2, "got %p\n", initonce.Ptr);
ok(g_initctxt == (void*)0xdeadbee0, "got %p\n", initonce.Ptr);
SetLastError( 0xdeadbeef );
ret = pInitOnceBeginInitialize(&initonce, INIT_ONCE_CHECK_ONLY|INIT_ONCE_ASYNC, &pending, &g_initctxt);
ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER, "wrong ret %d err %u\n", ret, GetLastError());
}
static CONDITION_VARIABLE buffernotempty,buffernotfull;
static CONDITION_VARIABLE buffernotempty = CONDITION_VARIABLE_INIT;
static CONDITION_VARIABLE buffernotfull = CONDITION_VARIABLE_INIT;
static CRITICAL_SECTION buffercrit;
static BOOL condvar_stop = FALSE, condvar_sleeperr = FALSE;
static LONG bufferlen,totalproduced,totalconsumed;
static LONG condvar_producer_sleepcnt,condvar_consumer_sleepcnt;
#define BUFFER_SIZE 10
#define BUFFER_SIZE 5
static DWORD WINAPI condvar_producer(LPVOID x) {
DWORD sleepinterval = 5;
while (1) {
Sleep(rand() % 10);
Sleep(sleepinterval);
if (sleepinterval > 1)
sleepinterval -= 1;
EnterCriticalSection(&buffercrit);
while ((bufferlen == BUFFER_SIZE) && !condvar_stop) {
condvar_producer_sleepcnt++;
if (!pSleepConditionVariableCS(&buffernotfull, &buffercrit, 2000))
condvar_sleeperr = TRUE;
if (!pSleepConditionVariableCS(&buffernotfull, &buffercrit, sleepinterval)) {
if (GetLastError() != ERROR_TIMEOUT)
condvar_sleeperr = TRUE;
}
}
if (condvar_stop) {
LeaveCriticalSection(&buffercrit);
@ -1275,13 +1427,16 @@ static DWORD WINAPI condvar_producer(LPVOID x) {
static DWORD WINAPI condvar_consumer(LPVOID x) {
DWORD *cnt = (DWORD*)x;
DWORD sleepinterval = 1;
while (1) {
EnterCriticalSection(&buffercrit);
while ((bufferlen == 0) && !condvar_stop) {
condvar_consumer_sleepcnt++;
if (!pSleepConditionVariableCS (&buffernotempty, &buffercrit, 2000))
condvar_sleeperr = TRUE;
if (!pSleepConditionVariableCS (&buffernotempty, &buffercrit, sleepinterval)) {
if (GetLastError() != ERROR_TIMEOUT)
condvar_sleeperr = TRUE;
}
}
if (condvar_stop && (bufferlen == 0)) {
LeaveCriticalSection(&buffercrit);
@ -1292,16 +1447,17 @@ static DWORD WINAPI condvar_consumer(LPVOID x) {
(*cnt)++;
LeaveCriticalSection(&buffercrit);
pWakeConditionVariable(&buffernotfull);
Sleep(rand() % 10);
Sleep(sleepinterval);
if (sleepinterval < 5) sleepinterval += 1;
}
return 0;
}
static void test_condvars(void)
static void test_condvars_consumer_producer(void)
{
HANDLE hp1,hp2,hc1,hc2;
HANDLE hp1,hp2,hp3,hc1,hc2,hc3;
DWORD dummy;
DWORD cnt1,cnt2;
DWORD cnt1,cnt2,cnt3;
if (!pInitializeConditionVariable) {
/* function is not yet in XP, only in newer Windows */
@ -1311,15 +1467,24 @@ static void test_condvars(void)
}
/* Implement a producer / consumer scheme with non-full / non-empty triggers */
pInitializeConditionVariable(&buffernotfull);
/* If we have static initialized condition variables, InitializeConditionVariable
* is not strictly necessary.
* pInitializeConditionVariable(&buffernotfull);
*/
pInitializeConditionVariable(&buffernotempty);
InitializeCriticalSection(&buffercrit);
bufferlen = totalproduced = totalconsumed = cnt1 = cnt2 = 0;
/* Larger Test: consumer/producer example */
bufferlen = totalproduced = totalconsumed = cnt1 = cnt2 = cnt3 = 0;
hp1 = CreateThread(NULL, 0, condvar_producer, NULL, 0, &dummy);
hp2 = CreateThread(NULL, 0, condvar_producer, NULL, 0, &dummy);
hp3 = CreateThread(NULL, 0, condvar_producer, NULL, 0, &dummy);
hc1 = CreateThread(NULL, 0, condvar_consumer, (PVOID)&cnt1, 0, &dummy);
hc2 = CreateThread(NULL, 0, condvar_consumer, (PVOID)&cnt2, 0, &dummy);
hc3 = CreateThread(NULL, 0, condvar_consumer, (PVOID)&cnt3, 0, &dummy);
/* Limit run to 0.5 seconds. */
Sleep(500);
@ -1331,10 +1496,16 @@ static void test_condvars(void)
pWakeAllConditionVariable (&buffernotfull);
pWakeAllConditionVariable (&buffernotempty);
/* (mostly an implementation detail)
* ok(buffernotfull.Ptr == NULL, "buffernotfull.Ptr is %p\n", buffernotfull.Ptr);
*/
WaitForSingleObject(hp1, 1000);
WaitForSingleObject(hp2, 1000);
WaitForSingleObject(hp3, 1000);
WaitForSingleObject(hc1, 1000);
WaitForSingleObject(hc2, 1000);
WaitForSingleObject(hc3, 1000);
ok(totalconsumed == totalproduced,
"consumed %d != produced %d\n", totalconsumed, totalproduced);
@ -1342,13 +1513,144 @@ static void test_condvars(void)
/* Checking cnt1 - cnt2 for non-0 would be not good, the case where
* one consumer does not get anything to do is possible. */
trace("produced %d, c1 %d, c2 %d\n", totalproduced, cnt1, cnt2);
trace("produced %d, c1 %d, c2 %d, c3 %d\n", totalproduced, cnt1, cnt2, cnt3);
/* The sleeps of the producer or consumer should not go above 100* produced count,
* otherwise the implementation does not sleep correctly. But yet again, this is
* not hard defined. */
trace("producer sleep %d, consumer sleep %d\n", condvar_producer_sleepcnt, condvar_consumer_sleepcnt);
}
/* Sample test for some sequence of events happening, sequenced using "condvar_seq" */
static DWORD condvar_seq = 0;
static CONDITION_VARIABLE condvar_base = CONDITION_VARIABLE_INIT;
static CRITICAL_SECTION condvar_crit;
/* Sequence of wake/sleep to check boundary conditions:
* 0: init
* 1: producer emits a WakeConditionVaribale without consumer waiting.
* 2: consumer sleeps without a wake expecting timeout
* 3: producer emits a WakeAllConditionVaribale without consumer waiting.
* 4: consumer sleeps without a wake expecting timeout
* 5: a wake is handed to a SleepConditionVariableCS
* 6: a wakeall is handed to a SleepConditionVariableCS
* 7: sleep after above should timeout
* 8: wake with crit section locked into the sleep timeout
* 9: end
*/
static DWORD WINAPI condvar_base_producer(LPVOID x) {
while (condvar_seq < 1) Sleep(1);
pWakeConditionVariable (&condvar_base);
condvar_seq = 2;
while (condvar_seq < 3) Sleep(1);
pWakeAllConditionVariable (&condvar_base);
condvar_seq = 4;
while (condvar_seq < 5) Sleep(1);
EnterCriticalSection (&condvar_crit);
pWakeConditionVariable (&condvar_base);
LeaveCriticalSection (&condvar_crit);
while (condvar_seq < 6) Sleep(1);
EnterCriticalSection (&condvar_crit);
pWakeAllConditionVariable (&condvar_base);
LeaveCriticalSection (&condvar_crit);
while (condvar_seq < 8) Sleep(1);
EnterCriticalSection (&condvar_crit);
pWakeConditionVariable (&condvar_base);
Sleep(50);
LeaveCriticalSection (&condvar_crit);
return 0;
}
static DWORD WINAPI condvar_base_consumer(LPVOID x) {
BOOL ret;
while (condvar_seq < 2) Sleep(1);
/* wake was emitted, but we were not sleeping */
EnterCriticalSection (&condvar_crit);
ret = pSleepConditionVariableCS(&condvar_base, &condvar_crit, 10);
LeaveCriticalSection (&condvar_crit);
ok (!ret, "SleepConditionVariableCS should return FALSE on out of band wake\n");
ok (GetLastError() == ERROR_TIMEOUT, "SleepConditionVariableCS should return ERROR_TIMEOUT on out of band wake, not %d\n", GetLastError());
condvar_seq = 3;
while (condvar_seq < 4) Sleep(1);
/* wake all was emitted, but we were not sleeping */
EnterCriticalSection (&condvar_crit);
ret = pSleepConditionVariableCS(&condvar_base, &condvar_crit, 10);
LeaveCriticalSection (&condvar_crit);
ok (!ret, "SleepConditionVariableCS should return FALSE on out of band wake\n");
ok (GetLastError() == ERROR_TIMEOUT, "SleepConditionVariableCS should return ERROR_TIMEOUT on out of band wake, not %d\n", GetLastError());
EnterCriticalSection (&condvar_crit);
condvar_seq = 5;
ret = pSleepConditionVariableCS(&condvar_base, &condvar_crit, 200);
LeaveCriticalSection (&condvar_crit);
ok (ret, "SleepConditionVariableCS should return TRUE on good wake\n");
EnterCriticalSection (&condvar_crit);
condvar_seq = 6;
ret = pSleepConditionVariableCS(&condvar_base, &condvar_crit, 200);
LeaveCriticalSection (&condvar_crit);
ok (ret, "SleepConditionVariableCS should return TRUE on good wakeall\n");
condvar_seq = 7;
EnterCriticalSection (&condvar_crit);
ret = pSleepConditionVariableCS(&condvar_base, &condvar_crit, 10);
LeaveCriticalSection (&condvar_crit);
ok (!ret, "SleepConditionVariableCS should return FALSE on out of band wake\n");
ok (GetLastError() == ERROR_TIMEOUT, "SleepConditionVariableCS should return ERROR_TIMEOUT on out of band wake, not %d\n", GetLastError());
EnterCriticalSection (&condvar_crit);
condvar_seq = 8;
ret = pSleepConditionVariableCS(&condvar_base, &condvar_crit, 20);
LeaveCriticalSection (&condvar_crit);
ok (ret, "SleepConditionVariableCS should still return TRUE on crit unlock delay\n");
condvar_seq = 9;
return 0;
}
static void test_condvars_base(void) {
HANDLE hp, hc;
DWORD dummy;
BOOL ret;
if (!pInitializeConditionVariable) {
/* function is not yet in XP, only in newer Windows */
/* and not yet implemented in Wine for some days/weeks */
todo_wine win_skip("no condition variable support.\n");
return;
}
InitializeCriticalSection (&condvar_crit);
EnterCriticalSection (&condvar_crit);
ret = pSleepConditionVariableCS(&condvar_base, &condvar_crit, 10);
LeaveCriticalSection (&condvar_crit);
ok (!ret, "SleepConditionVariableCS should return FALSE on untriggered condvar\n");
ok (GetLastError() == ERROR_TIMEOUT, "SleepConditionVariableCS should return ERROR_TIMEOUT on untriggered condvar, not %d\n", GetLastError());
hp = CreateThread(NULL, 0, condvar_base_producer, NULL, 0, &dummy);
hc = CreateThread(NULL, 0, condvar_base_consumer, NULL, 0, &dummy);
condvar_seq = 1; /* go */
while (condvar_seq < 9)
Sleep (5);
WaitForSingleObject(hp, 100);
WaitForSingleObject(hc, 100);
}
START_TEST(sync)
{
HMODULE hdll = GetModuleHandle("kernel32");
@ -1381,5 +1683,6 @@ START_TEST(sync)
test_WaitForSingleObject();
test_WaitForMultipleObjects();
test_initonce();
test_condvars();
test_condvars_base();
test_condvars_consumer_producer();
}

View file

@ -713,22 +713,22 @@ static VOID test_thread_priority(void)
0,curthreadId);
ok(access_thread!=NULL,"OpenThread returned an invalid handle\n");
if (access_thread!=NULL) {
obey_ar(pSetThreadPriorityBoost(access_thread,1)==0);
todo_wine obey_ar(pSetThreadPriorityBoost(access_thread,1)==0);
todo_wine obey_ar(pGetThreadPriorityBoost(access_thread,&disabled)==0);
ok(CloseHandle(access_thread),"Error Closing thread handle\n");
}
}
rc = pSetThreadPriorityBoost(curthread,1);
ok( rc != 0, "error=%d\n",GetLastError());
todo_wine {
rc = pSetThreadPriorityBoost(curthread,1);
ok( rc != 0, "error=%d\n",GetLastError());
rc=pGetThreadPriorityBoost(curthread,&disabled);
ok(rc!=0 && disabled==1,
"rc=%d error=%d disabled=%d\n",rc,GetLastError(),disabled);
rc = pSetThreadPriorityBoost(curthread,0);
ok( rc != 0, "error=%d\n",GetLastError());
}
rc = pSetThreadPriorityBoost(curthread,0);
ok( rc != 0, "error=%d\n",GetLastError());
rc=pGetThreadPriorityBoost(curthread,&disabled);
ok(rc!=0 && disabled==0,
"rc=%d error=%d disabled=%d\n",rc,GetLastError(),disabled);
@ -829,8 +829,6 @@ static VOID test_thread_processor(void)
ok(retMask == processMask, "SetThreadAffinityMask failed\n");
retMask = SetThreadAffinityMask(curthread,~(ULONG_PTR)0 >> 3);
ok(retMask == processMask, "SetThreadAffinityMask failed\n");
retMask = SetThreadAffinityMask(curthread,~(ULONG_PTR)1);
ok(retMask == 0, "SetThreadAffinityMask succeeded\n");
}
/* NOTE: This only works on WinNT/2000/XP) */
if (pSetThreadIdealProcessor) {

View file

@ -336,6 +336,29 @@ static void test_GetTimeZoneInformation(void)
l_time = system_time_to_minutes(&local);
ok(l_time - s_time == diff, "got %d, expected %d\n",
(LONG)(l_time - s_time), diff);
/* test 23:01, 31st of December date */
memset(&tzinfo, 0, sizeof(tzinfo));
tzinfo.StandardDate.wMonth = 10;
tzinfo.StandardDate.wDay = 5;
tzinfo.StandardDate.wHour = 2;
tzinfo.StandardDate.wMinute = 0;
tzinfo.DaylightDate.wMonth = 4;
tzinfo.DaylightDate.wDay = 1;
tzinfo.DaylightDate.wHour = 2;
tzinfo.Bias = 0;
tzinfo.StandardBias = 0;
tzinfo.DaylightBias = -60;
utc.wYear = 2012;
utc.wMonth = 12;
utc.wDay = 31;
utc.wHour = 23;
utc.wMinute = 1;
res = pSystemTimeToTzSpecificLocalTime(&tzinfo, &utc, &local);
ok(res, "SystemTimeToTzSpecificLocalTime error %u\n", GetLastError());
ok(local.wYear==2012 && local.wMonth==12 && local.wDay==31 && local.wHour==23 && local.wMinute==1,
"got (%d-%d-%d %02d:%02d), expected (2012-12-31 23:01)\n",
local.wYear, local.wMonth, local.wDay, local.wHour, local.wMinute);
}
static void test_FileTimeToSystemTime(void)

View file

@ -300,8 +300,6 @@ static void test_VirtualAlloc(void)
memset( addr1, 0x55, 20 );
ok( *(DWORD *)addr1 == 0x55555555, "wrong data %x\n", *(DWORD *)addr1 );
if(winetest_interactive)
{
addr2 = VirtualAlloc( addr1, 0x1000, MEM_RESET, PAGE_NOACCESS );
ok( addr2 == addr1 || broken( !addr2 && GetLastError() == ERROR_INVALID_PARAMETER), /* win9x */
"VirtualAlloc failed err %u\n", GetLastError() );
@ -327,9 +325,6 @@ if(winetest_interactive)
ok( !addr2, "VirtualAlloc failed\n" );
ok( GetLastError() == ERROR_INVALID_ADDRESS, "wrong error %u\n", GetLastError() );
}
}
else
skip("MEM_RESET is not currently supported\n");
/* invalid protection values */
SetLastError(0xdeadbeef);
@ -717,8 +712,8 @@ static void test_MapViewOfFile(void)
ok(info.BaseAddress == ptr, "BaseAddress should have been %p but was %p instead\n", ptr, info.BaseAddress);
ok(info.AllocationBase == ptr, "AllocationBase should have been %p but was %p instead\n", ptr, info.AllocationBase);
ok(info.RegionSize == 0x10000, "RegionSize should have been 0x10000 but was 0x%lx\n", info.RegionSize);
ok(info.State == MEM_COMMIT, "State should have been MEM_RESERVE instead of 0x%x\n", info.State);
ok(info.Protect == PAGE_READONLY, "Protect should have been 0 instead of 0x%x\n", info.Protect);
ok(info.State == MEM_COMMIT, "State should have been MEM_COMMIT instead of 0x%x\n", info.State);
ok(info.Protect == PAGE_READONLY, "Protect should have been PAGE_READONLY instead of 0x%x\n", info.Protect);
if (info.Type == MEM_PRIVATE) /* win9x is different for uncommitted mappings */
{
ok(info.AllocationProtect == PAGE_NOACCESS,
@ -753,8 +748,6 @@ static void test_MapViewOfFile(void)
ok(info.Type == MEM_MAPPED, "Type should have been MEM_MAPPED instead of 0x%x\n", info.Type);
}
if(winetest_interactive)
{
addr = VirtualAlloc( ptr, MAPPING_SIZE, MEM_RESET, PAGE_READONLY );
ok( addr == ptr || broken(!addr && GetLastError() == ERROR_INVALID_PARAMETER), /* win9x */
"VirtualAlloc failed with error %u\n", GetLastError() );
@ -763,9 +756,6 @@ if(winetest_interactive)
ok( !ret || broken(ret) /* win9x */, "VirtualFree succeeded\n" );
if (!ret)
ok( GetLastError() == ERROR_INVALID_PARAMETER, "VirtualFree failed with %u\n", GetLastError() );
}
else
skip("MEM_RESET is not currently supported\n");
ret = UnmapViewOfFile(ptr2);
ok(ret, "UnmapViewOfFile failed with error %d\n", GetLastError());
@ -1591,7 +1581,7 @@ static void test_VirtualProtect(void)
{ PAGE_EXECUTE_WRITECOPY | PAGE_EXECUTE_READWRITE | PAGE_EXECUTE_READ, 0 }, /* 0xe0 */
{ PAGE_EXECUTE_WRITECOPY | PAGE_EXECUTE_READWRITE | PAGE_EXECUTE_READ | PAGE_EXECUTE, 0 } /* 0xf0 */
};
char *base;
char *base, *ptr;
DWORD ret, old_prot, rw_prot, exec_prot, i, j;
MEMORY_BASIC_INFORMATION info;
SYSTEM_INFO si;
@ -1661,6 +1651,27 @@ static void test_VirtualProtect(void)
{
DWORD prot = exec_prot | rw_prot;
SetLastError(0xdeadbeef);
ptr = VirtualAlloc(base, si.dwPageSize, MEM_COMMIT, prot);
if ((rw_prot && exec_prot) || (!rw_prot && !exec_prot))
{
ok(!ptr, "VirtualAlloc(%02x) should fail\n", prot);
ok(GetLastError() == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
}
else
{
if (prot & (PAGE_WRITECOPY | PAGE_EXECUTE_WRITECOPY))
{
ok(!ptr, "VirtualAlloc(%02x) should fail\n", prot);
ok(GetLastError() == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
}
else
{
ok(ptr != NULL, "VirtualAlloc(%02x) error %d\n", prot, GetLastError());
ok(ptr == base, "expected %p, got %p\n", base, ptr);
}
}
SetLastError(0xdeadbeef);
ret = VirtualProtect(base, si.dwPageSize, prot, &old_prot);
if ((rw_prot && exec_prot) || (!rw_prot && !exec_prot))
@ -1744,7 +1755,7 @@ static void test_VirtualAlloc_protection(void)
{ PAGE_EXECUTE_WRITECOPY | PAGE_EXECUTE_READWRITE | PAGE_EXECUTE_READ, FALSE }, /* 0xe0 */
{ PAGE_EXECUTE_WRITECOPY | PAGE_EXECUTE_READWRITE | PAGE_EXECUTE_READ | PAGE_EXECUTE, FALSE } /* 0xf0 */
};
char *base;
char *base, *ptr;
DWORD ret, i;
MEMORY_BASIC_INFORMATION info;
SYSTEM_INFO si;
@ -1782,6 +1793,10 @@ static void test_VirtualAlloc_protection(void)
ok(info.Protect == td[i].prot, "%d: got %#x != expected %#x\n", i, info.Protect, td[i].prot);
}
SetLastError(0xdeadbeef);
ptr = VirtualAlloc(base, si.dwPageSize, MEM_COMMIT, td[i].prot);
ok(ptr == base, "%d: VirtualAlloc failed %d\n", i, GetLastError());
VirtualFree(base, 0, MEM_FREE);
}
else
@ -1834,7 +1849,7 @@ static void test_CreateFileMapping_protection(void)
{ PAGE_EXECUTE_WRITECOPY | PAGE_EXECUTE_READWRITE | PAGE_EXECUTE_READ, FALSE, PAGE_NOACCESS }, /* 0xe0 */
{ PAGE_EXECUTE_WRITECOPY | PAGE_EXECUTE_READWRITE | PAGE_EXECUTE_READ | PAGE_EXECUTE, FALSE, PAGE_NOACCESS } /* 0xf0 */
};
char *base;
char *base, *ptr;
DWORD ret, i, alloc_prot, prot, old_prot;
MEMORY_BASIC_INFORMATION info;
SYSTEM_INFO si;
@ -1906,6 +1921,26 @@ static void test_CreateFileMapping_protection(void)
ok(info.Protect == td[i].prot, "%d: got %#x != expected %#x\n", i, info.Protect, td[i].prot);
}
SetLastError(0xdeadbeef);
ptr = VirtualAlloc(base, si.dwPageSize, MEM_COMMIT, td[i].prot);
ok(!ptr, "%d: VirtualAlloc(%02x) should fail\n", i, td[i].prot);
/* FIXME: remove once Wine is fixed */
if (td[i].prot == PAGE_WRITECOPY || td[i].prot == PAGE_EXECUTE_WRITECOPY)
todo_wine
ok(GetLastError() == ERROR_ACCESS_DENIED, "%d: expected ERROR_ACCESS_DENIED, got %d\n", i, GetLastError());
else
ok(GetLastError() == ERROR_ACCESS_DENIED, "%d: expected ERROR_ACCESS_DENIED, got %d\n", i, GetLastError());
SetLastError(0xdeadbeef);
ret = VirtualProtect(base, si.dwPageSize, td[i].prot, &old_prot);
if (td[i].prot == PAGE_READONLY || td[i].prot == PAGE_WRITECOPY)
ok(ret, "%d: VirtualProtect(%02x) error %d\n", i, td[i].prot, GetLastError());
else
{
ok(!ret, "%d: VirtualProtect(%02x) should fail\n", i, td[i].prot);
ok(GetLastError() == ERROR_INVALID_PARAMETER, "%d: expected ERROR_INVALID_PARAMETER, got %d\n", i, GetLastError());
}
UnmapViewOfFile(base);
CloseHandle(hmap);
}
@ -2206,7 +2241,7 @@ static void test_mapping(void)
{ FILE_MAP_EXECUTE | SECTION_MAP_EXECUTE | FILE_MAP_READ | FILE_MAP_WRITE, PAGE_EXECUTE_READWRITE }, /* 0x2e */
{ FILE_MAP_EXECUTE | SECTION_MAP_EXECUTE | FILE_MAP_READ | FILE_MAP_WRITE | FILE_MAP_COPY, PAGE_EXECUTE_READWRITE } /* 0x2f */
};
void *base, *nt_base;
void *base, *nt_base, *ptr;
DWORD i, j, k, ret, old_prot, prev_prot;
SYSTEM_INFO si;
char temp_path[MAX_PATH];
@ -2386,6 +2421,20 @@ static void test_mapping(void)
}
}
for (k = 0; k < sizeof(page_prot)/sizeof(page_prot[0]); k++)
{
/*trace("map %#x, view %#x, requested prot %#x\n", page_prot[i], view[j].prot, page_prot[k]);*/
SetLastError(0xdeadbeef);
ptr = VirtualAlloc(base, si.dwPageSize, MEM_COMMIT, page_prot[k]);
ok(!ptr, "VirtualAlloc(%02x) should fail\n", page_prot[k]);
/* FIXME: remove once Wine is fixed */
if (page_prot[k] == PAGE_WRITECOPY || page_prot[k] == PAGE_EXECUTE_WRITECOPY)
todo_wine
ok(GetLastError() == ERROR_ACCESS_DENIED, "expected ERROR_ACCESS_DENIED, got %d\n", GetLastError());
else
ok(GetLastError() == ERROR_ACCESS_DENIED, "expected ERROR_ACCESS_DENIED, got %d\n", GetLastError());
}
UnmapViewOfFile(base);
}
@ -2396,6 +2445,48 @@ static void test_mapping(void)
DeleteFile(file_name);
}
static void test_shared_memory(int is_child)
{
HANDLE mapping;
LONG *p;
SetLastError(0xdeadbef);
mapping = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, 4096, "winetest_virtual.c");
ok(mapping != 0, "CreateFileMapping error %d\n", GetLastError());
if (is_child)
ok(GetLastError() == ERROR_ALREADY_EXISTS, "expected ERROR_ALREADY_EXISTS, got %d\n", GetLastError());
SetLastError(0xdeadbef);
p = MapViewOfFile(mapping, FILE_MAP_READ|FILE_MAP_WRITE, 0, 0, 4096);
ok(p != NULL, "MapViewOfFile error %d\n", GetLastError());
if (is_child)
{
ok(*p == 0x1a2b3c4d, "expected 0x1a2b3c4d in child, got %#x\n", *p);
}
else
{
char **argv;
char cmdline[MAX_PATH];
PROCESS_INFORMATION pi;
STARTUPINFO si = { sizeof(si) };
DWORD ret;
*p = 0x1a2b3c4d;
winetest_get_mainargs(&argv);
sprintf(cmdline, "\"%s\" virtual sharedmem", argv[0]);
ret = CreateProcess(argv[0], cmdline, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
ok(ret, "CreateProcess(%s) error %d\n", cmdline, GetLastError());
winetest_wait_child_process(pi.hProcess);
CloseHandle(pi.hThread);
CloseHandle(pi.hProcess);
}
UnmapViewOfFile(p);
CloseHandle(mapping);
}
START_TEST(virtual)
{
int argc;
@ -2409,6 +2500,11 @@ START_TEST(virtual)
Sleep(5000); /* spawned process runs for at most 5 seconds */
return;
}
if (!strcmp(argv[2], "sharedmem"))
{
test_shared_memory(1);
return;
}
while (1)
{
void *mem;
@ -2434,6 +2530,7 @@ START_TEST(virtual)
pNtMapViewOfSection = (void *)GetProcAddress(GetModuleHandle("ntdll.dll"), "NtMapViewOfSection");
pNtUnmapViewOfSection = (void *)GetProcAddress(GetModuleHandle("ntdll.dll"), "NtUnmapViewOfSection");
test_shared_memory(0);
test_mapping();
test_CreateFileMapping_protection();
test_VirtualAlloc_protection();
@ -2447,8 +2544,5 @@ START_TEST(virtual)
test_IsBadReadPtr();
test_IsBadWritePtr();
test_IsBadCodePtr();
if(winetest_interactive)
test_write_watch();
else
skip("test_write_watch - MEM_WRITE_WATCH is currently not supported\n");
test_write_watch();
}

View file

@ -53,6 +53,7 @@ static BOOL (WINAPI *pFindVolumeClose)(HANDLE);
static UINT (WINAPI *pGetLogicalDriveStringsA)(UINT,LPSTR);
static UINT (WINAPI *pGetLogicalDriveStringsW)(UINT,LPWSTR);
static BOOL (WINAPI *pGetVolumeInformationA)(LPCSTR, LPSTR, DWORD, LPDWORD, LPDWORD, LPDWORD, LPSTR, DWORD);
static BOOL (WINAPI *pGetVolumePathNameA)(LPCSTR, LPSTR, DWORD);
static BOOL (WINAPI *pGetVolumePathNamesForVolumeNameA)(LPCSTR, LPSTR, DWORD, LPDWORD);
static BOOL (WINAPI *pGetVolumePathNamesForVolumeNameW)(LPCWSTR, LPWSTR, DWORD, LPDWORD);
@ -590,6 +591,83 @@ static void test_disk_extents(void)
CloseHandle( handle );
}
static void test_GetVolumePathNameA(void)
{
BOOL ret;
char volume[MAX_PATH];
char expected[] = "C:\\", pathC1[] = "C:\\", pathC2[] = "C::";
DWORD error;
if (!pGetVolumePathNameA)
{
win_skip("required functions not found\n");
return;
}
SetLastError( 0xdeadbeef );
ret = pGetVolumePathNameA(NULL, NULL, 0);
error = GetLastError();
ok(!ret, "expected failure\n");
todo_wine
ok(error == ERROR_INVALID_PARAMETER
|| broken( error == 0xdeadbeef) /* <=XP */,
"expected ERROR_INVALID_PARAMETER got %u\n", error);
SetLastError( 0xdeadbeef );
ret = pGetVolumePathNameA("", NULL, 0);
error = GetLastError();
ok(!ret, "expected failure\n");
todo_wine
ok(error == ERROR_INVALID_PARAMETER
|| broken( error == 0xdeadbeef) /* <=XP */,
"expected ERROR_INVALID_PARAMETER got %u\n", error);
SetLastError( 0xdeadbeef );
ret = pGetVolumePathNameA(pathC1, NULL, 0);
error = GetLastError();
ok(!ret, "expected failure\n");
todo_wine
ok(error == ERROR_INVALID_PARAMETER
|| broken(error == ERROR_FILENAME_EXCED_RANGE) /* <=XP */,
"expected ERROR_INVALID_PARAMETER got %u\n", error);
SetLastError( 0xdeadbeef );
ret = pGetVolumePathNameA(pathC1, volume, 0);
error = GetLastError();
ok(!ret, "expected failure\n");
todo_wine
ok(error == ERROR_INVALID_PARAMETER
|| broken(error == ERROR_FILENAME_EXCED_RANGE ) /* <=XP */,
"expected ERROR_INVALID_PARAMETER got %u\n", error);
SetLastError( 0xdeadbeef );
ret = pGetVolumePathNameA(pathC1, volume, 1);
error = GetLastError();
ok(!ret, "expected failure\n");
todo_wine
ok(error == ERROR_FILENAME_EXCED_RANGE, "expected ERROR_FILENAME_EXCED_RANGE got %u\n", error);
volume[0] = '\0';
ret = pGetVolumePathNameA(pathC1, volume, sizeof(volume));
ok(ret, "expected success\n");
ok(!strcmp(expected, volume), "expected name '%s', returned '%s'\n", pathC1, volume);
pathC1[0] = tolower(pathC1[0]);
volume[0] = '\0';
ret = pGetVolumePathNameA(pathC1, volume, sizeof(volume));
ok(ret, "expected success\n");
todo_wine
ok(!strcmp(expected, volume) || broken(!strcasecmp(expected, volume)) /* <=XP */,
"expected name '%s', returned '%s'\n", expected, volume);
volume[0] = '\0';
ret = pGetVolumePathNameA(pathC2, volume, sizeof(volume));
todo_wine
ok(ret, "expected success\n");
todo_wine
ok(!strcmp(expected, volume), "expected name '%s', returned '%s'\n", expected, volume);
}
static void test_GetVolumePathNamesForVolumeNameA(void)
{
BOOL ret;
@ -777,18 +855,13 @@ static void test_dvd_read_structure(HANDLE handle)
/* Test whether this ioctl is supported */
ret = DeviceIoControl(handle, IOCTL_DVD_READ_STRUCTURE, &dvdReadStructure, sizeof(DVD_READ_STRUCTURE),
&completeDvdLayerDescriptor, sizeof(struct COMPLETE_DVD_LAYER_DESCRIPTOR), &nbBytes, NULL);
if ((!ret && GetLastError() == ERROR_INVALID_FUNCTION)
|| (!ret && GetLastError() == ERROR_NOT_SUPPORTED))
if(!ret)
{
skip("IOCTL_DVD_READ_STRUCTURE not supported\n");
skip("IOCTL_DVD_READ_STRUCTURE not supported: %u\n", GetLastError());
return;
}
ok(ret || broken(GetLastError() == ERROR_NOT_READY) || broken(GetLastError() == ERROR_INVALID_PARAMETER),
"IOCTL_DVD_READ_STRUCTURE (DvdPhysicalDescriptor) failed, last error = %u\n", GetLastError());
if(!ret)
return;
/* Confirm there is always a header before the actual data */
ok( completeDvdLayerDescriptor.Header.Length == 0x0802, "Length is 0x%04x instead of 0x0802\n", completeDvdLayerDescriptor.Header.Length);
ok( completeDvdLayerDescriptor.Header.Reserved[0] == 0, "Reserved[0] is %x instead of 0\n", completeDvdLayerDescriptor.Header.Reserved[0]);
@ -933,12 +1006,14 @@ START_TEST(volume)
pGetLogicalDriveStringsA = (void *) GetProcAddress(hdll, "GetLogicalDriveStringsA");
pGetLogicalDriveStringsW = (void *) GetProcAddress(hdll, "GetLogicalDriveStringsW");
pGetVolumeInformationA = (void *) GetProcAddress(hdll, "GetVolumeInformationA");
pGetVolumePathNameA = (void *) GetProcAddress(hdll, "GetVolumePathNameA");
pGetVolumePathNamesForVolumeNameA = (void *) GetProcAddress(hdll, "GetVolumePathNamesForVolumeNameA");
pGetVolumePathNamesForVolumeNameW = (void *) GetProcAddress(hdll, "GetVolumePathNamesForVolumeNameW");
test_query_dos_deviceA();
test_define_dos_deviceA();
test_FindFirstVolume();
test_GetVolumePathNameA();
test_GetVolumeNameForVolumeMountPointA();
test_GetVolumeNameForVolumeMountPointW();
test_GetLogicalDriveStringsA();