blob: d9430747de78a49e40659a09e0fb81138d414f0f [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 Moolenaar43dded82017-02-09 16:06:17 +010075func Test_set_guifont()
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +010076 let skipped = ''
77
78 let guifont_saved = &guifont
Bram Moolenaar43dded82017-02-09 16:06:17 +010079 if has('xfontset')
80 " Prevent 'guifontset' from canceling 'guifont'.
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +010081 let guifontset_saved = &guifontset
Bram Moolenaar43dded82017-02-09 16:06:17 +010082 set guifontset=
83 endif
84
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +010085 if !g:x11_based_gui
86 let skipped = g:not_implemented
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +010087 elseif has('gui_athena') || has('gui_motif')
Bram Moolenaar43dded82017-02-09 16:06:17 +010088 " Non-empty font list with invalid font names.
89 "
90 " This test is twofold: (1) It checks if the command fails as expected
91 " when there are no loadable fonts found in the list. (2) It checks if
92 " 'guifont' remains the same after the command loads none of the fonts
93 " listed.
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +010094 let flist = &guifont
Bram Moolenaar43dded82017-02-09 16:06:17 +010095 call assert_fails('set guifont=-notexist1-*,-notexist2-*')
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +010096 call assert_equal(flist, &guifont)
Bram Moolenaar43dded82017-02-09 16:06:17 +010097
98 " Non-empty font list with a valid font name. Should pick up the first
99 " valid font.
100 set guifont=-notexist1-*,fixed,-notexist2-*
101 call assert_equal('fixed', getfontname())
102
103 " Empty list. Should fallback to the built-in default.
104 set guifont=
105 call assert_equal('7x13', getfontname())
106
107 elseif has('gui_gtk2') || has('gui_gnome') || has('gui_gtk3')
108 " For GTK, what we refer to as 'font names' in our manual are actually
109 " 'initial font patterns'. A valid font which matches the 'canonical font
110 " pattern' constructed from a given 'initial pattern' is to be looked up
111 " and loaded. That explains why the GTK GUIs appear to accept 'invalid
112 " font names'.
113 "
114 " Non-empty list. Should always pick up the first element, no matter how
115 " strange it is, as explained above.
116 set guifont=(´・ω・`)\ 12,Courier\ 12
117 call assert_equal('(´・ω・`) 12', getfontname())
118
119 " Empty list. Should fallback to the built-in default.
120 set guifont=
121 call assert_equal('Monospace 10', getfontname())
Bram Moolenaar43dded82017-02-09 16:06:17 +0100122 endif
123
124 if has('xfontset')
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100125 let &guifontset = guifontset_saved
Bram Moolenaar43dded82017-02-09 16:06:17 +0100126 endif
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100127 let &guifont = guifont_saved
Bram Moolenaar43dded82017-02-09 16:06:17 +0100128
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100129 if !empty(skipped)
130 throw skipped
Bram Moolenaar43dded82017-02-09 16:06:17 +0100131 endif
132endfunc
133
Bram Moolenaar10434672017-02-12 19:59:08 +0100134func Test_set_guifontset()
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100135 let skipped = ''
Bram Moolenaar10434672017-02-12 19:59:08 +0100136
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100137 if !has('xfontset')
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +0100138 let skipped = g:not_supported . 'xfontset'
Bram Moolenaar10434672017-02-12 19:59:08 +0100139 else
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100140 let ctype_saved = v:ctype
141
142 " First, since XCreateFontSet(3) is very sensitive to locale, fonts must
143 " be chosen meticulously.
144 let font_head = '-misc-fixed-medium-r-normal--14'
145
146 let font_aw70 = font_head . '-130-75-75-c-70'
147 let font_aw140 = font_head . '-130-75-75-c-140'
148
149 let font_jisx0201 = font_aw70 . '-jisx0201.1976-0'
150 let font_jisx0208 = font_aw140 . '-jisx0208.1983-0'
151
152 let full_XLFDs = join([ font_jisx0208, font_jisx0201 ], ',')
153 let short_XLFDs = join([ font_aw140, font_aw70 ], ',')
154 let singleton = font_head . '-*'
155 let aliases = 'k14,r14'
156
157 " Second, among 'locales', look up such a locale that gets 'set
158 " guifontset=' to work successfully with every fontset specified with
159 " 'fontsets'.
160 let locales = [ 'ja_JP.UTF-8', 'ja_JP.eucJP', 'ja_JP.SJIS' ]
161 let fontsets = [ full_XLFDs, short_XLFDs, singleton, aliases ]
162
163 let feasible = 0
164 for locale in locales
165 try
166 exec 'language ctype' locale
167 catch /^Vim\%((\a\+)\)\=:E197/
168 continue
169 endtry
170 let done = 0
171 for fontset in fontsets
172 try
173 exec 'set guifontset=' . fontset
174 catch /^Vim\%((\a\+)\)\=:E\%(250\|252\|234\|597\|598\)/
175 break
176 endtry
177 let done += 1
178 endfor
179 if done == len(fontsets)
180 let feasible = 1
181 break
182 endif
183 endfor
184
185 " Third, give a set of tests if it is found feasible.
186 if !feasible
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +0100187 let skipped = g:not_hosted
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100188 else
189 " N.B. 'v:ctype' has already been set to an appropriate value in the
190 " previous loop.
191 for fontset in fontsets
192 exec 'set guifontset=' . fontset
193 call assert_equal(fontset, &guifontset)
194 endfor
195 endif
196
197 " Finally, restore ctype.
198 exec 'language ctype' ctype_saved
Bram Moolenaar10434672017-02-12 19:59:08 +0100199 endif
200
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100201 if !empty(skipped)
202 throw skipped
Bram Moolenaar10434672017-02-12 19:59:08 +0100203 endif
204endfunc
205
206func Test_set_guifontwide()
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100207 let skipped = ''
Bram Moolenaar10434672017-02-12 19:59:08 +0100208
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +0100209 if !g:x11_based_gui
210 let skipped = g:not_implemented
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100211 elseif has('gui_gtk')
212 let guifont_saved = &guifont
213 let guifontwide_saved = &guifontwide
Bram Moolenaar10434672017-02-12 19:59:08 +0100214
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100215 let fc_match = exepath('fc-match')
216 if empty(fc_match)
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +0100217 let skipped = g:not_hosted
Bram Moolenaar10434672017-02-12 19:59:08 +0100218 else
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100219 let &guifont = system('fc-match -f "%{family[0]} %{size}" monospace:size=10:lang=en')
220 let wide = system('fc-match -f "%{family[0]} %{size}" monospace:size=10:lang=ja')
221 exec 'set guifontwide=' . fnameescape(wide)
222 call assert_equal(wide, &guifontwide)
Bram Moolenaar10434672017-02-12 19:59:08 +0100223 endif
224
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100225 let &guifontwide = guifontwide_saved
226 let &guifont = guifont_saved
Bram Moolenaar10434672017-02-12 19:59:08 +0100227
228 elseif has('gui_athena') || has('gui_motif')
229 " guifontwide is premised upon the xfontset feature.
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100230 if !has('xfontset')
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +0100231 let skipped = g:not_supported . 'xfontset'
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100232 else
233 let encoding_saved = &encoding
234 let guifont_saved = &guifont
235 let guifontset_saved = &guifontset
236 let guifontwide_saved = &guifontwide
Bram Moolenaar10434672017-02-12 19:59:08 +0100237
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100238 let nfont = '-misc-fixed-medium-r-normal-*-18-120-100-100-c-90-iso10646-1'
239 let wfont = '-misc-fixed-medium-r-normal-*-18-120-100-100-c-180-iso10646-1'
Bram Moolenaar10434672017-02-12 19:59:08 +0100240
241 set encoding=utf-8
242
243 " Case 1: guifontset is empty
244 set guifontset=
245
246 " Case 1-1: Automatic selection
247 set guifontwide=
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100248 exec 'set guifont=' . nfont
249 call assert_equal(wfont, &guifontwide)
Bram Moolenaar10434672017-02-12 19:59:08 +0100250
251 " Case 1-2: Manual selection
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100252 exec 'set guifontwide=' . wfont
253 exec 'set guifont=' . nfont
254 call assert_equal(wfont, &guifontwide)
Bram Moolenaar10434672017-02-12 19:59:08 +0100255
256 " Case 2: guifontset is invalid
257 try
258 set guifontset=-*-notexist-*
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100259 call assert_false(1, "'set guifontset=-*-notexist-*' should have failed")
Bram Moolenaar10434672017-02-12 19:59:08 +0100260 catch
261 call assert_exception('E598')
262 endtry
263 " Set it to an invalid value brutally for preparation.
264 let &guifontset = '-*-notexist-*'
265
266 " Case 2-1: Automatic selection
267 set guifontwide=
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100268 exec 'set guifont=' . nfont
269 call assert_equal(wfont, &guifontwide)
Bram Moolenaar10434672017-02-12 19:59:08 +0100270
271 " Case 2-2: Manual selection
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100272 exec 'set guifontwide=' . wfont
273 exec 'set guifont=' . nfont
274 call assert_equal(wfont, &guifontwide)
Bram Moolenaar10434672017-02-12 19:59:08 +0100275
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100276 let &guifontwide = guifontwide_saved
277 let &guifontset = guifontset_saved
278 let &guifont = guifont_saved
279 let &encoding = encoding_saved
Bram Moolenaar10434672017-02-12 19:59:08 +0100280 endif
Bram Moolenaar10434672017-02-12 19:59:08 +0100281 endif
282
Bram Moolenaar4e9dbc72017-02-17 13:44:48 +0100283 if !empty(skipped)
284 throw skipped
Bram Moolenaar10434672017-02-12 19:59:08 +0100285 endif
286endfunc
287
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +0100288func Test_set_guiheadroom()
289 let skipped = ''
290
291 if !g:x11_based_gui
292 let skipped = g:not_supported . 'guiheadroom'
293 else
294 " Since this script is to be read together with '-U NONE', the default
295 " value must be preserved.
296 call assert_equal(50, &guiheadroom)
297 endif
298
299 if !empty(skipped)
300 throw skipped
301 endif
302endfunc
303
Bram Moolenaar13c724f2017-02-05 20:54:26 +0100304func Test_getwinpos()
305 call assert_match('Window position: X \d\+, Y \d\+', execute('winpos'))
306 call assert_true(getwinposx() >= 0)
307 call assert_true(getwinposy() >= 0)
Bram Moolenaar6f785742017-02-06 22:11:55 +0100308endfunc
Bram Moolenaar13c724f2017-02-05 20:54:26 +0100309
Bram Moolenaar877e9572016-08-04 20:05:50 +0200310func Test_shell_command()
311 new
Bram Moolenaar9d5b8762016-08-04 21:21:13 +0200312 r !echo hello
313 call assert_equal('hello', substitute(getline(2), '\W', '', 'g'))
Bram Moolenaar877e9572016-08-04 20:05:50 +0200314 bwipe!
Bram Moolenaar877e9572016-08-04 20:05:50 +0200315endfunc
Bram Moolenaar13c724f2017-02-05 20:54:26 +0100316
317func Test_windowid_variable()
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +0100318 if g:x11_based_gui || has('win32')
Bram Moolenaar13c724f2017-02-05 20:54:26 +0100319 call assert_true(v:windowid > 0)
320 else
321 call assert_equal(0, v:windowid)
322 endif
Bram Moolenaar6f785742017-02-06 22:11:55 +0100323endfunc