OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2017 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 #include "ui/base/test/ios/ui_image_test_utils.h" | |
6 | |
7 #include "base/mac/scoped_cftyperef.h" | |
8 | |
9 namespace ui { | |
10 namespace test { | |
11 namespace uiimage_utils { | |
12 | |
13 UIImage* UIImageWithSizeAndSolidColor(CGSize const& size, UIColor* color) { | |
14 UIGraphicsBeginImageContext(size); | |
15 CGContextRef context = UIGraphicsGetCurrentContext(); | |
16 CGContextSetFillColorWithColor(context, [color CGColor]); | |
17 CGContextFillRect(context, CGRectMake(0, 0, size.width, size.height)); | |
18 UIImage* image_with_solid_color = UIGraphicsGetImageFromCurrentImageContext(); | |
19 UIGraphicsEndImageContext(); | |
20 return image_with_solid_color; | |
21 } | |
22 | |
23 bool UIImagesAreEqual(UIImage* image_1, UIImage* image_2) { | |
24 if (image_1 == image_2) | |
25 return true; | |
26 | |
27 if (!CGSizeEqualToSize(image_1.size, image_2.size)) | |
28 return false; | |
29 | |
30 bool images_are_equal = false; | |
31 | |
32 base::ScopedCFTypeRef<CFDataRef> data_ref_1( | |
33 CGDataProviderCopyData(CGImageGetDataProvider(image_1.CGImage))); | |
34 base::ScopedCFTypeRef<CFDataRef> data_ref_2( | |
35 CGDataProviderCopyData(CGImageGetDataProvider(image_2.CGImage))); | |
36 CFIndex length_1 = CFDataGetLength(data_ref_1); | |
37 CFIndex length_2 = CFDataGetLength(data_ref_2); | |
38 if (length_1 == length_2) { | |
sdefresne
2017/01/30 16:56:20
Can you use early return here too?
if (length_1
jif
2017/02/03 10:54:49
Done.
| |
39 const UInt8* ptr_1 = CFDataGetBytePtr(data_ref_1); | |
40 const UInt8* ptr_2 = CFDataGetBytePtr(data_ref_2); | |
41 | |
42 // memcmp returns 0 if length is 0. | |
43 if (memcmp(ptr_1, ptr_2, length_1) == 0) | |
44 images_are_equal = true; | |
45 } | |
46 | |
47 return images_are_equal; | |
48 } | |
49 | |
50 } // namespace uiimage_utils | |
51 } // namespace test | |
52 } // namespace ui | |
OLD | NEW |