Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 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 #import "ui/ios/NSString+CrStringDrawing.h" | |
| 5 | |
| 6 #include "base/mac/scoped_nsobject.h" | |
| 7 #include "base/strings/sys_string_conversions.h" | |
| 8 #include "testing/gtest/include/gtest/gtest.h" | |
| 9 #include "testing/platform_test.h" | |
| 10 | |
| 11 namespace { | |
| 12 | |
| 13 typedef PlatformTest NSStringCrStringDrawing; | |
| 14 | |
| 15 // These tests verify that the category methods return the same values as the | |
| 16 // deprecated methods, so ignore warnings about using deprecated methods. | |
| 17 #pragma clang diagnostic push | |
| 18 #pragma clang diagnostic ignored "-Wdeprecated-declarations" | |
| 19 | |
| 20 TEST_F(NSStringCrStringDrawing, SizeWithFont) { | |
| 21 NSArray* fonts = @[ | |
| 22 [NSNull null], | |
| 23 [UIFont systemFontOfSize:16], | |
| 24 [UIFont boldSystemFontOfSize:10], | |
| 25 [UIFont fontWithName:@"Helvetica" size:12.0], | |
| 26 ]; | |
| 27 for (UIFont* font in fonts) { | |
| 28 if ([font isEqual:[NSNull null]]) | |
| 29 font = nil; | |
| 30 std::string fontTag = "with font "; | |
| 31 fontTag.append(base::SysNSStringToUTF8(font ? [font description] : @"nil")); | |
| 32 EXPECT_EQ([@"" sizeWithFont:font].width, | |
| 33 [@"" cr_sizeWithFont:font].width) << fontTag; | |
| 34 EXPECT_EQ([@"" sizeWithFont:font].height, | |
| 35 [@"" cr_sizeWithFont:font].height) << fontTag; | |
| 36 EXPECT_EQ([@"Test" sizeWithFont:font].width, | |
| 37 [@"Test" cr_sizeWithFont:font].width) << fontTag; | |
| 38 EXPECT_EQ([@"Test" sizeWithFont:font].height, | |
| 39 [@"Test" cr_sizeWithFont:font].height) << fontTag; | |
| 40 EXPECT_EQ([@"你好" sizeWithFont:font].width, | |
| 41 [@"你好" cr_sizeWithFont:font].width) << fontTag; | |
| 42 EXPECT_EQ([@"你好" sizeWithFont:font].height, | |
| 43 [@"你好" cr_sizeWithFont:font].height) << fontTag; | |
| 44 NSString* longString = @"★ This is a test string that is very long."; | |
| 45 EXPECT_EQ([longString sizeWithFont:font].width, | |
| 46 [longString cr_sizeWithFont:font].width) << fontTag; | |
| 47 EXPECT_EQ([longString sizeWithFont:font].height, | |
| 48 [longString cr_sizeWithFont:font].height) << fontTag; | |
| 49 } | |
| 50 } | |
| 51 | |
|
stuartmorgan
2014/08/29 14:48:31
We should have unit test coverage of the other new
lliabraa
2014/09/02 13:29:15
Done.
| |
| 52 #pragma clang diagnostic pop // ignored "-Wdeprecated-declarations" | |
| 53 | |
| 54 } // namespace | |
| OLD | NEW |