Mercurial > vim
annotate src/testdir/test_sound.vim @ 32232:daef00e8d99f v9.0.1447
patch 9.0.1447: condition is always true
Commit: https://github.com/vim/vim/commit/474891bc89e657100bd37c29129451a0e601879d
Author: zeertzjq <zeertzjq@outlook.com>
Date: Wed Apr 12 21:36:03 2023 +0100
patch 9.0.1447: condition is always true
Problem: Condition is always true.
Solution: Remove the useless condition. (closes https://github.com/vim/vim/issues/12253)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Wed, 12 Apr 2023 22:45:03 +0200 |
parents | 71137f73c94d |
children | 70c1a9c6f41d |
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 |
24824
a9ffc9154b32
patch 8.2.2950: sound code not fully tested
Bram Moolenaar <Bram@vim.org>
parents:
23118
diff
changeset
|
18 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
|
19 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
|
20 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
|
21 if has('osx') |
71137f73c94d
patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents:
24842
diff
changeset
|
22 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
|
23 endif |
71137f73c94d
patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents:
24842
diff
changeset
|
24 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
|
25 if id == 0 |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
26 throw 'Skipped: bell event not available' |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
27 endif |
24824
a9ffc9154b32
patch 8.2.2950: sound code not fully tested
Bram Moolenaar <Bram@vim.org>
parents:
23118
diff
changeset
|
28 |
17004
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
29 " Stop it quickly, avoid annoying the user. |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
30 sleep 20m |
18017
988e5a868b60
patch 8.1.2004: more functions can be used as methods
Bram Moolenaar <Bram@vim.org>
parents:
17708
diff
changeset
|
31 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
|
32 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
|
33 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
|
34 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
|
35 endfunc |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
36 |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
37 func Test_play_silent() |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
38 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
|
39 let g:playcallback_count = 0 |
17004
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
40 |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
41 " play without callback |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
42 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
|
43 if id1 == 0 |
b99b33f8475b
patch 8.1.1508: sound keeps failing on Travis
Bram Moolenaar <Bram@vim.org>
parents:
17004
diff
changeset
|
44 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
|
45 endif |
17004
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
46 |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
47 " 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
|
48 let id2 = fname->sound_playfile('PlayCallback') |
17004
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
49 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
|
50 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
|
51 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
|
52 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
|
53 |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
54 let id2 = sound_playfile(fname, 'PlayCallback') |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
55 call assert_true(id2 > 0) |
353ed7ef78df
patch 8.1.1502: cannot play any sound
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
56 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
|
57 call sound_clear() |
23118
24326797a9aa
patch 8.2.2105: sound test is a bit flaky
Bram Moolenaar <Bram@vim.org>
parents:
21765
diff
changeset
|
58 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
|
59 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
|
60 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
|
61 |
a9ffc9154b32
patch 8.2.2950: sound code not fully tested
Bram Moolenaar <Bram@vim.org>
parents:
23118
diff
changeset
|
62 " 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
|
63 " 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
|
64 call sound_playfile(fname, 'PlayCallback') |
a9ffc9154b32
patch 8.2.2950: sound code not fully tested
Bram Moolenaar <Bram@vim.org>
parents:
23118
diff
changeset
|
65 call sound_playfile(fname, 'PlayCallback') |
a9ffc9154b32
patch 8.2.2950: sound code not fully tested
Bram Moolenaar <Bram@vim.org>
parents:
23118
diff
changeset
|
66 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
|
67 |
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17131
diff
changeset
|
68 " 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
|
69 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
|
70 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
|
71 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
|
72 endfunc |
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17131
diff
changeset
|
73 |
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17131
diff
changeset
|
74 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
|
75 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
|
76 sleep 50m |
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17131
diff
changeset
|
77 call sound_clear() |
23118
24326797a9aa
patch 8.2.2105: sound test is a bit flaky
Bram Moolenaar <Bram@vim.org>
parents:
21765
diff
changeset
|
78 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
|
79 endfunc |
21765
08940efa6b4e
patch 8.2.1432: various inconsistencies in test files
Bram Moolenaar <Bram@vim.org>
parents:
18017
diff
changeset
|
80 |
24824
a9ffc9154b32
patch 8.2.2950: sound code not fully tested
Bram Moolenaar <Bram@vim.org>
parents:
23118
diff
changeset
|
81 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
|
82 " 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
|
83 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
|
84 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
|
85 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
|
86 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
|
87 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
|
88 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
|
89 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
|
90 endif |
24824
a9ffc9154b32
patch 8.2.2950: sound code not fully tested
Bram Moolenaar <Bram@vim.org>
parents:
23118
diff
changeset
|
91 |
a9ffc9154b32
patch 8.2.2950: sound code not fully tested
Bram Moolenaar <Bram@vim.org>
parents:
23118
diff
changeset
|
92 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
|
93 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
|
94 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
|
95 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
|
96 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
|
97 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
|
98 endfunc |
a9ffc9154b32
patch 8.2.2950: sound code not fully tested
Bram Moolenaar <Bram@vim.org>
parents:
23118
diff
changeset
|
99 |
21765
08940efa6b4e
patch 8.2.1432: various inconsistencies in test files
Bram Moolenaar <Bram@vim.org>
parents:
18017
diff
changeset
|
100 " vim: shiftwidth=2 sts=2 expandtab |