Merge "Wifi: Add CTS test for WifiManager.MulticastLock"
This commit is contained in:
committed by
Android (Google) Code Review
commit
5efd98c85a
@@ -31,6 +31,7 @@
|
||||
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" />
|
||||
<uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE" />
|
||||
|
||||
<application android:usesCleartextTraffic="true">
|
||||
<uses-library android:name="android.test.runner" />
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Copyright (C) 2019 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 android.net.wifi.cts;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.net.wifi.WifiManager.MulticastLock;
|
||||
import android.test.AndroidTestCase;
|
||||
|
||||
public class MulticastLockTest extends AndroidTestCase {
|
||||
|
||||
private static final String WIFI_TAG = "MulticastLockTest";
|
||||
|
||||
/**
|
||||
* Verify acquire and release of Multicast locks
|
||||
*/
|
||||
public void testMulticastLock() {
|
||||
if (!WifiFeature.isWifiSupported(getContext())) {
|
||||
// skip the test if WiFi is not supported
|
||||
return;
|
||||
}
|
||||
WifiManager wm = (WifiManager) getContext().getSystemService(Context.WIFI_SERVICE);
|
||||
MulticastLock mcl = wm.createMulticastLock(WIFI_TAG);
|
||||
|
||||
mcl.setReferenceCounted(true);
|
||||
assertFalse(mcl.isHeld());
|
||||
mcl.acquire();
|
||||
assertTrue(mcl.isHeld());
|
||||
mcl.release();
|
||||
assertFalse(mcl.isHeld());
|
||||
mcl.acquire();
|
||||
mcl.acquire();
|
||||
assertTrue(mcl.isHeld());
|
||||
mcl.release();
|
||||
assertTrue(mcl.isHeld());
|
||||
mcl.release();
|
||||
assertFalse(mcl.isHeld());
|
||||
assertNotNull(mcl.toString());
|
||||
try {
|
||||
mcl.release();
|
||||
fail("should throw out exception because release is called"
|
||||
+" a greater number of times than acquire");
|
||||
} catch (RuntimeException e) {
|
||||
// expected
|
||||
}
|
||||
|
||||
mcl = wm.createMulticastLock(WIFI_TAG);
|
||||
mcl.setReferenceCounted(false);
|
||||
assertFalse(mcl.isHeld());
|
||||
mcl.acquire();
|
||||
assertTrue(mcl.isHeld());
|
||||
mcl.release();
|
||||
assertFalse(mcl.isHeld());
|
||||
mcl.acquire();
|
||||
mcl.acquire();
|
||||
assertTrue(mcl.isHeld());
|
||||
mcl.release();
|
||||
assertFalse(mcl.isHeld());
|
||||
assertNotNull(mcl.toString());
|
||||
// releasing again after release: but ignored for non-referenced locks
|
||||
mcl.release();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user