blob: 77e4f2e9a6cc169ee3b0560667006076f6e966d9 [file] [log] [blame]
Bram Moolenaar877e9572016-08-04 20:05:50 +02001" Tests specifically for the GUI
2
3if !has('gui') || ($DISPLAY == "" && !has('gui_running'))
4 finish
5endif
6
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +01007source setup_gui.vim
Bram Moolenaar13c724f2017-02-05 20:54:26 +01008
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +01009func Setup()
10 call GUISetUpCommon()
Bram Moolenaar50fa8dd2016-08-09 22:58:21 +020011endfunc
12
13func TearDown()
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +010014 call GUITearDownCommon()
Bram Moolenaar877e9572016-08-04 20:05:50 +020015endfunc
16
17" Test for resetting "secure" flag after GUI has started.
18" Must be run first.
19func Test_1_set_secure()
20 set exrc secure
21 gui -f
22 call assert_equal(1, has('gui_running'))
23endfunc
24
Bram Moolenaar6f785742017-02-06 22:11:55 +010025func Test_getfontname_with_arg()
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +010026 let skipped = ''
27
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +010028 if !g:x11_based_gui
29 let skipped = g:not_implemented
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +010030 elseif has('gui_athena') || has('gui_motif')
Bram Moolenaar6f785742017-02-06 22:11:55 +010031 " Invalid font name. The result should be an empty string.
32 call assert_equal('', getfontname('notexist'))
33
34 " Valid font name. This is usually the real name of 7x13 by default.
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +010035 let fname = '-misc-fixed-medium-r-normal--13-120-75-75-c-70-iso8859-1'
36 call assert_equal(fname, getfontname(fname))
Bram Moolenaar6f785742017-02-06 22:11:55 +010037
38 elseif has('gui_gtk2') || has('gui_gnome') || has('gui_gtk3')
39 " Invalid font name. The result should be the name plus the default size.
40 call assert_equal('notexist 10', getfontname('notexist'))
41
42 " Valid font name. This is usually the real name of Monospace by default.
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +010043 let fname = 'Bitstream Vera Sans Mono 12'
44 call assert_equal(fname, getfontname(fname))
45 endif
46
47 if !empty(skipped)
48 throw skipped
Bram Moolenaar6f785742017-02-06 22:11:55 +010049 endif
50endfunc
51
52func Test_getfontname_without_arg()
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +010053 let skipped = ''
54
55 let fname = getfontname()
56
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +010057 if !g:x11_based_gui
58 let skipped = g:not_implemented
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +010059 elseif has('gui_kde')
Bram Moolenaar6f785742017-02-06 22:11:55 +010060 " 'expected' is the value specified by SetUp() above.
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +010061 call assert_equal('Courier 10 Pitch/8/-1/5/50/0/0/0/0/0', fname)
Bram Moolenaar6f785742017-02-06 22:11:55 +010062 elseif has('gui_athena') || has('gui_motif')
63 " 'expected' is DFLT_FONT of gui_x11.c.
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +010064 call assert_equal('7x13', fname)
Bram Moolenaar6f785742017-02-06 22:11:55 +010065 elseif has('gui_gtk2') || has('gui_gnome') || has('gui_gtk3')
66 " 'expected' is DEFAULT_FONT of gui_gtk_x11.c.
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +010067 call assert_equal('Monospace 10', fname)
68 endif
69
70 if !empty(skipped)
71 throw skipped
Bram Moolenaar6f785742017-02-06 22:11:55 +010072 endif
73endfunc
74
Bram Moolenaar5074a0e2017-02-26 15:08:21 +010075func Test_quoteplus()
76 let skipped = ''
77
78 if !g:x11_based_gui
79 let skipped = g:not_supported . 'quoteplus'
80 else
81 let quoteplus_saved = @+
82
83 let test_call = 'Can you hear me?'
84 let test_response = 'Yes, I can.'
85 let vim_exe = exepath(v:progpath)
86 let testee = 'VIMRUNTIME=' . $VIMRUNTIME . '; export VIMRUNTIME;'
87 \ . vim_exe . ' -f -g -u NONE -U NONE --noplugin -c ''%s'''
88 let cmd = 'call feedkeys("'
89 \ . '\"+p'
90 \ . ':s/' . test_call . '/' . test_response . '/\<CR>'
91 \ . '\"+yis'
92 \ . ':q!\<CR>", "tx")'
93 let run_vimtest = printf(testee, cmd)
94
95 " Set the quoteplus register to test_call, and another gvim will launched.
96 " Then, it first tries to paste the content of its own quotedplus register
97 " onto it. Second, it tries to substitute test_responce for the pasted
98 " sentence. If the sentence is identical to test_call, the substitution
99 " should succeed. Third, it tries to yank the result of the substitution
100 " to its own quoteplus register, and last it quits. When system()
101 " returns, the content of the quoteplus register should be identical to
102 " test_response if those quoteplus registers are synchronized properly
103 " with/through the X11 clipboard.
104 let @+ = test_call
105 call system(run_vimtest)
106 call assert_equal(test_response, @+)
107
108 let @+ = quoteplus_saved
109 endif
110
111 if !empty(skipped)
112 throw skipped
113 endif
114endfunc
115
Bram Moolenaar43dded82017-02-09 16:06:17 +0100116func Test_set_guifont()
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100117 let skipped = ''
118
119 let guifont_saved = &guifont
Bram Moolenaar43dded82017-02-09 16:06:17 +0100120 if has('xfontset')
121 " Prevent 'guifontset' from canceling 'guifont'.
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100122 let guifontset_saved = &guifontset
Bram Moolenaar43dded82017-02-09 16:06:17 +0100123 set guifontset=
124 endif
125
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +0100126 if !g:x11_based_gui
127 let skipped = g:not_implemented
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100128 elseif has('gui_athena') || has('gui_motif')
Bram Moolenaar43dded82017-02-09 16:06:17 +0100129 " Non-empty font list with invalid font names.
130 "
131 " This test is twofold: (1) It checks if the command fails as expected
132 " when there are no loadable fonts found in the list. (2) It checks if
133 " 'guifont' remains the same after the command loads none of the fonts
134 " listed.
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100135 let flist = &guifont
Bram Moolenaar43dded82017-02-09 16:06:17 +0100136 call assert_fails('set guifont=-notexist1-*,-notexist2-*')
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100137 call assert_equal(flist, &guifont)
Bram Moolenaar43dded82017-02-09 16:06:17 +0100138
139 " Non-empty font list with a valid font name. Should pick up the first
140 " valid font.
141 set guifont=-notexist1-*,fixed,-notexist2-*
142 call assert_equal('fixed', getfontname())
143
144 " Empty list. Should fallback to the built-in default.
145 set guifont=
146 call assert_equal('7x13', getfontname())
147
148 elseif has('gui_gtk2') || has('gui_gnome') || has('gui_gtk3')
149 " For GTK, what we refer to as 'font names' in our manual are actually
150 " 'initial font patterns'. A valid font which matches the 'canonical font
151 " pattern' constructed from a given 'initial pattern' is to be looked up
152 " and loaded. That explains why the GTK GUIs appear to accept 'invalid
153 " font names'.
154 "
155 " Non-empty list. Should always pick up the first element, no matter how
156 " strange it is, as explained above.
157 set guifont=(´・ω・`)\ 12,Courier\ 12
158 call assert_equal('(´・ω・`) 12', getfontname())
159
160 " Empty list. Should fallback to the built-in default.
161 set guifont=
162 call assert_equal('Monospace 10', getfontname())
Bram Moolenaar43dded82017-02-09 16:06:17 +0100163 endif
164
165 if has('xfontset')
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100166 let &guifontset = guifontset_saved
Bram Moolenaar43dded82017-02-09 16:06:17 +0100167 endif
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100168 let &guifont = guifont_saved
Bram Moolenaar43dded82017-02-09 16:06:17 +0100169
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100170 if !empty(skipped)
171 throw skipped
Bram Moolenaar43dded82017-02-09 16:06:17 +0100172 endif
173endfunc
174
Bram Moolenaar10434672017-02-12 19:59:08 +0100175func Test_set_guifontset()
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100176 let skipped = ''
Bram Moolenaar10434672017-02-12 19:59:08 +0100177
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100178 if !has('xfontset')
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +0100179 let skipped = g:not_supported . 'xfontset'
Bram Moolenaar10434672017-02-12 19:59:08 +0100180 else
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100181 let ctype_saved = v:ctype
182
183 " First, since XCreateFontSet(3) is very sensitive to locale, fonts must
184 " be chosen meticulously.
185 let font_head = '-misc-fixed-medium-r-normal--14'
186
187 let font_aw70 = font_head . '-130-75-75-c-70'
188 let font_aw140 = font_head . '-130-75-75-c-140'
189
190 let font_jisx0201 = font_aw70 . '-jisx0201.1976-0'
191 let font_jisx0208 = font_aw140 . '-jisx0208.1983-0'
192
193 let full_XLFDs = join([ font_jisx0208, font_jisx0201 ], ',')
194 let short_XLFDs = join([ font_aw140, font_aw70 ], ',')
195 let singleton = font_head . '-*'
196 let aliases = 'k14,r14'
197
198 " Second, among 'locales', look up such a locale that gets 'set
199 " guifontset=' to work successfully with every fontset specified with
200 " 'fontsets'.
201 let locales = [ 'ja_JP.UTF-8', 'ja_JP.eucJP', 'ja_JP.SJIS' ]
202 let fontsets = [ full_XLFDs, short_XLFDs, singleton, aliases ]
203
204 let feasible = 0
205 for locale in locales
206 try
207 exec 'language ctype' locale
208 catch /^Vim\%((\a\+)\)\=:E197/
209 continue
210 endtry
211 let done = 0
212 for fontset in fontsets
213 try
214 exec 'set guifontset=' . fontset
215 catch /^Vim\%((\a\+)\)\=:E\%(250\|252\|234\|597\|598\)/
216 break
217 endtry
218 let done += 1
219 endfor
220 if done == len(fontsets)
221 let feasible = 1
222 break
223 endif
224 endfor
225
226 " Third, give a set of tests if it is found feasible.
227 if !feasible
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +0100228 let skipped = g:not_hosted
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100229 else
230 " N.B. 'v:ctype' has already been set to an appropriate value in the
231 " previous loop.
232 for fontset in fontsets
233 exec 'set guifontset=' . fontset
234 call assert_equal(fontset, &guifontset)
235 endfor
236 endif
237
238 " Finally, restore ctype.
239 exec 'language ctype' ctype_saved
Bram Moolenaar10434672017-02-12 19:59:08 +0100240 endif
241
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100242 if !empty(skipped)
243 throw skipped
Bram Moolenaar10434672017-02-12 19:59:08 +0100244 endif
245endfunc
246
247func Test_set_guifontwide()
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100248 let skipped = ''
Bram Moolenaar10434672017-02-12 19:59:08 +0100249
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +0100250 if !g:x11_based_gui
251 let skipped = g:not_implemented
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100252 elseif has('gui_gtk')
253 let guifont_saved = &guifont
254 let guifontwide_saved = &guifontwide
Bram Moolenaar10434672017-02-12 19:59:08 +0100255
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100256 let fc_match = exepath('fc-match')
257 if empty(fc_match)
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +0100258 let skipped = g:not_hosted
Bram Moolenaar10434672017-02-12 19:59:08 +0100259 else
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100260 let &guifont = system('fc-match -f "%{family[0]} %{size}" monospace:size=10:lang=en')
261 let wide = system('fc-match -f "%{family[0]} %{size}" monospace:size=10:lang=ja')
262 exec 'set guifontwide=' . fnameescape(wide)
263 call assert_equal(wide, &guifontwide)
Bram Moolenaar10434672017-02-12 19:59:08 +0100264 endif
265
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100266 let &guifontwide = guifontwide_saved
267 let &guifont = guifont_saved
Bram Moolenaar10434672017-02-12 19:59:08 +0100268
269 elseif has('gui_athena') || has('gui_motif')
270 " guifontwide is premised upon the xfontset feature.
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100271 if !has('xfontset')
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +0100272 let skipped = g:not_supported . 'xfontset'
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100273 else
274 let encoding_saved = &encoding
275 let guifont_saved = &guifont
276 let guifontset_saved = &guifontset
277 let guifontwide_saved = &guifontwide
Bram Moolenaar10434672017-02-12 19:59:08 +0100278
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100279 let nfont = '-misc-fixed-medium-r-normal-*-18-120-100-100-c-90-iso10646-1'
280 let wfont = '-misc-fixed-medium-r-normal-*-18-120-100-100-c-180-iso10646-1'
Bram Moolenaar10434672017-02-12 19:59:08 +0100281
282 set encoding=utf-8
283
284 " Case 1: guifontset is empty
285 set guifontset=
286
287 " Case 1-1: Automatic selection
288 set guifontwide=
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100289 exec 'set guifont=' . nfont
290 call assert_equal(wfont, &guifontwide)
Bram Moolenaar10434672017-02-12 19:59:08 +0100291
292 " Case 1-2: Manual selection
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100293 exec 'set guifontwide=' . wfont
294 exec 'set guifont=' . nfont
295 call assert_equal(wfont, &guifontwide)
Bram Moolenaar10434672017-02-12 19:59:08 +0100296
297 " Case 2: guifontset is invalid
298 try
299 set guifontset=-*-notexist-*
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100300 call assert_false(1, "'set guifontset=-*-notexist-*' should have failed")
Bram Moolenaar10434672017-02-12 19:59:08 +0100301 catch
302 call assert_exception('E598')
303 endtry
304 " Set it to an invalid value brutally for preparation.
305 let &guifontset = '-*-notexist-*'
306
307 " Case 2-1: Automatic selection
308 set guifontwide=
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100309 exec 'set guifont=' . nfont
310 call assert_equal(wfont, &guifontwide)
Bram Moolenaar10434672017-02-12 19:59:08 +0100311
312 " Case 2-2: Manual selection
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100313 exec 'set guifontwide=' . wfont
314 exec 'set guifont=' . nfont
315 call assert_equal(wfont, &guifontwide)
Bram Moolenaar10434672017-02-12 19:59:08 +0100316
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100317 let &guifontwide = guifontwide_saved
318 let &guifontset = guifontset_saved
319 let &guifont = guifont_saved
320 let &encoding = encoding_saved
Bram Moolenaar10434672017-02-12 19:59:08 +0100321 endif
Bram Moolenaar10434672017-02-12 19:59:08 +0100322 endif
323
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100324 if !empty(skipped)
325 throw skipped
Bram Moolenaar10434672017-02-12 19:59:08 +0100326 endif
327endfunc
328
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +0100329func Test_set_guiheadroom()
330 let skipped = ''
331
332 if !g:x11_based_gui
333 let skipped = g:not_supported . 'guiheadroom'
334 else
335 " Since this script is to be read together with '-U NONE', the default
336 " value must be preserved.
337 call assert_equal(50, &guiheadroom)
338 endif
339
340 if !empty(skipped)
341 throw skipped
342 endif
343endfunc
344
Bram Moolenaar13c724f2017-02-05 20:54:26 +0100345func Test_getwinpos()
346 call assert_match('Window position: X \d\+, Y \d\+', execute('winpos'))
347 call assert_true(getwinposx() >= 0)
348 call assert_true(getwinposy() >= 0)
Bram Moolenaar6f785742017-02-06 22:11:55 +0100349endfunc
Bram Moolenaar13c724f2017-02-05 20:54:26 +0100350
Bram Moolenaar877e9572016-08-04 20:05:50 +0200351func Test_shell_command()
352 new
Bram Moolenaar9d5b8762016-08-04 21:21:13 +0200353 r !echo hello
354 call assert_equal('hello', substitute(getline(2), '\W', '', 'g'))
Bram Moolenaar877e9572016-08-04 20:05:50 +0200355 bwipe!
Bram Moolenaar877e9572016-08-04 20:05:50 +0200356endfunc
Bram Moolenaar13c724f2017-02-05 20:54:26 +0100357
358func Test_windowid_variable()
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +0100359 if g:x11_based_gui || has('win32')
Bram Moolenaar13c724f2017-02-05 20:54:26 +0100360 call assert_true(v:windowid > 0)
361 else
362 call assert_equal(0, v:windowid)
363 endif
Bram Moolenaar6f785742017-02-06 22:11:55 +0100364endfunc