source: josm/trunk/test/unit/org/openstreetmap/josm/tools/AudioPlayerTest.java@ 9504

Last change on this file since 9504 was 9145, checked in by Don-vip, 8 years ago

see #12229 - add junit timeout. Even if audio unit tests can be run in headless mode on my machine, Jenkins does not like this test...

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