xref: /aosp_15_r20/external/cronet/base/debug/gdi_debug_util_win_unittest.cc (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2019 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "base/debug/gdi_debug_util_win.h"
6 
7 #include <windows.h>
8 
9 #include "base/win/scoped_hdc.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11 
12 // GDI handles can occasionally come out of nowhere on the shared table, so
13 // when writing the tests below, make sure you do differential snapshots to
14 // count handles.
15 
TEST(GdiDebugUtilWin,GdiHandleCountsCreateDC)16 TEST(GdiDebugUtilWin, GdiHandleCountsCreateDC) {
17   base::debug::GdiHandleCounts handle_counts_start =
18       base::debug::GetGDIHandleCountsInCurrentProcessForTesting();
19   base::win::ScopedGetDC dc(nullptr);
20   ASSERT_TRUE(static_cast<HDC>(dc));
21   base::debug::GdiHandleCounts handle_counts_now =
22       base::debug::GetGDIHandleCountsInCurrentProcessForTesting();
23   EXPECT_EQ(1, handle_counts_now.dcs - handle_counts_start.dcs);
24   EXPECT_EQ(
25       1, handle_counts_now.total_tracked - handle_counts_start.total_tracked);
26 }
27 
28 // TODO(robliao): Create tests for other types once we figure out how often GDI
29 // updates the handle table.
30