File: ui_image_test_utils_unittest.mm

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (53 lines) | stat: -rw-r--r-- 1,894 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#import "ui/base/test/ios/ui_image_test_utils.h"

#include "testing/gtest/include/gtest/gtest.h"

namespace ui::test {

// Test the creation of UIImages.
TEST(UIImageTestUtilsTest, TestImageCreation) {
  CGSize size = CGSizeMake(10, 10);
  UIImage* image =
      uiimage_utils::UIImageWithSizeAndSolidColor(size, [UIColor redColor]);
  EXPECT_TRUE(CGSizeEqualToSize(size, image.size));
}

// Test the detection of identical UIImages.
TEST(UIImageTestUtilsTest, TestImageEquality) {
  CGSize size10x10 = CGSizeMake(10, 10);
  CGSize size5x20 = CGSizeMake(5, 20);
  UIColor* green = [UIColor greenColor];
  UIColor* blue = [UIColor blueColor];

  UIImage* imageblue10x10 =
      uiimage_utils::UIImageWithSizeAndSolidColor(size10x10, blue);
  UIImage* imageblue5x20 =
      uiimage_utils::UIImageWithSizeAndSolidColor(size5x20, blue);
  UIImage* imageGreen10x10 =
      uiimage_utils::UIImageWithSizeAndSolidColor(size10x10, green);
  UIImage* imageGreen10x10Bis =
      uiimage_utils::UIImageWithSizeAndSolidColor(size10x10, green);

  // Test with |nil| parameters.
  EXPECT_TRUE(uiimage_utils::UIImagesAreEqual(nil, nil));
  EXPECT_FALSE(uiimage_utils::UIImagesAreEqual(nil, imageblue10x10));
  EXPECT_FALSE(uiimage_utils::UIImagesAreEqual(imageblue10x10, nil));

  // Test with images with different sizes (but same amount of pixels), same
  // color.
  EXPECT_FALSE(uiimage_utils::UIImagesAreEqual(imageblue10x10, imageblue5x20));

  // Test with images with same size, different color.
  EXPECT_FALSE(
      uiimage_utils::UIImagesAreEqual(imageblue10x10, imageGreen10x10));

  // Test with images with same size, same color.
  EXPECT_TRUE(
      uiimage_utils::UIImagesAreEqual(imageGreen10x10, imageGreen10x10Bis));
}

}  // namespace ui::test