| 1 | package tmcsim.cadsimulator; |
|---|
| 2 | |
|---|
| 3 | import java.util.Vector; |
|---|
| 4 | import java.util.logging.Level; |
|---|
| 5 | import java.util.logging.Logger; |
|---|
| 6 | import static junit.framework.Assert.assertEquals; |
|---|
| 7 | import static junit.framework.Assert.assertFalse; |
|---|
| 8 | import junit.framework.TestCase; |
|---|
| 9 | import tmcsim.client.cadclientgui.data.IncidentEvent; |
|---|
| 10 | |
|---|
| 11 | /** |
|---|
| 12 | * |
|---|
| 13 | * @author jdalbey |
|---|
| 14 | */ |
|---|
| 15 | public class SoundPlayerTest extends TestCase |
|---|
| 16 | { |
|---|
| 17 | |
|---|
| 18 | SoundPlayer player; |
|---|
| 19 | |
|---|
| 20 | public SoundPlayerTest(String testName) |
|---|
| 21 | { |
|---|
| 22 | super(testName); |
|---|
| 23 | } |
|---|
| 24 | |
|---|
| 25 | @Override |
|---|
| 26 | protected void setUp() throws Exception |
|---|
| 27 | { |
|---|
| 28 | super.setUp(); |
|---|
| 29 | } |
|---|
| 30 | |
|---|
| 31 | /** |
|---|
| 32 | * Test of run method, of class SoundPlayer. |
|---|
| 33 | */ |
|---|
| 34 | public void testRun() |
|---|
| 35 | { |
|---|
| 36 | System.out.println("run"); |
|---|
| 37 | Vector dummy = new Vector(); |
|---|
| 38 | // the frog clip is actually 3 seconds long, but we specify clip duration of 2 |
|---|
| 39 | // to demonstrate that the subsequent clip will start before the first one finishes. |
|---|
| 40 | // This shows that SoundPlayer assumes correct clip durations. |
|---|
| 41 | IncidentEvent evt1 = new IncidentEvent(0, null, "frog-croak.mp3", 2, dummy, dummy); |
|---|
| 42 | IncidentEvent evt2 = new IncidentEvent(0, null, "bikehorn.mp3", 1, dummy, dummy); |
|---|
| 43 | player = new SoundPlayer("test/resources/"); |
|---|
| 44 | player.start(); |
|---|
| 45 | player.enqueueClip(evt1); |
|---|
| 46 | player.enqueueClip(evt2); |
|---|
| 47 | try |
|---|
| 48 | { |
|---|
| 49 | Thread.sleep(5000); |
|---|
| 50 | } catch (InterruptedException ex) |
|---|
| 51 | { |
|---|
| 52 | Logger.getLogger(SoundPlayerTest.class.getName()).log(Level.SEVERE, null, ex); |
|---|
| 53 | } |
|---|
| 54 | assertEquals(".wav didn't complete playing", IncidentEvent.EVENT_STATUS.COMPLETED, evt2.eventStatus); |
|---|
| 55 | } |
|---|
| 56 | |
|---|
| 57 | public void testEnqueueClip() |
|---|
| 58 | { |
|---|
| 59 | System.out.println("enqueueClip"); |
|---|
| 60 | Vector dummy = new Vector(); |
|---|
| 61 | IncidentEvent evt1 = new IncidentEvent(0, null, "frog-croak.mp3", 4, dummy, dummy); |
|---|
| 62 | player = new SoundPlayer("test/resources/"); |
|---|
| 63 | player.setAudioEnabled(false); |
|---|
| 64 | player.start(); |
|---|
| 65 | player.enqueueClip(evt1); |
|---|
| 66 | // Note: we don't wait for the clip to complete. |
|---|
| 67 | // So if audio is disabled, the clip will get marked complete without being played. |
|---|
| 68 | assertEquals(".wav played when audio disabled", IncidentEvent.EVENT_STATUS.COMPLETED, evt1.eventStatus); |
|---|
| 69 | } |
|---|
| 70 | |
|---|
| 71 | public void testDeQueueAll() |
|---|
| 72 | { |
|---|
| 73 | System.out.println("deQueueAll"); |
|---|
| 74 | Vector dummy = new Vector(); |
|---|
| 75 | IncidentEvent evt1 = new IncidentEvent(0, null, "bikehorn.mp3", 1, dummy, dummy); |
|---|
| 76 | IncidentEvent evt2 = new IncidentEvent(0, null, "bikehorn.mp3", 2, dummy, dummy); |
|---|
| 77 | player = new SoundPlayer("test/resources/"); |
|---|
| 78 | player.start(); |
|---|
| 79 | player.enqueueClip(evt1); |
|---|
| 80 | player.enqueueClip(evt2); |
|---|
| 81 | player.deQueueAll(); |
|---|
| 82 | try |
|---|
| 83 | { |
|---|
| 84 | Thread.sleep(2000); |
|---|
| 85 | } catch (InterruptedException ex) |
|---|
| 86 | { |
|---|
| 87 | Logger.getLogger(SoundPlayerTest.class.getName()).log(Level.SEVERE, null, ex); |
|---|
| 88 | } |
|---|
| 89 | assertFalse(".wav played after dequeue all", IncidentEvent.EVENT_STATUS.COMPLETED == evt2.eventStatus); |
|---|
| 90 | } |
|---|
| 91 | } |
|---|