Change build targets for settings tests
1. Split existing tests into fully automatable (unit/) and not fully automatable (app/) 2. Revert previous changes to test runners on app/ 3. Fix some typos in readme This will enable us to add the fully automatable test target SettingsUnitTests to the continuous integration tests on the platform. Change-Id: I0f42c59fde84891e4bfc379150c2f0c61ce1329f
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (C) 2012 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.settings;
|
||||
|
||||
import android.test.AndroidTestCase;
|
||||
import android.test.suitebuilder.annotation.SmallTest;
|
||||
|
||||
import com.android.settingslib.DeviceInfoUtils;
|
||||
|
||||
public class DeviceInfoSettingsTest extends AndroidTestCase {
|
||||
|
||||
@SmallTest
|
||||
public void testGetFormattedKernelVersion() throws Exception {
|
||||
if ("Unavailable".equals(DeviceInfoUtils.getFormattedKernelVersion())) {
|
||||
fail("formatKernelVersion can't cope with this device's /proc/version");
|
||||
}
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
public void testFormatKernelVersion() throws Exception {
|
||||
assertEquals("Unavailable", DeviceInfoUtils.formatKernelVersion(""));
|
||||
assertEquals("2.6.38.8-gg784\n" +
|
||||
"root@hpao4.eem.corp.google.com #2\n" +
|
||||
"Fri Feb 24 03:31:23 PST 2012",
|
||||
DeviceInfoUtils.formatKernelVersion("Linux version 2.6.38.8-gg784 " +
|
||||
"(root@hpao4.eem.corp.google.com) " +
|
||||
"(gcc version 4.4.3 (Ubuntu 4.4.3-4ubuntu5) ) #2 SMP " +
|
||||
"Fri Feb 24 03:31:23 PST 2012"));
|
||||
assertEquals("3.0.31-g6fb96c9\n" +
|
||||
"android-build@vpbs1.mtv.corp.google.com #1\n" +
|
||||
"Thu Jun 28 11:02:39 PDT 2012",
|
||||
DeviceInfoUtils.formatKernelVersion("Linux version 3.0.31-g6fb96c9 " +
|
||||
"(android-build@vpbs1.mtv.corp.google.com) " +
|
||||
"(gcc version 4.6.x-google 20120106 (prerelease) (GCC) ) #1 " +
|
||||
"SMP PREEMPT Thu Jun 28 11:02:39 PDT 2012"));
|
||||
assertEquals("2.6.38.8-a-b-jellybean+\n" +
|
||||
"x@y #1\n" +
|
||||
"Tue Aug 28 22:10:46 CDT 2012",
|
||||
DeviceInfoUtils.formatKernelVersion("Linux version " +
|
||||
"2.6.38.8-a-b-jellybean+ (x@y) " +
|
||||
"(gcc version 4.4.3 (GCC) ) #1 PREEMPT Tue Aug 28 22:10:46 CDT 2012"));
|
||||
}
|
||||
}
|
||||
79
tests/unit/src/com/android/settings/UtilsTest.java
Normal file
79
tests/unit/src/com/android/settings/UtilsTest.java
Normal file
@@ -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.settings;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static junit.framework.Assert.assertNull;
|
||||
import static org.mockito.Mockito.eq;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.pm.UserInfo;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.test.AndroidTestCase;
|
||||
import android.test.suitebuilder.annotation.SmallTest;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
public class UtilsTest extends AndroidTestCase {
|
||||
private static final int TEST_PRIMARY_USER_ID = 10;
|
||||
private static final int TEST_MANAGED_PROFILE_ID = 11;
|
||||
|
||||
@Mock private UserManager mUserManager;
|
||||
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
// // this is necessary for mockito to work
|
||||
System.setProperty("dexmaker.dexcache", getContext().getCacheDir().toString());
|
||||
|
||||
MockitoAnnotations.initMocks(this);
|
||||
when(mUserManager.getUserHandle()).thenReturn(TEST_PRIMARY_USER_ID);
|
||||
UserInfo primaryUser = new UserInfo(TEST_PRIMARY_USER_ID, null,
|
||||
UserInfo.FLAG_INITIALIZED | UserInfo.FLAG_PRIMARY);
|
||||
when(mUserManager.getUserInfo(TEST_PRIMARY_USER_ID)).thenReturn(primaryUser);
|
||||
UserInfo managedProfile = new UserInfo(TEST_MANAGED_PROFILE_ID, null,
|
||||
UserInfo.FLAG_INITIALIZED | UserInfo.FLAG_MANAGED_PROFILE);
|
||||
when(mUserManager.getUserInfo(eq(TEST_MANAGED_PROFILE_ID))).thenReturn(managedProfile);
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
public void testGetManagedProfile() {
|
||||
UserHandle[] userHandles = new UserHandle[] {
|
||||
new UserHandle(TEST_PRIMARY_USER_ID),
|
||||
new UserHandle(TEST_MANAGED_PROFILE_ID)
|
||||
};
|
||||
when(mUserManager.getUserProfiles())
|
||||
.thenReturn(new ArrayList<UserHandle>(Arrays.asList(userHandles)));
|
||||
assertEquals(TEST_MANAGED_PROFILE_ID,
|
||||
Utils.getManagedProfile(mUserManager).getIdentifier());
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
public void testGetManagedProfile_notPresent() {
|
||||
UserHandle[] userHandles = new UserHandle[] {
|
||||
new UserHandle(TEST_PRIMARY_USER_ID)
|
||||
};
|
||||
when(mUserManager.getUserProfiles())
|
||||
.thenReturn(new ArrayList<UserHandle>(Arrays.asList(userHandles)));
|
||||
assertNull(Utils.getManagedProfile(mUserManager));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
* Copyright (C) 2010 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.settings.bluetooth;
|
||||
|
||||
import android.test.AndroidTestCase;
|
||||
import android.test.suitebuilder.annotation.SmallTest;
|
||||
import android.text.InputFilter;
|
||||
import android.text.SpannableStringBuilder;
|
||||
|
||||
import com.android.settings.bluetooth.Utf8ByteLengthFilter;
|
||||
|
||||
public class Utf8ByteLengthFilterTest extends AndroidTestCase {
|
||||
|
||||
@SmallTest
|
||||
public void testFilter() {
|
||||
// Define the variables
|
||||
CharSequence source;
|
||||
SpannableStringBuilder dest;
|
||||
// Constructor to create a LengthFilter
|
||||
InputFilter lengthFilter = new Utf8ByteLengthFilter(10);
|
||||
InputFilter[] filters = {lengthFilter};
|
||||
|
||||
// filter() implicitly invoked. If the total length > filter length, the filter will
|
||||
// cut off the source CharSequence from beginning to fit the filter length.
|
||||
source = "abc";
|
||||
dest = new SpannableStringBuilder("abcdefgh");
|
||||
dest.setFilters(filters);
|
||||
|
||||
dest.insert(1, source);
|
||||
String expectedString1 = "aabbcdefgh";
|
||||
assertEquals(expectedString1, dest.toString());
|
||||
|
||||
dest.replace(5, 8, source);
|
||||
String expectedString2 = "aabbcabcgh";
|
||||
assertEquals(expectedString2, dest.toString());
|
||||
|
||||
dest.insert(2, source);
|
||||
assertEquals(expectedString2, dest.toString());
|
||||
|
||||
dest.delete(1, 3);
|
||||
String expectedString3 = "abcabcgh";
|
||||
assertEquals(expectedString3, dest.toString());
|
||||
|
||||
dest.append("12345");
|
||||
String expectedString4 = "abcabcgh12";
|
||||
assertEquals(expectedString4, dest.toString());
|
||||
|
||||
source = "\u60a8\u597d"; // 2 Chinese chars == 6 bytes in UTF-8
|
||||
dest.replace(8, 10, source);
|
||||
assertEquals(expectedString3, dest.toString());
|
||||
|
||||
dest.replace(0, 1, source);
|
||||
String expectedString5 = "\u60a8bcabcgh";
|
||||
assertEquals(expectedString5, dest.toString());
|
||||
|
||||
dest.replace(0, 4, source);
|
||||
String expectedString6 = "\u60a8\u597dbcgh";
|
||||
assertEquals(expectedString6, dest.toString());
|
||||
|
||||
source = "\u00a3\u00a5"; // 2 Latin-1 chars == 4 bytes in UTF-8
|
||||
dest.delete(2, 6);
|
||||
dest.insert(0, source);
|
||||
String expectedString7 = "\u00a3\u00a5\u60a8\u597d";
|
||||
assertEquals(expectedString7, dest.toString());
|
||||
|
||||
dest.replace(2, 3, source);
|
||||
String expectedString8 = "\u00a3\u00a5\u00a3\u597d";
|
||||
assertEquals(expectedString8, dest.toString());
|
||||
|
||||
dest.replace(3, 4, source);
|
||||
String expectedString9 = "\u00a3\u00a5\u00a3\u00a3\u00a5";
|
||||
assertEquals(expectedString9, dest.toString());
|
||||
|
||||
// filter() explicitly invoked
|
||||
dest = new SpannableStringBuilder("abcdefgh");
|
||||
CharSequence beforeFilterSource = "TestLengthFilter";
|
||||
String expectedAfterFilter = "TestLength";
|
||||
CharSequence actualAfterFilter = lengthFilter.filter(beforeFilterSource, 0,
|
||||
beforeFilterSource.length(), dest, 0, dest.length());
|
||||
assertEquals(expectedAfterFilter, actualAfterFilter);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user