[AVIFIL32_WINETEST]
[reactos.git] / rostests / winetests / avifil32 / api.c
index a0b5ee8..4b35b8f 100644 (file)
@@ -33,6 +33,7 @@
 
 /* ########################### */
 
 
 /* ########################### */
 
+DEFINE_AVIGUID(CLSID_WAVFile,   0x00020003, 0, 0);
 static const CHAR winetest0[] = "winetest0";
 static const CHAR winetest1[] = "winetest1";
 static const CHAR testfilename[]  = "wine_avifil32_test.avi";
 static const CHAR winetest0[] = "winetest0";
 static const CHAR winetest1[] = "winetest1";
 static const CHAR testfilename[]  = "wine_avifil32_test.avi";
@@ -230,38 +231,38 @@ static void test_EditStreamSetInfo(void)
 {
     PAVISTREAM stream = NULL;
     HRESULT hres;
 {
     PAVISTREAM stream = NULL;
     HRESULT hres;
-    AVISTREAMINFO info, info2;
+    AVISTREAMINFOA info, info2;
 
     hres = CreateEditableStream(&stream, NULL);
     ok(hres == AVIERR_OK, "got 0x%08X, expected AVIERR_OK\n", hres);
 
     /* Size parameter is somehow checked (notice the crash with size=-1 below) */
 
     hres = CreateEditableStream(&stream, NULL);
     ok(hres == AVIERR_OK, "got 0x%08X, expected AVIERR_OK\n", hres);
 
     /* Size parameter is somehow checked (notice the crash with size=-1 below) */
-    hres = EditStreamSetInfo(stream, NULL, 0);
+    hres = EditStreamSetInfoA(stream, NULL, 0);
     ok( hres == AVIERR_BADSIZE, "got 0x%08X, expected AVIERR_BADSIZE\n", hres);
 
     ok( hres == AVIERR_BADSIZE, "got 0x%08X, expected AVIERR_BADSIZE\n", hres);
 
-    hres = EditStreamSetInfo(stream, NULL, sizeof(AVISTREAMINFO)-1 );
+    hres = EditStreamSetInfoA(stream, NULL, sizeof(AVISTREAMINFOA)-1 );
     ok( hres == AVIERR_BADSIZE, "got 0x%08X, expected AVIERR_BADSIZE\n", hres);
 
     if(0)
     {   
         /* Crashing - first parameter not checked */
     ok( hres == AVIERR_BADSIZE, "got 0x%08X, expected AVIERR_BADSIZE\n", hres);
 
     if(0)
     {   
         /* Crashing - first parameter not checked */
-        EditStreamSetInfo(NULL, &info, sizeof(AVISTREAMINFO) );
+        EditStreamSetInfoA(NULL, &info, sizeof(info) );
 
         /* Crashing - second parameter not checked */
 
         /* Crashing - second parameter not checked */
-        EditStreamSetInfo(stream, NULL, sizeof(AVISTREAMINFO) );
+        EditStreamSetInfoA(stream, NULL, sizeof(AVISTREAMINFOA) );
 
 
-        EditStreamSetInfo(stream, NULL, -1);
+        EditStreamSetInfoA(stream, NULL, -1);
     }
 
     }
 
-    hres = AVIStreamInfo(stream, &info, sizeof(AVISTREAMINFO) );
+    hres = AVIStreamInfoA(stream, &info, sizeof(info) );
     ok( hres == 0, "got 0x%08X, expected 0\n", hres);
 
              /* Does the function check what's it's updating ? */
 
 #define IS_INFO_UPDATED(m) do { \
     ok( hres == 0, "got 0x%08X, expected 0\n", hres);
 
              /* Does the function check what's it's updating ? */
 
 #define IS_INFO_UPDATED(m) do { \
-    hres = EditStreamSetInfo(stream, &info, sizeof(AVISTREAMINFO) ); \
+    hres = EditStreamSetInfoA(stream, &info, sizeof(info) ); \
     ok( hres == 0, "got 0x%08X, expected 0\n", hres); \
     ok( hres == 0, "got 0x%08X, expected 0\n", hres); \
-    hres = AVIStreamInfo(stream, &info2, sizeof(AVISTREAMINFO) ); \
+    hres = AVIStreamInfoA(stream, &info2, sizeof(info2) ); \
     ok( hres == 0, "got 0x%08X, expected 0\n", hres); \
     ok( info2.m == info.m, "EditStreamSetInfo did not update "#m" parameter\n" ); \
     } while(0)
     ok( hres == 0, "got 0x%08X, expected 0\n", hres); \
     ok( info2.m == info.m, "EditStreamSetInfo did not update "#m" parameter\n" ); \
     } while(0)
@@ -336,7 +337,7 @@ static void create_avi_file(const COMMON_AVI_HEADERS *cah, char *filename)
     HANDLE hFile;
     DWORD written;
 
     HANDLE hFile;
     DWORD written;
 
-    hFile = CreateFile(filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
+    hFile = CreateFileA(filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
 
     ok(hFile != INVALID_HANDLE_VALUE, "Couldn't create file\n");
 
 
     ok(hFile != INVALID_HANDLE_VALUE, "Couldn't create file\n");
 
@@ -364,17 +365,16 @@ static void test_default_data(void)
     LONG lSize;
     PAVISTREAM pStream0;
     PAVISTREAM pStream1;
     LONG lSize;
     PAVISTREAM pStream0;
     PAVISTREAM pStream1;
-    AVISTREAMINFO asi0;
-    AVISTREAMINFO asi1;
+    AVISTREAMINFOA asi0, asi1;
     WAVEFORMATEX wfx;
 
     WAVEFORMATEX wfx;
 
-    GetTempPath(MAX_PATH, filename);
+    GetTempPathA(MAX_PATH, filename);
     strcpy(filename+strlen(filename), testfilename);
 
     init_test_struct(&cah);
     create_avi_file(&cah, filename);
 
     strcpy(filename+strlen(filename), testfilename);
 
     init_test_struct(&cah);
     create_avi_file(&cah, filename);
 
-    res = AVIFileOpen(&pFile, filename, OF_SHARE_DENY_WRITE, 0L);
+    res = AVIFileOpenA(&pFile, filename, OF_SHARE_DENY_WRITE, 0L);
     ok(res != AVIERR_BADFORMAT, "Unable to open file: error1=%u\n", AVIERR_BADFORMAT);
     ok(res != AVIERR_MEMORY, "Unable to open file: error2=%u\n", AVIERR_MEMORY);
     ok(res != AVIERR_FILEREAD, "Unable to open file: error3=%u\n", AVIERR_FILEREAD);
     ok(res != AVIERR_BADFORMAT, "Unable to open file: error1=%u\n", AVIERR_BADFORMAT);
     ok(res != AVIERR_MEMORY, "Unable to open file: error2=%u\n", AVIERR_MEMORY);
     ok(res != AVIERR_FILEREAD, "Unable to open file: error3=%u\n", AVIERR_FILEREAD);
@@ -388,10 +388,10 @@ static void test_default_data(void)
     res = AVIFileGetStream(pFile, &pStream1, 0, 1);
     ok(res == 0, "Unable to open audio stream: error=%u\n", res);
 
     res = AVIFileGetStream(pFile, &pStream1, 0, 1);
     ok(res == 0, "Unable to open audio stream: error=%u\n", res);
 
-    res = AVIStreamInfo(pStream0, &asi0, sizeof(AVISTREAMINFO));
+    res = AVIStreamInfoA(pStream0, &asi0, sizeof(asi0));
     ok(res == 0, "Unable to read stream info: error=%u\n", res);
 
     ok(res == 0, "Unable to read stream info: error=%u\n", res);
 
-    res = AVIStreamInfo(pStream1, &asi1, sizeof(AVISTREAMINFO));
+    res = AVIStreamInfoA(pStream1, &asi1, sizeof(asi1));
     ok(res == 0, "Unable to read stream info: error=%u\n", res);
 
     res = AVIStreamReadFormat(pStream0, AVIStreamStart(pStream1), NULL, &lSize);
     ok(res == 0, "Unable to read stream info: error=%u\n", res);
 
     res = AVIStreamReadFormat(pStream0, AVIStreamStart(pStream1), NULL, &lSize);
@@ -450,7 +450,7 @@ static void test_default_data(void)
     AVIStreamRelease(pStream0);
     AVIStreamRelease(pStream1);
     AVIFileRelease(pFile);
     AVIStreamRelease(pStream0);
     AVIStreamRelease(pStream1);
     AVIFileRelease(pFile);
-    ok(DeleteFile(filename) !=0, "Deleting file %s failed\n", filename);
+    ok(DeleteFileA(filename) !=0, "Deleting file %s failed\n", filename);
 }
 
 static void test_amh_corruption(void)
 }
 
 static void test_amh_corruption(void)
@@ -460,7 +460,7 @@ static void test_amh_corruption(void)
     PAVIFILE pFile;
     int res;
 
     PAVIFILE pFile;
     int res;
 
-    GetTempPath(MAX_PATH, filename);
+    GetTempPathA(MAX_PATH, filename);
     strcpy(filename+strlen(filename), testfilename);
 
     /* Make sure only AVI files with the proper headers will be loaded */
     strcpy(filename+strlen(filename), testfilename);
 
     /* Make sure only AVI files with the proper headers will be loaded */
@@ -468,10 +468,10 @@ static void test_amh_corruption(void)
     cah.fh[3] = mmioFOURCC('A', 'V', 'i', ' ');
 
     create_avi_file(&cah, filename);
     cah.fh[3] = mmioFOURCC('A', 'V', 'i', ' ');
 
     create_avi_file(&cah, filename);
-    res = AVIFileOpen(&pFile, filename, OF_SHARE_DENY_WRITE, 0L);
+    res = AVIFileOpenA(&pFile, filename, OF_SHARE_DENY_WRITE, 0L);
     ok(res != 0, "Able to open file: error=%u\n", res);
 
     ok(res != 0, "Able to open file: error=%u\n", res);
 
-    ok(DeleteFile(filename) !=0, "Deleting file %s failed\n", filename);
+    ok(DeleteFileA(filename) !=0, "Deleting file %s failed\n", filename);
 }
 
 static void test_ash1_corruption(void)
 }
 
 static void test_ash1_corruption(void)
