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() |
Bram Moolenaar | 9b28352 | 2019-06-17 22:19:33 +0200 | [diff] [blame] | 13 | if has('win32') |
| 14 | throw 'Skipped: Playing event with callback is not supported on Windows' |
| 15 | endif |
| 16 | |
Bram Moolenaar | 427f5b6 | 2019-06-09 13:43:51 +0200 | [diff] [blame] | 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 |
| 27 | endfunc |
| 28 | |
| 29 | func Test_play_silent() |
| 30 | let fname = fnamemodify('silent.wav', '%p') |
| 31 | |
| 32 | " play without callback |
| 33 | let id1 = sound_playfile(fname) |
Bram Moolenaar | 541faf7 | 2019-06-09 15:35:41 +0200 | [diff] [blame] | 34 | if id1 == 0 |
| 35 | throw 'Skipped: playing a sound is not working' |
| 36 | endif |
Bram Moolenaar | 427f5b6 | 2019-06-09 13:43:51 +0200 | [diff] [blame] | 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 |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 48 | call sound_clear() |
Bram Moolenaar | 427f5b6 | 2019-06-09 13:43:51 +0200 | [diff] [blame] | 49 | call assert_equal(id2, g:id) |
| 50 | call assert_equal(1, g:result) |
| 51 | endfunc |