1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.tools;
|
---|
3 |
|
---|
4 | import static org.junit.Assert.assertFalse;
|
---|
5 | import static org.junit.Assert.assertTrue;
|
---|
6 |
|
---|
7 | import java.io.File;
|
---|
8 | import java.net.MalformedURLException;
|
---|
9 | import java.net.URL;
|
---|
10 |
|
---|
11 | import org.junit.BeforeClass;
|
---|
12 | import org.junit.Ignore;
|
---|
13 | import org.junit.Test;
|
---|
14 | import org.openstreetmap.josm.JOSMFixture;
|
---|
15 | import org.openstreetmap.josm.TestUtils;
|
---|
16 |
|
---|
17 | /**
|
---|
18 | * Unit tests of {@link AudioPlayer} class.
|
---|
19 | */
|
---|
20 | @Ignore("unresolved sporadic deadlock - see #13809")
|
---|
21 | public class AudioPlayerTest {
|
---|
22 |
|
---|
23 | // We play wav files of about 4 seconds + pause, so define timeout at 16 seconds
|
---|
24 | private static final long MAX_DURATION = 16000;
|
---|
25 |
|
---|
26 | /**
|
---|
27 | * Setup test.
|
---|
28 | */
|
---|
29 | @BeforeClass
|
---|
30 | public static void setUp() {
|
---|
31 | JOSMFixture.createUnitTestFixture().init();
|
---|
32 | }
|
---|
33 |
|
---|
34 | /**
|
---|
35 | * Test method for {@code AudioPlayer#play(URL)}
|
---|
36 | * @throws Exception audio fault exception, e.g. can't open stream, unhandleable audio format
|
---|
37 | * @throws MalformedURLException wrong URL
|
---|
38 | */
|
---|
39 | @Test(timeout = 4*MAX_DURATION)
|
---|
40 | public void testPlay() throws MalformedURLException, Exception {
|
---|
41 | File wav1 = new File(TestUtils.getRegressionDataFile(6851, "20111003_121226.wav"));
|
---|
42 | File wav2 = new File(TestUtils.getRegressionDataFile(6851, "20111003_121557.wav"));
|
---|
43 |
|
---|
44 | for (File w : new File[] {wav1, wav2}) {
|
---|
45 | System.out.println("Playing " + w.toPath());
|
---|
46 | URL url = w.toURI().toURL();
|
---|
47 | long start = System.currentTimeMillis();
|
---|
48 | AudioPlayer.play(url);
|
---|
49 | assertTrue(AudioPlayer.playing());
|
---|
50 | assertFalse(AudioPlayer.paused());
|
---|
51 | AudioPlayer.pause();
|
---|
52 | assertFalse(AudioPlayer.playing());
|
---|
53 | assertTrue(AudioPlayer.paused());
|
---|
54 | AudioPlayer.play(url, AudioPlayer.position());
|
---|
55 | while (AudioPlayer.playing() && (System.currentTimeMillis() - start) < MAX_DURATION) {
|
---|
56 | Thread.sleep(500);
|
---|
57 | }
|
---|
58 | long duration = System.currentTimeMillis() - start;
|
---|
59 | System.out.println("Play finished after " + Utils.getDurationString(duration));
|
---|
60 | assertTrue(duration < MAX_DURATION);
|
---|
61 | AudioPlayer.reset();
|
---|
62 | Thread.sleep(1000); // precaution, see #13809
|
---|
63 | }
|
---|
64 | }
|
---|
65 | }
|
---|