summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMukesh Agrawal <quiche@google.com>2016-02-22 21:05:52 +0000
committerAndroid Partner Code Review <android-gerrit-partner@google.com>2016-02-22 21:05:52 +0000
commitd2410df493b1da7c9ff9e2026df4e4a30288f080 (patch)
treea4c3863db260126978938d637f2958aa4a89636f
parent75a3fd9a4d37dd6ba1a0ac3e174673e3b80795d1 (diff)
parent1b8a2b3c8724e29ce669f5bd6b0b82250824d034 (diff)
Merge "WifiLogger: add unit test for startLogging()" into mm-wireless-dev
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiLoggerTest.java79
1 files changed, 79 insertions, 0 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiLoggerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiLoggerTest.java
new file mode 100644
index 000000000..6ff51c007
--- /dev/null
+++ b/tests/wifitests/src/com/android/server/wifi/WifiLoggerTest.java
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.server.wifi;
+
+import android.test.suitebuilder.annotation.SmallTest;
+
+import static org.mockito.Mockito.anyInt;
+import static org.mockito.Mockito.eq;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+
+/**
+ * Unit tests for {@link com.android.server.wifi.WifiLogger}.
+ */
+@SmallTest
+public class WifiLoggerTest {
+ public static final String TAG = "WifiLoggerTest";
+
+ @Mock WifiStateMachine mWsm;
+ @Mock WifiNative mWifiNative;
+ WifiLogger mWifiLogger;
+
+ private static final String FAKE_RING_BUFFER_NAME = "fake-ring-buffer";
+
+ /**
+ * Initializes common state (e.g. mocks) needed by test cases.
+ */
+ @Before
+ public void setUp() throws Exception {
+ MockitoAnnotations.initMocks(this);
+
+ WifiNative.RingBufferStatus fakeRbs = new WifiNative.RingBufferStatus();
+ WifiNative.RingBufferStatus[] ringBufferStatuses = new WifiNative.RingBufferStatus[] {
+ fakeRbs
+ };
+ fakeRbs.name = FAKE_RING_BUFFER_NAME;
+ when(mWifiNative.getRingBufferStatus()).thenReturn(ringBufferStatuses);
+
+ mWifiLogger = new WifiLogger(mWsm, mWifiNative);
+ }
+
+ /**
+ * Verifies that startLogging() restarts HAL ringbuffers.
+ *
+ * Specifically: verifies that startLogging()
+ * a) stops any ring buffer logging that might be already running,
+ * b) instructs WifiNative to enable ring buffers of the appropriate log level.
+ */
+ @Test
+ public void startLoggingStopsAndRestartsRingBufferLogging() throws Exception {
+ final boolean verbosityToggle = false;
+ mWifiLogger.startLogging(verbosityToggle);
+ verify(mWifiNative).startLoggingRingBuffer(
+ eq(WifiLogger.VERBOSE_NO_LOG), anyInt(), anyInt(), anyInt(),
+ eq(FAKE_RING_BUFFER_NAME));
+ verify(mWifiNative).startLoggingRingBuffer(
+ eq(WifiLogger.VERBOSE_NORMAL_LOG), anyInt(), anyInt(), anyInt(),
+ eq(FAKE_RING_BUFFER_NAME));
+ }
+}