TestSongspublic class TestSongs extends android.test.ActivityInstrumentationTestCase Junit / Instrumentation test case for the TrackBrowserActivity |
Fields Summary |
---|
private static String | TAG |
Constructors Summary |
---|
public TestSongs()
super("com.android.music",TrackBrowserActivity.class);
|
Methods Summary |
---|
public void | addNewPlaylist()Add 10 new playlists with unsorted title order
Instrumentation inst = getInstrumentation();
for (int i=0; i< MusicPlayerNames.NO_OF_PLAYLIST; i++){
inst.invokeContextMenuAction(getActivity(), MusicUtils.Defs.NEW_PLAYLIST, 0);
Thread.sleep(MusicPlayerNames.WAIT_SHORT_TIME);
//Remove the default playlist name
for (int j=0; j< MusicPlayerNames.DEFAULT_PLAYLIST_LENGTH; j++)
inst.sendKeyDownUpSync(KeyEvent.KEYCODE_DEL);
inst.sendStringSync(MusicPlayerNames.unsortedPlaylistTitle[i]);
inst.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_DOWN);
inst.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_CENTER);
Thread.sleep(MusicPlayerNames.WAIT_LONG_TIME);
inst.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_DOWN);
Thread.sleep(MusicPlayerNames.WAIT_LONG_TIME);
}
| private void | copy(java.io.File src, java.io.File dst)
InputStream in = new FileInputStream(src);
OutputStream out = new FileOutputStream(dst);
// Transfer bytes from in to out
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
in.close();
out.close();
Log.v(TAG, "Copy file");
| private void | rescanSdcard()
Intent scanIntent = new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://"
+ Environment.getExternalStorageDirectory()));
Log.v(TAG,"start the intent");
IntentFilter intentFilter = new IntentFilter(Intent.ACTION_MEDIA_SCANNER_STARTED);
intentFilter.addDataScheme("file");
getActivity().sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://"
+ Environment.getExternalStorageDirectory())));
Thread.sleep(MusicPlayerNames.WAIT_VERY_LONG_TIME);
| protected void | setUp()
super.setUp();
| protected void | tearDown()
super.tearDown();
| public void | testAddPlaylist()Test case 1: tests the new playlist added with sorted order.
Verification: The new playlist title should be sorted in alphabetical order
Cursor mCursor;
addNewPlaylist();
//Verify the new playlist is created, check the playlist table
String[] cols = new String[] {
MediaStore.Audio.Playlists.NAME
};
ContentResolver resolver = getActivity().getContentResolver();
if (resolver == null) {
System.out.println("resolver = null");
} else {
String whereclause = MediaStore.Audio.Playlists.NAME + " != ''";
mCursor = resolver.query(MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI,
cols, whereclause, null,
MediaStore.Audio.Playlists.NAME);
//Check the new playlist
mCursor.moveToFirst();
for (int j=0;j<10;j++){
assertEquals("New sorted Playlist title:", MusicPlayerNames.expectedPlaylistTitle[j], mCursor.getString(0));
mCursor.moveToNext();
}
}
| public void | testDeleteSong()Test case 3: Delete a song
Test case precondition: Copy a song and rescan the sdcard
Verification: The song is deleted from the sdcard and mediastore
Instrumentation inst = getInstrumentation();
Cursor mCursor;
//Copy a song from the golden directory
Log.v(TAG, "Copy a temp file to the sdcard");
File goldenfile = new File(MusicPlayerNames.GOLDENSONG);
File toBeDeleteSong = new File(MusicPlayerNames.DELETESONG);
copy(goldenfile, toBeDeleteSong);
rescanSdcard();
//Delete the file from music player
Thread.sleep(MusicPlayerNames.WAIT_LONG_TIME);
inst.sendStringSync(MusicPlayerNames.TOBEDELETESONGNAME);
Thread.sleep(MusicPlayerNames.WAIT_LONG_TIME);
inst.invokeContextMenuAction(getActivity(), MusicUtils.Defs.DELETE_ITEM, 0);
inst.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_DOWN);
inst.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_CENTER);
Thread.sleep(MusicPlayerNames.WAIT_LONG_TIME);
//Clear the search string
for (int j=0; j< MusicPlayerNames.TOBEDELETESONGNAME.length(); j++)
inst.sendKeyDownUpSync(KeyEvent.KEYCODE_DEL);
//Verfiy the item is removed from sdcard
File checkDeletedFile = new File(MusicPlayerNames.DELETESONG);
assertFalse(TAG, checkDeletedFile.exists());
ContentResolver resolver = getActivity().getContentResolver();
if (resolver == null) {
System.out.println("resolver = null");
} else {
String whereclause = MediaStore.Audio.Media.DISPLAY_NAME + " = '" +
MusicPlayerNames.TOBEDELETESONGNAME + "'";
mCursor = resolver.query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
null, whereclause, null, null);
boolean isEmptyCursor = mCursor.moveToFirst();
assertFalse(TAG,isEmptyCursor);
}
| public void | testSetRingtone()Test case 2: Set a song as ringtone
Test case precondition: The testing device should wipe data before
run the test case.
Verification: The count of audio.media.is_ringtone equal to 1.
Cursor mCursor;
Instrumentation inst = getInstrumentation();
inst.invokeContextMenuAction(getActivity(), MusicUtils.Defs.USE_AS_RINGTONE, 0);
//This only check if there only 1 ringtone set in music player
ContentResolver resolver = getActivity().getContentResolver();
if (resolver == null) {
System.out.println("resolver = null");
} else {
String whereclause = MediaStore.Audio.Media.IS_RINGTONE + " = 1";
mCursor = resolver.query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
null, whereclause, null, null);
//Check the new playlist
mCursor.moveToFirst();
int isRingtoneSet = mCursor.getCount();
assertEquals(TAG, MusicPlayerNames.EXPECTED_NO_RINGTONE, isRingtoneSet);
}
|
|