diff options
author | Santiago Etchebehere <santie@google.com> | 2021-06-18 15:58:14 -0700 |
---|---|---|
committer | Santiago Etchebehere <santie@google.com> | 2021-06-18 16:56:30 -0700 |
commit | 3af6019b81980edce9eb00be657f6a3aade8dc82 (patch) | |
tree | c86d65c27f5ff8646eef25778bdb1fdcf5c36a71 /tests | |
parent | 5001447b8634dc3a00c02677db300e40c93aceaf (diff) |
Update serialization of WallpaperColors
Do not assume mMainColors and mAllColors contain the same
color since recent changes modified that.
Update equals and hashCode as well to account for this.
Bug: 191391779
Bug: 191374703
Test: atest WallpaperColorsTest
Change-Id: I8c7775055a2360ec3a91cee76a42d14a143ec7fb
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Internal/src/android/app/WallpaperColorsTest.java | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/Internal/src/android/app/WallpaperColorsTest.java b/tests/Internal/src/android/app/WallpaperColorsTest.java index 45d3dade82b6..9ffb236d3f59 100644 --- a/tests/Internal/src/android/app/WallpaperColorsTest.java +++ b/tests/Internal/src/android/app/WallpaperColorsTest.java @@ -20,6 +20,7 @@ import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; +import android.os.Parcel; import androidx.test.filters.SmallTest; import androidx.test.runner.AndroidJUnit4; @@ -106,4 +107,26 @@ public class WallpaperColorsTest { // This would crash: canvas.drawBitmap(image, 0, 0, new Paint()); } + + /** + * Parcelled WallpaperColors object should equal the original. + */ + @Test + public void testParcelUnparcel() { + Bitmap image = Bitmap.createBitmap(300, 300, Bitmap.Config.ARGB_8888); + WallpaperColors colors = WallpaperColors.fromBitmap(image); + Parcel parcel = Parcel.obtain(); + colors.writeToParcel(parcel, 0); + parcel.setDataPosition(0); + WallpaperColors reconstructed = new WallpaperColors(parcel); + parcel.recycle(); + Assert.assertEquals("WallpaperColors recreated from Parcel should equal original", + colors, reconstructed); + Assert.assertEquals("getAllColors() on WallpaperColors recreated from Parcel should" + + "return the same as the original", + colors.getAllColors(), reconstructed.getAllColors()); + Assert.assertEquals("getMainColors() on WallpaperColors recreated from Parcel should" + + "return the same as the original", + colors.getMainColors(), reconstructed.getMainColors()); + } } |