From 00dc5fa4d767b2edbb0e9d42931c0fd9585c1b90 Mon Sep 17 00:00:00 2001 From: Julius Schwartzenberg Date: Fri, 25 Dec 2009 20:29:43 +0100 Subject: initial version of avifile testing framework --- dlls/avifil32/tests/api.c | 72 ++++++++++++++++++ dlls/avifil32/tests/api_test.h | 160 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 232 insertions(+), 0 deletions(-) create mode 100644 dlls/avifil32/tests/api_test.h diff --git a/dlls/avifil32/tests/api.c b/dlls/avifil32/tests/api.c index 55b194f..c41ebfb 100644 --- a/dlls/avifil32/tests/api.c +++ b/dlls/avifil32/tests/api.c @@ -20,6 +20,7 @@ */ #include +#include #include "windef.h" #include "winbase.h" @@ -28,6 +29,8 @@ #include "vfw.h" #include "wine/test.h" +#include "api_test.h" + /* ########################### */ static const CHAR winetest0[] = "winetest0"; @@ -87,11 +90,80 @@ static void test_AVISaveOptions(void) /* ########################### */ +void init_test_struct(COMMON_AVI_HEADERS *cah) +{ + MainAVIHeader *mah = malloc(sizeof(MainAVIHeader)); + AVIStreamHeader *ash0 = malloc(sizeof(AVIStreamHeader)); + AVIStreamHeader *ash1 = malloc(sizeof(AVIStreamHeader)); + PCMWAVEFORMAT *pcmwf = malloc(sizeof(PCMWAVEFORMAT)); + memcpy(mah, &defmah, sizeof(defmah)); + memcpy(ash0, &defash0, sizeof(defash0)); + memcpy(ash1, &defash1, sizeof(defash1)); + memcpy(pcmwf, &defpcmwf, sizeof(defpcmwf)); + cah->mah = mah; + cah->ash0 = ash0; + cah->ash1 = ash1; + cah->pcmwf = pcmwf; +} + +void create_avi_file(COMMON_AVI_HEADERS *cah) +{ + FILE * pFile; + pFile = fopen("small.avi", "wb"); + + fwrite(file_header, 1, sizeof(file_header), pFile); /* de file wordt hier niet goed aangemaakt */ + fwrite(cah->mah, 1, sizeof(MainAVIHeader), pFile); + fwrite(streamlist, 1, sizeof(streamlist), pFile); + fwrite(cah->ash0, 1, 0x38, pFile); + fwrite(videostreamformat, 1, sizeof(videostreamformat), pFile); + fwrite(padding1, 1, sizeof(padding1), pFile); + fwrite(videopropheader, 1, sizeof(videopropheader), pFile); + fwrite(cah->ash1, 1, 0x38, pFile); + fwrite(audiostreamformat_pre, 1, sizeof(audiostreamformat_pre), pFile); + fwrite(cah->pcmwf, 1, sizeof(PCMWAVEFORMAT), pFile); + fwrite(data, 1, sizeof(data), pFile); + + fclose (pFile); +} + +void test_default_data() +{ + COMMON_AVI_HEADERS *cah; + PAVIFILE pFile; + int res; + LONG lSize; + WAVEFORMATEX wfx; + PAVISTREAM pStream; + + cah = calloc(sizeof(int),4); + init_test_struct(cah); + create_avi_file(cah); + + res = AVIFileOpen(&pFile, "small.avi", OF_SHARE_DENY_WRITE, 0L); + ok(res == 0, "Unable to open file: error=%u\n", res); + + res = AVIFileGetStream(pFile, &pStream, 0, 1); + ok(res == 0, "Unable to open audio stream: error=%u\n", res); + + ok(AVIStreamReadFormat(pStream, AVIStreamStart(pStream), NULL, &lSize) == 0, "Unable to read format size\n"); + ok(AVIStreamReadFormat(pStream, AVIStreamStart(pStream), &wfx, &lSize) == 0, "Unable to read format\n"); + + ok(wfx.wFormatTag == 1, "got %u (expected 1)\n",wfx.wFormatTag); + ok(wfx.nChannels == 2, "got %u (expected 2)\n",wfx.nChannels); + ok(wfx.wFormatTag == 1, "got %u (expected 1)\n",wfx.wFormatTag); + ok(wfx.nSamplesPerSec == 11025, "got %u (expected 11025)\n",wfx.nSamplesPerSec); + ok(wfx.nAvgBytesPerSec == 22050, "got %u (expected 22050)\n",wfx.nAvgBytesPerSec); + ok(wfx.nBlockAlign == 2, "got %u (expected 2)\n",wfx.nBlockAlign); +} + +/* ########################### */ + START_TEST(api) { AVIFileInit(); test_AVISaveOptions(); + test_default_data(); AVIFileExit(); } diff --git a/dlls/avifil32/tests/api_test.h b/dlls/avifil32/tests/api_test.h new file mode 100644 index 0000000..395cfa3 --- /dev/null +++ b/dlls/avifil32/tests/api_test.h @@ -0,0 +1,160 @@ +/* + * Unit test suite header for AVI Functions + * + * Copyright 2009 Julius Schwartzenberg + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + * + */ + + +typedef struct common_avi_headers { + MainAVIHeader *mah; + AVIStreamHeader *ash0; + AVIStreamHeader *ash1; + PCMWAVEFORMAT *pcmwf; +} COMMON_AVI_HEADERS; + +static const MainAVIHeader defmah = +{ + 0x00008256, /* dwMicroSecPerFrame */ + 0x000080e8, /* dwMaxBytesPerSec */ + 0x00000000, /* dwPaddingGranularity */ + 0x00000910, /* dwFlags */ + 1, /* dwTotalFrames */ + 0, /* dwInitialFrames */ + 2, /* dwStreams */ + 0x00100000, /* dwSuggestedBufferSize*/ + 8, /* dwWidth */ + 6, /* dwHeight */ + { 0, 0, 0, 0 } /* dwReserved[4] */ +}; + +static const AVIStreamHeader defash0 = +{ + streamtypeVIDEO, /* fccType */ + 0x30323449, /* fccHandler */ + 0x00000000, /* dwFlags */ + 0, /* wPriority */ + 0, /* wLanguage */ + 0, /* dwInitialFrames */ + 0x000003e9, /* dwScale */ + 0x00007530, /* dwRate */ + 0, /* dwStart */ + 1, /* dwLength */ + 0x00100000, /* dwSuggestedBufferSize*/ + 0xffffffff, /* dwQuality */ + 0, /* dwSampleSize */ + { 0, 0, 0, 0 } /* short left right top bottom */ +}; + +static const AVIStreamHeader defash1 = +{ + /* AVIStreamHeader */ + streamtypeAUDIO, /* fccType */ + 1, /* fccHandler */ + 0, /* dwFlags */ + 0, /* wPriority */ + 0, /* wLanguage */ + 0, /* dwInitialFrames */ + 1, /* dwScale */ + 0x00002b11, /* dwRate */ + 0, /* dwStart */ + 0x00000665, /* dwLength */ + 0x00003000, /* dwSuggestedBufferSize*/ + 0xffffffff, /* dwQuality */ + 2, /* dwSampleSize */ + { 0, 0, 0, 0 } /* short left right top bottom */ +}; + +static const PCMWAVEFORMAT defpcmwf = +{ + { + 1, /* wFormatTag */ + 2, /* nChannels */ + 11025, /* nSamplesPerSec */ + 22050, /* nAvgBytesPerSec */ + 2, /* nBlockAlign */ + }, + 8, /* wBitsPerSample */ +}; + +/* Extra data needed to get the VFW API to load the file */ +DWORD file_header[] = +{ + FOURCC_RIFF, 0x34c6 /* length */, formtypeAVI, + FOURCC_LIST, 0x1ac /* length */, + listtypeAVIHEADER, ckidAVIMAINHDR, sizeof(MainAVIHeader), +}; + +/* MainAVIHeader mah */ + +DWORD streamlist[] = +{ + FOURCC_LIST, 0xd4 /* length */, + listtypeSTREAMHEADER, ckidSTREAMHEADER, 0x38 /* length */, +}; + +/* AVIStreamHeader ash0 */ + +DWORD videostreamformat[] = +{ + ckidSTREAMFORMAT, 0x28 /* length */, + 0x00000028, 0x00000008, 0x00000006, 0x00180001, + 0x30323449, 0x00000090, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, +}; +DWORD padding1[] = +{ + ckidAVIPADDING, 0xc /* length */, + 0x00000004, 0x00000000, 0x63643030 +}; +DWORD videopropheader[] = +{ + 0x70727076, 0x44 /* length */, + 0x00000000, 0x00000000, + 0x0000001e, 0x00000008, 0x00000006, 0x00100009, + 0x00000008, 0x00000006, 0x00000001, 0x00000006, + 0x00000008, 0x00000006, 0x00000008, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, + FOURCC_LIST, 0x70 /* length */, + listtypeSTREAMHEADER, ckidSTREAMHEADER, 0x38 /* length */, +}; + +/* AVIStreamHeader ash1 */ + +DWORD audiostreamformat_pre[] = +{ + ckidSTREAMFORMAT, sizeof(PCMWAVEFORMAT) /* length */, +}; + +/* PCMWAVEFORMAT pcmwf */ + +DWORD data[] = +{ + ckidAVIPADDING, 0xc /* length */, + 0x00000004, 0x00000000, 0x62773130, + ckidAVIPADDING, 0xc /* length */, + 0x6c6d646f, 0x686c6d64, 0x000000f8, + FOURCC_LIST, 0x18 /* length */, + 0x4f464e49, + 0x54465349, 0xc /* length */, + 0x6676614c, 0x332e3235, 0x00302e37, + ckidAVIPADDING, 0x4 /* length */, + 0, + + FOURCC_LIST, 0xd1b /* length */, listtypeAVIMOVIE, + 0, 0 +}; -- 1.6.3.3