xref: /vim-8.2.3635/src/testdir/test_sound.vim (revision fcfe1a9b)
1" 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  if has('win32')
14    throw 'Skipped: Playing event with callback is not supported on Windows'
15  endif
16
17  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)
34  if id1 == 0
35    throw 'Skipped: playing a sound is not working'
36  endif
37
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
48  call sound_clear()
49  call assert_equal(id2, g:id)
50  call assert_equal(1, g:result)
51endfunc
52