Index: ui/gfx/platform_font_win_unittest.cc |
=================================================================== |
--- ui/gfx/platform_font_win_unittest.cc (revision 0) |
+++ ui/gfx/platform_font_win_unittest.cc (revision 0) |
@@ -0,0 +1,82 @@ |
+// Copyright (c) 2012 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/platform_font_win.h" |
+ |
+#include "base/logging.h" |
+#include "base/memory/ref_counted.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+#include "ui/gfx/font.h" |
+ |
+namespace gfx { |
+ |
+TEST(PlatformFontWinTest, DeriveFontWithHeight_SameHeight) { |
msw
2012/04/26 21:04:42
optional: It'd be awesome if we could combine thes
Alexei Svitkine (slow)
2012/04/26 21:45:56
Done.
|
+ const Font font; |
+ PlatformFontWin* platform_font = |
+ static_cast<PlatformFontWin*>(font.platform_font()); |
+ |
+ Font derived_font = |
+ platform_font->DeriveFontWithHeight(font.GetHeight(), font.GetStyle()); |
+ EXPECT_EQ(font.GetHeight(), derived_font.GetHeight()); |
+ EXPECT_EQ(font.GetStyle(), derived_font.GetStyle()); |
+ |
+ derived_font = platform_font->DeriveFontWithHeight(font.GetHeight(), |
+ Font::BOLD); |
+ EXPECT_EQ(font.GetHeight(), derived_font.GetHeight()); |
+ EXPECT_EQ(Font::BOLD, derived_font.GetStyle()); |
+} |
+ |
+TEST(PlatformFontWinTest, DeriveFontWithHeight_Smaller) { |
+ const Font base_font; |
+ |
+ for (int i = 1; i < 10; i++) { |
+ const int target_height = base_font.GetHeight() - i; |
+ |
+ Font expected_font = base_font; |
+ do { |
+ expected_font = expected_font.DeriveFont(-1, 0); |
msw
2012/04/26 21:04:42
This is slightly un-intuitive... can you explain i
Alexei Svitkine (slow)
2012/04/26 21:45:56
Added comments.
|
+ } while (expected_font.GetHeight() > target_height); |
msw
2012/04/26 21:04:42
Should we [EXPECT|ASSERT]_LE(expected_font.GetHeig
Alexei Svitkine (slow)
2012/04/26 21:45:56
Done.
|
+ |
+ PlatformFontWin* platform_font = |
+ static_cast<PlatformFontWin*>(base_font.platform_font()); |
+ |
+ Font derived_font = platform_font->DeriveFontWithHeight(target_height, 0); |
+ EXPECT_EQ(expected_font.GetFontSize(), derived_font.GetFontSize()); |
msw
2012/04/26 21:04:42
Also EXPECT_LE(expected_font.GetHeight(), target_h
Alexei Svitkine (slow)
2012/04/26 21:45:56
Done.
|
+ EXPECT_EQ(0, derived_font.GetStyle()); |
+ |
+ derived_font = platform_font->DeriveFontWithHeight(target_height, |
+ Font::BOLD); |
+ EXPECT_EQ(expected_font.GetFontSize(), derived_font.GetFontSize()); |
msw
2012/04/26 21:04:42
Also EXPECT_LE(expected_font.GetHeight(), target_h
Alexei Svitkine (slow)
2012/04/26 21:45:56
Done.
|
+ EXPECT_EQ(Font::BOLD, derived_font.GetStyle()); |
+ } |
+} |
+ |
+TEST(PlatformFontWinTest, DeriveFontWithHeight_Larger) { |
+ const Font base_font; |
+ |
+ for (int i = 1; i < 10; i++) { |
+ const int target_height = base_font.GetHeight() + i; |
+ |
+ Font expected_font = base_font; |
+ Font larger_font = base_font.DeriveFont(1, 0); |
+ while (larger_font.GetHeight() <= target_height) { |
+ expected_font = larger_font; |
+ larger_font = larger_font.DeriveFont(1, 0); |
+ } |
msw
2012/04/26 21:04:42
Should we [EXPECT|ASSERT]_LE(expected_font.GetHeig
Alexei Svitkine (slow)
2012/04/26 21:45:56
Done.
|
+ |
+ PlatformFontWin* platform_font = |
+ static_cast<PlatformFontWin*>(base_font.platform_font()); |
+ |
+ Font derived_font = platform_font->DeriveFontWithHeight(target_height, 0); |
+ EXPECT_EQ(expected_font.GetFontSize(), derived_font.GetFontSize()); |
msw
2012/04/26 21:04:42
Also EXPECT_LE(expected_font.GetHeight(), target_h
Alexei Svitkine (slow)
2012/04/26 21:45:56
Done.
|
+ EXPECT_EQ(0, derived_font.GetStyle()); |
+ |
+ derived_font = platform_font->DeriveFontWithHeight(target_height, |
+ Font::BOLD); |
+ EXPECT_EQ(expected_font.GetFontSize(), derived_font.GetFontSize()); |
msw
2012/04/26 21:04:42
Also EXPECT_LE(expected_font.GetHeight(), target_h
Alexei Svitkine (slow)
2012/04/26 21:45:56
Done.
|
+ EXPECT_EQ(Font::BOLD, derived_font.GetStyle()); |
+ } |
+} |
+ |
+} // namespace gfx |