Merge changes from topic "rm-forceAllNetworkTypes-sc-v2-dev" into sc-v2-dev
* changes: Test a template matches mobile and mobile wildcard Remove ForceAllNetworkTypes from test
This commit is contained in:
@@ -39,6 +39,8 @@ import android.net.NetworkTemplate.OEM_MANAGED_YES
|
||||
import android.net.NetworkTemplate.SUBSCRIBER_ID_MATCH_RULE_EXACT
|
||||
import android.net.NetworkTemplate.WIFI_NETWORKID_ALL
|
||||
import android.net.NetworkTemplate.buildTemplateCarrierMetered
|
||||
import android.net.NetworkTemplate.buildTemplateMobileAll
|
||||
import android.net.NetworkTemplate.buildTemplateMobileWildcard
|
||||
import android.net.NetworkTemplate.buildTemplateMobileWithRatType
|
||||
import android.net.NetworkTemplate.buildTemplateWifi
|
||||
import android.net.NetworkTemplate.buildTemplateWifiWildcard
|
||||
@@ -170,6 +172,57 @@ class NetworkTemplateTest {
|
||||
templateWifiSsidAllImsi1.assertMatches(identWifiImsi1Ssid2)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testMobileMatches() {
|
||||
val templateMobileImsi1 = buildTemplateMobileAll(TEST_IMSI1)
|
||||
val templateMobileImsi2WithRatType = buildTemplateMobileWithRatType(TEST_IMSI2,
|
||||
TelephonyManager.NETWORK_TYPE_UMTS)
|
||||
|
||||
val mobileImsi1 = buildNetworkState(TYPE_MOBILE, TEST_IMSI1, null /* ssid */,
|
||||
OEM_NONE, true /* metered */)
|
||||
val identMobile1 = buildNetworkIdentity(mockContext, mobileImsi1,
|
||||
false /* defaultNetwork */, TelephonyManager.NETWORK_TYPE_UMTS)
|
||||
val mobileImsi2 = buildMobileNetworkState(TEST_IMSI2)
|
||||
val identMobile2Umts = buildNetworkIdentity(mockContext, mobileImsi2,
|
||||
false /* defaultNetwork */, TelephonyManager.NETWORK_TYPE_UMTS)
|
||||
|
||||
val identWifiImsi1Ssid1 = buildNetworkIdentity(
|
||||
mockContext, buildWifiNetworkState(TEST_IMSI1, TEST_SSID1), true, 0)
|
||||
|
||||
// Verify that the template matches type and the subscriberId.
|
||||
templateMobileImsi1.assertMatches(identMobile1)
|
||||
templateMobileImsi2WithRatType.assertMatches(identMobile2Umts)
|
||||
|
||||
// Verify that the template does not match the different subscriberId.
|
||||
templateMobileImsi1.assertDoesNotMatch(identMobile2Umts)
|
||||
templateMobileImsi2WithRatType.assertDoesNotMatch(identMobile1)
|
||||
|
||||
// Verify that the different type does not match.
|
||||
templateMobileImsi1.assertDoesNotMatch(identWifiImsi1Ssid1)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testMobileWildcardMatches() {
|
||||
val templateMobileWildcard = buildTemplateMobileWildcard()
|
||||
val templateMobileNullImsiWithRatType = buildTemplateMobileWithRatType(null,
|
||||
TelephonyManager.NETWORK_TYPE_UMTS)
|
||||
|
||||
val mobileImsi1 = buildMobileNetworkState(TEST_IMSI1)
|
||||
val identMobile1 = buildNetworkIdentity(mockContext, mobileImsi1,
|
||||
false /* defaultNetwork */, TelephonyManager.NETWORK_TYPE_UMTS)
|
||||
|
||||
// Verify that the template matches any subscriberId.
|
||||
templateMobileWildcard.assertMatches(identMobile1)
|
||||
templateMobileNullImsiWithRatType.assertMatches(identMobile1)
|
||||
|
||||
val identWifiImsi1Ssid1 = buildNetworkIdentity(
|
||||
mockContext, buildWifiNetworkState(TEST_IMSI1, TEST_SSID1), true, 0)
|
||||
|
||||
// Verify that the different type does not match.
|
||||
templateMobileWildcard.assertDoesNotMatch(identWifiImsi1Ssid1)
|
||||
templateMobileNullImsiWithRatType.assertDoesNotMatch(identWifiImsi1Ssid1)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testCarrierMeteredMatches() {
|
||||
val templateCarrierImsi1Metered = buildTemplateCarrierMetered(TEST_IMSI1)
|
||||
|
||||
@@ -98,14 +98,11 @@ public class NetworkStatsCollectionTest {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
sOriginalClock = RecurrenceRule.sClock;
|
||||
// ignore any device overlay while testing
|
||||
NetworkTemplate.forceAllNetworkTypes();
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
RecurrenceRule.sClock = sOriginalClock;
|
||||
NetworkTemplate.resetForceAllNetworkTypes();
|
||||
}
|
||||
|
||||
private void setClock(Instant instant) {
|
||||
@@ -123,7 +120,7 @@ public class NetworkStatsCollectionTest {
|
||||
|
||||
// verify that history read correctly
|
||||
assertSummaryTotal(collection, buildTemplateMobileAll(TEST_IMSI),
|
||||
636016770L, 709306L, 88038768L, 518836L, NetworkStatsAccess.Level.DEVICE);
|
||||
636014522L, 709291L, 88037144L, 518820L, NetworkStatsAccess.Level.DEVICE);
|
||||
|
||||
// now export into a unified format
|
||||
final ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
@@ -137,7 +134,7 @@ public class NetworkStatsCollectionTest {
|
||||
// and read back into structure, verifying that totals are same
|
||||
collection.read(new ByteArrayInputStream(bos.toByteArray()));
|
||||
assertSummaryTotal(collection, buildTemplateMobileAll(TEST_IMSI),
|
||||
636016770L, 709306L, 88038768L, 518836L, NetworkStatsAccess.Level.DEVICE);
|
||||
636014522L, 709291L, 88037144L, 518820L, NetworkStatsAccess.Level.DEVICE);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -151,7 +148,7 @@ public class NetworkStatsCollectionTest {
|
||||
|
||||
// verify that history read correctly
|
||||
assertSummaryTotal(collection, buildTemplateMobileAll(TEST_IMSI),
|
||||
637076152L, 711413L, 88343717L, 521022L, NetworkStatsAccess.Level.DEVICE);
|
||||
637073904L, 711398L, 88342093L, 521006L, NetworkStatsAccess.Level.DEVICE);
|
||||
|
||||
// now export into a unified format
|
||||
final ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
@@ -165,7 +162,7 @@ public class NetworkStatsCollectionTest {
|
||||
// and read back into structure, verifying that totals are same
|
||||
collection.read(new ByteArrayInputStream(bos.toByteArray()));
|
||||
assertSummaryTotal(collection, buildTemplateMobileAll(TEST_IMSI),
|
||||
637076152L, 711413L, 88343717L, 521022L, NetworkStatsAccess.Level.DEVICE);
|
||||
637073904L, 711398L, 88342093L, 521006L, NetworkStatsAccess.Level.DEVICE);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user