OSDN Git Service

Merge "docs: Add documentation for equals() method" into qt-dev
[android-x86/frameworks-base.git] / services / tests / mockingservicestests / src / com / android / server / display / color / DisplayTransformManagerTest.java
1 /*
2  * Copyright (C) 2019 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 package com.android.server.display.color;
18
19 import static com.android.dx.mockito.inline.extended.ExtendedMockito.anyString;
20 import static com.android.dx.mockito.inline.extended.ExtendedMockito.doAnswer;
21 import static com.android.server.display.color.DisplayTransformManager.LEVEL_COLOR_MATRIX_NIGHT_DISPLAY;
22 import static com.android.server.display.color.DisplayTransformManager.PERSISTENT_PROPERTY_DISPLAY_COLOR;
23 import static com.android.server.display.color.DisplayTransformManager.PERSISTENT_PROPERTY_SATURATION;
24
25 import static com.google.common.truth.Truth.assertThat;
26
27 import static org.mockito.ArgumentMatchers.any;
28
29 import android.hardware.display.ColorDisplayManager;
30 import android.os.SystemProperties;
31
32 import androidx.test.runner.AndroidJUnit4;
33
34 import com.android.dx.mockito.inline.extended.ExtendedMockito;
35
36 import org.junit.After;
37 import org.junit.Before;
38 import org.junit.Test;
39 import org.junit.runner.RunWith;
40 import org.mockito.MockitoSession;
41 import org.mockito.quality.Strictness;
42 import org.mockito.stubbing.Answer;
43
44 import java.util.HashMap;
45
46 @RunWith(AndroidJUnit4.class)
47 public class DisplayTransformManagerTest {
48
49     private MockitoSession mSession;
50     private DisplayTransformManager mDtm;
51     private float[] mNightDisplayMatrix;
52     private HashMap<String, String> mSystemProperties;
53
54     @Before
55     public void setUp() {
56         mDtm = new DisplayTransformManager();
57         mNightDisplayMatrix = mDtm.getColorMatrix(LEVEL_COLOR_MATRIX_NIGHT_DISPLAY);
58
59         mSession = ExtendedMockito.mockitoSession()
60                 .initMocks(this)
61                 .strictness(Strictness.LENIENT)
62                 .spyStatic(SystemProperties.class)
63                 .startMocking();
64         mSystemProperties = new HashMap<>();
65
66         doAnswer((Answer<Void>) invocationOnMock -> {
67                     mSystemProperties.put(invocationOnMock.getArgument(0),
68                             invocationOnMock.getArgument(1));
69                     return null;
70                 }
71         ).when(() -> SystemProperties.set(anyString(), any()));
72     }
73
74     @After
75     public void tearDown() throws Exception {
76         mSession.finishMocking();
77         mSystemProperties.clear();
78     }
79
80     @Test
81     public void setColorMode_natural() {
82         mDtm.setColorMode(ColorDisplayManager.COLOR_MODE_NATURAL, mNightDisplayMatrix);
83         assertThat(mSystemProperties.get(PERSISTENT_PROPERTY_DISPLAY_COLOR))
84                 .isEqualTo("0" /* managed */);
85         assertThat(mSystemProperties.get(PERSISTENT_PROPERTY_SATURATION))
86                 .isEqualTo("1.0" /* natural */);
87     }
88
89     @Test
90     public void setColorMode_boosted() {
91         mDtm.setColorMode(ColorDisplayManager.COLOR_MODE_BOOSTED, mNightDisplayMatrix);
92
93         assertThat(mSystemProperties.get(PERSISTENT_PROPERTY_DISPLAY_COLOR))
94                 .isEqualTo("0" /* managed */);
95         assertThat(mSystemProperties.get(PERSISTENT_PROPERTY_SATURATION))
96                 .isEqualTo("1.1" /* boosted */);
97     }
98
99     @Test
100     public void setColorMode_saturated() {
101         mDtm.setColorMode(ColorDisplayManager.COLOR_MODE_SATURATED, mNightDisplayMatrix);
102         assertThat(mSystemProperties.get(PERSISTENT_PROPERTY_DISPLAY_COLOR))
103                 .isEqualTo("1" /* unmanaged */);
104         assertThat(mSystemProperties.get(PERSISTENT_PROPERTY_SATURATION))
105                 .isEqualTo("1.0" /* natural */);
106     }
107
108     @Test
109     public void setColorMode_automatic() {
110         mDtm.setColorMode(ColorDisplayManager.COLOR_MODE_AUTOMATIC, mNightDisplayMatrix);
111         assertThat(mSystemProperties.get(PERSISTENT_PROPERTY_DISPLAY_COLOR))
112                 .isEqualTo("2" /* enhanced */);
113         assertThat(mSystemProperties.get(PERSISTENT_PROPERTY_SATURATION))
114                 .isEqualTo("1.0" /* natural */);
115     }
116
117     @Test
118     public void setColorMode_vendor() {
119         mDtm.setColorMode(0x100, mNightDisplayMatrix);
120         assertThat(mSystemProperties.get(PERSISTENT_PROPERTY_DISPLAY_COLOR))
121                 .isEqualTo(Integer.toString(0x100) /* pass-through */);
122         assertThat(mSystemProperties.get(PERSISTENT_PROPERTY_SATURATION))
123                 .isEqualTo("1.0" /* natural */);
124     }
125
126     @Test
127     public void setColorMode_outOfBounds() {
128         mDtm.setColorMode(0x50, mNightDisplayMatrix);
129         assertThat(mSystemProperties.get(PERSISTENT_PROPERTY_DISPLAY_COLOR))
130                 .isEqualTo(null);
131         assertThat(mSystemProperties.get(PERSISTENT_PROPERTY_SATURATION))
132                 .isEqualTo(null);
133     }
134 }