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