Skip to content

Commit c64ed2b

Browse files
dpellebrammool
authored andcommitted
patch 8.2.2950: sound code not fully tested
Problem: Sound code not fully tested. Solution: Add more sound tests. (Dominique Pellé, closes #8332)
1 parent 3cfa5b1 commit c64ed2b

2 files changed

Lines changed: 38 additions & 3 deletions

File tree

src/testdir/test_sound.vim

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
" Tests for the sound feature
22

3+
source check.vim
34
source shared.vim
45

5-
if !has('sound')
6-
throw 'Skipped: sound feature not available'
7-
endif
6+
CheckFeature sound
87

98
func PlayCallback(id, result)
9+
let g:playcallback_count += 1
1010
let g:id = a:id
1111
let g:result = a:result
1212
endfunc
@@ -15,20 +15,24 @@ func Test_play_event()
1515
if has('win32')
1616
throw 'Skipped: Playing event with callback is not supported on Windows'
1717
endif
18+
let g:playcallback_count = 0
1819
let g:id = 0
1920
let id = 'bell'->sound_playevent('PlayCallback')
2021
if id == 0
2122
throw 'Skipped: bell event not available'
2223
endif
24+
2325
" Stop it quickly, avoid annoying the user.
2426
sleep 20m
2527
eval id->sound_stop()
2628
call WaitForAssert({-> assert_equal(id, g:id)})
2729
call assert_equal(1, g:result) " sound was aborted
30+
call assert_equal(1, g:playcallback_count)
2831
endfunc
2932

3033
func Test_play_silent()
3134
let fname = fnamemodify('silent.wav', '%p')
35+
let g:playcallback_count = 0
3236

3337
" play without callback
3438
let id1 = sound_playfile(fname)
@@ -41,13 +45,21 @@ func Test_play_silent()
4145
call assert_true(id2 > 0)
4246
call WaitForAssert({-> assert_equal(id2, g:id)})
4347
call assert_equal(0, g:result)
48+
call assert_equal(1, g:playcallback_count)
4449

4550
let id2 = sound_playfile(fname, 'PlayCallback')
4651
call assert_true(id2 > 0)
4752
sleep 20m
4853
call sound_clear()
4954
call WaitForAssert({-> assert_equal(id2, g:id)})
5055
call assert_equal(1, g:result) " sound was aborted
56+
call assert_equal(2, g:playcallback_count)
57+
58+
" Play 2 sounds almost at the same time to exercise
59+
" code with multiple callbacks in the callback list.
60+
call sound_playfile(fname, 'PlayCallback')
61+
call sound_playfile(fname, 'PlayCallback')
62+
call WaitForAssert({-> assert_equal(4, g:playcallback_count)})
5163

5264
" recursive use was causing a crash
5365
func PlayAgain(id, fname)
@@ -62,4 +74,25 @@ func Test_play_silent()
6274
call WaitForAssert({-> assert_true(g:id > 0)})
6375
endfunc
6476

77+
func Test_play_event_error()
78+
" Do not run test on Windows as:
79+
" - playing event with callback is not supported on Windows.
80+
" - FIXME: even without callback, sound_playevent('') does not return 0 on Windows. Bug?
81+
CheckNotMSWindows
82+
83+
call assert_equal(0, sound_playevent(''))
84+
call assert_equal(0, sound_playevent(test_null_string()))
85+
call assert_equal(0, sound_playevent('doesnotexist'))
86+
call assert_equal(0, sound_playevent('doesnotexist', 'doesnotexist'))
87+
call assert_equal(0, sound_playevent(test_null_string(), test_null_string()))
88+
call assert_equal(0, sound_playevent(test_null_string(), test_null_function()))
89+
90+
call assert_equal(0, sound_playfile(''))
91+
call assert_equal(0, sound_playfile(test_null_string()))
92+
call assert_equal(0, sound_playfile('doesnotexist'))
93+
call assert_equal(0, sound_playfile('doesnotexist', 'doesnotexist'))
94+
call assert_equal(0, sound_playfile(test_null_string(), test_null_string()))
95+
call assert_equal(0, sound_playfile(test_null_string(), test_null_function()))
96+
endfunc
97+
6598
" vim: shiftwidth=2 sts=2 expandtab

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,8 @@ static char *(features[]) =
750750

751751
static int included_patches[] =
752752
{ /* Add new patch number below this line */
753+
/**/
754+
2950,
753755
/**/
754756
2949,
755757
/**/

0 commit comments

Comments
 (0)