blob: e74aa132da8542b52f01386234f8d8010281f045 [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()
Bram Moolenaar9b283522019-06-17 22:19:33 +020013 if has('win32')
14 throw 'Skipped: Playing event with callback is not supported on Windows'
15 endif
16
Bram Moolenaar427f5b62019-06-09 13:43:51 +020017 let id = sound_playevent('bell', 'PlayCallback')
18 if id == 0
19 throw 'Skipped: bell event not available'
20 endif
21 " Stop it quickly, avoid annoying the user.
22 sleep 20m
23 call sound_stop(id)
24 sleep 20m
25 call assert_equal(id, g:id)
26 call assert_equal(1, g:result) " sound was aborted
27endfunc
28
29func Test_play_silent()
30 let fname = fnamemodify('silent.wav', '%p')
31
32 " play without callback
33 let id1 = sound_playfile(fname)
Bram Moolenaar541faf72019-06-09 15:35:41 +020034 if id1 == 0
35 throw 'Skipped: playing a sound is not working'
36 endif
Bram Moolenaar427f5b62019-06-09 13:43:51 +020037
38 " play until the end
39 let id2 = sound_playfile(fname, 'PlayCallback')
40 call assert_true(id2 > 0)
41 sleep 500m
42 call assert_equal(id2, g:id)
43 call assert_equal(0, g:result)
44
45 let id2 = sound_playfile(fname, 'PlayCallback')
46 call assert_true(id2 > 0)
47 sleep 20m
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +020048 call sound_clear()
Bram Moolenaar427f5b62019-06-09 13:43:51 +020049 call assert_equal(id2, g:id)
50 call assert_equal(1, g:result)
51endfunc