Update the address of the Free Software Foundation.
[wine/gsoc_dplay.git] / dlls / winmm / tests / mmio.c
blob309105d141000e3bebdc1ddc735d16736924c80f
1 /*
2 * Unit tests for mmio APIs
4 * Copyright 2005 Dmitry Timoshkov
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <assert.h>
22 #include <stdarg.h>
24 #include "windef.h"
25 #include "winbase.h"
26 #include "wingdi.h"
27 #include "mmsystem.h"
28 #include "vfw.h"
29 #include "wine/test.h"
31 static const DWORD RIFF_buf[] =
33 FOURCC_RIFF, 7*sizeof(DWORD)+sizeof(MainAVIHeader), mmioFOURCC('A','V','I',' '),
34 FOURCC_LIST, sizeof(DWORD)+sizeof(MMCKINFO)+sizeof(MainAVIHeader), listtypeAVIHEADER,
35 ckidAVIMAINHDR, sizeof(MainAVIHeader),
36 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
37 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
38 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
39 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
42 static void test_mmioDescend(void)
44 MMRESULT ret;
45 HMMIO hmmio;
46 MMIOINFO mmio;
47 MMCKINFO ckRiff, ckList, ck;
49 memset(&mmio, 0, sizeof(mmio));
50 mmio.fccIOProc = FOURCC_MEM;
51 mmio.cchBuffer = sizeof(RIFF_buf);
52 mmio.pchBuffer = (char *)&RIFF_buf;
54 /*hmmio = mmioOpen("msrle.avi", NULL, MMIO_READ);*/
55 hmmio = mmioOpen(NULL, &mmio, MMIO_READ);
56 ok(hmmio != 0, "mmioOpen error %u\n", mmio.wErrorRet);
57 trace("hmmio = %p\n", hmmio);
59 /* first normal RIFF AVI parsing */
60 ret = mmioDescend(hmmio, &ckRiff, NULL, 0);
61 ok(ret == MMSYSERR_NOERROR, "mmioDescend error %u\n", ret);
62 ok(ckRiff.ckid == FOURCC_RIFF, "wrong ckid: %04lx\n", ckRiff.ckid);
63 ok(ckRiff.fccType == formtypeAVI, "wrong fccType: %04lx\n", ckRiff.fccType);
64 trace("ckid %4.4s cksize %04lx fccType %4.4s off %04lx flags %04lx\n",
65 (LPCSTR)&ckRiff.ckid, ckRiff.cksize, (LPCSTR)&ckRiff.fccType,
66 ckRiff.dwDataOffset, ckRiff.dwFlags);
68 ret = mmioDescend(hmmio, &ckList, &ckRiff, 0);
69 ok(ret == MMSYSERR_NOERROR, "mmioDescend error %u\n", ret);
70 ok(ckList.ckid == FOURCC_LIST, "wrong ckid: %04lx\n", ckList.ckid);
71 ok(ckList.fccType == listtypeAVIHEADER, "wrong fccType: %04lx\n", ckList.fccType);
72 trace("ckid %4.4s cksize %04lx fccType %4.4s off %04lx flags %04lx\n",
73 (LPCSTR)&ckList.ckid, ckList.cksize, (LPCSTR)&ckList.fccType,
74 ckList.dwDataOffset, ckList.dwFlags);
76 ret = mmioDescend(hmmio, &ck, &ckList, 0);
77 ok(ret == MMSYSERR_NOERROR, "mmioDescend error %u\n", ret);
78 ok(ck.ckid == ckidAVIMAINHDR, "wrong ckid: %04lx\n", ck.ckid);
79 ok(ck.fccType == 0, "wrong fccType: %04lx\n", ck.fccType);
80 trace("ckid %4.4s cksize %04lx fccType %4.4s off %04lx flags %04lx\n",
81 (LPCSTR)&ck.ckid, ck.cksize, (LPCSTR)&ck.fccType,
82 ck.dwDataOffset, ck.dwFlags);
84 /* test various mmioDescend flags */
86 mmioSeek(hmmio, 0, SEEK_SET);
87 memset(&ck, 0x55, sizeof(ck));
88 ret = mmioDescend(hmmio, &ck, NULL, MMIO_FINDRIFF);
89 ok(ret == MMIOERR_CHUNKNOTFOUND ||
90 ret == MMIOERR_INVALIDFILE, "mmioDescend returned %u\n", ret);
92 mmioSeek(hmmio, 0, SEEK_SET);
93 memset(&ck, 0x55, sizeof(ck));
94 ck.ckid = 0;
95 ret = mmioDescend(hmmio, &ck, NULL, MMIO_FINDRIFF);
96 ok(ret == MMIOERR_CHUNKNOTFOUND ||
97 ret == MMIOERR_INVALIDFILE, "mmioDescend returned %u\n", ret);
99 mmioSeek(hmmio, 0, SEEK_SET);
100 memset(&ck, 0x55, sizeof(ck));
101 ck.fccType = 0;
102 ret = mmioDescend(hmmio, &ck, NULL, MMIO_FINDRIFF);
103 ok(ret == MMSYSERR_NOERROR, "mmioDescend error %u\n", ret);
104 ok(ck.ckid == FOURCC_RIFF, "wrong ckid: %04lx\n", ck.ckid);
105 ok(ck.fccType == formtypeAVI, "wrong fccType: %04lx\n", ck.fccType);
107 mmioSeek(hmmio, 0, SEEK_SET);
108 memset(&ck, 0x55, sizeof(ck));
109 ret = mmioDescend(hmmio, &ck, NULL, 0);
110 ok(ret == MMSYSERR_NOERROR, "mmioDescend error %u\n", ret);
111 ok(ck.ckid == FOURCC_RIFF, "wrong ckid: %04lx\n", ck.ckid);
112 ok(ck.fccType == formtypeAVI, "wrong fccType: %04lx\n", ck.fccType);
114 /* do NOT seek, use current file position */
115 memset(&ck, 0x55, sizeof(ck));
116 ck.fccType = 0;
117 ret = mmioDescend(hmmio, &ck, NULL, MMIO_FINDLIST);
118 ok(ret == MMSYSERR_NOERROR, "mmioDescend error %u\n", ret);
119 ok(ck.ckid == FOURCC_LIST, "wrong ckid: %04lx\n", ck.ckid);
120 ok(ck.fccType == listtypeAVIHEADER, "wrong fccType: %04lx\n", ck.fccType);
122 mmioSeek(hmmio, 0, SEEK_SET);
123 memset(&ck, 0x55, sizeof(ck));
124 ck.ckid = 0;
125 ck.fccType = listtypeAVIHEADER;
126 ret = mmioDescend(hmmio, &ck, NULL, MMIO_FINDCHUNK);
127 ok(ret == MMSYSERR_NOERROR, "mmioDescend error %u\n", ret);
128 ok(ck.ckid == FOURCC_RIFF, "wrong ckid: %04lx\n", ck.ckid);
129 ok(ck.fccType == formtypeAVI, "wrong fccType: %04lx\n", ck.fccType);
131 /* do NOT seek, use current file position */
132 memset(&ck, 0x55, sizeof(ck));
133 ck.ckid = FOURCC_LIST;
134 ret = mmioDescend(hmmio, &ck, NULL, MMIO_FINDCHUNK);
135 ok(ret == MMSYSERR_NOERROR, "mmioDescend error %u\n", ret);
136 ok(ck.ckid == FOURCC_LIST, "wrong ckid: %04lx\n", ck.ckid);
137 ok(ck.fccType == listtypeAVIHEADER, "wrong fccType: %04lx\n", ck.fccType);
139 mmioSeek(hmmio, 0, SEEK_SET);
140 memset(&ck, 0x55, sizeof(ck));
141 ck.ckid = FOURCC_RIFF;
142 ret = mmioDescend(hmmio, &ck, NULL, MMIO_FINDCHUNK);
143 ok(ret == MMSYSERR_NOERROR, "mmioDescend error %u\n", ret);
144 ok(ck.ckid == FOURCC_RIFF, "wrong ckid: %04lx\n", ck.ckid);
145 ok(ck.fccType == formtypeAVI, "wrong fccType: %04lx\n", ck.fccType);
147 /* do NOT seek, use current file position */
148 memset(&ckList, 0x55, sizeof(ckList));
149 ckList.ckid = 0;
150 ret = mmioDescend(hmmio, &ckList, &ck, MMIO_FINDCHUNK);
151 ok(ret == MMSYSERR_NOERROR, "mmioDescend error %u\n", ret);
152 ok(ckList.ckid == FOURCC_LIST, "wrong ckid: %04lx\n", ckList.ckid);
153 ok(ckList.fccType == listtypeAVIHEADER, "wrong fccType: %04lx\n", ckList.fccType);
155 mmioSeek(hmmio, 0, SEEK_SET);
156 memset(&ck, 0x55, sizeof(ck));
157 ret = mmioDescend(hmmio, &ck, NULL, MMIO_FINDCHUNK);
158 ok(ret == MMIOERR_CHUNKNOTFOUND ||
159 ret == MMIOERR_INVALIDFILE, "mmioDescend returned %u\n", ret);
160 ok(ck.ckid != 0x55555555, "wrong ckid: %04lx\n", ck.ckid);
161 ok(ck.fccType != 0x55555555, "wrong fccType: %04lx\n", ck.fccType);
162 ok(ck.dwDataOffset != 0x55555555, "wrong dwDataOffset: %04lx\n", ck.dwDataOffset);
164 mmioSeek(hmmio, 0, SEEK_SET);
165 memset(&ck, 0x55, sizeof(ck));
166 ret = mmioDescend(hmmio, &ck, NULL, MMIO_FINDRIFF);
167 ok(ret == MMIOERR_CHUNKNOTFOUND ||
168 ret == MMIOERR_INVALIDFILE, "mmioDescend returned %u\n", ret);
170 mmioClose(hmmio, 0);
173 START_TEST(mmio)
175 test_mmioDescend();