@@ -481,9 +481,9 @@ static void test_ash1_corruption(void)
     PAVIFILE pFile;
     int res;
     PAVISTREAM pStream1;
     PAVIFILE pFile;
     int res;
     PAVISTREAM pStream1;
-    AVISTREAMINFO asi1;
+    AVISTREAMINFOA asi1;
 
 
-    GetTempPath(MAX_PATH, filename);
+    GetTempPathA(MAX_PATH, filename);
     strcpy(filename+strlen(filename), testfilename);
 
     /* Corrupt the sample size in the audio stream header */
     strcpy(filename+strlen(filename), testfilename);
 
     /* Corrupt the sample size in the audio stream header */
@@ -492,13 +492,13 @@ static void test_ash1_corruption(void)
 
     create_avi_file(&cah, filename);
 
 
     create_avi_file(&cah, filename);
 
-    res = AVIFileOpen(&pFile, filename, OF_SHARE_DENY_WRITE, 0L);
+    res = AVIFileOpenA(&pFile, filename, OF_SHARE_DENY_WRITE, 0L);
     ok(res == 0, "Unable to open file: error=%u\n", res);
 
     res = AVIFileGetStream(pFile, &pStream1, 0, 1);
     ok(res == 0, "Unable to open audio stream: error=%u\n", res);
 
     ok(res == 0, "Unable to open file: error=%u\n", res);
 
     res = AVIFileGetStream(pFile, &pStream1, 0, 1);
     ok(res == 0, "Unable to open audio stream: error=%u\n", res);
 
