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.server.wifi.util; 18 19 import static org.junit.Assert.*; 20 21 import android.net.wifi.WifiManager; 22 23 import androidx.test.filters.SmallTest; 24 25 import com.android.server.wifi.WifiBaseTest; 26 27 import org.junit.Test; 28 29 import java.io.PrintWriter; 30 import java.io.StringWriter; 31 import java.util.regex.Pattern; 32 33 /** 34 * Unit tests for {@link com.android.server.wifi.util.LastCallerInfoManager}. 35 */ 36 @SmallTest 37 public class LastCallerInfoManagerTest extends WifiBaseTest { 38 39 private LastCallerInfoManager mLastCallerInfoManager = new LastCallerInfoManager(); 40 /** 41 * Test that the dump matches the values put 42 */ 43 @Test testPutAndDump()44 public void testPutAndDump() throws Exception { 45 mLastCallerInfoManager.put(WifiManager.API_SOFT_AP, 10, 11, 12, "Package", true); 46 47 StringWriter sw = new StringWriter(); 48 mLastCallerInfoManager.dump(new PrintWriter(sw)); 49 String serviceDump = sw.toString(); 50 Pattern logLineRegex = Pattern.compile( 51 "SoftAp: tid=10 uid=11 pid=12 packageName=Package toggleState=true"); 52 assertTrue("dump did not contain the expected log" 53 + ": " + serviceDump + "\n", logLineRegex.matcher(serviceDump).find()); 54 } 55 56 @Test testGet()57 public void testGet() { 58 // expect null before anything is set 59 assertNull(mLastCallerInfoManager.get(WifiManager.API_SCANNING_ENABLED)); 60 61 // Test getting some LastCallerInfo 62 mLastCallerInfoManager.put(WifiManager.API_SCANNING_ENABLED, 10, 11, 12, "Package", true); 63 LastCallerInfoManager.LastCallerInfo lastCallerInfo = 64 mLastCallerInfoManager.get(WifiManager.API_SCANNING_ENABLED); 65 assertEquals("Package", lastCallerInfo.getPackageName()); 66 assertTrue(lastCallerInfo.getToggleState()); 67 } 68 69 } 70