Ziqing Hui : windowscodecs/tests: Add tests for DdsDecoder_GetFrame() and DdsFrameDecode_GetSize().

Alexandre Julliard julliard at winehq.org
Fri May 22 13:51:09 CDT 2020


Module: wine
Branch: master
Commit: ff9b2936edfc81e7a4909ee24cdccefcf3a8a69a
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=ff9b2936edfc81e7a4909ee24cdccefcf3a8a69a

Author: Ziqing Hui <zhui at codeweavers.com>
Date:   Fri May 22 11:17:31 2020 +0800

windowscodecs/tests: Add tests for DdsDecoder_GetFrame() and DdsFrameDecode_GetSize().

Signed-off-by: Ziqing Hui <zhui at codeweavers.com>
Signed-off-by: Vincent Povirk <vincent at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/windowscodecs/tests/ddsformat.c | 123 ++++++++++++++++++++++++++---------
 1 file changed, 94 insertions(+), 29 deletions(-)

diff --git a/dlls/windowscodecs/tests/ddsformat.c b/dlls/windowscodecs/tests/ddsformat.c
index bc22cc5072..e31ca576fc 100644
--- a/dlls/windowscodecs/tests/ddsformat.c
+++ b/dlls/windowscodecs/tests/ddsformat.c
@@ -120,6 +120,21 @@ static BYTE test_dds_array[] = {
     0xCC, 0x55, 0xCC, 0x55, 0x0E, 0x84, 0x0E, 0x84, 0x00, 0x00, 0x00, 0x00
 };
 
+static struct test_data {
+    void *data;
+    UINT size;
+    UINT expected_frame_count;
+    WICDdsParameters expected_parameters;
+} test_data[] = {
+    { test_dds_image,   sizeof(test_dds_image),   1,
+      { 4, 4, 1, 1, 1, DXGI_FORMAT_BC1_UNORM, WICDdsTexture2D, WICDdsAlphaModePremultiplied } },
+    { test_dds_mipmaps, sizeof(test_dds_mipmaps), 3,
+      { 4, 4, 1, 3, 1, DXGI_FORMAT_BC1_UNORM, WICDdsTexture2D, WICDdsAlphaModePremultiplied } },
+    { test_dds_volume,  sizeof(test_dds_volume),  7,
+      { 4, 4, 4, 3, 1, DXGI_FORMAT_BC1_UNORM, WICDdsTexture3D, WICDdsAlphaModePremultiplied } },
+    { test_dds_array,   sizeof(test_dds_array),   9,
+      { 4, 4, 1, 3, 3, DXGI_FORMAT_BC1_UNORM, WICDdsTexture2D, WICDdsAlphaModeUnknown } },
+};
 
 static IWICImagingFactory *factory = NULL;
 
@@ -278,22 +293,6 @@ static void test_dds_decoder_global_properties(IWICBitmapDecoder *decoder)
 
 static void test_dds_decoder_image_parameters(void)
 {
-    static struct test_data {
-        void *data;
-        UINT size;
-        UINT expected_frame_count;
-        WICDdsParameters expected_parameters;
-    } test_data[] = {
-        { test_dds_image,   sizeof(test_dds_image),   1,
-          { 4, 4, 1, 1, 1, DXGI_FORMAT_BC1_UNORM, WICDdsTexture2D, WICDdsAlphaModePremultiplied } },
-        { test_dds_mipmaps, sizeof(test_dds_mipmaps), 3,
-          { 4, 4, 1, 3, 1, DXGI_FORMAT_BC1_UNORM, WICDdsTexture2D, WICDdsAlphaModePremultiplied } },
-        { test_dds_volume,  sizeof(test_dds_volume),  7,
-          { 4, 4, 4, 3, 1, DXGI_FORMAT_BC1_UNORM, WICDdsTexture3D, WICDdsAlphaModePremultiplied } },
-        { test_dds_array,   sizeof(test_dds_array),   9,
-          { 4, 4, 1, 3, 3, DXGI_FORMAT_BC1_UNORM, WICDdsTexture2D, WICDdsAlphaModeUnknown } },
-    };
-
     int i;
     HRESULT hr;
     WICDdsParameters parameters;
@@ -368,28 +367,94 @@ static void test_dds_decoder_image_parameters(void)
     }
 }
 
