From 2af6baad08dd028352116bb5ad775af7d2242288 Mon Sep 17 00:00:00 2001 From: Chun-wei Fan Date: Fri, 13 Dec 2024 11:09:03 +0800 Subject: [PATCH] tests: Add more tests for COM refcounts As suggested by Luca Bacci, so that we keep track of things more clearly in terms of COM. --- glib/tests/cxx.cpp | 10 ++++++---- glib/tests/win32.c | 10 ++++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/glib/tests/cxx.cpp b/glib/tests/cxx.cpp index b3a5d684f..4b4dd5800 100644 --- a/glib/tests/cxx.cpp +++ b/glib/tests/cxx.cpp @@ -548,12 +548,14 @@ test_clear_com (void) g_assert_null (o); g_assert_true (SUCCEEDED (CoCreateInstance (CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER, IID_IWICImagingFactory, (void **)&tmp))); g_assert_nonnull (tmp); - tmp->QueryInterface (IID_IWICImagingFactory, (void **)&o); /* IWICImagingFactory::QueryInterface increments the refcount */ + tmp->QueryInterface (IID_IWICImagingFactory, (void **)&o); /* IWICImagingFactory::QueryInterface increments tmp's refcount */ g_assert_nonnull (o); - g_assert_cmpint (o->AddRef (), ==, 3); /* refcount incremented again */ - g_win32_clear_com (&o); + g_assert_cmpint (tmp->AddRef (), ==, 3); /* tmp's refcount incremented again */ + g_win32_clear_com (&o); /* tmp's refcount gets decremented */ g_assert_null (o); - tmp->Release (); + g_assert_cmpint (tmp->Release (), ==, 1); /* tmp's refcount gets decremented, again */ + g_win32_clear_com (&tmp); + g_assert_null (tmp); CoUninitialize (); } diff --git a/glib/tests/win32.c b/glib/tests/win32.c index cea548707..5e10f0338 100644 --- a/glib/tests/win32.c +++ b/glib/tests/win32.c @@ -168,12 +168,14 @@ test_clear_com (void) g_assert_null (o); g_assert_true (SUCCEEDED (CoCreateInstance (&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER, &IID_IWICImagingFactory, (void **)&tmp))); g_assert_nonnull (tmp); - IWICImagingFactory_QueryInterface (tmp, &IID_IWICImagingFactory, (void **)&o); /* IWICImagingFactory_QueryInterface increments the refcount */ + IWICImagingFactory_QueryInterface (tmp, &IID_IWICImagingFactory, (void **)&o); /* IWICImagingFactory_QueryInterface increments tmp's refcount */ g_assert_nonnull (o); - g_assert_cmpint (IWICImagingFactory_AddRef (o), ==, 3); /* refcount incremented again */ - g_win32_clear_com (&o); + g_assert_cmpint (IWICImagingFactory_AddRef (tmp), ==, 3); /* tmp's refcount incremented, again */ + g_win32_clear_com (&o); /* tmp's refcount decrements */ g_assert_null (o); - IWICImagingFactory_Release (tmp); + g_assert_cmpint (IWICImagingFactory_Release (tmp), ==, 1); /* tmp's refcount decrements, again */ + g_win32_clear_com (&tmp); + g_assert_null (tmp); CoUninitialize (); }