blob: e47c677e99f6608a97605c7bd5b4e88dcef99c4c [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)
Bram Moolenaar541faf72019-06-09 15:35:41 +020030 if id1 == 0
31 throw 'Skipped: playing a sound is not working'
32 endif
Bram Moolenaar427f5b62019-06-09 13:43:51 +020033
34 " play until the end
35 let id2 = sound_playfile(fname, 'PlayCallback')
36 call assert_true(id2 > 0)
37 sleep 500m
38 call assert_equal(id2, g:id)
39 call assert_equal(0, g:result)
40
41 let id2 = sound_playfile(fname, 'PlayCallback')
42 call assert_true(id2 > 0)
43 sleep 20m
44 call sound_stopall()
45 call assert_equal(id2, g:id)
46 call assert_equal(1, g:result)
47endfunc