1testexecdir = join_paths(installed_test_bindir, 'gtk')
2testdatadir = join_paths(installed_test_datadir, 'gtk')
3
4gtk_tests_export_dynamic_ldflag = []
5
6if cc.get_id() != 'msvc'
7  if os_darwin
8    gtk_tests_export_dynamic_ldflag = ['-Wl,-export_dynamic']
9  else
10    gtk_tests_export_dynamic_ldflag = ['-Wl,--export-dynamic']
11  endif
12endif
13
14# Available keys for each test:
15#
16#  - 'name': the test name; used for the test and to determine the base
17#            source file for the test (MANDATORY)
18#  - 'sources': (array): additional sources needed by the test
19#  - 'c_args': (array): additional compiler arguments
20#  - 'link_args': (array): additional linker arguments
21#  - 'suites': (array): additional test suites
22tests = [
23  { 'name': 'accel' },
24# sadly, mesons xfail support seems busted
25#  { 'name': 'accessor-apis' },
26  { 'name': 'action' },
27  { 'name': 'adjustment' },
28  { 'name': 'bitset' },
29  {
30    'name': 'builder',
31    'link_args': gtk_tests_export_dynamic_ldflag,
32  },
33  { 'name': 'builderparser' },
34  { 'name': 'calendar' },
35  { 'name': 'cellarea' },
36  { 'name': 'check-icon-names' },
37  { 'name': 'cssprovider' },
38  { 'name': 'defaultvalue' },
39  { 'name': 'entry' },
40  { 'name': 'expression' },
41  { 'name': 'filefilter' },
42  { 'name': 'filter' },
43  { 'name': 'filterlistmodel' },
44  {
45    'name': 'filterlistmodel-exhaustive',
46    'suites': ['slow'],
47  },
48  { 'name': 'flattenlistmodel' },
49  { 'name': 'floating' },
50  { 'name': 'flowbox' },
51  #{ 'name': 'gestures' },
52  { 'name': 'grid' },
53  { 'name': 'grid-layout' },
54  { 'name': 'icontheme' },
55  { 'name': 'label' },
56  { 'name': 'listbox' },
57  { 'name': 'main' },
58  { 'name': 'maplistmodel' },
59  { 'name': 'multiselection' },
60  { 'name': 'notify' },
61  { 'name': 'no-gtk-init' },
62  { 'name': 'object' },
63  { 'name': 'objects-finalize' },
64  { 'name': 'papersize' },
65  #{ 'name': 'popover' },
66  { 'name': 'recentmanager' },
67  { 'name': 'regression-tests' },
68  { 'name': 'scrolledwindow' },
69  { 'name': 'searchbar' },
70  { 'name': 'shortcuts' },
71  { 'name': 'singleselection' },
72  { 'name': 'slicelistmodel' },
73  { 'name': 'sorter' },
74  { 'name': 'sortlistmodel' },
75  { 'name': 'sortlistmodel-exhaustive' },
76  { 'name': 'spinbutton' },
77  { 'name': 'stringlist' },
78  { 'name': 'templates' },
79  { 'name': 'textbuffer' },
80  { 'name': 'textiter' },
81  { 'name': 'theme-validate' },
82  { 'name': 'tooltips' },
83  { 'name': 'treelistmodel' },
84  {
85    'name': 'treemodel',
86    'sources': [
87      'treemodel.c',
88      'liststore.c',
89      'treestore.c',
90      'filtermodel.c',
91      'modelrefcount.c',
92      'sortmodel.c',
93      'gtktreemodelrefcount.c',
94    ],
95  },
96  { 'name': 'treepath' },
97  { 'name': 'treesorter' },
98  { 'name': 'treeview' },
99  { 'name': 'typename' },
100  { 'name': 'displayclose' },
101  { 'name': 'revealer-size' },
102  { 'name': 'widgetorder' },
103  { 'name': 'widget-refcount' },
104]
105
106# Tests that test private apis and therefore are linked against libgtk-4.a
107internal_tests = [
108  { 'name': 'bitmask' },
109  {
110    'name': 'composetable',
111    'sources': [
112      'composetable.c',
113      '../testutils.c'
114    ],
115  },
116  { 'name': 'imcontext' },
117  { 'name': 'constraint-solver' },
118  { 'name': 'rbtree-crash' },
119  { 'name': 'propertylookuplistmodel' },
120  { 'name': 'rbtree' },
121  { 'name': 'timsort' },
122  { 'name': 'texthistory' },
123  { 'name': 'fnmatch' },
124]
125
126# Tests that are expected to fail
127xfail = [
128  # we are still missing some accessors
129  'accessor-apis',
130  # one of the window resizing tests fails after
131  # the GdkToplevel refactoring, and needs a big
132  # gtkwindow.c configure request cleanup
133  'window',
134]
135
136is_debug = get_option('buildtype').startswith('debug')
137
138test_cargs = []
139
140test_env = environment()
141test_env.set('GTK_A11Y', 'test')
142test_env.set('GSK_RENDERER', 'cairo')
143test_env.set('G_TEST_SRCDIR', meson.current_source_dir())
144test_env.set('G_TEST_BUILDDIR', meson.current_build_dir())
145test_env.set('GIO_USE_VFS', 'local')
146test_env.set('GSETTINGS_BACKEND', 'memory')
147test_env.set('G_ENABLE_DIAGNOSTIC', '0')
148
149if os_unix
150  # tests += [['defaultvalue']]  # disabled in Makefile.am as well
151  test_cargs += ['-DHAVE_UNIX_PRINT_WIDGETS']
152endif
153
154foreach flag: common_cflags
155  if flag not in ['-Werror=missing-prototypes', '-Werror=missing-declarations', '-fvisibility=hidden']
156    test_cargs += flag
157  endif
158endforeach
159
160foreach t : tests
161  test_name = t.get('name')
162  test_srcs = ['@0@.c'.format(test_name)] + t.get('sources', [])
163  test_extra_cargs = t.get('c_args', [])
164  test_extra_ldflags = t.get('link_args', [])
165  test_extra_suites = t.get('suites', [])
166  test_timeout = 60
167
168  test_exe = executable(test_name,
169    sources: test_srcs,
170    c_args: test_cargs + test_extra_cargs,
171    link_args: test_extra_ldflags,
172    dependencies: libgtk_dep,
173    install: get_option('install-tests'),
174    install_dir: testexecdir,
175  )
176
177  expect_fail = xfail.contains(test_name)
178
179  if test_extra_suites.contains('slow')
180    test_timeout = 90
181  endif
182
183  test(test_name, test_exe,
184    args: [ '--tap', '-k' ],
185    protocol: 'tap',
186    timeout: test_timeout,
187    env: test_env,
188    suite: ['gtk'] + test_extra_suites,
189    should_fail: expect_fail,
190  )
191endforeach
192
193foreach t : internal_tests
194  test_name = t.get('name')
195  test_srcs = ['@0@.c'.format(test_name)] + t.get('sources', [])
196  test_extra_cargs = t.get('c_args', [])
197  test_extra_ldflags = t.get('link_args', [])
198  test_extra_suites = t.get('suites', [])
199  test_timeout = 60
200
201  test_exe = executable(test_name,
202    sources: test_srcs,
203    c_args: test_cargs + test_extra_cargs,
204    link_args: test_extra_ldflags,
205    dependencies: libgtk_static_dep,
206    install: get_option('install-tests'),
207    install_dir: testexecdir,
208  )
209
210  expect_fail = xfail.contains(test_name)
211
212  if test_extra_suites.contains('slow')
213    test_timeout = 90
214  endif
215
216  test(test_name, test_exe,
217    args: [ '--tap', '-k' ],
218    protocol: 'tap',
219    timeout: test_timeout,
220    env: test_env,
221    suite: ['gtk'] + test_extra_suites,
222    should_fail: expect_fail,
223  )
224endforeach
225
226# FIXME: if objc autotestkeywords_CPPFLAGS += -DHAVE_OBJC=1 -x objective-c++
227if add_languages('cpp', required: false, native: false)
228  test_exe = executable('autotestkeywords',
229    sources: 'autotestkeywords.cc',
230    dependencies: libgtk_dep,
231    install: get_option('install-tests'),
232    install_dir: testexecdir,
233  )
234  test('c++ keywords', test_exe,
235    args: [ '--tap', '-k' ],
236    #protocol: 'tap',
237    env: test_env,
238    suite: 'gtk',
239  )
240  if get_option('install-tests')
241    conf = configuration_data()
242    conf.set('testexecdir', testexecdir)
243    conf.set('test', 'autotestkeywords')
244    configure_file(input: 'gtk.test.in',
245      output: 'autotestkeywords.test',
246      configuration: conf,
247      install_dir: testdatadir,
248    )
249  endif
250endif
251
252
253focus_chain_tests = [
254  # test     direction
255  [ 'basic', 'tab' ],
256  [ 'basic', 'tab-backward' ],
257  [ 'basic', 'left' ],
258  [ 'basic', 'right' ],
259  [ 'widget-factory', 'tab' ],
260  [ 'widget-factory', 'tab-backward' ],
261  # flaky
262  # [ 'widget-factory', 'up' ],
263  # [ 'widget-factory', 'down' ],
264  [ 'widget-factory', 'left' ],
265  # this one is flaky in ci, for unclear reasons
266  #[ 'widget-factory', 'right' ],
267  [ 'widget-factory2', 'tab' ],
268  [ 'widget-factory2', 'tab-backward' ],
269  # in ci, we don't show a color picker, so the focus chain
270  # for page3 is missing an expected button in the color editor
271  #[ 'widget-factory3', 'tab' ],
272  #[ 'widget-factory3', 'tab-backward' ],
273]
274
275focus_chain = executable(
276  'test-focus-chain',
277  sources: ['test-focus-chain.c', '../testutils.c'],
278  dependencies: libgtk_dep,
279  c_args: common_cflags,
280  install: get_option('install-tests'),
281  install_dir: testexecdir
282)
283
284foreach test : focus_chain_tests
285  test(test[0] + ' ' + test[1], focus_chain,
286    args: [
287      join_paths(meson.current_source_dir(), 'focus-chain', test[0] + '.ui'),
288      join_paths(meson.current_source_dir(), 'focus-chain', test[0] + '.' + test[1]),
289    ],
290    env: test_env,
291    suite: [ 'gtk', 'focus' ],
292  )
293endforeach
294
295
296if get_option('install-tests')
297  foreach t : tests
298    test_name = t.get('name')
299    conf = configuration_data()
300    conf.set('testexecdir', testexecdir)
301    conf.set('test', test_name)
302    configure_file(input: 'gtk.test.in',
303      output: '@0@.test'.format(test_name),
304      configuration: conf,
305      install_dir: testdatadir,
306    )
307  endforeach
308
309  install_subdir('icons', install_dir: testexecdir)
310  install_subdir('icons2', install_dir: testexecdir)
311  install_subdir('ui', install_dir: testexecdir)
312endif
313
314if false and get_option ('profiler')
315
316  performance_env = test_env
317  performance_env.set('GTK_THEME', 'Empty')
318
319  test('performance-layout', test_performance,
320    args: [
321      '--mark', 'size allocation',
322      join_paths(meson.current_build_dir(), '../../demos/widget-factory/gtk4-widget-factory'),
323    ],
324    env: performance_env,
325    suite: [ 'gtk' ],
326  )
327
328  test('performance-snapshot', test_performance,
329    args: [
330      '--mark', 'widget snapshot',
331      join_paths(meson.current_build_dir(), '../../demos/widget-factory/gtk4-widget-factory'),
332    ],
333    env: performance_env,
334    suite: [ 'gtk' ],
335  )
336endif
337