blob: 0a158e72cd9dfbb1f0fcad9f0cded369f4ae8d90 [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 Moolenaar13c724f2017-02-05 20:54:26 +01007let s:x11_based_gui = has('gui_athena') || has('gui_motif')
8 \ || has('gui_gtk2') || has('gui_gnome') || has('gui_gtk3')
9
Bram Moolenaar877e9572016-08-04 20:05:50 +020010" For KDE set a font, empty 'guifont' may cause a hang.
11func SetUp()
12 if has("gui_kde")
13 set guifont=Courier\ 10\ Pitch/8/-1/5/50/0/0/0/0/0
14 endif
Bram Moolenaar50fa8dd2016-08-09 22:58:21 +020015
Bram Moolenaarf1ab9c12017-02-01 12:32:58 +010016 " 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 Moolenaar56e6bd72017-02-01 12:08:47 +010020 let $XDG_CACHE_HOME = g:tester_HOME . '/.cache'
21 endif
Bram Moolenaar50fa8dd2016-08-09 22:58:21 +020022 call mkdir('Xhome')
23 let $HOME = fnamemodify('Xhome', ':p')
24endfunc
25
26func TearDown()
27 call delete('Xhome', 'rf')
Bram Moolenaar877e9572016-08-04 20:05:50 +020028endfunc
29
30" Test for resetting "secure" flag after GUI has started.
31" Must be run first.
32func Test_1_set_secure()
33 set exrc secure
34 gui -f
35 call assert_equal(1, has('gui_running'))
36endfunc
37
Bram Moolenaar6f785742017-02-06 22:11:55 +010038func 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.
44 let l:fname = '-Misc-Fixed-Medium-R-Normal--13-120-75-75-C-70-ISO10646-1'
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
57endfunc
58
59func 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
73endfunc
74
Bram Moolenaar13c724f2017-02-05 20:54:26 +010075func Test_getwinpos()
76 call assert_match('Window position: X \d\+, Y \d\+', execute('winpos'))
77 call assert_true(getwinposx() >= 0)
78 call assert_true(getwinposy() >= 0)
Bram Moolenaar6f785742017-02-06 22:11:55 +010079endfunc
Bram Moolenaar13c724f2017-02-05 20:54:26 +010080
Bram Moolenaar877e9572016-08-04 20:05:50 +020081func Test_shell_command()
82 new
Bram Moolenaar9d5b8762016-08-04 21:21:13 +020083 r !echo hello
84 call assert_equal('hello', substitute(getline(2), '\W', '', 'g'))
Bram Moolenaar877e9572016-08-04 20:05:50 +020085 bwipe!
Bram Moolenaar877e9572016-08-04 20:05:50 +020086endfunc
Bram Moolenaar13c724f2017-02-05 20:54:26 +010087
88func Test_windowid_variable()
89 if s:x11_based_gui || has('win32')
90 call assert_true(v:windowid > 0)
91 else
92 call assert_equal(0, v:windowid)
93 endif
Bram Moolenaar6f785742017-02-06 22:11:55 +010094endfunc