-    res = AVIStreamInfo(pStream1, &asi1, sizeof(AVISTREAMINFO));
+    res = AVIStreamInfoA(pStream1, &asi1, sizeof(asi1));
     ok(res == 0, "Unable to read stream info: error=%u\n", res);
 
     /* The result will still be 2, because the value is dynamically replaced with the nBlockAlign
     ok(res == 0, "Unable to read stream info: error=%u\n", res);
 
     /* The result will still be 2, because the value is dynamically replaced with the nBlockAlign
@@ -507,7 +507,7 @@ static void test_ash1_corruption(void)
 
     AVIStreamRelease(pStream1);
     AVIFileRelease(pFile);
 
     AVIStreamRelease(pStream1);
     AVIFileRelease(pFile);
-    ok(DeleteFile(filename) !=0, "Deleting file %s failed\n", filename);
+    ok(DeleteFileA(filename) !=0, "Deleting file %s failed\n", filename);
 }
 
 static void test_ash1_corruption2(void)
 }
 
 static void test_ash1_corruption2(void)
@@ -517,9 +517,9 @@ static void test_ash1_corruption2(void)
     PAVIFILE pFile;
     int res;
     PAVISTREAM pStream1;
     PAVIFILE pFile;
     int res;
     PAVISTREAM pStream1;
-    AVISTREAMINFO asi1;
+    AVISTREAMINFOA asi1;
 
 
-    GetTempPath(MAX_PATH, filename);
+    GetTempPathA(MAX_PATH, filename);
     strcpy(filename+strlen(filename), testfilename);
 
     /* Corrupt the block alignment in the audio format header */
     strcpy(filename+strlen(filename), testfilename);
 
     /* Corrupt the block alignment in the audio format header */
