blob: 54c6a29dbe3595249e78d88a7d158bd7eed4db39 [file] [log] [blame]
Bram Moolenaar427f5b62019-06-09 13:43:51 +02001" Tests for the sound feature
2
3if !has('sound')
4 throw 'Skipped: sound feature not available'
5endif
6
7func PlayCallback(id, result)
8 let g:id = a:id
9 let g:result = a:result
10endfunc
11
12func Test_play_event()
13 let id = sound_playevent('bell', 'PlayCallback')
14 if id == 0
15 throw 'Skipped: bell event not available'
16 endif
17 " Stop it quickly, avoid annoying the user.
18 sleep 20m
19 call sound_stop(id)
20 sleep 20m
21 call assert_equal(id, g:id)
22 call assert_equal(1, g:result) " sound was aborted
23endfunc
24
25func Test_play_silent()
26 let fname = fnamemodify('silent.wav', '%p')
27
28 " play without callback
29 let id1 = sound_playfile(fname)
30 call assert_true(id1 > 0)
31
32 " play until the end
33 let id2 = sound_playfile(fname, 'PlayCallback')
34 call assert_true(id2 > 0)
35 sleep 500m
36 call assert_equal(id2, g:id)
37 call assert_equal(0, g:result)
38
39 let id2 = sound_playfile(fname, 'PlayCallback')
40 call assert_true(id2 > 0)
41 sleep 20m
42 call sound_stopall()
43 call assert_equal(id2, g:id)
44 call assert_equal(1, g:result)
45endfunc