-static void test_dds_decoder(void)
+static void test_dds_decoder_frame_size(IWICBitmapDecoder *decoder, IWICBitmapFrameDecode *frame_decode,
+                                        UINT frame_count, int i, int frame_index)
 {
     HRESULT hr;
-    IWICStream *stream = NULL;
-    IWICBitmapDecoder *decoder = NULL;
-
-    stream = create_stream(test_dds_image, sizeof(test_dds_image));
-    if (!stream) goto end;
+    WICDdsParameters params;
+    IWICDdsDecoder *dds_decoder;
+    UINT width, height ,expected_width, expected_height, slice_index, depth;
 
-    decoder = create_decoder();
-    if (!decoder) goto end;
+    hr = IWICBitmapDecoder_QueryInterface(decoder, &IID_IWICDdsDecoder, (void **)&dds_decoder);
+    ok(hr == S_OK, "%d: QueryInterface failed, hr=%x\n", i, hr);
+    if (hr != S_OK) goto end;
+    hr = IWICDdsDecoder_GetParameters(dds_decoder, &params);
+    ok (hr == S_OK, "%d: GetParameters failed, hr=%x\n", i, hr);
+    if (hr != S_OK) goto end;
 
-    hr = init_decoder(decoder, stream, S_OK, -1);
+    hr = IWICBitmapFrameDecode_GetSize(frame_decode, &width, &height);
+    todo_wine ok (hr == S_OK, "%d: GetSize failed for frame %d, hr=%x\n", i, frame_index, hr);
     if (hr != S_OK) goto end;
 
+    depth = params.Depth;
+    expected_width = params.Width;
+    expected_height = params.Height;
+    slice_index = frame_index % (frame_count / params.ArraySize);
+    while (slice_index >= depth)
+    {
+        if (expected_width > 1) expected_width /= 2;
+        if (expected_height > 1) expected_height /= 2;
+        slice_index -= depth;
+        if (depth > 1) depth /= 2;
+    }
+    ok (width == expected_width, "%d: Expected width %d for frame %d, got %d\n", i, expected_width, frame_index, width);
+    ok (height == expected_height, "%d: Expected height %d for frame %d, got %d\n", i, expected_height, frame_index, height);
+
+end:
+    if (dds_decoder) IWICDdsDecoder_Release(dds_decoder);
+}
+
+static void test_dds_decoder_frame(IWICBitmapDecoder *decoder, int i)
+{
+    HRESULT hr;
+    UINT frame_count, j;
+
+    hr = IWICBitmapDecoder_GetFrameCount(decoder, &frame_count);
+    ok (hr == S_OK, "%d: GetFrameCount failed, hr=%x\n", i, hr);
+    if (hr != S_OK) return;
+
+    for (j = 0; j < frame_count; j++)
+    {
+        IWICBitmapFrameDecode *frame_decode = NULL;
+
+        hr = IWICBitmapDecoder_GetFrame(decoder, j, &frame_decode);
+        ok (hr == S_OK, "%d: GetFrame failed for frame %d, hr=%x\n", i, j, hr);
+        if (hr != S_OK) {
+            IWICBitmapFrameDecode_Release(frame_decode);
+            continue;
+        }
+
+        test_dds_decoder_frame_size(decoder, frame_decode, frame_count, i, j);
+    }
+}
+
+static void test_dds_decoder(void)
+{
+    int i;
+    HRESULT hr;
+
     test_dds_decoder_initialize();
-    test_dds_decoder_global_properties(decoder);
     test_dds_decoder_image_parameters();
 
-end:
-    if (decoder) IWICBitmapDecoder_Release(decoder);
-    if (stream) IWICStream_Release(stream);
+    for (i = 0; i < ARRAY_SIZE(test_data); i++)
+    {
+        IWICStream *stream = NULL;
+        IWICBitmapDecoder *decoder = NULL;
+
+        stream = create_stream(test_data[i].data, test_data[i].size);
+        if (!stream) goto next;
+        decoder = create_decoder();
+        if (!decoder) goto next;
+        hr = init_decoder(decoder, stream, S_OK, -1);
+        if (hr != S_OK) goto next;
+
+        test_dds_decoder_global_properties(decoder);
+        test_dds_decoder_frame(decoder, i);
+
+    next:
+        if (decoder) IWICBitmapDecoder_Release(decoder);
+        if (stream) IWICStream_Release(stream);
+    }
 }
 
 START_TEST(ddsformat)




More information about the wine-cvs mailing list