Flutter Engine
The Flutter Engine
dl_mask_filter_unittests.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter 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 "flutter/display_list/effects/dl_mask_filter.h"
6#include "flutter/display_list/testing/dl_test_equality.h"
7#include "flutter/display_list/utils/dl_comparable.h"
8#include "gtest/gtest.h"
9
10namespace flutter {
11namespace testing {
12
13TEST(DisplayListMaskFilter, BlurConstructor) {
15}
16
17TEST(DisplayListMaskFilter, BlurShared) {
19 ASSERT_NE(filter.shared().get(), &filter);
20 ASSERT_EQ(*filter.shared(), filter);
21}
22
23TEST(DisplayListMaskFilter, BlurAsBlur) {
25 ASSERT_NE(filter.asBlur(), nullptr);
26 ASSERT_EQ(filter.asBlur(), &filter);
27}
28
29TEST(DisplayListMaskFilter, BlurContents) {
31 ASSERT_EQ(filter.style(), DlBlurStyle::kNormal);
32 ASSERT_EQ(filter.sigma(), 5.0);
33}
34
35TEST(DisplayListMaskFilter, BlurEquals) {
38 TestEquals(filter1, filter2);
39}
40
41TEST(DisplayListMaskFilter, BlurNotEquals) {
45 TestNotEquals(filter1, filter2, "Blur style differs");
46 TestNotEquals(filter1, filter3, "blur radius differs");
47}
48
50 // a and b have the same nullness or values
51 ASSERT_TRUE(Equals(a, b));
52 ASSERT_FALSE(NotEquals(a, b));
53 ASSERT_TRUE(Equals(b, a));
54 ASSERT_FALSE(NotEquals(b, a));
55}
56
58 // a and b do not have the same nullness or values
59 ASSERT_FALSE(Equals(a, b));
60 ASSERT_TRUE(NotEquals(a, b));
61 ASSERT_FALSE(Equals(b, a));
62 ASSERT_TRUE(NotEquals(b, a));
63}
64
65void testEquals(const std::shared_ptr<const DlMaskFilter>& a, DlMaskFilter* b) {
66 // a and b have the same nullness or values
67 ASSERT_TRUE(Equals(a, b));
68 ASSERT_FALSE(NotEquals(a, b));
69 ASSERT_TRUE(Equals(b, a));
70 ASSERT_FALSE(NotEquals(b, a));
71}
72
73void testNotEquals(const std::shared_ptr<const DlMaskFilter>& a,
74 DlMaskFilter* b) {
75 // a and b do not have the same nullness or values
76 ASSERT_FALSE(Equals(a, b));
77 ASSERT_TRUE(NotEquals(a, b));
78 ASSERT_FALSE(Equals(b, a));
79 ASSERT_TRUE(NotEquals(b, a));
80}
81
82void testEquals(const std::shared_ptr<const DlMaskFilter>& a,
83 const std::shared_ptr<const DlMaskFilter>& b) {
84 // a and b have the same nullness or values
85 ASSERT_TRUE(Equals(a, b));
86 ASSERT_FALSE(NotEquals(a, b));
87 ASSERT_TRUE(Equals(b, a));
88 ASSERT_FALSE(NotEquals(b, a));
89}
90
91void testNotEquals(const std::shared_ptr<const DlMaskFilter>& a,
92 const std::shared_ptr<const DlMaskFilter>& b) {
93 // a and b do not have the same nullness or values
94 ASSERT_FALSE(Equals(a, b));
95 ASSERT_TRUE(NotEquals(a, b));
96 ASSERT_FALSE(Equals(b, a));
97 ASSERT_TRUE(NotEquals(b, a));
98}
99
100TEST(DisplayListMaskFilter, ComparableTemplates) {
104 std::shared_ptr<DlMaskFilter> shared_null;
105
106 // null to null
107 testEquals(nullptr, nullptr);
108 testEquals(shared_null, nullptr);
109 testEquals(shared_null, shared_null);
110
111 // ptr to null
112 testNotEquals(&filter1a, nullptr);
113 testNotEquals(&filter1b, nullptr);
114 testNotEquals(&filter2, nullptr);
115
116 // shared_ptr to null and shared_null to ptr
117 testNotEquals(filter1a.shared(), nullptr);
118 testNotEquals(filter1b.shared(), nullptr);
119 testNotEquals(filter2.shared(), nullptr);
120 testNotEquals(shared_null, &filter1a);
121 testNotEquals(shared_null, &filter1b);
122 testNotEquals(shared_null, &filter2);
123
124 // ptr to ptr
125 testEquals(&filter1a, &filter1a);
126 testEquals(&filter1a, &filter1b);
127 testEquals(&filter1b, &filter1b);
128 testEquals(&filter2, &filter2);
129 testNotEquals(&filter1a, &filter2);
130
131 // shared_ptr to ptr
132 testEquals(filter1a.shared(), &filter1a);
133 testEquals(filter1a.shared(), &filter1b);
134 testEquals(filter1b.shared(), &filter1b);
135 testEquals(filter2.shared(), &filter2);
136 testNotEquals(filter1a.shared(), &filter2);
137 testNotEquals(filter1b.shared(), &filter2);
138 testNotEquals(filter2.shared(), &filter1a);
139 testNotEquals(filter2.shared(), &filter1b);
140
141 // shared_ptr to shared_ptr
142 testEquals(filter1a.shared(), filter1a.shared());
143 testEquals(filter1a.shared(), filter1b.shared());
144 testEquals(filter1b.shared(), filter1b.shared());
145 testEquals(filter2.shared(), filter2.shared());
146 testNotEquals(filter1a.shared(), filter2.shared());
147 testNotEquals(filter1b.shared(), filter2.shared());
148 testNotEquals(filter2.shared(), filter1a.shared());
149 testNotEquals(filter2.shared(), filter1b.shared());
150}
151
152} // namespace testing
153} // namespace flutter
const DlBlurMaskFilter * asBlur() const override
DlBlurStyle style() const
std::shared_ptr< DlMaskFilter > shared() const override
SkScalar sigma() const
static bool b
struct MyStruct a[10]
void testNotEquals(DlMaskFilter *a, DlMaskFilter *b)
void testEquals(DlMaskFilter *a, DlMaskFilter *b)
static void TestNotEquals(T &source1, T &source2, const std::string &label)
static void TestEquals(T &source1, T &source2)
TEST(DisplayListComplexity, EmptyDisplayList)
bool Equals(const T *a, const T *b)
Definition: dl_comparable.h:19
bool NotEquals(const T *a, const T *b)
Definition: dl_comparable.h:70
@ kNormal
fuzzy inside and outside
@ kInner
fuzzy inside, nothing outside