@@ -528,20 +528,20 @@ static void test_ash1_corruption2(void)
 
     create_avi_file(&cah, filename);
 
 
     create_avi_file(&cah, filename);
 
-    res = AVIFileOpen(&pFile, filename, OF_SHARE_DENY_WRITE, 0L);
+    res = AVIFileOpenA(&pFile, filename, OF_SHARE_DENY_WRITE, 0L);
     ok(res == 0, "Unable to open file: error=%u\n", res);
 
     res = AVIFileGetStream(pFile, &pStream1, 0, 1);
     ok(res == 0, "Unable to open audio stream: error=%u\n", res);
 
     ok(res == 0, "Unable to open file: error=%u\n", res);
 
     res = AVIFileGetStream(pFile, &pStream1, 0, 1);
     ok(res == 0, "Unable to open audio stream: error=%u\n", res);
 
-    ok(AVIStreamInfo(pStream1, &asi1, sizeof(AVISTREAMINFO)) == 0, "Unable to read stream info\n");
+    ok(AVIStreamInfoA(pStream1, &asi1, sizeof(asi1)) == 0, "Unable to read stream info\n");
 
     /* The result will also be the corrupt value, as explained above. */
     ok(asi1.dwSampleSize == 0xdead, "got 0x%x (expected 0xdead)\n", asi1.dwSampleSize);
 
     AVIStreamRelease(pStream1);
     AVIFileRelease(pFile);
 
     /* The result will also be the corrupt value, as explained above. */
     ok(asi1.dwSampleSize == 0xdead, "got 0x%x (expected 0xdead)\n", asi1.dwSampleSize);
 
     AVIStreamRelease(pStream1);
     AVIFileRelease(pFile);
-    ok(DeleteFile(filename) !=0, "Deleting file %s failed\n", filename);
+    ok(DeleteFileA(filename) !=0, "Deleting file %s failed\n", filename);
 }
 
 /* Outer IUnknown for COM aggregation tests */
 }
 
 /* Outer IUnknown for COM aggregation tests */
@@ -653,6 +653,67 @@ static void test_COM(void)
     while (IAVIFile_Release(avif));
 }
 
     while (IAVIFile_Release(avif));
 }
 
