msi: Use msi_strcpy_to_awstring to return the string in MsiComponentGetPath.
[wine] / dlls / winmm / tests / mmio.c
1 /*
2  * Unit tests for mmio APIs
3  *
4  * Copyright 2005 Dmitry Timoshkov
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include <assert.h>
22 #include <stdarg.h>
23
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"
30
31 static const DWORD RIFF_buf[] =
32 {
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
40 };
41
42 static void test_mmioDescend(void)
43 {
44     MMRESULT ret;
45     HMMIO hmmio;
46     MMIOINFO mmio;
47     MMCKINFO ckRiff, ckList, ck;
48
49     memset(&mmio, 0, sizeof(mmio));
50     mmio.fccIOProc = FOURCC_MEM;
51     mmio.cchBuffer = sizeof(RIFF_buf);
52     mmio.pchBuffer = (char *)&RIFF_buf;
53
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);
58
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);
67
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);
75
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);
83
84     /* test various mmioDescend flags */
85
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);
91
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);
98
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);
106
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);
113
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);
121
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);
130
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);
138
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);
146
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);
154
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);
163
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);
169
170     mmioClose(hmmio, 0);
171 }
172
173 START_TEST(mmio)
174 {
175     test_mmioDescend();
176 }