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 <windows.h> 6 7 #include "base/debug/gdi_debug_util_win.h" 8 #include "base/win/scoped_hdc.h" 9 #include "testing/gtest/include/gtest/gtest.h" 10 11 // GDI handles can occasionally come out of nowhere on the shared table, so 12 // when writing the tests below, make sure you do differential snapshots to 13 // count handles. 14 TEST(GdiDebugUtilWin,GdiHandleCountsCreateDC)15TEST(GdiDebugUtilWin, GdiHandleCountsCreateDC) { 16 base::debug::GdiHandleCounts handle_counts_start = 17 base::debug::GetGDIHandleCountsInCurrentProcessForTesting(); 18 base::win::ScopedGetDC dc(nullptr); 19 ASSERT_TRUE(static_cast<HDC>(dc)); 20 base::debug::GdiHandleCounts handle_counts_now = 21 base::debug::GetGDIHandleCountsInCurrentProcessForTesting(); 22 EXPECT_EQ(1, handle_counts_now.dcs - handle_counts_start.dcs); 23 EXPECT_EQ( 24 1, handle_counts_now.total_tracked - handle_counts_start.total_tracked); 25 } 26 27 // TODO(robliao): Create tests for other types once we figure out how often GDI 28 // updates the handle table. 29