+static void test_COM_wavfile(void)
+{
+    struct unk_impl unk_obj = {{&unk_vtbl}, 19, NULL};
+    IAVIFile *avif = NULL;
+    IPersistFile *pf;
+    IAVIStream *avis;
+    IUnknown *unk;
+    ULONG refcount;
+    HRESULT hr;
+
+    /* COM aggregation */
+    hr = CoCreateInstance(&CLSID_WAVFile, &unk_obj.IUnknown_iface, CLSCTX_INPROC_SERVER,
+            &IID_IUnknown, (void**)&unk_obj.inner_unk);
+    ok(hr == S_OK, "COM aggregation failed: %08x, expected S_OK\n", hr);
+    hr = IUnknown_QueryInterface(&unk_obj.IUnknown_iface, &IID_IAVIFile, (void**)&avif);
+    ok(hr == S_OK, "QueryInterface for IID_IAVIFile failed: %08x\n", hr);
+    refcount = IAVIFile_AddRef(avif);
+    ok(refcount == unk_obj.ref, "WAVFile just pretends to support COM aggregation\n");
+    refcount = IAVIFile_Release(avif);
+    ok(refcount == unk_obj.ref, "WAVFile just pretends to support COM aggregation\n");
+    hr = IAVIFile_QueryInterface(avif, &IID_IPersistFile, (void**)&pf);
+    ok(hr == S_OK, "QueryInterface for IID_IPersistFile failed: %08x\n", hr);
+    refcount = IPersistFile_Release(pf);
+    ok(refcount == unk_obj.ref, "WAVFile just pretends to support COM aggregation\n");
+    refcount = IAVIFile_Release(avif);
+    ok(refcount == 19, "Outer ref count should be back at 19 but is %d\n", refcount);
+    refcount = IUnknown_Release(unk_obj.inner_unk);
+    ok(refcount == 0, "Inner ref count should be 0 but is %u\n", refcount);
+
+    /* Invalid RIID */
+    hr = CoCreateInstance(&CLSID_WAVFile, NULL, CLSCTX_INPROC_SERVER, &IID_IAVIStreaming,
+            (void**)&avif);
+    ok(hr == E_NOINTERFACE, "WAVFile create failed: %08x, expected E_NOINTERFACE\n", hr);
+
+    /* Same refcount for all WAVFile interfaces */
+    hr = CoCreateInstance(&CLSID_WAVFile, NULL, CLSCTX_INPROC_SERVER, &IID_IAVIFile, (void**)&avif);
+    ok(hr == S_OK, "WAVFile create failed: %08x, expected S_OK\n", hr);
+    refcount = IAVIFile_AddRef(avif);
+    ok(refcount == 2, "refcount == %u, expected 2\n", refcount);
+
+    hr = IAVIFile_QueryInterface(avif, &IID_IPersistFile, (void**)&pf);
+    ok(hr == S_OK, "QueryInterface for IID_IPersistFile failed: %08x\n", hr);
+    refcount = IPersistFile_AddRef(pf);
+    ok(refcount == 4, "refcount == %u, expected 4\n", refcount);
+    refcount = IPersistFile_Release(pf);
+
+    hr = IAVIFile_QueryInterface(avif, &IID_IAVIStream, (void**)&avis);
+    ok(hr == S_OK, "QueryInterface for IID_IAVIStream failed: %08x\n", hr);
+    refcount = IAVIStream_AddRef(avis);
+    ok(refcount == 5, "refcount == %u, expected 5\n", refcount);
+    refcount = IAVIStream_Release(avis);
+
+    hr = IAVIFile_QueryInterface(avif, &IID_IUnknown, (void**)&unk);
+    ok(hr == S_OK, "QueryInterface for IID_IUnknown failed: %08x\n", hr);
+    refcount = IUnknown_AddRef(unk);
+    ok(refcount == 6, "refcount == %u, expected 6\n", refcount);
+    refcount = IUnknown_Release(unk);
+
+    while (IAVIFile_Release(avif));
+}
+
 START_TEST(api)
 {
 
 START_TEST(api)
 {
 
@@ -664,6 +725,7 @@ START_TEST(api)
     test_ash1_corruption();
     test_ash1_corruption2();
     test_COM();
     test_ash1_corruption();
     test_ash1_corruption2();
     test_COM();
+    test_COM_wavfile();
     AVIFileExit();
 
 }
     AVIFileExit();
 
 }