1 /*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include <gtest/gtest.h>
18 #include <effects/StretchEffect.h>
19 #include "tests/common/TestUtils.h"
20 #include "Properties.h"
21
22 using namespace android;
23 using namespace android::uirenderer;
24
TEST(StretchEffect,noStretchDirectionDoesNotRequireLayer)25 TEST(StretchEffect, noStretchDirectionDoesNotRequireLayer) {
26 Properties::setStretchEffectBehavior(StretchEffectBehavior::ShaderHWUI);
27 auto stretchEffect = StretchEffect({.fX = 0.f, .fY = 0.f}, 100.f, 100.f);
28 ASSERT_FALSE(stretchEffect.requiresLayer());
29
30 Properties::setStretchEffectBehavior(StretchEffectBehavior::UniformScale);
31 ASSERT_FALSE(stretchEffect.requiresLayer());
32 }
33
TEST(StretchEffect,horizontalStretchRequiresLayer)34 TEST(StretchEffect, horizontalStretchRequiresLayer) {
35 Properties::setStretchEffectBehavior(StretchEffectBehavior::ShaderHWUI);
36 auto stretchEffect = StretchEffect({.fX = 1.f, .fY = 0.f}, 100.f, 100.f);
37 ASSERT_TRUE(stretchEffect.requiresLayer());
38
39 Properties::setStretchEffectBehavior(StretchEffectBehavior::UniformScale);
40 ASSERT_TRUE(stretchEffect.requiresLayer());
41 }
42
TEST(StretchEffect,verticalStretchRequiresLayer)43 TEST(StretchEffect, verticalStretchRequiresLayer) {
44 Properties::setStretchEffectBehavior(StretchEffectBehavior::ShaderHWUI);
45
46 auto stretchEffect = StretchEffect({.fX = 0.f, .fY = 1.f}, 100.f, 100.f);
47 ASSERT_TRUE(stretchEffect.requiresLayer());
48
49 Properties::setStretchEffectBehavior(StretchEffectBehavior::UniformScale);
50 ASSERT_TRUE(stretchEffect.requiresLayer());
51 }
52
TEST(StretchEffect,bidirectionalStretchRequiresLayer)53 TEST(StretchEffect, bidirectionalStretchRequiresLayer) {
54 Properties::setStretchEffectBehavior(StretchEffectBehavior::ShaderHWUI);
55
56 auto stretchEffect = StretchEffect({.fX = 1.f, .fY = 1.f}, 100.f, 100.f);
57 ASSERT_TRUE(stretchEffect.requiresLayer());
58
59 Properties::setStretchEffectBehavior(StretchEffectBehavior::UniformScale);
60 ASSERT_TRUE(stretchEffect.requiresLayer());
61 }