diff options
author | TreeHugger Robot <treehugger-gerrit@google.com> | 2018-10-08 23:27:27 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2018-10-08 23:27:27 +0000 |
commit | 972045236311f884b61486954b4dce4f5ed7ac60 (patch) | |
tree | 45481359aa506cb4b6579c841e38621750d4d741 /tests | |
parent | b769edec465e81119dbddacbb448a95452e1732d (diff) | |
parent | efb7e84242e174f7bb1a994889742820d229935d (diff) | |
download | android_packages_apps_Trebuchet-972045236311f884b61486954b4dce4f5ed7ac60.tar.gz android_packages_apps_Trebuchet-972045236311f884b61486954b4dce4f5ed7ac60.tar.bz2 android_packages_apps_Trebuchet-972045236311f884b61486954b4dce4f5ed7ac60.zip |
Merge "Converting long item IDs to int" into ub-launcher3-master
Diffstat (limited to 'tests')
7 files changed, 145 insertions, 85 deletions
diff --git a/tests/src/com/android/launcher3/model/AddWorkspaceItemsTaskTest.java b/tests/src/com/android/launcher3/model/AddWorkspaceItemsTaskTest.java index 38e211b69..6673ba928 100644 --- a/tests/src/com/android/launcher3/model/AddWorkspaceItemsTaskTest.java +++ b/tests/src/com/android/launcher3/model/AddWorkspaceItemsTaskTest.java @@ -23,7 +23,8 @@ import com.android.launcher3.LauncherProvider; import com.android.launcher3.LauncherSettings; import com.android.launcher3.ShortcutInfo; import com.android.launcher3.util.GridOccupancy; -import com.android.launcher3.util.LongArrayMap; +import com.android.launcher3.util.IntArray; +import com.android.launcher3.util.IntSparseArrayMap; import org.junit.Before; import org.junit.Test; @@ -43,15 +44,15 @@ public class AddWorkspaceItemsTaskTest extends BaseModelUpdateTaskTestCase { private final ComponentName mComponent1 = new ComponentName("a", "b"); private final ComponentName mComponent2 = new ComponentName("b", "b"); - private ArrayList<Long> existingScreens; - private ArrayList<Long> newScreens; - private LongArrayMap<GridOccupancy> screenOccupancy; + private IntArray existingScreens; + private IntArray newScreens; + private IntSparseArrayMap<GridOccupancy> screenOccupancy; @Before public void initData() throws Exception { - existingScreens = new ArrayList<>(); - screenOccupancy = new LongArrayMap<>(); - newScreens = new ArrayList<>(); + existingScreens = new IntArray(); + screenOccupancy = new IntSparseArrayMap<>(); + newScreens = new IntArray(); idp.numColumns = 5; idp.numRows = 5; @@ -65,7 +66,7 @@ public class AddWorkspaceItemsTaskTest extends BaseModelUpdateTaskTestCase { return new AddWorkspaceItemsTask(list) { @Override - protected void updateScreens(Context context, ArrayList<Long> workspaceScreens) { } + protected void updateScreens(Context context, IntArray workspaceScreens) { } }; } @@ -77,18 +78,18 @@ public class AddWorkspaceItemsTaskTest extends BaseModelUpdateTaskTestCase { // Second screen has 2 holes of sizes 3x2 and 2x3 setupWorkspaceWithHoles(nextId, 2, new Rect(2, 0, 5, 2), new Rect(0, 2, 2, 5)); - Pair<Long, int[]> spaceFound = newTask() + int[] spaceFound = newTask() .findSpaceForItem(appState, bgDataModel, existingScreens, newScreens, 1, 1); - assertEquals(2L, (long) spaceFound.first); - assertTrue(screenOccupancy.get(spaceFound.first) - .isRegionVacant(spaceFound.second[0], spaceFound.second[1], 1, 1)); + assertEquals(2, spaceFound[0]); + assertTrue(screenOccupancy.get(spaceFound[0]) + .isRegionVacant(spaceFound[1], spaceFound[2], 1, 1)); // Find a larger space spaceFound = newTask() .findSpaceForItem(appState, bgDataModel, existingScreens, newScreens, 2, 3); - assertEquals(2L, (long) spaceFound.first); - assertTrue(screenOccupancy.get(spaceFound.first) - .isRegionVacant(spaceFound.second[0], spaceFound.second[1], 2, 3)); + assertEquals(2, spaceFound[0]); + assertTrue(screenOccupancy.get(spaceFound[0]) + .isRegionVacant(spaceFound[1], spaceFound[2], 2, 3)); } @Test @@ -97,11 +98,11 @@ public class AddWorkspaceItemsTaskTest extends BaseModelUpdateTaskTestCase { setupWorkspaceWithHoles(1, 1, new Rect(2, 0, 5, 2), new Rect(0, 2, 2, 5)); commitScreensToDb(); - ArrayList<Long> oldScreens = new ArrayList<>(existingScreens); - Pair<Long, int[]> spaceFound = newTask() + IntArray oldScreens = existingScreens.clone(); + int[] spaceFound = newTask() .findSpaceForItem(appState, bgDataModel, existingScreens, newScreens, 3, 3); - assertFalse(oldScreens.contains(spaceFound.first)); - assertTrue(newScreens.contains(spaceFound.first)); + assertFalse(oldScreens.contains(spaceFound[0])); + assertTrue(newScreens.contains(spaceFound[0])); } @Test @@ -135,7 +136,7 @@ public class AddWorkspaceItemsTaskTest extends BaseModelUpdateTaskTestCase { // only info2 should be added because info was already added to the workspace // in setupWorkspaceWithHoles() - verify(callbacks).bindAppsAdded(any(ArrayList.class), notAnimated.capture(), + verify(callbacks).bindAppsAdded(any(IntArray.class), notAnimated.capture(), animated.capture()); assertTrue(notAnimated.getValue().isEmpty()); @@ -143,7 +144,7 @@ public class AddWorkspaceItemsTaskTest extends BaseModelUpdateTaskTestCase { assertTrue(animated.getValue().contains(info2)); } - private int setupWorkspaceWithHoles(int startId, long screenId, Rect... holes) { + private int setupWorkspaceWithHoles(int startId, int screenId, Rect... holes) { GridOccupancy occupancy = new GridOccupancy(idp.numColumns, idp.numRows); occupancy.markCells(0, 0, idp.numColumns, idp.numRows, true); for (Rect r : holes) { @@ -183,7 +184,7 @@ public class AddWorkspaceItemsTaskTest extends BaseModelUpdateTaskTestCase { int count = existingScreens.size(); for (int i = 0; i < count; i++) { ContentValues v = new ContentValues(); - long screenId = existingScreens.get(i); + int screenId = existingScreens.get(i); v.put(LauncherSettings.WorkspaceScreens._ID, screenId); v.put(LauncherSettings.WorkspaceScreens.SCREEN_RANK, i); ops.add(ContentProviderOperation.newInsert(uri).withValues(v).build()); diff --git a/tests/src/com/android/launcher3/model/CacheDataUpdatedTaskTest.java b/tests/src/com/android/launcher3/model/CacheDataUpdatedTaskTest.java index db8004445..5fe9018e1 100644 --- a/tests/src/com/android/launcher3/model/CacheDataUpdatedTaskTest.java +++ b/tests/src/com/android/launcher3/model/CacheDataUpdatedTaskTest.java @@ -53,7 +53,7 @@ public class CacheDataUpdatedTaskTest extends BaseModelUpdateTaskTestCase { // Verify that only the app icons of app1 (id 1 & 2) are updated. Custom shortcut (id 7) // is not updated - verifyUpdate(1L, 2L); + verifyUpdate(1, 2); // Verify that only app1 var updated in allAppsList assertFalse(allAppsList.data.isEmpty()); @@ -80,11 +80,11 @@ public class CacheDataUpdatedTaskTest extends BaseModelUpdateTaskTestCase { // app3 has only restored apps (id 5, 6) and shortcuts (id 9). Verify that only apps were // were updated - verifyUpdate(5L, 6L); + verifyUpdate(5, 6); } - private void verifyUpdate(Long... idsUpdated) { - HashSet<Long> updates = new HashSet<>(Arrays.asList(idsUpdated)); + private void verifyUpdate(Integer... idsUpdated) { + HashSet<Integer> updates = new HashSet<>(Arrays.asList(idsUpdated)); for (ItemInfo info : bgDataModel.itemsIdMap) { if (updates.contains(info.id)) { assertEquals(NEW_LABEL_PREFIX + info.id, info.title); diff --git a/tests/src/com/android/launcher3/model/GridSizeMigrationTaskTest.java b/tests/src/com/android/launcher3/model/GridSizeMigrationTaskTest.java index b2fd1d968..7fa401b14 100644 --- a/tests/src/com/android/launcher3/model/GridSizeMigrationTaskTest.java +++ b/tests/src/com/android/launcher3/model/GridSizeMigrationTaskTest.java @@ -17,6 +17,7 @@ import com.android.launcher3.LauncherModel; import com.android.launcher3.LauncherProvider; import com.android.launcher3.LauncherSettings; import com.android.launcher3.model.GridSizeMigrationTask.MultiStepMigrationTask; +import com.android.launcher3.util.IntArray; import com.android.launcher3.util.TestLauncherProvider; import org.junit.Before; @@ -24,7 +25,6 @@ import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; -import java.util.ArrayList; import java.util.HashSet; import java.util.LinkedList; @@ -43,8 +43,8 @@ public class GridSizeMigrationTaskTest { new ProviderTestRule.Builder(TestLauncherProvider.class, LauncherProvider.AUTHORITY) .build(); - private static final long DESKTOP = LauncherSettings.Favorites.CONTAINER_DESKTOP; - private static final long HOTSEAT = LauncherSettings.Favorites.CONTAINER_HOTSEAT; + private static final int DESKTOP = LauncherSettings.Favorites.CONTAINER_DESKTOP; + private static final int HOTSEAT = LauncherSettings.Favorites.CONTAINER_HOTSEAT; private static final int APPLICATION = LauncherSettings.Favorites.ITEM_TYPE_APPLICATION; private static final int SHORTCUT = LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT; @@ -75,7 +75,7 @@ public class GridSizeMigrationTaskTest { @Test public void testHotseatMigration_apps_dropped() throws Exception { - long[] hotseatItems = { + int[] hotseatItems = { addItem(APPLICATION, 0, HOTSEAT, 0, 0), addItem(SHORTCUT, 1, HOTSEAT, 0, 0), -1, @@ -92,7 +92,7 @@ public class GridSizeMigrationTaskTest { @Test public void testHotseatMigration_shortcuts_dropped() throws Exception { - long[] hotseatItems = { + int[] hotseatItems = { addItem(APPLICATION, 0, HOTSEAT, 0, 0), addItem(30, 1, HOTSEAT, 0, 0), -1, @@ -107,11 +107,11 @@ public class GridSizeMigrationTaskTest { verifyHotseat(hotseatItems[1], hotseatItems[3], hotseatItems[4]); } - private void verifyHotseat(long... sortedIds) { + private void verifyHotseat(int... sortedIds) { int screenId = 0; int total = 0; - for (long id : sortedIds) { + for (int id : sortedIds) { Cursor c = mProviderRule.getResolver().query(LauncherSettings.Favorites.CONTENT_URI, new String[]{LauncherSettings.Favorites._ID}, "container=-101 and screen=" + screenId, null, null, null); @@ -139,7 +139,7 @@ public class GridSizeMigrationTaskTest { @Test public void testWorkspace_empty_row_column_removed() throws Exception { - long[][][] ids = createGrid(new int[][][]{{ + int[][][] ids = createGrid(new int[][][]{{ { 0, 0, -1, 1}, { 3, 1, -1, 4}, { -1, -1, -1, -1}, @@ -150,7 +150,7 @@ public class GridSizeMigrationTaskTest { new Point(4, 4), new Point(3, 3)).migrateWorkspace(); // Column 2 and row 2 got removed. - verifyWorkspace(new long[][][] {{ + verifyWorkspace(new int[][][] {{ {ids[0][0][0], ids[0][0][1], ids[0][0][3]}, {ids[0][1][0], ids[0][1][1], ids[0][1][3]}, {ids[0][3][0], ids[0][3][1], ids[0][3][3]}, @@ -159,7 +159,7 @@ public class GridSizeMigrationTaskTest { @Test public void testWorkspace_new_screen_created() throws Exception { - long[][][] ids = createGrid(new int[][][]{{ + int[][][] ids = createGrid(new int[][][]{{ { 0, 0, 0, 1}, { 3, 1, 0, 4}, { -1, -1, -1, -1}, @@ -170,7 +170,7 @@ public class GridSizeMigrationTaskTest { new Point(4, 4), new Point(3, 3)).migrateWorkspace(); // Items in the second column get moved to new screen - verifyWorkspace(new long[][][] {{ + verifyWorkspace(new int[][][] {{ {ids[0][0][0], ids[0][0][1], ids[0][0][3]}, {ids[0][1][0], ids[0][1][1], ids[0][1][3]}, {ids[0][3][0], ids[0][3][1], ids[0][3][3]}, @@ -181,7 +181,7 @@ public class GridSizeMigrationTaskTest { @Test public void testWorkspace_items_merged_in_next_screen() throws Exception { - long[][][] ids = createGrid(new int[][][]{{ + int[][][] ids = createGrid(new int[][][]{{ { 0, 0, 0, 1}, { 3, 1, 0, 4}, { -1, -1, -1, -1}, @@ -196,7 +196,7 @@ public class GridSizeMigrationTaskTest { // Items in the second column of the first screen should get placed on the 3rd // row of the second screen - verifyWorkspace(new long[][][] {{ + verifyWorkspace(new int[][][] {{ {ids[0][0][0], ids[0][0][1], ids[0][0][3]}, {ids[0][1][0], ids[0][1][1], ids[0][1][3]}, {ids[0][3][0], ids[0][3][1], ids[0][3][3]}, @@ -211,7 +211,7 @@ public class GridSizeMigrationTaskTest { public void testWorkspace_items_not_merged_in_next_screen() throws Exception { // First screen has 2 items that need to be moved, but second screen has only one // empty space after migration (top-left corner) - long[][][] ids = createGrid(new int[][][]{{ + int[][][] ids = createGrid(new int[][][]{{ { 0, 0, 0, 1}, { 3, 1, 0, 4}, { -1, -1, -1, -1}, @@ -227,7 +227,7 @@ public class GridSizeMigrationTaskTest { new Point(4, 4), new Point(3, 3)).migrateWorkspace(); // Items in the second column of the first screen should get placed on a new screen. - verifyWorkspace(new long[][][] {{ + verifyWorkspace(new int[][][] {{ {ids[0][0][0], ids[0][0][1], ids[0][0][3]}, {ids[0][1][0], ids[0][1][1], ids[0][1][3]}, {ids[0][3][0], ids[0][3][1], ids[0][3][3]}, @@ -244,7 +244,7 @@ public class GridSizeMigrationTaskTest { public void testWorkspace_first_row_blocked() throws Exception { // The first screen has one item on the 4th column which needs moving, as the first row // will be kept empty. - long[][][] ids = createGrid(new int[][][]{{ + int[][][] ids = createGrid(new int[][][]{{ { -1, -1, -1, -1}, { 3, 1, 7, 0}, { 8, 7, 7, -1}, @@ -255,7 +255,7 @@ public class GridSizeMigrationTaskTest { new Point(4, 4), new Point(3, 4)).migrateWorkspace(); // Items in the second column of the first screen should get placed on a new screen. - verifyWorkspace(new long[][][] {{ + verifyWorkspace(new int[][][] {{ { -1, -1, -1}, {ids[0][1][0], ids[0][1][1], ids[0][1][2]}, {ids[0][2][0], ids[0][2][1], ids[0][2][2]}, @@ -268,7 +268,7 @@ public class GridSizeMigrationTaskTest { @Test public void testWorkspace_items_moved_to_empty_first_row() throws Exception { // Items will get moved to the next screen to keep the first screen empty. - long[][][] ids = createGrid(new int[][][]{{ + int[][][] ids = createGrid(new int[][][]{{ { -1, -1, -1, -1}, { 0, 1, 0, 0}, { 8, 7, 7, -1}, @@ -279,7 +279,7 @@ public class GridSizeMigrationTaskTest { new Point(4, 4), new Point(3, 3)).migrateWorkspace(); // Items in the second column of the first screen should get placed on a new screen. - verifyWorkspace(new long[][][] {{ + verifyWorkspace(new int[][][] {{ { -1, -1, -1}, {ids[0][2][0], ids[0][2][1], ids[0][2][2]}, {ids[0][3][0], ids[0][3][1], ids[0][3][2]}, @@ -289,7 +289,7 @@ public class GridSizeMigrationTaskTest { }}); } - private long[][][] createGrid(int[][][] typeArray) throws Exception { + private int[][][] createGrid(int[][][] typeArray) throws Exception { return createGrid(typeArray, 1); } @@ -300,14 +300,14 @@ public class GridSizeMigrationTaskTest { * two represent the workspace grid. * @return the same grid representation where each entry is the corresponding item id. */ - private long[][][] createGrid(int[][][] typeArray, long startScreen) throws Exception { + private int[][][] createGrid(int[][][] typeArray, int startScreen) throws Exception { LauncherSettings.Settings.call(mProviderRule.getResolver(), LauncherSettings.Settings.METHOD_CREATE_EMPTY_DB); - long[][][] ids = new long[typeArray.length][][]; + int[][][] ids = new int[typeArray.length][][]; for (int i = 0; i < typeArray.length; i++) { // Add screen to DB - long screenId = startScreen + i; + int screenId = startScreen + i; // Keep the screen id counter up to date LauncherSettings.Settings.call(mProviderRule.getResolver(), @@ -318,9 +318,9 @@ public class GridSizeMigrationTaskTest { v.put(LauncherSettings.WorkspaceScreens.SCREEN_RANK, i); mProviderRule.getResolver().insert(LauncherSettings.WorkspaceScreens.CONTENT_URI, v); - ids[i] = new long[typeArray[i].length][]; + ids[i] = new int[typeArray[i].length][]; for (int y = 0; y < typeArray[i].length; y++) { - ids[i][y] = new long[typeArray[i][y].length]; + ids[i][y] = new int[typeArray[i][y].length]; for (int x = 0; x < typeArray[i][y].length; x++) { if (typeArray[i][y][x] < 0) { // Empty cell @@ -339,16 +339,16 @@ public class GridSizeMigrationTaskTest { * @param ids A 3d array where the first dimension represents the screen, and the rest two * represent the workspace grid. */ - private void verifyWorkspace(long[][][] ids) { - ArrayList<Long> allScreens = LauncherModel.loadWorkspaceScreensDb(mContext); + private void verifyWorkspace(int[][][] ids) { + IntArray allScreens = LauncherModel.loadWorkspaceScreensDb(mContext); assertEquals(ids.length, allScreens.size()); int total = 0; for (int i = 0; i < ids.length; i++) { - long screenId = allScreens.get(i); + int screenId = allScreens.get(i); for (int y = 0; y < ids[i].length; y++) { for (int x = 0; x < ids[i][y].length; x++) { - long id = ids[i][y][x]; + int id = ids[i][y][x]; Cursor c = mProviderRule.getResolver().query( LauncherSettings.Favorites.CONTENT_URI, @@ -382,10 +382,10 @@ public class GridSizeMigrationTaskTest { * @param type {@link #APPLICATION} or {@link #SHORTCUT} or >= 2 for * folder (where the type represents the number of items in the folder). */ - private long addItem(int type, long screen, long container, int x, int y) throws Exception { - long id = LauncherSettings.Settings.call(mProviderRule.getResolver(), + private int addItem(int type, int screen, int container, int x, int y) throws Exception { + int id = LauncherSettings.Settings.call(mProviderRule.getResolver(), LauncherSettings.Settings.METHOD_NEW_ITEM_ID) - .getLong(LauncherSettings.Settings.EXTRA_VALUE); + .getInt(LauncherSettings.Settings.EXTRA_VALUE); ContentValues values = new ContentValues(); values.put(LauncherSettings.Favorites._ID, id); diff --git a/tests/src/com/android/launcher3/model/LoaderCursorTest.java b/tests/src/com/android/launcher3/model/LoaderCursorTest.java index a21f86177..ac1be1777 100644 --- a/tests/src/com/android/launcher3/model/LoaderCursorTest.java +++ b/tests/src/com/android/launcher3/model/LoaderCursorTest.java @@ -18,6 +18,7 @@ import com.android.launcher3.ShortcutInfo; import com.android.launcher3.Utilities; import com.android.launcher3.compat.LauncherAppsCompat; import com.android.launcher3.icons.BitmapInfo; +import com.android.launcher3.util.IntArray; import org.junit.Before; import org.junit.Test; @@ -149,83 +150,83 @@ public class LoaderCursorTest { @Test public void checkItemPlacement_wrongWorkspaceScreen() { - ArrayList<Long> workspaceScreens = new ArrayList<>(Arrays.asList(1L, 3L)); + IntArray workspaceScreens = IntArray.wrap(1, 3); mIDP.numRows = 4; mIDP.numColumns = 4; mIDP.numHotseatIcons = 3; // Item on unknown screen are not placed assertFalse(mLoaderCursor.checkItemPlacement( - newItemInfo(0, 0, 1, 1, CONTAINER_DESKTOP, 4L), workspaceScreens)); + newItemInfo(0, 0, 1, 1, CONTAINER_DESKTOP, 4), workspaceScreens)); assertFalse(mLoaderCursor.checkItemPlacement( - newItemInfo(0, 0, 1, 1, CONTAINER_DESKTOP, 5L), workspaceScreens)); + newItemInfo(0, 0, 1, 1, CONTAINER_DESKTOP, 5), workspaceScreens)); assertFalse(mLoaderCursor.checkItemPlacement( - newItemInfo(0, 0, 1, 1, CONTAINER_DESKTOP, 2L), workspaceScreens)); + newItemInfo(0, 0, 1, 1, CONTAINER_DESKTOP, 2), workspaceScreens)); assertTrue(mLoaderCursor.checkItemPlacement( - newItemInfo(0, 0, 1, 1, CONTAINER_DESKTOP, 1L), workspaceScreens)); + newItemInfo(0, 0, 1, 1, CONTAINER_DESKTOP, 1), workspaceScreens)); assertTrue(mLoaderCursor.checkItemPlacement( - newItemInfo(0, 0, 1, 1, CONTAINER_DESKTOP, 3L), workspaceScreens)); + newItemInfo(0, 0, 1, 1, CONTAINER_DESKTOP, 3), workspaceScreens)); } @Test public void checkItemPlacement_outsideBounds() { - ArrayList<Long> workspaceScreens = new ArrayList<>(Arrays.asList(1L, 2L)); + IntArray workspaceScreens = IntArray.wrap(1, 2); mIDP.numRows = 4; mIDP.numColumns = 4; mIDP.numHotseatIcons = 3; // Item outside screen bounds are not placed assertFalse(mLoaderCursor.checkItemPlacement( - newItemInfo(4, 4, 1, 1, CONTAINER_DESKTOP, 1L), workspaceScreens)); + newItemInfo(4, 4, 1, 1, CONTAINER_DESKTOP, 1), workspaceScreens)); } @Test public void checkItemPlacement_overlappingItems() { - ArrayList<Long> workspaceScreens = new ArrayList<>(Arrays.asList(1L, 2L)); + IntArray workspaceScreens = IntArray.wrap(1, 2); mIDP.numRows = 4; mIDP.numColumns = 4; mIDP.numHotseatIcons = 3; // Overlapping items are not placed assertTrue(mLoaderCursor.checkItemPlacement( - newItemInfo(0, 0, 1, 1, CONTAINER_DESKTOP, 1L), workspaceScreens)); + newItemInfo(0, 0, 1, 1, CONTAINER_DESKTOP, 1), workspaceScreens)); assertFalse(mLoaderCursor.checkItemPlacement( - newItemInfo(0, 0, 1, 1, CONTAINER_DESKTOP, 1L), workspaceScreens)); + newItemInfo(0, 0, 1, 1, CONTAINER_DESKTOP, 1), workspaceScreens)); assertTrue(mLoaderCursor.checkItemPlacement( - newItemInfo(0, 0, 1, 1, CONTAINER_DESKTOP, 2L), workspaceScreens)); + newItemInfo(0, 0, 1, 1, CONTAINER_DESKTOP, 2), workspaceScreens)); assertFalse(mLoaderCursor.checkItemPlacement( - newItemInfo(0, 0, 1, 1, CONTAINER_DESKTOP, 2L), workspaceScreens)); + newItemInfo(0, 0, 1, 1, CONTAINER_DESKTOP, 2), workspaceScreens)); assertTrue(mLoaderCursor.checkItemPlacement( - newItemInfo(1, 1, 1, 1, CONTAINER_DESKTOP, 1L), workspaceScreens)); + newItemInfo(1, 1, 1, 1, CONTAINER_DESKTOP, 1), workspaceScreens)); assertTrue(mLoaderCursor.checkItemPlacement( - newItemInfo(2, 2, 2, 2, CONTAINER_DESKTOP, 1L), workspaceScreens)); + newItemInfo(2, 2, 2, 2, CONTAINER_DESKTOP, 1), workspaceScreens)); assertFalse(mLoaderCursor.checkItemPlacement( - newItemInfo(3, 2, 1, 2, CONTAINER_DESKTOP, 1L), workspaceScreens)); + newItemInfo(3, 2, 1, 2, CONTAINER_DESKTOP, 1), workspaceScreens)); } @Test public void checkItemPlacement_hotseat() { - ArrayList<Long> workspaceScreens = new ArrayList<>(); + IntArray workspaceScreens = new IntArray(); mIDP.numRows = 4; mIDP.numColumns = 4; mIDP.numHotseatIcons = 3; // Hotseat items are only placed based on screenId assertTrue(mLoaderCursor.checkItemPlacement( - newItemInfo(3, 3, 1, 1, CONTAINER_HOTSEAT, 1L), workspaceScreens)); + newItemInfo(3, 3, 1, 1, CONTAINER_HOTSEAT, 1), workspaceScreens)); assertTrue(mLoaderCursor.checkItemPlacement( - newItemInfo(3, 3, 1, 1, CONTAINER_HOTSEAT, 2L), workspaceScreens)); + newItemInfo(3, 3, 1, 1, CONTAINER_HOTSEAT, 2), workspaceScreens)); assertFalse(mLoaderCursor.checkItemPlacement( - newItemInfo(3, 3, 1, 1, CONTAINER_HOTSEAT, 3L), workspaceScreens)); + newItemInfo(3, 3, 1, 1, CONTAINER_HOTSEAT, 3), workspaceScreens)); } private ItemInfo newItemInfo(int cellX, int cellY, int spanX, int spanY, - long container, long screenId) { + int container, int screenId) { ItemInfo info = new ItemInfo(); info.cellX = cellX; info.cellY = cellY; diff --git a/tests/src/com/android/launcher3/model/PackageInstallStateChangedTaskTest.java b/tests/src/com/android/launcher3/model/PackageInstallStateChangedTaskTest.java index 435686ff8..25100dc3d 100644 --- a/tests/src/com/android/launcher3/model/PackageInstallStateChangedTaskTest.java +++ b/tests/src/com/android/launcher3/model/PackageInstallStateChangedTaskTest.java @@ -48,18 +48,18 @@ public class PackageInstallStateChangedTaskTest extends BaseModelUpdateTaskTestC public void testSessionUpdate_shortcuts_updated() throws Exception { executeTaskForTest(newTask("app3", 30)); - verifyProgressUpdate(30, 5L, 6L, 7L); + verifyProgressUpdate(30, 5, 6, 7); } @Test public void testSessionUpdate_widgets_updated() throws Exception { executeTaskForTest(newTask("app4", 30)); - verifyProgressUpdate(30, 8L, 9L); + verifyProgressUpdate(30, 8, 9); } - private void verifyProgressUpdate(int progress, Long... idsUpdated) { - HashSet<Long> updates = new HashSet<>(Arrays.asList(idsUpdated)); + private void verifyProgressUpdate(int progress, Integer... idsUpdated) { + HashSet<Integer> updates = new HashSet<>(Arrays.asList(idsUpdated)); for (ItemInfo info : bgDataModel.itemsIdMap) { if (info instanceof ShortcutInfo) { assertEquals(updates.contains(info.id) ? progress: 0, diff --git a/tests/src/com/android/launcher3/ui/widget/BindWidgetTest.java b/tests/src/com/android/launcher3/ui/widget/BindWidgetTest.java index c1dc43bf8..94f9e39bf 100644 --- a/tests/src/com/android/launcher3/ui/widget/BindWidgetTest.java +++ b/tests/src/com/android/launcher3/ui/widget/BindWidgetTest.java @@ -282,7 +282,7 @@ public class BindWidgetTest extends AbstractLauncherUiTest { */ private void setupAndVerifyContents( LauncherAppWidgetInfo item, Class<?> widgetClass, String desc) { - long screenId = Workspace.FIRST_SCREEN_ID; + int screenId = Workspace.FIRST_SCREEN_ID; // Update the screen id counter for the provider. LauncherSettings.Settings.call(mResolver, LauncherSettings.Settings.METHOD_NEW_SCREEN_ID); @@ -298,7 +298,7 @@ public class BindWidgetTest extends AbstractLauncherUiTest { ContentWriter writer = new ContentWriter(mTargetContext); item.id = LauncherSettings.Settings.call( mResolver, LauncherSettings.Settings.METHOD_NEW_ITEM_ID) - .getLong(LauncherSettings.Settings.EXTRA_VALUE); + .getInt(LauncherSettings.Settings.EXTRA_VALUE); item.screenId = screenId; item.onAddToDatabase(writer); writer.put(LauncherSettings.Favorites._ID, item.id); diff --git a/tests/src/com/android/launcher3/util/IntSetTest.java b/tests/src/com/android/launcher3/util/IntSetTest.java new file mode 100644 index 000000000..934b749f5 --- /dev/null +++ b/tests/src/com/android/launcher3/util/IntSetTest.java @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2018 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.launcher3.util; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import androidx.test.filters.SmallTest; +import androidx.test.runner.AndroidJUnit4; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +/** + * Unit tests for {@link IntSet} + */ +@SmallTest +@RunWith(AndroidJUnit4.class) +public class IntSetTest { + + @Test + public void testDuplicateEntries() { + IntSet set = new IntSet(); + + set.add(2); + assertEquals(1, set.size()); + + set.add(2); + assertEquals(1, set.size()); + assertTrue(set.contains(2)); + assertFalse(set.contains(1)); + + set.add(1); + assertEquals(2, set.size()); + assertTrue(set.contains(2)); + assertTrue(set.contains(1)); + + + set.add(10); + assertEquals(3, set.size()); + + assertEquals("1, 2, 10", set.mArray.toConcatString()); + } +} |