annotate src/testdir/test_sound.vim @ 35172:c98f002b1fe4 default tip

runtime(doc): fix typo in usr_52.txt Commit: https://github.com/vim/vim/commit/b7258738f80f26be302a84a99f968b3bdc2f29bb Author: Christian Brabandt <cb@256bit.org> Date: Sun May 12 19:04:47 2024 +0200 runtime(doc): fix typo in usr_52.txt fixes: https://github.com/vim/vim/issues/14758 Signed-off-by: Christian Brabandt <cb@256bit.org>
author Christian Brabandt <cb@256bit.org>
date Sun, 12 May 2024 19:15:08 +0200
parents 9ecae383d568
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
17004
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1 " Tests for the sound feature
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2
24824
a9ffc9154b32 patch 8.2.2950: sound code not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 23118
diff changeset
3 source check.vim
23118
24326797a9aa patch 8.2.2105: sound test is a bit flaky
Bram Moolenaar <Bram@vim.org>
parents: 21765
diff changeset
4 source shared.vim
24326797a9aa patch 8.2.2105: sound test is a bit flaky
Bram Moolenaar <Bram@vim.org>
parents: 21765
diff changeset
5
24824
a9ffc9154b32 patch 8.2.2950: sound code not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 23118
diff changeset
6 CheckFeature sound
17004
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8 func PlayCallback(id, result)
24824
a9ffc9154b32 patch 8.2.2950: sound code not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 23118
diff changeset
9 let g:playcallback_count += 1
17004
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10 let g:id = a:id
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
11 let g:result = a:result
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
12 endfunc
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
13
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
14 func Test_play_event()
17131
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
15 if has('win32')
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
16 throw 'Skipped: Playing event with callback is not supported on Windows'
be5a5cfc991a patch 8.1.1565: MS-Windows: no sound support
Bram Moolenaar <Bram@vim.org>
parents: 17026
diff changeset
17 endif
34795
9ecae383d568 patch 9.1.0271: CI sound test aborts with undefined variable
Christian Brabandt <cb@256bit.org>
parents: 34349
diff changeset
18 let g:result = 0
24824
a9ffc9154b32 patch 8.2.2950: sound code not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 23118
diff changeset
19 let g:playcallback_count = 0
23118
24326797a9aa patch 8.2.2105: sound test is a bit flaky
Bram Moolenaar <Bram@vim.org>
parents: 21765
diff changeset
20 let g:id = 0
30719
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 24842
diff changeset
21 let event_name = 'bell'
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 24842
diff changeset
22 if has('osx')
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 24842
diff changeset
23 let event_name = 'Tink'
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 24842
diff changeset
24 endif
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 24842
diff changeset
25 let id = event_name->sound_playevent('PlayCallback')
17004
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
26 if id == 0
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
27 throw 'Skipped: bell event not available'
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
28 endif
24824
a9ffc9154b32 patch 8.2.2950: sound code not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 23118
diff changeset
29
17004
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
30 " Stop it quickly, avoid annoying the user.
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
31 sleep 20m
18017
988e5a868b60 patch 8.1.2004: more functions can be used as methods
Bram Moolenaar <Bram@vim.org>
parents: 17708
diff changeset
32 eval id->sound_stop()
23118
24326797a9aa patch 8.2.2105: sound test is a bit flaky
Bram Moolenaar <Bram@vim.org>
parents: 21765
diff changeset
33 call WaitForAssert({-> assert_equal(id, g:id)})
17004
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
34 call assert_equal(1, g:result) " sound was aborted
24824
a9ffc9154b32 patch 8.2.2950: sound code not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 23118
diff changeset
35 call assert_equal(1, g:playcallback_count)
17004
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
36 endfunc
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
37
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
38 func Test_play_silent()
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
39 let fname = fnamemodify('silent.wav', '%p')
24824
a9ffc9154b32 patch 8.2.2950: sound code not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 23118
diff changeset
40 let g:playcallback_count = 0
34795
9ecae383d568 patch 9.1.0271: CI sound test aborts with undefined variable
Christian Brabandt <cb@256bit.org>
parents: 34349
diff changeset
41 let g:result = -1
17004
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
42
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
43 " play without callback
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
44 let id1 = sound_playfile(fname)
17016
b99b33f8475b patch 8.1.1508: sound keeps failing on Travis
Bram Moolenaar <Bram@vim.org>
parents: 17004
diff changeset
45 if id1 == 0
b99b33f8475b patch 8.1.1508: sound keeps failing on Travis
Bram Moolenaar <Bram@vim.org>
parents: 17004
diff changeset
46 throw 'Skipped: playing a sound is not working'
b99b33f8475b patch 8.1.1508: sound keeps failing on Travis
Bram Moolenaar <Bram@vim.org>
parents: 17004
diff changeset
47 endif
17004
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
48
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
49 " play until the end
18017
988e5a868b60 patch 8.1.2004: more functions can be used as methods
Bram Moolenaar <Bram@vim.org>
parents: 17708
diff changeset
50 let id2 = fname->sound_playfile('PlayCallback')
17004
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
51 call assert_true(id2 > 0)
23118
24326797a9aa patch 8.2.2105: sound test is a bit flaky
Bram Moolenaar <Bram@vim.org>
parents: 21765
diff changeset
52 call WaitForAssert({-> assert_equal(id2, g:id)})
17004
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
53 call assert_equal(0, g:result)
24824
a9ffc9154b32 patch 8.2.2950: sound code not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 23118
diff changeset
54 call assert_equal(1, g:playcallback_count)
17004
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
55
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
56 let id2 = sound_playfile(fname, 'PlayCallback')
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
57 call assert_true(id2 > 0)
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
58 sleep 20m
17026
905e1b154058 patch 8.1.1513: all popup functionality is in functions, except :popupclear
Bram Moolenaar <Bram@vim.org>
parents: 17016
diff changeset
59 call sound_clear()
23118
24326797a9aa patch 8.2.2105: sound test is a bit flaky
Bram Moolenaar <Bram@vim.org>
parents: 21765
diff changeset
60 call WaitForAssert({-> assert_equal(id2, g:id)})
24326797a9aa patch 8.2.2105: sound test is a bit flaky
Bram Moolenaar <Bram@vim.org>
parents: 21765
diff changeset
61 call assert_equal(1, g:result) " sound was aborted
24824
a9ffc9154b32 patch 8.2.2950: sound code not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 23118
diff changeset
62 call assert_equal(2, g:playcallback_count)
a9ffc9154b32 patch 8.2.2950: sound code not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 23118
diff changeset
63
a9ffc9154b32 patch 8.2.2950: sound code not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 23118
diff changeset
64 " Play 2 sounds almost at the same time to exercise
a9ffc9154b32 patch 8.2.2950: sound code not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 23118
diff changeset
65 " code with multiple callbacks in the callback list.
a9ffc9154b32 patch 8.2.2950: sound code not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 23118
diff changeset
66 call sound_playfile(fname, 'PlayCallback')
a9ffc9154b32 patch 8.2.2950: sound code not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 23118
diff changeset
67 call sound_playfile(fname, 'PlayCallback')
a9ffc9154b32 patch 8.2.2950: sound code not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 23118
diff changeset
68 call WaitForAssert({-> assert_equal(4, g:playcallback_count)})
17708
10696f279e20 patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents: 17131
diff changeset
69
10696f279e20 patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents: 17131
diff changeset
70 " recursive use was causing a crash
10696f279e20 patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents: 17131
diff changeset
71 func PlayAgain(id, fname)
10696f279e20 patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents: 17131
diff changeset
72 let g:id = a:id
10696f279e20 patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents: 17131
diff changeset
73 let g:id_again = sound_playfile(a:fname)
10696f279e20 patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents: 17131
diff changeset
74 endfunc
10696f279e20 patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents: 17131
diff changeset
75
10696f279e20 patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents: 17131
diff changeset
76 let id3 = sound_playfile(fname, {id, res -> PlayAgain(id, fname)})
10696f279e20 patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents: 17131
diff changeset
77 call assert_true(id3 > 0)
10696f279e20 patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents: 17131
diff changeset
78 sleep 50m
10696f279e20 patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents: 17131
diff changeset
79 call sound_clear()
23118
24326797a9aa patch 8.2.2105: sound test is a bit flaky
Bram Moolenaar <Bram@vim.org>
parents: 21765
diff changeset
80 call WaitForAssert({-> assert_true(g:id > 0)})
17004
353ed7ef78df patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
81 endfunc
21765
08940efa6b4e patch 8.2.1432: various inconsistencies in test files
Bram Moolenaar <Bram@vim.org>
parents: 18017
diff changeset
82
24824
a9ffc9154b32 patch 8.2.2950: sound code not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 23118
diff changeset
83 func Test_play_event_error()
24842
237dace53473 patch 8.2.2959: sound_playfile() is not tested on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 24824
diff changeset
84 " FIXME: sound_playevent() doesn't return 0 in case of error on Windows.
237dace53473 patch 8.2.2959: sound_playfile() is not tested on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 24824
diff changeset
85 if !has('win32')
237dace53473 patch 8.2.2959: sound_playfile() is not tested on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 24824
diff changeset
86 call assert_equal(0, sound_playevent(''))
237dace53473 patch 8.2.2959: sound_playfile() is not tested on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 24824
diff changeset
87 call assert_equal(0, sound_playevent(test_null_string()))
237dace53473 patch 8.2.2959: sound_playfile() is not tested on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 24824
diff changeset
88 call assert_equal(0, sound_playevent('doesnotexist'))
237dace53473 patch 8.2.2959: sound_playfile() is not tested on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 24824
diff changeset
89 call assert_equal(0, sound_playevent('doesnotexist', 'doesnotexist'))
237dace53473 patch 8.2.2959: sound_playfile() is not tested on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 24824
diff changeset
90 call assert_equal(0, sound_playevent(test_null_string(), test_null_string()))
237dace53473 patch 8.2.2959: sound_playfile() is not tested on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 24824
diff changeset
91 call assert_equal(0, sound_playevent(test_null_string(), test_null_function()))
237dace53473 patch 8.2.2959: sound_playfile() is not tested on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 24824
diff changeset
92 endif
24824
a9ffc9154b32 patch 8.2.2950: sound code not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 23118
diff changeset
93
a9ffc9154b32 patch 8.2.2950: sound code not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 23118
diff changeset
94 call assert_equal(0, sound_playfile(''))
a9ffc9154b32 patch 8.2.2950: sound code not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 23118
diff changeset
95 call assert_equal(0, sound_playfile(test_null_string()))
a9ffc9154b32 patch 8.2.2950: sound code not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 23118
diff changeset
96 call assert_equal(0, sound_playfile('doesnotexist'))
a9ffc9154b32 patch 8.2.2950: sound code not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 23118
diff changeset
97 call assert_equal(0, sound_playfile('doesnotexist', 'doesnotexist'))
a9ffc9154b32 patch 8.2.2950: sound code not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 23118
diff changeset
98 call assert_equal(0, sound_playfile(test_null_string(), test_null_string()))
a9ffc9154b32 patch 8.2.2950: sound code not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 23118
diff changeset
99 call assert_equal(0, sound_playfile(test_null_string(), test_null_function()))
a9ffc9154b32 patch 8.2.2950: sound code not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 23118
diff changeset
100 endfunc
a9ffc9154b32 patch 8.2.2950: sound code not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 23118
diff changeset
101
21765
08940efa6b4e patch 8.2.1432: various inconsistencies in test files
Bram Moolenaar <Bram@vim.org>
parents: 18017
diff changeset
102 " vim: shiftwidth=2 sts=2 expandtab