Bram Moolenaar | 427f5b6 | 2019-06-09 13:43:51 +0200 | [diff] [blame] | 1 | " Tests for the sound feature |
| 2 | |
| 3 | if !has('sound') |
| 4 | throw 'Skipped: sound feature not available' |
| 5 | endif |
| 6 | |
| 7 | func PlayCallback(id, result) |
| 8 | let g:id = a:id |
| 9 | let g:result = a:result |
| 10 | endfunc |
| 11 | |
| 12 | func 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 |
| 23 | endfunc |
| 24 | |
| 25 | func Test_play_silent() |
| 26 | let fname = fnamemodify('silent.wav', '%p') |
| 27 | |
| 28 | " play without callback |
| 29 | let id1 = sound_playfile(fname) |
| 30 | call assert_true(id1 > 0) |
| 31 | |
| 32 | " play until the end |
| 33 | let id2 = sound_playfile(fname, 'PlayCallback') |
| 34 | call assert_true(id2 > 0) |
| 35 | sleep 500m |
| 36 | call assert_equal(id2, g:id) |
| 37 | call assert_equal(0, g:result) |
| 38 | |
| 39 | let id2 = sound_playfile(fname, 'PlayCallback') |
| 40 | call assert_true(id2 > 0) |
| 41 | sleep 20m |
| 42 | call sound_stopall() |
| 43 | call assert_equal(id2, g:id) |
| 44 | call assert_equal(1, g:result) |
| 45 | endfunc |