1 /* 2 * Copyright (C) 2015 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package android.media.cts; 17 18 import android.media.MediaDescription; 19 import android.media.browse.MediaBrowser.MediaItem; 20 import android.os.Parcel; 21 import android.test.AndroidTestCase; 22 23 /** 24 * Test {@link android.media.browse.MediaBrowser.MediaItem}. 25 */ 26 public class MediaItemTest extends AndroidTestCase { 27 private static final String DESCRIPTION = "test_description"; 28 private static final String MEDIA_ID = "test_media_id"; 29 private static final String TITLE = "test_title"; 30 private static final String SUBTITLE = "test_subtitle"; 31 testBrowsableMediaItem()32 public void testBrowsableMediaItem() { 33 MediaDescription description = new MediaDescription.Builder() 34 .setDescription(DESCRIPTION).setMediaId(MEDIA_ID) 35 .setTitle(TITLE).setSubtitle(SUBTITLE).build(); 36 MediaItem mediaItem = new MediaItem(description, MediaItem.FLAG_BROWSABLE); 37 38 assertEquals(description.toString(), mediaItem.getDescription().toString()); 39 assertEquals(MEDIA_ID, mediaItem.getMediaId()); 40 assertEquals(MediaItem.FLAG_BROWSABLE, mediaItem.getFlags()); 41 assertTrue(mediaItem.isBrowsable()); 42 assertFalse(mediaItem.isPlayable()); 43 44 // Test writeToParcel 45 Parcel p = Parcel.obtain(); 46 mediaItem.writeToParcel(p, 0); 47 p.setDataPosition(0); 48 assertEquals(mediaItem.getFlags(), p.readInt()); 49 assertEquals(description.toString(), 50 MediaDescription.CREATOR.createFromParcel(p).toString()); 51 p.recycle(); 52 } 53 testPlayableMediaItem()54 public void testPlayableMediaItem() { 55 MediaDescription description = new MediaDescription.Builder() 56 .setDescription(DESCRIPTION).setMediaId(MEDIA_ID) 57 .setTitle(TITLE).setSubtitle(SUBTITLE).build(); 58 MediaItem mediaItem = new MediaItem(description, MediaItem.FLAG_PLAYABLE); 59 60 assertEquals(description.toString(), mediaItem.getDescription().toString()); 61 assertEquals(MEDIA_ID, mediaItem.getMediaId()); 62 assertEquals(MediaItem.FLAG_PLAYABLE, mediaItem.getFlags()); 63 assertFalse(mediaItem.isBrowsable()); 64 assertTrue(mediaItem.isPlayable()); 65 66 // Test writeToParcel 67 Parcel p = Parcel.obtain(); 68 mediaItem.writeToParcel(p, 0); 69 p.setDataPosition(0); 70 assertEquals(mediaItem.getFlags(), p.readInt()); 71 assertEquals(description.toString(), 72 MediaDescription.CREATOR.createFromParcel(p).toString()); 73 p.recycle(); 74 } 75 }