1 /*
2  * Copyright (C) 2021 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.systemui.qs
18 
19 import androidx.test.filters.SmallTest
20 import com.android.systemui.SysuiTestCase
21 import com.android.systemui.dump.DumpManager
22 import com.android.systemui.log.LogBufferFactory
23 import com.android.systemui.log.LogcatEchoTracker
24 import com.android.systemui.statusbar.disableflags.DisableFlagsLogger
25 import com.google.common.truth.Truth.assertThat
26 import java.io.PrintWriter
27 import java.io.StringWriter
28 import org.junit.Test
29 import org.mockito.Mockito.mock
30 
31 @SmallTest
32 class QSFragmentDisableFlagsLoggerTest : SysuiTestCase() {
33 
34     private val buffer = LogBufferFactory(DumpManager(), mock(LogcatEchoTracker::class.java))
35         .create("buffer", 10)
36     private val disableFlagsLogger = DisableFlagsLogger(
37         listOf(DisableFlagsLogger.DisableFlag(0b001, 'A', 'a')),
38         listOf(DisableFlagsLogger.DisableFlag(0b001, 'B', 'b'))
39     )
40     private val logger = QSFragmentDisableFlagsLogger(buffer, disableFlagsLogger)
41 
42     @Test
43     fun logDisableFlagChange_bufferHasStates() {
44         val state = DisableFlagsLogger.DisableState(0, 1)
45 
46         logger.logDisableFlagChange(state, state)
47 
48         val stringWriter = StringWriter()
49         buffer.dump(PrintWriter(stringWriter), tailLength = 0)
50         val actualString = stringWriter.toString()
51         val expectedLogString = disableFlagsLogger.getDisableFlagsString(
52             new = state, newAfterLocalModification = state
53         )
54 
55         assertThat(actualString).contains(expectedLogString)
56     }
57 }
58