blob: 1a9ffb5682cea27f571916d3c4f40939331da0f1 [file] [log] [blame]
Bram Moolenaar427f5b62019-06-09 13:43:51 +02001" 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()
Bram Moolenaar9b283522019-06-17 22:19:33 +020013 if has('win32')
14 throw 'Skipped: Playing event with callback is not supported on Windows'
15 endif
Bram Moolenaarf6ed61e2019-09-07 19:05:09 +020016 let id = 'bell'->sound_playevent('PlayCallback')
Bram Moolenaar427f5b62019-06-09 13:43:51 +020017 if id == 0
18 throw 'Skipped: bell event not available'
19 endif
20 " Stop it quickly, avoid annoying the user.
21 sleep 20m
Bram Moolenaarf6ed61e2019-09-07 19:05:09 +020022 eval id->sound_stop()
Bram Moolenaar28e67e02019-08-15 23:05:49 +020023 sleep 30m
Bram Moolenaar427f5b62019-06-09 13:43:51 +020024 call assert_equal(id, g:id)
25 call assert_equal(1, g:result) " sound was aborted
26endfunc
27
28func Test_play_silent()
29 let fname = fnamemodify('silent.wav', '%p')
30
31 " play without callback
32 let id1 = sound_playfile(fname)
Bram Moolenaar541faf72019-06-09 15:35:41 +020033 if id1 == 0
34 throw 'Skipped: playing a sound is not working'
35 endif
Bram Moolenaar427f5b62019-06-09 13:43:51 +020036
37 " play until the end
Bram Moolenaarf6ed61e2019-09-07 19:05:09 +020038 let id2 = fname->sound_playfile('PlayCallback')
Bram Moolenaar427f5b62019-06-09 13:43:51 +020039 call assert_true(id2 > 0)
40 sleep 500m
41 call assert_equal(id2, g:id)
42 call assert_equal(0, g:result)
43
44 let id2 = sound_playfile(fname, 'PlayCallback')
45 call assert_true(id2 > 0)
46 sleep 20m
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +020047 call sound_clear()
Bram Moolenaar28e67e02019-08-15 23:05:49 +020048 sleep 30m
Bram Moolenaar427f5b62019-06-09 13:43:51 +020049 call assert_equal(id2, g:id)
50 call assert_equal(1, g:result)
Bram Moolenaar28e67e02019-08-15 23:05:49 +020051
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)
Bram Moolenaar427f5b62019-06-09 13:43:51 +020064endfunc
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +020065
66" vim: shiftwidth=2 sts=2 expandtab