summaryrefslogtreecommitdiffstats
path: root/ui/gfx/font_unittest.cc
diff options
context:
space:
mode:
authorrsesek@chromium.org <rsesek@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-17 14:55:26 +0000
committerrsesek@chromium.org <rsesek@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-17 14:55:26 +0000
commit23fc1150567369788690026aae329ebbd0a17990 (patch)
treea46076ccc4ae01007ea7e7262c120fe6aa192d1c /ui/gfx/font_unittest.cc
parentb6b451a32b7753b453e30da75e8e63aadd5abc34 (diff)
downloadchromium_src-23fc1150567369788690026aae329ebbd0a17990.zip
chromium_src-23fc1150567369788690026aae329ebbd0a17990.tar.gz
chromium_src-23fc1150567369788690026aae329ebbd0a17990.tar.bz2
Fix leaks found on Linux in ui/gfx/font_unittest.cc.
Also update the comment in font.h that incorrectly described the Mac memory management for native font handles. BUG=73148 TEST=Linux Valgrind Review URL: http://codereview.chromium.org/6524042 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@75266 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/gfx/font_unittest.cc')
-rw-r--r--ui/gfx/font_unittest.cc30
1 files changed, 23 insertions, 7 deletions
diff --git a/ui/gfx/font_unittest.cc b/ui/gfx/font_unittest.cc
index d5854c0..7ea01db 100644
--- a/ui/gfx/font_unittest.cc
+++ b/ui/gfx/font_unittest.cc
@@ -1,20 +1,31 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/gfx/font.h"
#include "base/utf_string_conversions.h"
-#if defined(OS_WIN)
-#include "ui/gfx/platform_font_win.h"
-#endif // defined(OS_WIN)
#include "testing/gtest/include/gtest/gtest.h"
+#if defined(OS_LINUX)
+#include <pango/pango.h>
+#elif defined(OS_WIN)
+#include "ui/gfx/platform_font_win.h"
+#endif
+
namespace {
using gfx::Font;
class FontTest : public testing::Test {
+ public:
+ // Fulfills the memory management contract as outlined by the comment at
+ // gfx::Font::GetNativeFont().
+ void FreeIfNecessary(gfx::NativeFont font) {
+#if defined(OS_LINUX)
+ pango_font_description_free(font);
+#endif
+ }
};
#if defined(OS_WIN)
@@ -47,17 +58,21 @@ int ScopedMinimumFontSizeCallback::minimum_size_ = 0;
TEST_F(FontTest, LoadArial) {
Font cf(ASCIIToUTF16("Arial"), 16);
- ASSERT_TRUE(cf.GetNativeFont());
+ gfx::NativeFont native = cf.GetNativeFont();
+ ASSERT_TRUE(native);
ASSERT_EQ(cf.GetStyle(), Font::NORMAL);
ASSERT_EQ(cf.GetFontSize(), 16);
ASSERT_EQ(cf.GetFontName(), ASCIIToUTF16("Arial"));
+ FreeIfNecessary(native);
}
TEST_F(FontTest, LoadArialBold) {
Font cf(ASCIIToUTF16("Arial"), 16);
Font bold(cf.DeriveFont(0, Font::BOLD));
- ASSERT_TRUE(bold.GetNativeFont());
+ gfx::NativeFont native = bold.GetNativeFont();
+ ASSERT_TRUE(native);
ASSERT_EQ(bold.GetStyle(), Font::BOLD);
+ FreeIfNecessary(native);
}
TEST_F(FontTest, Ascent) {
@@ -116,5 +131,6 @@ TEST_F(FontTest, DeriveFontKeepsOriginalSizeIfHeightOk) {
GetObject(derived_font.GetNativeFont(), sizeof(LOGFONT), &font_info);
EXPECT_EQ(-6, font_info.lfHeight);
}
-#endif
+#endif // defined(OS_WIN)
+
} // namespace