From 64cbea525bdca2a986774fe6d88adcb865654513 Mon Sep 17 00:00:00 2001 From: Dmitry Timoshkov Date: Wed, 18 Jun 2008 18:53:48 +0900 Subject: [PATCH] winmm: Add the tests for mmioOpen and mmioSetBuffer, make them pass under Wine. --- dlls/winmm/mmio.c | 17 +-- dlls/winmm/tests/mmio.c | 264 ++++++++++++++++++++++++++++++++++++++-- 2 files changed, 264 insertions(+), 17 deletions(-) diff --git a/dlls/winmm/mmio.c b/dlls/winmm/mmio.c index c2df106e910..d0a4f499aaa 100644 --- a/dlls/winmm/mmio.c +++ b/dlls/winmm/mmio.c @@ -557,7 +557,6 @@ static MMRESULT MMIO_SetBuffer(WINE_MMIO* wm, void* pchBuffer, LONG cchBuffer, { TRACE("(%p %p %d %u)\n", wm, pchBuffer, cchBuffer, uFlags); - if (uFlags) return MMSYSERR_INVALPARAM; if (cchBuffer > 0xFFFF) WARN("Untested handling of huge mmio buffers (%d >= 64k)\n", cchBuffer); @@ -571,8 +570,11 @@ static MMRESULT MMIO_SetBuffer(WINE_MMIO* wm, void* pchBuffer, LONG cchBuffer, wm->info.dwFlags &= ~MMIO_ALLOCBUF; } + wm->bBufferLoaded = FALSE; + if (pchBuffer) { wm->info.pchBuffer = pchBuffer; + wm->bBufferLoaded = TRUE; } else if (cchBuffer) { if (!(wm->info.pchBuffer = HeapAlloc(GetProcessHeap(), 0, cchBuffer))) return MMIOERR_OUTOFMEMORY; @@ -586,7 +588,6 @@ static MMRESULT MMIO_SetBuffer(WINE_MMIO* wm, void* pchBuffer, LONG cchBuffer, wm->info.pchEndRead = wm->info.pchBuffer; wm->info.pchEndWrite = wm->info.pchBuffer + cchBuffer; wm->info.lBufOffset = wm->info.lDiskOffset; - wm->bBufferLoaded = FALSE; return MMSYSERR_NOERROR; } @@ -656,22 +657,22 @@ HMMIO MMIO_Open(LPSTR szFileName, MMIOINFO* refmminfo, DWORD dwOpenFlags, wm->bTmpIOProc = TRUE; } - wm->bBufferLoaded = FALSE; wm->ioProc->count++; + wm->info.dwFlags = dwOpenFlags; if (dwOpenFlags & MMIO_ALLOCBUF) { - if ((refmminfo->wErrorRet = MMIO_SetBuffer(wm, NULL, MMIO_DEFAULTBUFFER, 0))) + refmminfo->wErrorRet = MMIO_SetBuffer(wm, refmminfo->pchBuffer, + refmminfo->cchBuffer ? refmminfo->cchBuffer : MMIO_DEFAULTBUFFER, 0); + if (refmminfo->wErrorRet != MMSYSERR_NOERROR) goto error1; - } else if (wm->info.fccIOProc == FOURCC_MEM) { + } else { refmminfo->wErrorRet = MMIO_SetBuffer(wm, refmminfo->pchBuffer, refmminfo->cchBuffer, 0); if (refmminfo->wErrorRet != MMSYSERR_NOERROR) goto error1; - wm->bBufferLoaded = TRUE; - } /* else => unbuffered, wm->info.pchBuffer == NULL */ + } /* see mmioDosIOProc for that one */ wm->info.adwInfo[0] = refmminfo->adwInfo[0]; - wm->info.dwFlags = dwOpenFlags; /* call IO proc to actually open file */ refmminfo->wErrorRet = send_message(wm->ioProc, &wm->info, MMIOM_OPEN, diff --git a/dlls/winmm/tests/mmio.c b/dlls/winmm/tests/mmio.c index 72b16b18f32..856e6e0920c 100644 --- a/dlls/winmm/tests/mmio.c +++ b/dlls/winmm/tests/mmio.c @@ -28,7 +28,7 @@ #include "vfw.h" #include "wine/test.h" -static const DWORD RIFF_buf[] = +static DWORD RIFF_buf[] = { FOURCC_RIFF, 7*sizeof(DWORD)+sizeof(MainAVIHeader), mmioFOURCC('A','V','I',' '), FOURCC_LIST, sizeof(DWORD)+sizeof(MMCKINFO)+sizeof(MainAVIHeader), listtypeAVIHEADER, @@ -39,7 +39,7 @@ static const DWORD RIFF_buf[] = 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; -static void test_mmioDescend(void) +static void test_mmioDescend(char *fname) { MMRESULT ret; HMMIO hmmio; @@ -47,14 +47,16 @@ static void test_mmioDescend(void) MMCKINFO ckRiff, ckList, ck; memset(&mmio, 0, sizeof(mmio)); - mmio.fccIOProc = FOURCC_MEM; + mmio.fccIOProc = fname ? FOURCC_DOS : FOURCC_MEM; mmio.cchBuffer = sizeof(RIFF_buf); - mmio.pchBuffer = (char *)&RIFF_buf; - - /*hmmio = mmioOpen("msrle.avi", NULL, MMIO_READ);*/ - hmmio = mmioOpen(NULL, &mmio, MMIO_READ); + mmio.pchBuffer = (char *)RIFF_buf; + hmmio = mmioOpen(fname, &mmio, MMIO_READ); + if (fname && !hmmio) + { + trace("%s file is missing, skipping the test\n", fname); + return; + } ok(hmmio != 0, "mmioOpen error %u\n", mmio.wErrorRet); - trace("hmmio = %p\n", hmmio); /* first normal RIFF AVI parsing */ ret = mmioDescend(hmmio, &ckRiff, NULL, 0); @@ -170,7 +172,251 @@ static void test_mmioDescend(void) mmioClose(hmmio, 0); } +static void test_mmioOpen(char *fname) +{ + char buf[256]; + MMRESULT ret; + HMMIO hmmio; + MMIOINFO mmio; + + memset(&mmio, 0, sizeof(mmio)); + mmio.fccIOProc = fname ? FOURCC_DOS : FOURCC_MEM; + mmio.cchBuffer = sizeof(buf); + mmio.pchBuffer = buf; + hmmio = mmioOpen(fname, &mmio, MMIO_READ); + if (fname && !hmmio) + { + trace("%s file is missing, skipping the test\n", fname); + return; + } + ok(hmmio != 0, "mmioOpen error %u\n", mmio.wErrorRet); + + memset(&mmio, 0, sizeof(mmio)); + ret = mmioGetInfo(hmmio, &mmio, 0); + ok(ret == MMSYSERR_NOERROR, "mmioGetInfo error %u\n", ret); + ok(mmio.dwFlags == MMIO_READ, "expected MMIO_READ, got %x\n", mmio.dwFlags); + ok(mmio.wErrorRet == MMSYSERR_NOERROR, "expected MMSYSERR_NOERROR, got %u\n", mmio.wErrorRet); + ok(mmio.fccIOProc == (fname ? FOURCC_DOS : FOURCC_MEM), "got %4.4s\n", (LPCSTR)&mmio.fccIOProc); + ok(mmio.cchBuffer == sizeof(buf), "got %u\n", mmio.cchBuffer); + ok(mmio.pchBuffer == buf, "expected %p, got %p\n", buf, mmio.pchBuffer); + + mmioClose(hmmio, 0); + + memset(&mmio, 0, sizeof(mmio)); + mmio.fccIOProc = fname ? FOURCC_DOS : FOURCC_MEM; + mmio.cchBuffer = 0; + mmio.pchBuffer = buf; + hmmio = mmioOpen(fname, &mmio, MMIO_READ); + ok(hmmio != 0, "mmioOpen error %u\n", mmio.wErrorRet); + + memset(&mmio, 0, sizeof(mmio)); + ret = mmioGetInfo(hmmio, &mmio, 0); + ok(ret == MMSYSERR_NOERROR, "mmioGetInfo error %u\n", ret); + ok(mmio.dwFlags == MMIO_READ, "expected MMIO_READ, got %x\n", mmio.dwFlags); + ok(mmio.wErrorRet == MMSYSERR_NOERROR, "expected MMSYSERR_NOERROR, got %u\n", mmio.wErrorRet); + ok(mmio.fccIOProc == (fname ? FOURCC_DOS : FOURCC_MEM), "got %4.4s\n", (LPCSTR)&mmio.fccIOProc); + ok(mmio.cchBuffer == 0, "expected 0, got %u\n", mmio.cchBuffer); + ok(mmio.pchBuffer == buf, "expected %p, got %p\n", buf, mmio.pchBuffer); + + mmioClose(hmmio, 0); + + memset(&mmio, 0, sizeof(mmio)); + mmio.fccIOProc = fname ? FOURCC_DOS : FOURCC_MEM; + mmio.cchBuffer = 0; + mmio.pchBuffer = NULL; + hmmio = mmioOpen(fname, &mmio, MMIO_READ); + ok(hmmio != 0, "mmioOpen error %u\n", mmio.wErrorRet); + + memset(&mmio, 0, sizeof(mmio)); + ret = mmioGetInfo(hmmio, &mmio, 0); + ok(ret == MMSYSERR_NOERROR, "mmioGetInfo error %u\n", ret); + ok(mmio.dwFlags == MMIO_READ, "expected MMIO_READ, got %x\n", mmio.dwFlags); + ok(mmio.wErrorRet == MMSYSERR_NOERROR, "expected MMSYSERR_NOERROR, got %u\n", mmio.wErrorRet); + ok(mmio.fccIOProc == (fname ? FOURCC_DOS : FOURCC_MEM), "got %4.4s\n", (LPCSTR)&mmio.fccIOProc); + ok(mmio.cchBuffer == 0, "expected 0, got %u\n", mmio.cchBuffer); + ok(mmio.pchBuffer == NULL, "expected NULL\n"); + + mmioClose(hmmio, 0); + + memset(&mmio, 0, sizeof(mmio)); + mmio.fccIOProc = fname ? FOURCC_DOS : FOURCC_MEM; + mmio.cchBuffer = 256; + mmio.pchBuffer = NULL; + hmmio = mmioOpen(fname, &mmio, MMIO_READ); + ok(hmmio != 0, "mmioOpen error %u\n", mmio.wErrorRet); + + memset(&mmio, 0, sizeof(mmio)); + ret = mmioGetInfo(hmmio, &mmio, 0); + ok(ret == MMSYSERR_NOERROR, "mmioGetInfo error %u\n", ret); + ok(mmio.dwFlags == (MMIO_READ|MMIO_ALLOCBUF), "expected MMIO_READ|MMIO_ALLOCBUF, got %x\n", mmio.dwFlags); + ok(mmio.wErrorRet == MMSYSERR_NOERROR, "expected MMSYSERR_NOERROR, got %u\n", mmio.wErrorRet); + ok(mmio.fccIOProc == (fname ? FOURCC_DOS : FOURCC_MEM), "got %4.4s\n", (LPCSTR)&mmio.fccIOProc); + ok(mmio.cchBuffer == 256, "expected 256, got %u\n", mmio.cchBuffer); + ok(mmio.pchBuffer != NULL, "expected not NULL\n"); + + mmioClose(hmmio, 0); + + memset(&mmio, 0, sizeof(mmio)); + mmio.fccIOProc = fname ? FOURCC_DOS : FOURCC_MEM; + mmio.cchBuffer = sizeof(buf); + mmio.pchBuffer = buf; + hmmio = mmioOpen(fname, &mmio, MMIO_READ | MMIO_ALLOCBUF); + ok(hmmio != 0, "mmioOpen error %u\n", mmio.wErrorRet); + + memset(&mmio, 0, sizeof(mmio)); + ret = mmioGetInfo(hmmio, &mmio, 0); + ok(ret == MMSYSERR_NOERROR, "mmioGetInfo error %u\n", ret); + ok(mmio.dwFlags == MMIO_READ, "expected MMIO_READ, got %x\n", mmio.dwFlags); + ok(mmio.wErrorRet == MMSYSERR_NOERROR, "expected MMSYSERR_NOERROR, got %u\n", mmio.wErrorRet); + ok(mmio.fccIOProc == (fname ? FOURCC_DOS : FOURCC_MEM), "got %4.4s\n", (LPCSTR)&mmio.fccIOProc); + ok(mmio.cchBuffer == sizeof(buf), "got %u\n", mmio.cchBuffer); + ok(mmio.pchBuffer == buf, "expected %p, got %p\n", buf, mmio.pchBuffer); + + mmioClose(hmmio, 0); + + memset(&mmio, 0, sizeof(mmio)); + mmio.fccIOProc = fname ? FOURCC_DOS : FOURCC_MEM; + mmio.cchBuffer = 0; + mmio.pchBuffer = buf; + hmmio = mmioOpen(fname, &mmio, MMIO_READ | MMIO_ALLOCBUF); + ok(hmmio != 0, "mmioOpen error %u\n", mmio.wErrorRet); + + memset(&mmio, 0, sizeof(mmio)); + ret = mmioGetInfo(hmmio, &mmio, 0); + ok(ret == MMSYSERR_NOERROR, "mmioGetInfo error %u\n", ret); + ok(mmio.dwFlags == MMIO_READ, "expected MMIO_READ, got %x\n", mmio.dwFlags); + ok(mmio.wErrorRet == MMSYSERR_NOERROR, "expected MMSYSERR_NOERROR, got %u\n", mmio.wErrorRet); + ok(mmio.fccIOProc == (fname ? FOURCC_DOS : FOURCC_MEM), "got %4.4s\n", (LPCSTR)&mmio.fccIOProc); + ok(mmio.cchBuffer == MMIO_DEFAULTBUFFER, "expected MMIO_DEFAULTBUFFER, got %u\n", mmio.cchBuffer); + ok(mmio.pchBuffer == buf, "expected %p, got %p\n", buf, mmio.pchBuffer); + + mmioClose(hmmio, 0); + + memset(&mmio, 0, sizeof(mmio)); + mmio.fccIOProc = fname ? FOURCC_DOS : FOURCC_MEM; + mmio.cchBuffer = 0; + mmio.pchBuffer = NULL; + hmmio = mmioOpen(fname, &mmio, MMIO_READ | MMIO_ALLOCBUF); + ok(hmmio != 0, "mmioOpen error %u\n", mmio.wErrorRet); + + memset(&mmio, 0, sizeof(mmio)); + ret = mmioGetInfo(hmmio, &mmio, 0); + ok(ret == MMSYSERR_NOERROR, "mmioGetInfo error %u\n", ret); + ok(mmio.dwFlags == (MMIO_READ|MMIO_ALLOCBUF), "expected MMIO_READ|MMIO_ALLOCBUF, got %x\n", mmio.dwFlags); + ok(mmio.wErrorRet == MMSYSERR_NOERROR, "expected MMSYSERR_NOERROR, got %u\n", mmio.wErrorRet); + ok(mmio.fccIOProc == (fname ? FOURCC_DOS : FOURCC_MEM), "got %4.4s\n", (LPCSTR)&mmio.fccIOProc); + ok(mmio.cchBuffer == MMIO_DEFAULTBUFFER, "expected MMIO_DEFAULTBUFFER, got %u\n", mmio.cchBuffer); + ok(mmio.pchBuffer != NULL, "expected not NULL\n"); + + mmioClose(hmmio, 0); + + memset(&mmio, 0, sizeof(mmio)); + mmio.fccIOProc = fname ? FOURCC_DOS : FOURCC_MEM; + mmio.cchBuffer = 256; + mmio.pchBuffer = NULL; + hmmio = mmioOpen(fname, &mmio, MMIO_READ | MMIO_ALLOCBUF); + ok(hmmio != 0, "mmioOpen error %u\n", mmio.wErrorRet); + + memset(&mmio, 0, sizeof(mmio)); + ret = mmioGetInfo(hmmio, &mmio, 0); + ok(ret == MMSYSERR_NOERROR, "mmioGetInfo error %u\n", ret); + ok(mmio.dwFlags == (MMIO_READ|MMIO_ALLOCBUF), "expected MMIO_READ|MMIO_ALLOCBUF, got %x\n", mmio.dwFlags); + ok(mmio.wErrorRet == MMSYSERR_NOERROR, "expected MMSYSERR_NOERROR, got %u\n", mmio.wErrorRet); + ok(mmio.fccIOProc == (fname ? FOURCC_DOS : FOURCC_MEM), "got %4.4s\n", (LPCSTR)&mmio.fccIOProc); + ok(mmio.cchBuffer == 256, "expected 256, got %u\n", mmio.cchBuffer); + ok(mmio.pchBuffer != NULL, "expected not NULL\n"); + + mmioClose(hmmio, 0); +} + +static void test_mmioSetBuffer(char *fname) +{ + char buf[256]; + MMRESULT ret; + HMMIO hmmio; + MMIOINFO mmio; + + memset(&mmio, 0, sizeof(mmio)); + mmio.fccIOProc = fname ? FOURCC_DOS : FOURCC_MEM; + mmio.cchBuffer = sizeof(buf); + mmio.pchBuffer = buf; + hmmio = mmioOpen(fname, &mmio, MMIO_READ); + if (fname && !hmmio) + { + trace("%s file is missing, skipping the test\n", fname); + return; + } + ok(hmmio != 0, "mmioOpen error %u\n", mmio.wErrorRet); + + memset(&mmio, 0, sizeof(mmio)); + ret = mmioGetInfo(hmmio, &mmio, 0); + ok(ret == MMSYSERR_NOERROR, "mmioGetInfo error %u\n", ret); + ok(mmio.dwFlags == MMIO_READ, "expected MMIO_READ, got %x\n", mmio.dwFlags); + ok(mmio.wErrorRet == MMSYSERR_NOERROR, "expected MMSYSERR_NOERROR, got %u\n", mmio.wErrorRet); + ok(mmio.fccIOProc == (fname ? FOURCC_DOS : FOURCC_MEM), "got %4.4s\n", (LPCSTR)&mmio.fccIOProc); + ok(mmio.cchBuffer == sizeof(buf), "got %u\n", mmio.cchBuffer); + ok(mmio.pchBuffer == buf, "expected %p, got %p\n", buf, mmio.pchBuffer); + + ret = mmioSetBuffer(hmmio, NULL, 0, 0); + ok(ret == MMSYSERR_NOERROR, "mmioSetBuffer error %u\n", ret); + + memset(&mmio, 0, sizeof(mmio)); + ret = mmioGetInfo(hmmio, &mmio, 0); + ok(ret == MMSYSERR_NOERROR, "mmioGetInfo error %u\n", ret); + ok(mmio.dwFlags == MMIO_READ, "expected MMIO_READ, got %x\n", mmio.dwFlags); + ok(mmio.wErrorRet == MMSYSERR_NOERROR, "expected MMSYSERR_NOERROR, got %u\n", mmio.wErrorRet); + ok(mmio.fccIOProc == (fname ? FOURCC_DOS : FOURCC_MEM), "got %4.4s\n", (LPCSTR)&mmio.fccIOProc); + ok(mmio.cchBuffer == 0, "got not 0\n"); + ok(mmio.pchBuffer == NULL, "got not NULL buf\n"); + + ret = mmioSetBuffer(hmmio, NULL, 0, MMIO_ALLOCBUF); + ok(ret == MMSYSERR_NOERROR, "mmioSetBuffer error %u\n", ret); + + memset(&mmio, 0, sizeof(mmio)); + ret = mmioGetInfo(hmmio, &mmio, 0); + ok(ret == MMSYSERR_NOERROR, "mmioGetInfo error %u\n", ret); + ok(mmio.dwFlags == MMIO_READ, "expected MMIO_READ, got %x\n", mmio.dwFlags); + ok(mmio.wErrorRet == MMSYSERR_NOERROR, "expected MMSYSERR_NOERROR, got %u\n", mmio.wErrorRet); + ok(mmio.fccIOProc == (fname ? FOURCC_DOS : FOURCC_MEM), "got %4.4s\n", (LPCSTR)&mmio.fccIOProc); + ok(mmio.cchBuffer == 0, "got not 0\n"); + ok(mmio.pchBuffer == NULL, "got not NULL buf\n"); + + ret = mmioSetBuffer(hmmio, buf, 0, MMIO_ALLOCBUF); + ok(ret == MMSYSERR_NOERROR, "mmioSetBuffer error %u\n", ret); + + memset(&mmio, 0, sizeof(mmio)); + ret = mmioGetInfo(hmmio, &mmio, 0); + ok(ret == MMSYSERR_NOERROR, "mmioGetInfo error %u\n", ret); + ok(mmio.dwFlags == MMIO_READ, "expected MMIO_READ, got %x\n", mmio.dwFlags); + ok(mmio.wErrorRet == MMSYSERR_NOERROR, "expected MMSYSERR_NOERROR, got %u\n", mmio.wErrorRet); + ok(mmio.fccIOProc == (fname ? FOURCC_DOS : FOURCC_MEM), "got %4.4s\n", (LPCSTR)&mmio.fccIOProc); + ok(mmio.cchBuffer == 0, "got not 0\n"); + ok(mmio.pchBuffer == buf, "expected %p, got %p\n", buf, mmio.pchBuffer); + + ret = mmioSetBuffer(hmmio, NULL, 256, MMIO_WRITE|MMIO_ALLOCBUF); + ok(ret == MMSYSERR_NOERROR, "mmioSetBuffer error %u\n", ret); + + memset(&mmio, 0, sizeof(mmio)); + ret = mmioGetInfo(hmmio, &mmio, 0); + ok(ret == MMSYSERR_NOERROR, "mmioGetInfo error %u\n", ret); + ok(mmio.dwFlags == (MMIO_READ|MMIO_ALLOCBUF), "expected MMIO_READ|MMIO_ALLOCBUF, got %x\n", mmio.dwFlags); + ok(mmio.wErrorRet == MMSYSERR_NOERROR, "expected MMSYSERR_NOERROR, got %u\n", mmio.wErrorRet); + ok(mmio.fccIOProc == (fname ? FOURCC_DOS : FOURCC_MEM), "got %4.4s\n", (LPCSTR)&mmio.fccIOProc); + ok(mmio.cchBuffer == 256, "got %u\n", mmio.cchBuffer); + ok(mmio.pchBuffer != NULL, "expected not NULL\n"); + ok(mmio.pchBuffer != buf, "expected != buf\n"); + + mmioClose(hmmio, 0); +} + START_TEST(mmio) { - test_mmioDescend(); + char fname[] = "msrle.avi"; + + test_mmioDescend(NULL); + test_mmioDescend(fname); + test_mmioOpen(NULL); + test_mmioOpen(fname); + test_mmioSetBuffer(NULL); + test_mmioSetBuffer(fname); }