WindowManager.LayoutParams layoutParams = null; if (data.readInt() != 0) { layoutParams = WindowManager.LayoutParams.CREATOR.createFromParcel(data); Bundle bundle = null; if (data.readInt() != 0) { bundle = Bundle.CREATOR.createFromParcel(data);
parcel.setDataPosition(0); UserItem actualRead = UserItem.CREATOR.createFromParcel(parcel); assertEquals("username", actualRead.getId()); assertNotNull(actualRead.getCreated(RuntimeEnvironment.application)); assertEquals(0, actualRead.describeContents()); assertThat(UserItem.CREATOR.newArray(1)).hasSize(1);
@Test public void exceptionsAreParcelable() { ThreeDSecureAuthenticationResponse authResponse = ThreeDSecureAuthenticationResponse .fromException("Error!"); Parcel parcel = Parcel.obtain(); authResponse.writeToParcel(parcel, 0); parcel.setDataPosition(0); ThreeDSecureAuthenticationResponse parceled = ThreeDSecureAuthenticationResponse.CREATOR.createFromParcel(parcel); assertEquals(authResponse.isSuccess(), parceled.isSuccess()); assertEquals(authResponse.getException(), parceled.getException()); } }
parcel.setDataPosition(0); ParseObject newObject = ParseObject.CREATOR.createFromParcel(parcel); assertEquals(newObject.getClassName(), object.getClassName()); assertEquals(newObject.isDeleted, object.isDeleted);
maxCropResultWidth = in.readInt(); maxCropResultHeight = in.readInt(); activityTitle = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in); activityMenuIconColor = in.readInt(); outputUri = in.readParcelable(Uri.class.getClassLoader()); flipHorizontally = in.readByte() != 0; flipVertically = in.readByte() != 0; cropMenuCropButtonTitle = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in); cropMenuCropButtonIcon = in.readInt();
object.writeToParcel(parcel, 0); parcel.setDataPosition(0); ParseObject other = ParseObject.CREATOR.createFromParcel(parcel); assertTrue(other.isDirty("key")); assertTrue(other.isDirty("number"));
/** * Creates a new tab, which can be added to a {@link TabSwitcher} widget. * * @param source * The parcel, the tab should be created from, as an instance of the class {@link * Parcel}. The parcel may not be null */ private Tab(@NonNull final Parcel source) { this.title = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source); this.iconId = source.readInt(); this.iconBitmap = source.readParcelable(getClass().getClassLoader()); this.iconTintList = source.readParcelable(getClass().getClassLoader()); this.iconTintMode = (PorterDuff.Mode) source.readSerializable(); this.closeable = source.readInt() > 0; this.closeButtonIconId = source.readInt(); this.closeButtonIconBitmap = source.readParcelable(getClass().getClassLoader()); this.closeButtonIconTintList = source.readParcelable(getClass().getClassLoader()); this.closeButtonIconTintMode = (PorterDuff.Mode) source.readSerializable(); this.backgroundColor = source.readParcelable(getClass().getClassLoader()); this.contentBackgroundColor = source.readInt(); this.titleTextColor = source.readParcelable(getClass().getClassLoader()); this.progressBarShown = source.readInt() > 0; this.progressBarColor = source.readInt(); this.parameters = source.readBundle(getClass().getClassLoader()); }
@Test public void testParcelable() { ParseFieldOperations.registerDefaultDecoders(); ParseRelation<ParseObject> relation = new ParseRelation<>("Test"); ParseObject parent = new ParseObject("Parent"); parent.setObjectId("parentId"); relation.ensureParentAndKey(parent, "key"); ParseObject inner = new ParseObject("Test"); inner.setObjectId("innerId"); relation.add(inner); Parcel parcel = Parcel.obtain(); relation.writeToParcel(parcel, 0); parcel.setDataPosition(0); //noinspection unchecked ParseRelation<ParseObject> newRelation = ParseRelation.CREATOR.createFromParcel(parcel); assertEquals(newRelation.getTargetClass(), "Test"); assertEquals(newRelation.getKey(), "key"); assertEquals(newRelation.getParent().getClassName(), "Parent"); assertEquals(newRelation.getParent().getObjectId(), "parentId"); assertEquals(newRelation.getKnownObjects().size(), 1); // This would fail assertTrue(newRelation.hasKnownObject(inner)). // That is because ParseRelation uses == to check for known objects. }
@Test public void testParcelWhileSavingWithLDSEnabled() throws Exception { mockCurrentUserController(); TaskCompletionSource<ParseObject.State> tcs = mockObjectControllerForSave(); ParseObject object = new ParseObject("TestObject"); object.setObjectId("id"); OfflineStore lds = mock(OfflineStore.class); when(lds.getObject("TestObject", "id")).thenReturn(object); Parse.setLocalDatastore(lds); object.put("key", "value"); object.increment("number", 3); Task<Void> saveTask = object.saveInBackground(); assertTrue(object.hasOutstandingOperations()); // Saving assertFalse(object.isDirty()); // Not dirty because it's saving Parcel parcel = Parcel.obtain(); object.writeToParcel(parcel, 0); parcel.setDataPosition(0); ParseObject other = ParseObject.CREATOR.createFromParcel(parcel); assertSame(object, other); assertTrue(other.hasOutstandingOperations()); // Still saving assertFalse(other.isDirty()); // Still not dirty assertEquals(other.getNumber("number"), 3); tcs.setResult(null); saveTask.waitForCompletion(); Parse.setLocalDatastore(null); }
@Test public void testParcelWithCircularReferenceFromServer() { ParseObject parent = new ParseObject("Parent"); ParseObject child = new ParseObject("Child"); parent.setState(new ParseObject.State.Builder("Parent") .objectId("parentId") .put("self", parent) .put("child", child).build()); parent.setObjectId("parentId"); child.setState(new ParseObject.State.Builder("Child") .objectId("childId") .put("self", child) .put("parent", parent).build()); Parcel parcel = Parcel.obtain(); parent.writeToParcel(parcel, 0); parcel.setDataPosition(0); parent = ParseObject.CREATOR.createFromParcel(parcel); assertEquals(parent.getObjectId(), "parentId"); assertEquals(parent.getParseObject("self").getObjectId(), "parentId"); child = parent.getParseObject("child"); assertEquals(child.getObjectId(), "childId"); assertEquals(child.getParseObject("self").getObjectId(), "childId"); assertEquals(child.getParseObject("parent").getObjectId(), "parentId"); }
@Test public void testParcelWithCircularReference() { ParseObject parent = new ParseObject("Parent"); ParseObject child = new ParseObject("Child"); parent.setObjectId("parentId"); parent.put("self", parent); child.setObjectId("childId"); child.put("self", child); child.put("parent", parent); parent.put("child", child); Parcel parcel = Parcel.obtain(); parent.writeToParcel(parcel, 0); parcel.setDataPosition(0); parent = ParseObject.CREATOR.createFromParcel(parcel); assertEquals(parent.getObjectId(), "parentId"); assertEquals(parent.getParseObject("self").getObjectId(), "parentId"); child = parent.getParseObject("child"); assertEquals(child.getObjectId(), "childId"); assertEquals(child.getParseObject("self").getObjectId(), "childId"); assertEquals(child.getParseObject("parent").getObjectId(), "parentId"); }
@Test public void testParcelWhileDeletingWithLDSEnabled() throws Exception { mockCurrentUserController(); TaskCompletionSource<Void> tcs = mockObjectControllerForDelete(); ParseObject object = new ParseObject("TestObject"); object.setObjectId("id"); OfflineStore lds = mock(OfflineStore.class); when(lds.getObject("TestObject", "id")).thenReturn(object); Parse.setLocalDatastore(lds); Task<Void> deleteTask = object.deleteInBackground(); assertTrue(object.isDeleting); Parcel parcel = Parcel.obtain(); object.writeToParcel(parcel, 0); parcel.setDataPosition(0); ParseObject other = ParseObject.CREATOR.createFromParcel(parcel); assertSame(object, other); assertTrue(other.isDeleting); // Still deleting tcs.setResult(null); deleteTask.waitForCompletion(); // complete deletion on original object. assertFalse(other.isDeleting); assertTrue(other.isDeleted); Parse.setLocalDatastore(null); }
@Test public void testParcelWhileDeleting() throws Exception { mockCurrentUserController(); TaskCompletionSource<Void> tcs = mockObjectControllerForDelete(); ParseObject object = new ParseObject("TestObject"); object.setObjectId("id"); Task<Void> deleteTask = object.deleteInBackground(); // ensure Log.w is called.. assertTrue(object.isDeleting); Parcel parcel = Parcel.obtain(); object.writeToParcel(parcel, 0); parcel.setDataPosition(0); ParseObject other = ParseObject.CREATOR.createFromParcel(parcel); // By design, when LDS is off, we assume that old operations failed even if // they are still running on the old instance. assertFalse(other.isDeleting); assertTrue(object.isDeleting); tcs.setResult(null); deleteTask.waitForCompletion(); assertFalse(object.isDeleting); assertTrue(object.isDeleted); }
@Test public void testParcelable() { String mime = "mime"; String name = "name"; String url = "url"; ParseFile file = new ParseFile(new ParseFile.State.Builder() .name(name) .mimeType(mime) .url(url) .build()); Parcel parcel = Parcel.obtain(); file.writeToParcel(parcel, 0); parcel.setDataPosition(0); file = ParseFile.CREATOR.createFromParcel(parcel); assertEquals(file.getName(), name); assertEquals(file.getUrl(), url); assertEquals(file.getState().mimeType(), mime); assertFalse(file.isDirty()); }
@Test public void testParcelable() { ParseACL acl = new ParseACL(); acl.setReadAccess("userId", true); ParseUser user = new ParseUser(); user.setObjectId("userId2"); acl.setReadAccess(user, true); acl.setRoleWriteAccess("role", true); acl.setShared(true); Parcel parcel = Parcel.obtain(); acl.writeToParcel(parcel, 0); parcel.setDataPosition(0); acl = ParseACL.CREATOR.createFromParcel(parcel); assertTrue(acl.getReadAccess("userId")); assertTrue(acl.getReadAccess(user)); assertTrue(acl.getRoleWriteAccess("role")); assertTrue(acl.isShared()); assertFalse(acl.getPublicReadAccess()); assertFalse(acl.getPublicWriteAccess()); }
@Test public void writeRead() { HashMap<String,String> data = new HashMap<>(); data.put("A","B"); data.put("C","D"); SerializedSavedState savedState = new SerializedSavedState(View.BaseSavedState.EMPTY_STATE, data); savedState.serializer = new KryoSerializer(); assertEquals(data, savedState.get(HashMap.class)); Parcel parcel = Parcel.obtain(); savedState.writeToParcel(parcel,0); // rewind parcel so that we can read it from pos 0. Could also marshal and then unmarshal, // but lets include as little functionality outside of our class as possible parcel.setDataPosition(0); SerializedSavedState savedState2 = SerializedSavedState.CREATOR.createFromParcel(parcel); savedState.serializer = new KryoSerializer(); assertEquals(data, savedState2.get(HashMap.class)); } }
@Test public void testWriteToParcel() { final Parcelable parcelable = new View.BaseSavedState(AbsSavedState.EMPTY_STATE); final ExpandableSavedState ss = new ExpandableSavedState(parcelable); ss.setSize(1000); ss.setWeight(0.5f); final Parcel parcel = Parcel.obtain(); ss.writeToParcel(parcel, 0); parcel.setDataPosition(0); final ExpandableSavedState target = ExpandableSavedState.CREATOR.createFromParcel(parcel); assertThat(target.getSize(), is(1000)); assertThat(target.getWeight(), is(0.5f)); } }
@Test public void testParcelable() { List<ParseGeoPoint> points = new ArrayList<>(); points.add(new ParseGeoPoint(0, 0)); points.add(new ParseGeoPoint(0, 1)); points.add(new ParseGeoPoint(1, 1)); points.add(new ParseGeoPoint(1, 0)); ParsePolygon polygon = new ParsePolygon(points); Parcel parcel = Parcel.obtain(); polygon.writeToParcel(parcel, 0); parcel.setDataPosition(0); polygon = ParsePolygon.CREATOR.createFromParcel(parcel); assertEquals(polygon.getCoordinates(), points); } }
public void testModelParcelable() { TestModel model = new TestModel() .setFirstName("A") .setLastName("B") .setLuckyNumber(2) .setBirthday(System.currentTimeMillis()) .setIsHappy(true); Parcel parcel = Parcel.obtain(); model.writeToParcel(parcel, 0); parcel.setDataPosition(0); TestModel createdFromParcel = TestModel.CREATOR.createFromParcel(parcel); assertFalse(model == createdFromParcel); assertEquals(model, createdFromParcel); }
@Test public void testParcelableState() { ParseUser.State state = new ParseUser.State.Builder() .objectId("test") .isNew(true) .build(); ParseUser user = ParseObject.from(state); assertTrue(user.isNew()); Parcel parcel = Parcel.obtain(); user.writeToParcel(parcel, 0); parcel.setDataPosition(0); user = (ParseUser) ParseObject.CREATOR.createFromParcel(parcel); assertTrue(user.isNew()); }