Bram Moolenaar | 877e957 | 2016-08-04 20:05:50 +0200 | [diff] [blame] | 1 | " Tests specifically for the GUI |
| 2 | |
| 3 | if !has('gui') || ($DISPLAY == "" && !has('gui_running')) |
| 4 | finish |
| 5 | endif |
| 6 | |
Bram Moolenaar | 13c724f | 2017-02-05 20:54:26 +0100 | [diff] [blame] | 7 | let s:x11_based_gui = has('gui_athena') || has('gui_motif') |
| 8 | \ || has('gui_gtk2') || has('gui_gnome') || has('gui_gtk3') |
| 9 | |
Bram Moolenaar | 877e957 | 2016-08-04 20:05:50 +0200 | [diff] [blame] | 10 | " For KDE set a font, empty 'guifont' may cause a hang. |
| 11 | func SetUp() |
| 12 | if has("gui_kde") |
| 13 | set guifont=Courier\ 10\ Pitch/8/-1/5/50/0/0/0/0/0 |
| 14 | endif |
Bram Moolenaar | 50fa8dd | 2016-08-09 22:58:21 +0200 | [diff] [blame] | 15 | |
Bram Moolenaar | f1ab9c1 | 2017-02-01 12:32:58 +0100 | [diff] [blame] | 16 | " Gnome insists on creating $HOME/.gnome2/, set $HOME to avoid changing the |
| 17 | " actual home directory. But avoid triggering fontconfig by setting the |
| 18 | " cache directory. Only needed for Unix. |
| 19 | if $XDG_CACHE_HOME == '' && exists('g:tester_HOME') |
Bram Moolenaar | 56e6bd7 | 2017-02-01 12:08:47 +0100 | [diff] [blame] | 20 | let $XDG_CACHE_HOME = g:tester_HOME . '/.cache' |
| 21 | endif |
Bram Moolenaar | 50fa8dd | 2016-08-09 22:58:21 +0200 | [diff] [blame] | 22 | call mkdir('Xhome') |
| 23 | let $HOME = fnamemodify('Xhome', ':p') |
| 24 | endfunc |
| 25 | |
| 26 | func TearDown() |
| 27 | call delete('Xhome', 'rf') |
Bram Moolenaar | 877e957 | 2016-08-04 20:05:50 +0200 | [diff] [blame] | 28 | endfunc |
| 29 | |
| 30 | " Test for resetting "secure" flag after GUI has started. |
| 31 | " Must be run first. |
| 32 | func Test_1_set_secure() |
| 33 | set exrc secure |
| 34 | gui -f |
| 35 | call assert_equal(1, has('gui_running')) |
| 36 | endfunc |
| 37 | |
Bram Moolenaar | 6f78574 | 2017-02-06 22:11:55 +0100 | [diff] [blame] | 38 | func Test_getfontname_with_arg() |
| 39 | if has('gui_athena') || has('gui_motif') |
| 40 | " Invalid font name. The result should be an empty string. |
| 41 | call assert_equal('', getfontname('notexist')) |
| 42 | |
| 43 | " Valid font name. This is usually the real name of 7x13 by default. |
Bram Moolenaar | a9f8ffb | 2017-02-09 16:14:53 +0100 | [diff] [blame] | 44 | let l:fname = '-misc-fixed-medium-r-normal--13-120-75-75-c-70-iso8859-1' |
Bram Moolenaar | 6f78574 | 2017-02-06 22:11:55 +0100 | [diff] [blame] | 45 | call assert_equal(l:fname, getfontname(l:fname)) |
| 46 | |
| 47 | elseif has('gui_gtk2') || has('gui_gnome') || has('gui_gtk3') |
| 48 | " Invalid font name. The result should be the name plus the default size. |
| 49 | call assert_equal('notexist 10', getfontname('notexist')) |
| 50 | |
| 51 | " Valid font name. This is usually the real name of Monospace by default. |
| 52 | let l:fname = 'Bitstream Vera Sans Mono 12' |
| 53 | call assert_equal(l:fname, getfontname(l:fname)) |
| 54 | else |
| 55 | throw "Skipped: Matched font name unpredictable to test on this GUI" |
| 56 | endif |
| 57 | endfunc |
| 58 | |
| 59 | func Test_getfontname_without_arg() |
| 60 | let l:fname = getfontname() |
| 61 | if has('gui_kde') |
| 62 | " 'expected' is the value specified by SetUp() above. |
| 63 | call assert_equal('Courier 10 Pitch/8/-1/5/50/0/0/0/0/0', l:fname) |
| 64 | elseif has('gui_athena') || has('gui_motif') |
| 65 | " 'expected' is DFLT_FONT of gui_x11.c. |
| 66 | call assert_equal('7x13', l:fname) |
| 67 | elseif has('gui_gtk2') || has('gui_gnome') || has('gui_gtk3') |
| 68 | " 'expected' is DEFAULT_FONT of gui_gtk_x11.c. |
| 69 | call assert_equal('Monospace 10', l:fname) |
| 70 | else |
| 71 | throw "Skipped: Default font name unpredictable to test on this GUI" |
| 72 | endif |
| 73 | endfunc |
| 74 | |
Bram Moolenaar | 43dded8 | 2017-02-09 16:06:17 +0100 | [diff] [blame] | 75 | func Test_set_guifont() |
| 76 | let l:guifont_saved = &guifont |
| 77 | if has('xfontset') |
| 78 | " Prevent 'guifontset' from canceling 'guifont'. |
| 79 | let l:guifontset_saved = &guifontset |
| 80 | set guifontset= |
| 81 | endif |
| 82 | |
| 83 | let skipped = 0 |
| 84 | if has('gui_athena') || has('gui_motif') |
| 85 | " Non-empty font list with invalid font names. |
| 86 | " |
| 87 | " This test is twofold: (1) It checks if the command fails as expected |
| 88 | " when there are no loadable fonts found in the list. (2) It checks if |
| 89 | " 'guifont' remains the same after the command loads none of the fonts |
| 90 | " listed. |
| 91 | let l:flist = &guifont |
| 92 | call assert_fails('set guifont=-notexist1-*,-notexist2-*') |
| 93 | call assert_equal(l:flist, &guifont) |
| 94 | |
| 95 | " Non-empty font list with a valid font name. Should pick up the first |
| 96 | " valid font. |
| 97 | set guifont=-notexist1-*,fixed,-notexist2-* |
| 98 | call assert_equal('fixed', getfontname()) |
| 99 | |
| 100 | " Empty list. Should fallback to the built-in default. |
| 101 | set guifont= |
| 102 | call assert_equal('7x13', getfontname()) |
| 103 | |
| 104 | elseif has('gui_gtk2') || has('gui_gnome') || has('gui_gtk3') |
| 105 | " For GTK, what we refer to as 'font names' in our manual are actually |
| 106 | " 'initial font patterns'. A valid font which matches the 'canonical font |
| 107 | " pattern' constructed from a given 'initial pattern' is to be looked up |
| 108 | " and loaded. That explains why the GTK GUIs appear to accept 'invalid |
| 109 | " font names'. |
| 110 | " |
| 111 | " Non-empty list. Should always pick up the first element, no matter how |
| 112 | " strange it is, as explained above. |
| 113 | set guifont=(´・ω・`)\ 12,Courier\ 12 |
| 114 | call assert_equal('(´・ω・`) 12', getfontname()) |
| 115 | |
| 116 | " Empty list. Should fallback to the built-in default. |
| 117 | set guifont= |
| 118 | call assert_equal('Monospace 10', getfontname()) |
| 119 | |
| 120 | else |
| 121 | let skipped = 1 |
| 122 | endif |
| 123 | |
| 124 | if has('xfontset') |
| 125 | let &guifontset = l:guifontset_saved |
| 126 | endif |
| 127 | let &guifont = l:guifont_saved |
| 128 | |
| 129 | if skipped |
| 130 | throw "Skipped: Test not implemented yet for this GUI" |
| 131 | endif |
| 132 | endfunc |
| 133 | |
Bram Moolenaar | 1043467 | 2017-02-12 19:59:08 +0100 | [diff] [blame] | 134 | func Test_set_guifontset() |
| 135 | let skipped = 0 |
| 136 | |
| 137 | if has('xfontset') |
| 138 | let l:ctype_saved = v:ctype |
| 139 | |
| 140 | " For UTF-8 locales, XCreateFontSet(3) is likely to fail in constructing a |
| 141 | " fontset automatically from one or two simple XLFDs because it requires |
| 142 | " the host system to have a fairly comprehensive collection of fixed-width |
| 143 | " fonts with various sizes and registries/encodings in order to get the |
| 144 | " job done. To make the test meaningful for a wide variety of hosts, we |
| 145 | " confine ourselves to the following locale for which X11 historically has |
| 146 | " the fonts to use with. |
| 147 | language ctype ja_JP.eucJP |
| 148 | |
| 149 | " Since XCreateFontSet(3) is very sensitive to locale, fonts must be |
| 150 | " chosen meticulously. |
| 151 | let l:font_head = '-misc-fixed-medium-r-normal--14' |
| 152 | |
| 153 | let l:font_aw70 = l:font_head . '-130-75-75-c-70' |
| 154 | let l:font_aw140 = l:font_head . '-130-75-75-c-140' |
| 155 | |
| 156 | let l:font_jisx0201 = l:font_aw70 . '-jisx0201.1976-0' |
| 157 | let l:font_jisx0208 = l:font_aw140 . '-jisx0208.1983-0' |
| 158 | |
| 159 | " Full XLFDs |
| 160 | let l:fontset_name = join([ l:font_jisx0208, l:font_jisx0201 ], ',') |
| 161 | exec 'set guifontset=' . l:fontset_name |
| 162 | call assert_equal(l:fontset_name, &guifontset) |
| 163 | |
| 164 | " XLFDs w/o CharSetRegistry and CharSetEncoding |
| 165 | let l:fontset_name = join([ l:font_aw140, l:font_aw70 ], ',') |
| 166 | exec 'set guifontset=' . l:fontset_name |
| 167 | call assert_equal(l:fontset_name, &guifontset) |
| 168 | |
| 169 | " Singleton |
| 170 | let l:fontset_name = l:font_head . '-*' |
| 171 | exec 'set guifontset=' . l:fontset_name |
| 172 | call assert_equal(l:fontset_name, &guifontset) |
| 173 | |
| 174 | " Aliases |
| 175 | let l:fontset_name = 'k14,r14' |
| 176 | exec 'set guifontset=' . l:fontset_name |
| 177 | call assert_equal(l:fontset_name, &guifontset) |
| 178 | |
| 179 | exec 'language ctype' l:ctype_saved |
| 180 | |
| 181 | else |
| 182 | let skipped = 1 |
| 183 | endif |
| 184 | |
| 185 | if skipped |
| 186 | throw "Skipped: Not supported by this GUI" |
| 187 | endif |
| 188 | endfunc |
| 189 | |
| 190 | func Test_set_guifontwide() |
| 191 | let skipped = 0 |
| 192 | |
| 193 | if has('gui_gtk') |
| 194 | let l:guifont_saved = &guifont |
| 195 | let l:guifontwide_saved = &guifontwide |
| 196 | |
| 197 | let l:fc_match = exepath('fc-match') |
| 198 | if l:fc_match != '' |
| 199 | let &guifont = system('fc-match -f "%{family[0]} %{size}" monospace:size=10') |
| 200 | let l:wide = system('fc-match -f "%{family[0]} %{size}" monospace:size=10:lang=ja') |
| 201 | exec 'set guifontwide=' . fnameescape(l:wide) |
| 202 | call assert_equal(l:wide, &guifontwide) |
| 203 | else |
| 204 | let skipped = 3 |
| 205 | endif |
| 206 | |
| 207 | let &guifontwide = l:guifontwide_saved |
| 208 | let &guifont = l:guifont_saved |
| 209 | |
| 210 | elseif has('gui_athena') || has('gui_motif') |
| 211 | " guifontwide is premised upon the xfontset feature. |
| 212 | if has('xfontset') |
| 213 | let l:encoding_saved = &encoding |
| 214 | let l:guifont_saved = &guifont |
| 215 | let l:guifontset_saved = &guifontset |
| 216 | let l:guifontwide_saved = &guifontwide |
| 217 | |
| 218 | let l:nfont = '-misc-fixed-medium-r-normal-*-18-120-100-100-c-90-iso10646-1' |
| 219 | let l:wfont = '-misc-fixed-medium-r-normal-*-18-120-100-100-c-180-iso10646-1' |
| 220 | |
| 221 | set encoding=utf-8 |
| 222 | |
| 223 | " Case 1: guifontset is empty |
| 224 | set guifontset= |
| 225 | |
| 226 | " Case 1-1: Automatic selection |
| 227 | set guifontwide= |
| 228 | exec 'set guifont=' . l:nfont |
| 229 | call assert_equal(l:wfont, &guifontwide) |
| 230 | |
| 231 | " Case 1-2: Manual selection |
| 232 | exec 'set guifontwide=' . l:wfont |
| 233 | exec 'set guifont=' . l:nfont |
| 234 | call assert_equal(l:wfont, &guifontwide) |
| 235 | |
| 236 | " Case 2: guifontset is invalid |
| 237 | try |
| 238 | set guifontset=-*-notexist-* |
| 239 | call assert_false(1, "'set guifontset=notexist' should have failed") |
| 240 | catch |
| 241 | call assert_exception('E598') |
| 242 | endtry |
| 243 | " Set it to an invalid value brutally for preparation. |
| 244 | let &guifontset = '-*-notexist-*' |
| 245 | |
| 246 | " Case 2-1: Automatic selection |
| 247 | set guifontwide= |
| 248 | exec 'set guifont=' . l:nfont |
| 249 | call assert_equal(l:wfont, &guifontwide) |
| 250 | |
| 251 | " Case 2-2: Manual selection |
| 252 | exec 'set guifontwide=' . l:wfont |
| 253 | exec 'set guifont=' . l:nfont |
| 254 | call assert_equal(l:wfont, &guifontwide) |
| 255 | |
| 256 | let &guifontwide = l:guifontwide_saved |
| 257 | let &guifontset = l:guifontset_saved |
| 258 | let &guifont = l:guifont_saved |
| 259 | let &encoding = l:encoding_saved |
| 260 | else |
| 261 | let skipped = 2 |
| 262 | endif |
| 263 | else |
| 264 | let skipped = 1 |
| 265 | endif |
| 266 | |
| 267 | if skipped == 1 |
| 268 | throw "Skipped: Test not implemented yet for this GUI" |
| 269 | elseif skipped == 2 |
| 270 | throw "Skipped: Not supported by this GUI" |
| 271 | elseif skipped == 3 |
| 272 | throw "Skipped: Test not supported by the environment" |
| 273 | endif |
| 274 | endfunc |
| 275 | |
Bram Moolenaar | 13c724f | 2017-02-05 20:54:26 +0100 | [diff] [blame] | 276 | func Test_getwinpos() |
| 277 | call assert_match('Window position: X \d\+, Y \d\+', execute('winpos')) |
| 278 | call assert_true(getwinposx() >= 0) |
| 279 | call assert_true(getwinposy() >= 0) |
Bram Moolenaar | 6f78574 | 2017-02-06 22:11:55 +0100 | [diff] [blame] | 280 | endfunc |
Bram Moolenaar | 13c724f | 2017-02-05 20:54:26 +0100 | [diff] [blame] | 281 | |
Bram Moolenaar | 877e957 | 2016-08-04 20:05:50 +0200 | [diff] [blame] | 282 | func Test_shell_command() |
| 283 | new |
Bram Moolenaar | 9d5b876 | 2016-08-04 21:21:13 +0200 | [diff] [blame] | 284 | r !echo hello |
| 285 | call assert_equal('hello', substitute(getline(2), '\W', '', 'g')) |
Bram Moolenaar | 877e957 | 2016-08-04 20:05:50 +0200 | [diff] [blame] | 286 | bwipe! |
Bram Moolenaar | 877e957 | 2016-08-04 20:05:50 +0200 | [diff] [blame] | 287 | endfunc |
Bram Moolenaar | 13c724f | 2017-02-05 20:54:26 +0100 | [diff] [blame] | 288 | |
| 289 | func Test_windowid_variable() |
| 290 | if s:x11_based_gui || has('win32') |
| 291 | call assert_true(v:windowid > 0) |
| 292 | else |
| 293 | call assert_equal(0, v:windowid) |
| 294 | endif |
Bram Moolenaar | 6f78574 | 2017-02-06 22:11:55 +0100 | [diff] [blame] | 295 | endfunc |