gdi_debug_util_win_unittest.cc 1.1 KB

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