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 | |
5 #import <Foundation/Foundation.h> | |
6 | |
7 #include "base/basictypes.h" | |
8 #include "testing/platform_test.h" | |
9 #import "ui/ios/uikit_util.h" | |
10 | |
11 namespace { | |
12 | |
13 typedef PlatformTest UIKitUtilTest; | |
14 | |
15 TEST_F(UIKitUtilTest, AlignValueToUpperPixel) { | |
16 CGFloat scale = [[UIScreen mainScreen] scale]; | |
17 // Pick a few interesting values: already aligned, aligned on retina, and | |
18 // some unaligned values that would round differently. Ensure that all are | |
19 // "integer" values within <1 of the original value in the scaled space. | |
20 CGFloat test_values[] = { 10.0, 55.5, 3.1, 2.9 }; | |
21 const CGFloat kMaxAlignDelta = 0.9999; | |
22 size_t value_count = arraysize(test_values); | |
23 for (unsigned int i = 0; i < value_count; ++i) { | |
24 CGFloat aligned = ui::AlignValueToUpperPixel(test_values[i]); | |
25 EXPECT_FLOAT_EQ(aligned * scale, floor(aligned * scale)); | |
26 EXPECT_NEAR(aligned * scale, test_values[i] * scale, kMaxAlignDelta); | |
27 } | |
28 } | |
29 | |
30 TEST_F(UIKitUtilTest, AlignSizeToUpperPixel) { | |
31 CGFloat scale = [[UIScreen mainScreen] scale]; | |
32 // Pick a few interesting values: already aligned, aligned on retina, and | |
33 // some unaligned values that would round differently. Ensure that all are | |
34 // "integer" values within <1 of the original value in the scaled space. | |
35 CGFloat test_values[] = { 10.0, 55.5, 3.1, 2.9 }; | |
36 const CGFloat kMaxAlignDelta = 0.9999; | |
37 size_t value_count = arraysize(test_values); | |
38 for (unsigned int i = 0; i < value_count; ++i) { | |
39 CGFloat width = test_values[i]; | |
40 CGFloat height = test_values[(i + 1) % value_count]; | |
41 CGSize alignedSize = ui::AlignSizeToUpperPixel(CGSizeMake(width, height)); | |
42 EXPECT_FLOAT_EQ(floor(alignedSize.width * scale), | |
43 alignedSize.width * scale); | |
44 EXPECT_FLOAT_EQ(floor(alignedSize.height * scale), | |
45 alignedSize.height * scale); | |
46 EXPECT_NEAR(width * scale, alignedSize.width * scale, kMaxAlignDelta); | |
47 EXPECT_NEAR(height * scale, alignedSize.height * scale, kMaxAlignDelta); | |
48 } | |
49 } | |
50 | |
51 } // namespace | |
OLD | NEW |