Imported Upstream version 2.70.5
[platform/upstream/glib.git] / gio / tests / meson.build
1 common_gio_tests_deps = [
2   libglib_dep,
3   libgmodule_dep,
4   libgobject_dep,
5   libgio_dep,
6 ]
7
8 test_c_args = [
9   '-DG_LOG_DOMAIN="GLib-GIO"',
10   '-DGLIB_MKENUMS="@0@"'.format(glib_mkenums),
11   '-DGLIB_COMPILE_SCHEMAS="@0@"'.format(glib_compile_schemas.full_path()),
12   '-UG_DISABLE_ASSERT',
13 ]
14
15 # workaround for https://github.com/mesonbuild/meson/issues/6880
16 if build_machine.system() == 'linux'
17   libutil_name = 'libutil'
18   libutil = run_command('sh', '-c',
19     '''ldconfig -p | grep -o "[[:space:]]@0@\.so\(\.[0-9]\+\)\?\b"'''
20     .format(libutil_name), check: false).stdout().strip().split('\n')
21
22   if libutil.length() > 0
23       message('Found libutil as @0@'.format(libutil[0]))
24       test_c_args += '-DLIBUTIL_SONAME="@0@"'.format(libutil[0])
25   else
26       warning('libutil not found')
27   endif # libutil.length() > 0
28 endif # build_machine.system() == 'linux'
29
30 if host_machine.system() == 'windows'
31   common_gio_tests_deps += [iphlpapi_dep, winsock2, cc.find_library ('secur32')]
32 endif
33
34 subdir('gdbus-object-manager-example')
35
36 gengiotypefuncs_prog = find_program('gengiotypefuncs.py')
37 giotypefuncs_inc = custom_target(
38   'giotypefuncs.inc',
39   output : 'giotypefuncs.inc',
40   input : gio_headers + [gioenumtypes_h] + gobject_install_headers,
41   command: [gengiotypefuncs_prog, '@OUTPUT@', '@INPUT@'])
42
43 #  Test programs buildable on all platforms
44 gio_tests = {
45   'appmonitor' : {},
46   'async-close-output-stream' : {},
47   'async-splice-output-stream' : {},
48   'buffered-input-stream' : {},
49   'buffered-output-stream' : {},
50   'cancellable' : {},
51   'contexts' : {},
52   'contenttype' : {},
53   'converter-stream' : {},
54   'credentials' : {},
55   'data-input-stream' : {},
56   'data-output-stream' : {},
57   'defaultvalue' : {'extra_sources' : [giotypefuncs_inc]},
58   'fileattributematcher' : {},
59   'filter-streams' : {},
60   'giomodule' : {},
61   'gsubprocess' : {},
62   'g-file' : {},
63   'g-file-info' : {},
64   'g-icon' : {},
65   'gdbus-addresses' : {},
66   'gdbus-message' : {},
67   'inet-address' : {},
68   'io-stream' : {},
69   'memory-input-stream' : {},
70   'memory-monitor' : {},
71   'memory-output-stream' : {},
72   'mount-operation' : {},
73   'network-address' : {'extra_sources': ['mock-resolver.c']},
74   'network-monitor' : {},
75   'network-monitor-race' : {},
76   'permission' : {},
77   'pollable' : {'dependencies' : [libdl_dep]},
78   'power-profile-monitor' : {},
79   'proxy-test' : {},
80   'readwrite' : {},
81   'simple-async-result' : {},
82   'simple-proxy' : {},
83   'sleepy-stream' : {},
84   'socket' : {},
85   'socket-listener' : {},
86   'socket-service' : {},
87   'srvtarget' : {},
88   'task' : {},
89   'vfs' : {},
90   'volumemonitor' : {},
91   'glistmodel' : {},
92   'testfilemonitor' : {'suite' : ['slow', 'flaky']},
93   'thumbnail-verification' : {},
94   'tls-certificate' : {'extra_sources' : ['gtesttlsbackend.c']},
95   'tls-interaction' : {'extra_sources' : ['gtesttlsbackend.c']},
96   'tls-database' : {'extra_sources' : ['gtesttlsbackend.c']},
97   'tls-bindings' : {'extra_sources' : ['gtesttlsbackend.c']},
98   'gdbus-address-get-session' : {},
99   'win32-appinfo' : {},
100 }
101
102 test_extra_programs = {
103   'gdbus-connection-flush-helper' : {},
104   'gdbus-testserver' : {},
105   'gsubprocess-testprog' : {},
106 }
107
108 python_tests = [
109   'codegen.py',
110 ]
111
112 test_env = environment()
113 test_env.set('G_TEST_SRCDIR', meson.current_source_dir())
114 test_env.set('G_TEST_BUILDDIR', meson.current_build_dir())
115 test_env.set('GIO_MODULE_DIR', '')
116
117 # Check for libdbus1 - Optional - is only used in the GDBus test cases
118 # 1.2.14 required for dbus_message_set_serial
119 dbus1_dep = dependency('dbus-1', required : false, version : '>= 1.2.14')
120 if not dbus1_dep.found()
121   if cc.get_id() == 'msvc' or cc.get_id() == 'clang-cl'
122     # MSVC: Search for the DBus library by the configuration, which corresponds
123     # to the output of CMake builds of DBus.  Note that debugoptimized
124     # is really a Release build with .PDB files.
125     if vs_crt == 'debug'
126       dbus1_dep = cc.find_library('dbus-1d', required : false)
127     else
128       dbus1_dep = cc.find_library('dbus-1', required : false)
129     endif
130   endif
131 endif
132 if dbus1_dep.found()
133   glib_conf.set('HAVE_DBUS1', 1)
134
135   gio_tests += {
136     'gdbus-serialization' : {
137       'extra_sources' : ['gdbus-tests.c'],
138       'dependencies' : [dbus1_dep],
139     },
140     'gdbus-server-auth' : {
141       'dependencies' : [dbus1_dep],
142     },
143   }
144 else
145   # We can build a cut-down version of this test without libdbus
146   gio_tests += {
147     'gdbus-server-auth' : {},
148   }
149 endif
150
151 #  Test programs buildable on UNIX only
152 if host_machine.system() != 'windows'
153   gio_tests += {
154     'file' : {},
155     'gdbus-peer' : {
156       'dependencies' : [libgdbus_example_objectmanager_dep],
157       'install_rpath' : installed_tests_execdir
158     },
159     'gdbus-peer-object-manager' : {},
160     'live-g-file' : {},
161     'socket-address' : {},
162     'stream-rw_all' : {},
163     'unix-fd' : {},
164     'unix-mounts' : {},
165     'unix-streams' : {},
166     'g-file-info-filesystem-readonly' : {},
167     'gschema-compile' : {'install' : false},
168     'trash' : {},
169   }
170
171   # LD_PRELOAD modules don't work so well with AddressSanitizer
172   if have_rtld_next and get_option('b_sanitize') == 'none'
173     gio_tests += {
174       'gsocketclient-slow' : {
175         'depends' : [
176           shared_library('slow-connect-preload',
177             'slow-connect-preload.c',
178             name_prefix : '',
179             dependencies: libdl_dep,
180             install_dir : installed_tests_execdir,
181             install: installed_tests_enabled,
182           )
183         ],
184         'env' : {
185           'LD_PRELOAD': '@0@/slow-connect-preload.so'.format(meson.current_build_dir())
186         },
187         'installed_tests_env' : {
188           'LD_PRELOAD': '@0@/slow-connect-preload.so'.format(installed_tests_execdir),
189         },
190       },
191     }
192   endif
193
194   # Uninstalled because of the check-for-executable logic in DesktopAppInfo
195   # unable to find the installed executable
196   if not glib_have_cocoa
197     gio_tests += {
198       'appinfo' : {
199         'install' : false,
200       },
201       'desktop-app-info' : {
202         'install' : false,
203       },
204     }
205   endif
206
207   test_extra_programs += {
208     'basic-application' : {},
209     'dbus-launch' : {},
210     'appinfo-test' : {},
211   }
212
213   if not glib_have_cocoa
214     test_extra_programs += {
215       'apps' : {},
216     }
217     gio_tests += {
218       'mimeapps' : {},
219     }
220   endif
221
222   #  Test programs that need to bring up a session bus (requires dbus-daemon)
223   have_dbus_daemon = find_program('dbus-daemon', required : false).found()
224   if have_dbus_daemon
225     annotate_args = [
226       '--annotate', 'org.project.Bar', 'Key1', 'Value1',
227       '--annotate', 'org.project.Bar', 'org.gtk.GDBus.Internal', 'Value2',
228       '--annotate', 'org.project.Bar.HelloWorld()', 'Key3', 'Value3',
229       '--annotate', 'org.project.Bar::TestSignal', 'Key4', 'Value4',
230       '--annotate', 'org.project.Bar:ay', 'Key5', 'Value5',
231       '--annotate', 'org.project.Bar.TestPrimitiveTypes()[val_int32]', 'Key6', 'Value6',
232       '--annotate', 'org.project.Bar.TestPrimitiveTypes()[ret_uint32]', 'Key7', 'Value7',
233       '--annotate', 'org.project.Bar::TestSignal[array_of_strings]', 'Key8', 'Value8',
234     ]
235     # Generate gdbus-test-codegen-generated.{c,h}
236     gdbus_test_codegen_generated = custom_target('gdbus-test-codegen-generated',
237         input :   ['test-codegen.xml'],
238         output :  ['gdbus-test-codegen-generated.h',
239                    'gdbus-test-codegen-generated.c'],
240         depend_files : gdbus_codegen_built_files,
241         command : [python, gdbus_codegen,
242                    '--interface-prefix', 'org.project.',
243                    '--output-directory', '@OUTDIR@',
244                    '--generate-c-code', 'gdbus-test-codegen-generated',
245                    '--c-generate-object-manager',
246                    '--c-generate-autocleanup', 'all',
247                    '--c-namespace', 'Foo_iGen',
248                    '--generate-docbook', 'gdbus-test-codegen-generated-doc',
249                    annotate_args,
250                    '@INPUT@'])
251     # Generate gdbus-test-codegen-generated-min-required-2-64.{c,h}
252     gdbus_test_codegen_generated_min_required_2_64 = custom_target('gdbus-test-codegen-generated-min-required-2-64',
253         input :   ['test-codegen.xml'],
254         output :  ['gdbus-test-codegen-generated-min-required-2-64.h',
255                    'gdbus-test-codegen-generated-min-required-2-64.c'],
256         depend_files : gdbus_codegen_built_files,
257         command : [python, gdbus_codegen,
258                    '--glib-min-required', '2.64',
259                    '--interface-prefix', 'org.project.',
260                    '--output-directory', '@OUTDIR@',
261                    '--generate-c-code', 'gdbus-test-codegen-generated-min-required-2-64',
262                    '--c-generate-object-manager',
263                    '--c-generate-autocleanup', 'all',
264                    '--c-namespace', 'Foo_iGen',
265                    '--generate-docbook', 'gdbus-test-codegen-generated-doc',
266                    annotate_args,
267                    '@INPUT@'])
268     gdbus_test_codegen_generated_interface_info = [
269       custom_target('gdbus-test-codegen-generated-interface-info-h',
270           input :   ['test-codegen.xml'],
271           output :  ['gdbus-test-codegen-generated-interface-info.h'],
272           depend_files : gdbus_codegen_built_files,
273           command : [python, gdbus_codegen,
274                      '--interface-info-header',
275                      annotate_args,
276                      '--output', '@OUTPUT@',
277                      '@INPUT@']),
278       custom_target('gdbus-test-codegen-generated-interface-info-c',
279           input :   ['test-codegen.xml'],
280           output :  ['gdbus-test-codegen-generated-interface-info.c'],
281           depend_files : gdbus_codegen_built_files,
282           command : [python, gdbus_codegen,
283                      '--interface-info-body',
284                      annotate_args,
285                      '--output', '@OUTPUT@',
286                      '@INPUT@']),
287     ]
288
289     extra_sources = ['gdbus-sessionbus.c', 'gdbus-tests.c']
290
291     gio_tests += {
292       'actions' : {
293         'extra_sources' : extra_sources,
294         'suite' : ['slow'],
295       },
296       'gdbus-auth' : {'extra_sources' : extra_sources},
297       'gdbus-bz627724' : {'extra_sources' : extra_sources},
298       'gdbus-close-pending' : {'extra_sources' : extra_sources},
299       'gdbus-connection' : {'extra_sources' : extra_sources},
300       'gdbus-connection-loss' : {'extra_sources' : extra_sources},
301       'gdbus-connection-slow' : {'extra_sources' : extra_sources},
302       'gdbus-error' : {'extra_sources' : extra_sources},
303       'gdbus-exit-on-close' : {'extra_sources' : extra_sources},
304       'gdbus-export' : {
305         'extra_sources' : extra_sources,
306         'suite' : ['slow'],
307       },
308       'gdbus-introspection' : {'extra_sources' : extra_sources},
309       'gdbus-names' : {'extra_sources' : extra_sources},
310       'gdbus-proxy' : {'extra_sources' : extra_sources},
311       'gdbus-proxy-threads' : {
312         'extra_sources' : extra_sources,
313         'dependencies' : [dbus1_dep],
314       },
315       'gdbus-proxy-unique-name' : {'extra_sources' : extra_sources},
316       'gdbus-proxy-well-known-name' : {'extra_sources' : extra_sources},
317       'gdbus-test-codegen' : {
318         'extra_sources' : [extra_sources, gdbus_test_codegen_generated, gdbus_test_codegen_generated_interface_info],
319         'c_args' : ['-DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_2_32'],
320       },
321       'gdbus-threading' : {
322         'extra_sources' : extra_sources,
323         'suite' : ['slow'],
324       },
325       'gmenumodel' : {
326         'extra_sources' : extra_sources,
327         'suite' : ['slow'],
328       },
329       'gnotification' : {
330         'extra_sources' : [extra_sources, 'gnotification-server.c'],
331       },
332       'gdbus-test-codegen-old' : {
333         'source' : 'gdbus-test-codegen.c',
334         'extra_sources' : [extra_sources, gdbus_test_codegen_generated, gdbus_test_codegen_generated_interface_info],
335         'c_args' : ['-DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_2_36',
336                     '-DGLIB_VERSION_MAX_ALLOWED=GLIB_VERSION_2_36'],
337       },
338       'gdbus-test-codegen-min-required-2-64' : {
339         'source' : 'gdbus-test-codegen.c',
340         'extra_sources' : [extra_sources, gdbus_test_codegen_generated_min_required_2_64, gdbus_test_codegen_generated_interface_info],
341         'c_args' : ['-DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_2_64'],
342       },
343       'gapplication' : {'extra_sources' : extra_sources},
344     }
345
346     if not glib_have_cocoa
347       gio_tests += {
348         'dbus-appinfo' : {
349           'extra_sources' : extra_sources,
350         },
351       }
352     endif
353
354     fake_document_portal_generated = custom_target('fake-document-portal-generated',
355         input :   ['../org.freedesktop.portal.Documents.xml'],
356         output :  ['fake-document-portal-generated.h',
357                    'fake-document-portal-generated.c'],
358         depend_files : gdbus_codegen_built_files,
359         command : [python, gdbus_codegen,
360                    '--interface-prefix', 'org.freedesktop.portal.',
361                    '--output-directory', '@OUTDIR@',
362                    '--generate-c-code', 'fake-document-portal-generated',
363                    '--c-namespace', 'Fake',
364                    '@INPUT@'])
365
366     test_extra_programs += {
367       'fake-document-portal' : {
368         'extra_sources': fake_document_portal_generated,
369       },
370       'fake-service-name' : {}
371     }
372   endif # have_dbus_daemon
373
374   # This test is currently unreliable
375   executable('gdbus-overflow', 'gdbus-overflow.c',
376       c_args : test_c_args,
377       dependencies : common_gio_tests_deps,
378       install_dir : installed_tests_execdir,
379       install : installed_tests_enabled)
380
381   gio_tests += {
382     'gdbus-connection-flush' : {
383       'extra_sources' : ['test-io-stream.c', 'test-pipe-unix.c'],
384     },
385     'gdbus-non-socket' : {
386       'extra_sources' : ['gdbus-tests.c', 'test-io-stream.c', 'test-pipe-unix.c'],
387     },
388   }
389
390   # Generate test.mo from de.po using msgfmt
391   msgfmt = find_program('msgfmt', required : false)
392   if msgfmt.found()
393     subdir('de/LC_MESSAGES')
394     gio_tests += {
395       'gsettings' : {
396         'extra_sources' : [test_mo],
397         'c_args' : ['-DSRCDIR="@0@"'.format(meson.current_source_dir()),
398                     '-DTEST_LOCALE_PATH="@0@"'.format(test_mo_dir)],
399         'install' : false,
400       },
401     }
402   endif
403 endif # unix
404
405 #  Test programs buildable on Windows only
406 if host_machine.system() == 'windows'
407   gio_tests += {'win32-streams' : {}}
408 endif
409
410 if cc.get_id() != 'msvc'
411   gio_tests += {
412     'autoptr-gio' : {
413       'source' : 'autoptr.c',
414     },
415   }
416 endif
417
418 test_extra_programs += {
419   'gio-du' : {'install' : false},
420   'echo-server' : {'install' : false},
421   'filter-cat' : {'install' : false},
422   'gapplication-example-actions' : {'install' : false},
423   'gapplication-example-cmdline' : {'install' : false},
424   'gapplication-example-cmdline2' : {'install' : false},
425   'gapplication-example-cmdline3' : {'install' : false},
426   'gapplication-example-cmdline4' : {'install' : false},
427   'gapplication-example-dbushooks' : {'install' : false},
428   'gapplication-example-open' : {'install' : false},
429   'gdbus-daemon' : {
430     'extra_sources' : gdbus_daemon_sources,
431     'install' : false,
432   },
433   'gdbus-example-export' : {'install' : false},
434   'gdbus-example-own-name' : {'install' : false},
435   'gdbus-example-peer' : {'install' : false},
436   'gdbus-example-proxy-subclass' : {'install' : false},
437   'gdbus-example-server' : {'install' : false},
438   'gdbus-example-subtree' : {'install' : false},
439   'gdbus-example-watch-name' : {'install' : false},
440   'gdbus-example-watch-proxy' : {'install' : false},
441   'httpd' : {'install' : false},
442   'proxy' : {'install' : false},
443   'resolver' : {'install' : false},
444   'send-data' : {'install' : false},
445   'socket-server' : {'install' : false},
446   'socket-client' : {
447     'extra_sources' : ['gtlsconsoleinteraction.c'],
448     'install' : false,
449   },
450 }
451
452 gdbus_example_objectmanager_sources = files(
453   'gdbus-example-objectmanager-client.c',
454   'gdbus-example-objectmanager-server.c',
455 )
456
457 if cc.get_id() != 'msvc' and cc.get_id() != 'clang-cl'
458   test_extra_programs += {
459     # These three are manual-run tests because they need a session bus but don't bring one up themselves
460     # FIXME: these build but don't seem to work!
461     'gdbus-example-objectmanager-client' : {
462       'dependencies' : [libgdbus_example_objectmanager_dep],
463       'install' : false,
464     },
465     'gdbus-example-objectmanager-server' : {
466       'dependencies' : [libgdbus_example_objectmanager_dep],
467       'install' : false,
468     },
469     'gdbus-test-fixture' : {
470       'dependencies' : [libgdbus_example_objectmanager_dep],
471       'install' : false,
472     },
473   }
474 endif
475
476 if host_machine.system() != 'windows'
477   test_extra_programs += {
478     'gdbus-example-unix-fd-client' : {
479       'install' : false,
480     },
481   }
482 endif
483
484 appinfo_test_desktop_files = [
485   'appinfo-test-gnome.desktop',
486   'appinfo-test-notgnome.desktop',
487   'appinfo-test.desktop',
488   'appinfo-test2.desktop',
489 ]
490
491 cdata = configuration_data()
492 if installed_tests_enabled
493   cdata.set('installed_tests_dir', installed_tests_execdir)
494 else
495   cdata.set('installed_tests_dir', meson.current_build_dir())
496 endif
497
498 foreach appinfo_test_desktop_file : appinfo_test_desktop_files
499   if installed_tests_enabled
500     configure_file(
501       input: appinfo_test_desktop_file + '.in',
502       output: appinfo_test_desktop_file,
503       install_dir: installed_tests_execdir,
504       configuration: cdata,
505     )
506   else
507     configure_file(
508       input: appinfo_test_desktop_file + '.in',
509       output: appinfo_test_desktop_file,
510       configuration: cdata,
511     )
512   endif
513 endforeach
514
515 if installed_tests_enabled
516   install_data(
517     'contexts.c',
518     'g-icon.c',
519     'appinfo-test-actions.desktop',
520     'appinfo-test-static.desktop',
521     'file.c',
522     'org.gtk.test.dbusappinfo.desktop',
523     'org.gtk.test.dbusappinfo.flatpak.desktop',
524     'test1.overlay',
525     install_dir : installed_tests_execdir,
526   )
527   install_subdir('x-content', install_dir : installed_tests_execdir)
528   install_subdir('desktop-files', install_dir : installed_tests_execdir)
529   install_subdir('thumbnails', install_dir : installed_tests_execdir)
530   install_subdir('cert-tests', install_dir : installed_tests_execdir)
531
532   cdata = configuration_data()
533   cdata.set('installed_tests_dir', installed_tests_execdir)
534   cdata.set('program', 'static-link.py ' + glib_pkgconfigreldir)
535   configure_file(
536     input: installed_tests_template,
537     output: 'static-link.test',
538     install_dir: installed_tests_metadir,
539     configuration: cdata
540   )
541   install_subdir('static-link', install_dir : installed_tests_execdir)
542   install_data('static-link.py', install_dir : installed_tests_execdir)
543
544   monitor_tests = [
545     'memory-monitor-dbus',
546     'memory-monitor-portal',
547     'power-profile-monitor-dbus',
548     'power-profile-monitor-portal'
549   ]
550
551   foreach monitor_test : monitor_tests
552     cdata = configuration_data()
553     cdata.set('installed_tests_dir', installed_tests_execdir)
554     cdata.set('program', monitor_test + '.py')
555     cdata.set('env', '')
556     configure_file(
557       input: installed_tests_template_tap,
558       output: monitor_test + '.test',
559       install_dir: installed_tests_metadir,
560       configuration: cdata
561     )
562     cdata = configuration_data()
563     cdata.set('libexecdir', join_paths(glib_prefix, get_option('libexecdir')))
564     configure_file(
565       input: monitor_test + '.py.in',
566       output: monitor_test + '.py',
567       install_dir : installed_tests_execdir,
568       configuration: cdata,
569     )
570   endforeach
571 endif
572
573 if not meson.is_cross_build() or meson.has_exe_wrapper()
574
575   plugin_resources_c = custom_target('plugin-resources.c',
576     input : 'test4.gresource.xml',
577     output : 'plugin-resources.c',
578     command : [glib_compile_resources,
579                '--target=@OUTPUT@',
580                '--sourcedir=' + meson.current_source_dir(),
581                '--generate-source',
582                '--c-name', '_g_plugin',
583                '@INPUT@'])
584
585   shared_module('resourceplugin', 'resourceplugin.c', plugin_resources_c,
586     link_args : export_dynamic_ldflags,
587     dependencies : common_gio_tests_deps,
588     install_dir : installed_tests_execdir,
589     install : installed_tests_enabled
590   )
591
592   # referenced by test2.gresource.xml
593   big_test_resource = custom_target(
594     'gresource-big-test.txt',
595     input : ['gen-big-test-resource.py'],
596     output : ['gresource-big-test.txt'],
597     command : [python, '@INPUT0@', '@OUTPUT@'])
598
599   test_gresource = custom_target('test.gresource',
600     input : 'test.gresource.xml',
601     output : 'test.gresource',
602     command : [glib_compile_resources,
603                '--target=@OUTPUT@',
604                '--sourcedir=' + meson.current_source_dir(),
605                '--sourcedir=' + meson.current_build_dir(),
606                '@INPUT@'],
607     install_dir : installed_tests_execdir,
608     install : installed_tests_enabled)
609
610   test_resources2_c = custom_target('test_resources2.c',
611     input : 'test3.gresource.xml',
612     output : 'test_resources2.c',
613     command : [glib_compile_resources,
614                '--target=@OUTPUT@',
615                '--sourcedir=' + meson.current_source_dir(),
616                '--generate',
617                '--c-name', '_g_test2',
618                '--manual-register',
619                '@INPUT@'])
620
621   test_resources2_h = custom_target('test_resources2.h',
622     input : 'test3.gresource.xml',
623     output : 'test_resources2.h',
624     command : [glib_compile_resources,
625                '--target=@OUTPUT@',
626                '--sourcedir=' + meson.current_source_dir(),
627                '--generate',
628                '--c-name', '_g_test2',
629                '--manual-register',
630                '@INPUT@'])
631
632   test_resources_c = custom_target('test_resources.c',
633     input : 'test2.gresource.xml',
634     depends : big_test_resource,
635     output : 'test_resources.c',
636     command : [glib_compile_resources,
637                '--target=@OUTPUT@',
638                '--sourcedir=' + meson.current_source_dir(),
639                '--sourcedir=' + meson.current_build_dir(),
640                '--generate-source',
641                '--c-name', '_g_test1',
642                '@INPUT@'])
643
644   digit_test_resources_c = custom_target('digit_test_resources.c',
645     input : '111_digit_test.gresource.xml',
646     output : 'digit_test_resources.c',
647     command : [glib_compile_resources,
648                '--target=@OUTPUT@',
649                '--sourcedir=' + meson.current_source_dir(),
650                '--sourcedir=' + meson.current_build_dir(),
651                '--generate-source',
652                '--manual-register',
653                '@INPUT@'])
654
655   digit_test_resources_h = custom_target('digit_test_resources.h',
656     input : '111_digit_test.gresource.xml',
657     output : 'digit_test_resources.h',
658     command : [glib_compile_resources,
659                '--target=@OUTPUT@',
660                '--sourcedir=' + meson.current_source_dir(),
661                '--generate',
662                '--manual-register',
663                '@INPUT@'])
664
665   # referenced by test.gresource.xml
666   test_generated_txt = configure_file(input : 'test1.txt',
667     output : 'test-generated.txt',
668     copy : true,
669   )
670
671   resources_extra_sources = [
672     test_gresource,
673     test_resources_c,
674     test_resources2_c,
675     test_resources2_h,
676     digit_test_resources_c,
677     digit_test_resources_h,
678   ]
679
680   # Create object file containing resource data for testing the --external-data
681   # option. Currently only GNU ld and objcopy, or (as of 2019) LLVM ld and
682   # objcopy, support the right options.
683   objcopy_supports_add_symbol = false
684   objcopy = find_program('objcopy', required : false)
685   if objcopy.found()
686     # FIXME: This should be `check: true` because we never really expect
687     # `objcopy --help` to fail, given that `objcopy` exists. However, it does
688     # fail on FreeBSD because ELF Tool Chain has
689     # [a bug](https://sourceforge.net/p/elftoolchain/code/3950/).
690     # This can be changed back to `check: true` once our CI uses a FreeBSD
691     # version which includes the fix.
692     # See https://gitlab.gnome.org/GNOME/glib/-/merge_requests/2360#note_1318608
693     objcopy_supports_add_symbol = run_command(objcopy, '--help', check: false).stdout().contains('--add-symbol')
694   endif
695
696   ld = find_program('ld', required : false)
697
698   if build_machine.system() == 'linux' and objcopy.found() and objcopy_supports_add_symbol and ld.found()
699     test_gresource_binary = custom_target('test5.gresource',
700       input : 'test5.gresource.xml',
701       output : 'test5.gresource',
702       command : [glib_compile_resources,
703                  '--target=@OUTPUT@',
704                  '--sourcedir=' + meson.current_source_dir(),
705                  '--sourcedir=' + meson.current_build_dir(),
706                  '@INPUT@'],
707       install_dir : installed_tests_execdir,
708       install : installed_tests_enabled)
709
710     # Create resource data file
711     test_resources_binary_c = custom_target('test_resources_binary.c',
712       input : 'test5.gresource.xml',
713       output : 'test_resources_binary.c',
714       command : [glib_compile_resources,
715                  '--target=@OUTPUT@',
716                  '--sourcedir=' + meson.current_source_dir(),
717                  '--sourcedir=' + meson.current_build_dir(),
718                  '--generate-source',
719                  '--external-data',
720                  '--c-name', '_g_binary_test1',
721                  '@INPUT@'])
722
723     # Create object file containing resource data
724     test_resources_binary = custom_target('test_resources.o',
725       input : test_gresource_binary,
726       output : 'test_resources.o',
727       command : [ld,
728                  '-r',
729                  '-b','binary',
730                  '@INPUT@',
731                  '-o','@OUTPUT@'])
732
733     # Rename symbol to match the one in the C file
734     test_resources_binary2 = custom_target('test_resources2.o',
735       input : test_resources_binary,
736       output : 'test_resources2.o',
737       command : [objcopy,
738                  '--add-symbol','_g_binary_test1_resource_data=.data:0',
739                  '@INPUT@',
740                  '@OUTPUT@'])
741
742     resources_extra_sources += [
743       test_resources_binary_c,
744       test_resources_binary2,
745     ]
746   endif
747
748   gio_tests += {
749     'resources' : {
750       'extra_sources' : resources_extra_sources,
751     },
752   }
753 endif
754
755 foreach test_name, extra_args : gio_tests
756   source = extra_args.get('source', test_name + '.c')
757   extra_sources = extra_args.get('extra_sources', [])
758   install = installed_tests_enabled and extra_args.get('install', true)
759   installed_tests_env = extra_args.get('installed_tests_env', {})
760
761   if install
762     test_conf = configuration_data()
763     test_conf.set('installed_tests_dir', installed_tests_execdir)
764     test_conf.set('program', test_name)
765     test_env_override = ''
766     if installed_tests_env != {}
767       envs = []
768       foreach var, value : installed_tests_env
769          envs += '@0@=@1@'.format(var, value)
770       endforeach
771       test_env_override = '@0@ @1@ '.format(env_program.path(), ' '.join(envs))
772     endif
773     test_conf.set('env', test_env_override)
774     configure_file(
775       input: installed_tests_template_tap,
776       output: test_name + '.test',
777       install_dir: installed_tests_metadir,
778       configuration: test_conf
779     )
780   endif
781
782   exe = executable(test_name, [source, extra_sources],
783     c_args : test_c_args + extra_args.get('c_args', []),
784     dependencies : common_gio_tests_deps + extra_args.get('dependencies', []),
785     install_rpath : extra_args.get('install_rpath', ''),
786     install_dir: installed_tests_execdir,
787     install: install,
788   )
789
790   suite = ['gio'] + extra_args.get('suite', [])
791   timeout = suite.contains('slow') ? test_timeout_slow : test_timeout
792   local_test_env = test_env
793
794   foreach var, value : extra_args.get('env', {})
795     local_test_env.append(var, value)
796   endforeach
797
798   test(test_name, exe,
799     env : local_test_env,
800     timeout : timeout,
801     suite : suite,
802     is_parallel : extra_args.get('is_parallel', true),
803     depends : extra_args.get('depends', []),
804   )
805 endforeach
806
807 foreach program_name, extra_args : test_extra_programs
808   source = extra_args.get('source', program_name + '.c')
809   extra_sources = extra_args.get('extra_sources', [])
810   install = installed_tests_enabled and extra_args.get('install', true)
811   executable(program_name, [source, extra_sources],
812       c_args : test_c_args,
813       dependencies : common_gio_tests_deps + extra_args.get('dependencies', []),
814       install_dir : installed_tests_execdir,
815       install : install,
816   )
817 endforeach
818
819 foreach test_name : python_tests
820   test(
821     test_name,
822     python,
823     args: ['-B', files(test_name)],
824     env: test_env,
825     suite: ['gio', 'no-valgrind'],
826   )
827
828   if installed_tests_enabled
829     install_data(
830       files(test_name),
831       install_dir: installed_tests_execdir,
832       install_mode: 'rwxr-xr-x',
833     )
834
835     test_conf = configuration_data()
836     test_conf.set('installed_tests_dir', installed_tests_execdir)
837     test_conf.set('program', test_name)
838     test_conf.set('env', '')
839     configure_file(
840       input: installed_tests_template_tap,
841       output: test_name + '.test',
842       install_dir: installed_tests_metadir,
843       configuration: test_conf,
844     )
845   endif
846 endforeach
847
848 # TAP test runner for Python tests
849 if installed_tests_enabled
850   install_data(
851     files('taptestrunner.py'),
852     install_dir: installed_tests_execdir,
853   )
854 endif
855
856 subdir('services')
857 subdir('modules')