Methods Summary |
---|
private void | adjustSize()
adjustSize(0);
|
private void | adjustSize(int offset)
final int pos = mParcel.dataPosition();
mParcel.setDataPosition(offset);
mParcel.writeInt(pos - offset);
mParcel.setDataPosition(pos);
|
private void | assertParse()
mParcel.setDataPosition(0);
assertTrue(mMetadata.parse(mParcel));
|
private void | assertParseFail()
mParcel.setDataPosition(0);
assertFalse(mMetadata.parse(mParcel));
assertEquals(0, mParcel.dataPosition());
|
private void | resetParcel()
mParcel.setDataPosition(0);
// Most tests will use a properly formed parcel with a size
// and the meta marker so we add them by default.
mParcel.writeInt(-1); // Placeholder for the size
mParcel.writeInt(kMarker);
|
protected void | setUp()
super.setUp();
mMetadata = new Metadata();
mParcel = Parcel.obtain();
resetParcel();
|
public void | testBadMetadataType()
final int start = mParcel.dataPosition();
mParcel.writeInt(-1); // Placeholder for the length
mParcel.writeInt(Metadata.TITLE);
mParcel.writeInt(0); // Invalid type.
mParcel.writeString("dummy");
adjustSize(start);
adjustSize();
assertParseFail();
|
public void | testEmptyIsOk()
adjustSize();
assertParse();
|
public void | testGetBoolean()
writeBooleanRecord(Metadata.PAUSE_AVAILABLE, true);
writeBooleanRecord(Metadata.SEEK_AVAILABLE, true);
writeBooleanRecord(Metadata.SEEK_BACKWARD_AVAILABLE, true);
writeBooleanRecord(Metadata.SEEK_FORWARD_AVAILABLE, true);
adjustSize();
assertParse();
assertEquals(true, mMetadata.getBoolean(Metadata.PAUSE_AVAILABLE));
assertEquals(true, mMetadata.getBoolean(Metadata.SEEK_AVAILABLE));
assertEquals(true, mMetadata.getBoolean(Metadata.SEEK_BACKWARD_AVAILABLE));
assertEquals(true, mMetadata.getBoolean(Metadata.SEEK_FORWARD_AVAILABLE));
|
public void | testGetByteArray()
byte data[] = new byte[]{1,2,3,4,5};
writeByteArrayRecord(Metadata.ALBUM_ART, data);
adjustSize();
assertParse();
byte res[] = mMetadata.getByteArray(Metadata.ALBUM_ART);
for (int i = 0; i < data.length; ++i) {
assertEquals(data[i], res[i]);
}
|
public void | testGetDate()
writeDateRecord(Metadata.DATE, 0, "PST");
adjustSize();
assertParse();
assertEquals(new Date(0), mMetadata.getDate(Metadata.DATE));
|
public void | testGetDouble()
writeDoubleRecord(Metadata.VIDEO_FRAME_RATE, 29.97);
adjustSize();
assertParse();
assertEquals(29.97, mMetadata.getDouble(Metadata.VIDEO_FRAME_RATE));
|
public void | testGetEmptyString()
writeStringRecord(Metadata.TITLE, "");
adjustSize();
assertParse();
assertEquals("", mMetadata.getString(Metadata.TITLE));
|
public void | testGetInt()
writeIntRecord(Metadata.CD_TRACK_NUM, 1);
adjustSize();
assertParse();
assertEquals(1, mMetadata.getInt(Metadata.CD_TRACK_NUM));
|
public void | testGetLong()
writeLongRecord(Metadata.DURATION, 1L);
adjustSize();
assertParse();
assertEquals(1L, mMetadata.getLong(Metadata.DURATION));
|
public void | testGetNullString()
writeStringRecord(Metadata.TITLE, null);
adjustSize();
assertParse();
assertEquals(null, mMetadata.getString(Metadata.TITLE));
|
public void | testGetString()
writeStringRecord(Metadata.TITLE, "a title");
writeStringRecord(Metadata.GENRE, "comedy");
adjustSize();
assertParse();
assertEquals("a title", mMetadata.getString(Metadata.TITLE));
assertEquals("comedy", mMetadata.getString(Metadata.GENRE));
|
public void | testMissingData()
final int size = 20;
mParcel.writeInt(size);
mParcel.setDataSize(size - 1);
assertParseFail();
|
public void | testMissingSizeAndMarker()
for (int i = 0; i < kHeaderSize; ++i) {
mParcel.setDataPosition(0);
mParcel.setDataSize(i);
assertEquals(i, mParcel.dataAvail());
assertParseFail();
}
|
public void | testParseClearState()
writeStringRecord(Metadata.TITLE, "a title");
writeStringRecord(Metadata.GENRE, "comedy");
writeStringRecord(Metadata.firstCustomId(), "custom");
adjustSize();
assertParse();
resetParcel();
writeStringRecord(Metadata.MIME_TYPE, "audio/mpg");
adjustSize();
assertParse();
// Only the mime type metadata should be present.
assertEquals(1, mMetadata.keySet().size());
assertTrue(mMetadata.has(Metadata.MIME_TYPE));
assertFalse(mMetadata.has(Metadata.TITLE));
assertFalse(mMetadata.has(Metadata.GENRE));
assertFalse(mMetadata.has(Metadata.firstCustomId()));
|
public void | testRecordMissingId()
mParcel.writeInt(13); // record length
// misses metadata id and metadata type.
adjustSize();
assertParseFail();
|
public void | testRecordMissingPayload()
mParcel.writeInt(12);
mParcel.writeInt(Metadata.TITLE);
mParcel.writeInt(Metadata.STRING_VAL);
// misses payload
adjustSize();
assertParseFail();
|
public void | testRecordMissingType()
mParcel.writeInt(13); // record length lies
mParcel.writeInt(Metadata.TITLE);
// misses metadata type
adjustSize();
assertParseFail();
|
public void | testRecordWithZeroPayload()
mParcel.writeInt(0);
adjustSize();
assertParseFail();
|
public void | testRecordsFound()
writeStringRecord(Metadata.TITLE, "a title");
writeStringRecord(Metadata.GENRE, "comedy");
writeStringRecord(Metadata.firstCustomId(), "custom");
adjustSize();
assertParse();
assertTrue(mMetadata.has(Metadata.TITLE));
assertTrue(mMetadata.has(Metadata.GENRE));
assertTrue(mMetadata.has(Metadata.firstCustomId()));
assertFalse(mMetadata.has(Metadata.DRM_CRIPPLED));
assertEquals(3, mMetadata.keySet().size());
|
public void | testWrongType()
writeIntRecord(Metadata.DURATION, 5);
adjustSize();
assertParse();
try {
mMetadata.getString(Metadata.DURATION);
} catch (IllegalStateException ise) {
return;
}
fail("Exception was not thrown");
|
private void | writeBooleanRecord(int metadataId, boolean val)
final int start = mParcel.dataPosition();
mParcel.writeInt(-1); // Placeholder for the length
mParcel.writeInt(metadataId);
mParcel.writeInt(Metadata.BOOLEAN_VAL);
mParcel.writeInt(val ? 1 : 0);
adjustSize(start);
|
private void | writeByteArrayRecord(int metadataId, byte[] val)
final int start = mParcel.dataPosition();
mParcel.writeInt(-1); // Placeholder for the length
mParcel.writeInt(metadataId);
mParcel.writeInt(Metadata.BYTE_ARRAY_VAL);
mParcel.writeByteArray(val);
adjustSize(start);
|
private void | writeDateRecord(int metadataId, long time, java.lang.String tz)
final int start = mParcel.dataPosition();
mParcel.writeInt(-1); // Placeholder for the length
mParcel.writeInt(metadataId);
mParcel.writeInt(Metadata.DATE_VAL);
mParcel.writeLong(time);
mParcel.writeString(tz);
adjustSize(start);
|
private void | writeDoubleRecord(int metadataId, double val)
final int start = mParcel.dataPosition();
mParcel.writeInt(-1); // Placeholder for the length
mParcel.writeInt(metadataId);
mParcel.writeInt(Metadata.DOUBLE_VAL);
mParcel.writeDouble(val);
adjustSize(start);
|
private void | writeIntRecord(int metadataId, int val)
final int start = mParcel.dataPosition();
mParcel.writeInt(-1); // Placeholder for the length
mParcel.writeInt(metadataId);
mParcel.writeInt(Metadata.INTEGER_VAL);
mParcel.writeInt(val);
adjustSize(start);
|
private void | writeLongRecord(int metadataId, long val)
final int start = mParcel.dataPosition();
mParcel.writeInt(-1); // Placeholder for the length
mParcel.writeInt(metadataId);
mParcel.writeInt(Metadata.LONG_VAL);
mParcel.writeLong(val);
adjustSize(start);
|
private void | writeStringRecord(int metadataId, java.lang.String val)
final int start = mParcel.dataPosition();
mParcel.writeInt(-1); // Placeholder for the length
mParcel.writeInt(metadataId);
mParcel.writeInt(Metadata.STRING_VAL);
mParcel.writeString(val);
adjustSize(start);
|