Merge "Update serialization of WallpaperColors" into sc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
6aad992ea5
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user