OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 #import "ui/gfx/ios/NSString+CrStringDrawing.h" | 4 #import "ui/gfx/ios/NSString+CrStringDrawing.h" |
5 | 5 |
6 #include "base/mac/scoped_nsobject.h" | 6 #include "base/mac/scoped_nsobject.h" |
7 #include "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
8 #include "base/strings/sys_string_conversions.h" | 8 #include "base/strings/sys_string_conversions.h" |
| 9 #include "testing/gtest_mac.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
10 #include "testing/platform_test.h" | 11 #include "testing/platform_test.h" |
11 | 12 |
12 namespace { | 13 namespace { |
13 | 14 |
14 typedef PlatformTest NSStringCrStringDrawing; | 15 typedef PlatformTest NSStringCrStringDrawing; |
15 | 16 |
16 // These tests verify that the category methods return the same values as the | 17 // These tests verify that the category methods return the same values as the |
17 // deprecated methods, so ignore warnings about using deprecated methods. | 18 // deprecated methods, so ignore warnings about using deprecated methods. |
18 #pragma clang diagnostic push | 19 #pragma clang diagnostic push |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 | 142 |
142 // Verify that the pixel-aligned value is pixel-aligned. | 143 // Verify that the pixel-aligned value is pixel-aligned. |
143 EXPECT_FLOAT_EQ(roundf(size_with_pixel_aligned.width * scale), | 144 EXPECT_FLOAT_EQ(roundf(size_with_pixel_aligned.width * scale), |
144 size_with_pixel_aligned.width * scale) << test_tag; | 145 size_with_pixel_aligned.width * scale) << test_tag; |
145 EXPECT_FLOAT_EQ(roundf(size_with_pixel_aligned.height * scale), | 146 EXPECT_FLOAT_EQ(roundf(size_with_pixel_aligned.height * scale), |
146 size_with_pixel_aligned.height * scale) << test_tag; | 147 size_with_pixel_aligned.height * scale) << test_tag; |
147 } | 148 } |
148 } | 149 } |
149 } | 150 } |
150 | 151 |
| 152 TEST_F(NSStringCrStringDrawing, CutString) { |
| 153 EXPECT_NSEQ(@"foo", [@"foo" cr_stringByCuttingToIndex:4]); |
| 154 EXPECT_NSEQ(@"bar", [@"bar" cr_stringByCuttingToIndex:3]); |
| 155 EXPECT_NSEQ(@"f…", [@"foo" cr_stringByCuttingToIndex:2]); |
| 156 EXPECT_NSEQ(@"…", [@"bar" cr_stringByCuttingToIndex:1]); |
| 157 EXPECT_NSEQ(@"", [@"foo" cr_stringByCuttingToIndex:0]); |
| 158 } |
| 159 |
| 160 TEST_F(NSStringCrStringDrawing, ElideStringToFitInRect) { |
| 161 NSString* result = |
| 162 [@"lorem ipsum dolores" cr_stringByElidingToFitSize:CGSizeZero]; |
| 163 EXPECT_NSEQ(@"", result); |
| 164 result = [@"lorem ipsum dolores" |
| 165 cr_stringByElidingToFitSize:CGSizeMake(1000, 1000)]; |
| 166 EXPECT_NSEQ(@"lorem ipsum dolores", result); |
| 167 result = |
| 168 [@"lorem ipsum dolores" cr_stringByElidingToFitSize:CGSizeMake(30, 50)]; |
| 169 EXPECT_TRUE([@"lorem ipsum dolores" length] > [result length]); |
| 170 } |
| 171 |
151 } // namespace | 172 } // namespace |
OLD | NEW |