source: josm/trunk/test/unit/org/openstreetmap/josm/io/audio/AudioPlayerTest.java@ 15755

Last change on this file since 15755 was 15755, checked in by simon04, 4 years ago

Introduce Stopwatch class to measure elapsed time

  • Property svn:eol-style set to native
File size: 2.2 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.io.audio;
3
4import static org.junit.Assert.assertFalse;
5import static org.junit.Assert.assertTrue;
6
7import java.io.File;
8import java.net.MalformedURLException;
9import java.net.URL;
10
11import org.junit.BeforeClass;
12import org.junit.Ignore;
13import org.junit.Test;
14import org.openstreetmap.josm.JOSMFixture;
15import org.openstreetmap.josm.TestUtils;
16import org.openstreetmap.josm.tools.Stopwatch;
17
18/**
19 * Unit tests of {@link AudioPlayer} class.
20 */
21@Ignore("unresolved sporadic deadlock - see #13809")
22public 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}
Note: See TracBrowser for help on using the repository browser.