comparison src/testdir/test_sound.vim @ 17708:10696f279e20 v8.1.1851

patch 8.1.1851: crash when sound_playfile() callback plays sound commit https://github.com/vim/vim/commit/28e67e0c1496b7bb166a0acfb176690f219101ca Author: Bram Moolenaar <Bram@vim.org> Date: Thu Aug 15 23:05:49 2019 +0200 patch 8.1.1851: crash when sound_playfile() callback plays sound Problem: Crash when sound_playfile() callback plays sound. Solution: Invoke callback later from event loop.
author Bram Moolenaar <Bram@vim.org>
date Thu, 15 Aug 2019 23:15:04 +0200
parents be5a5cfc991a
children 988e5a868b60
comparison
equal deleted inserted replaced
17707:bf211be8ffd1 17708:10696f279e20
11 11
12 func Test_play_event() 12 func Test_play_event()
13 if has('win32') 13 if has('win32')
14 throw 'Skipped: Playing event with callback is not supported on Windows' 14 throw 'Skipped: Playing event with callback is not supported on Windows'
15 endif 15 endif
16
17 let id = sound_playevent('bell', 'PlayCallback') 16 let id = sound_playevent('bell', 'PlayCallback')
18 if id == 0 17 if id == 0
19 throw 'Skipped: bell event not available' 18 throw 'Skipped: bell event not available'
20 endif 19 endif
21 " Stop it quickly, avoid annoying the user. 20 " Stop it quickly, avoid annoying the user.
22 sleep 20m 21 sleep 20m
23 call sound_stop(id) 22 call sound_stop(id)
24 sleep 20m 23 sleep 30m
25 call assert_equal(id, g:id) 24 call assert_equal(id, g:id)
26 call assert_equal(1, g:result) " sound was aborted 25 call assert_equal(1, g:result) " sound was aborted
27 endfunc 26 endfunc
28 27
29 func Test_play_silent() 28 func Test_play_silent()
44 43
45 let id2 = sound_playfile(fname, 'PlayCallback') 44 let id2 = sound_playfile(fname, 'PlayCallback')
46 call assert_true(id2 > 0) 45 call assert_true(id2 > 0)
47 sleep 20m 46 sleep 20m
48 call sound_clear() 47 call sound_clear()
48 sleep 30m
49 call assert_equal(id2, g:id) 49 call assert_equal(id2, g:id)
50 call assert_equal(1, g:result) 50 call assert_equal(1, g:result)
51
52 " recursive use was causing a crash
53 func PlayAgain(id, fname)
54 let g:id = a:id
55 let g:id_again = sound_playfile(a:fname)
56 endfunc
57
58 let id3 = sound_playfile(fname, {id, res -> PlayAgain(id, fname)})
59 call assert_true(id3 > 0)
60 sleep 50m
61 call sound_clear()
62 sleep 30m
63 call assert_true(g:id_again > 0)
51 endfunc 64 endfunc