Imported Upstream version 2.69.1
[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)).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   memory_monitor_tests = [
545     'memory-monitor-dbus',
546     'memory-monitor-portal',
547   ]
548
549   foreach memory_monitor_test : memory_monitor_tests
550     cdata = configuration_data()
551     cdata.set('installed_tests_dir', installed_tests_execdir)
552     cdata.set('program', memory_monitor_test + '.py')
553     cdata.set('env', '')
554     configure_file(
555       input: installed_tests_template_tap,
556       output: memory_monitor_test + '.test',
557       install_dir: installed_tests_metadir,
558       configuration: cdata
559     )
560     cdata = configuration_data()
561     cdata.set('libexecdir', join_paths(glib_prefix, get_option('libexecdir')))
562     configure_file(
563       input: memory_monitor_test + '.py.in',
564       output: memory_monitor_test + '.py',
565       install_dir : installed_tests_execdir,
566       configuration: cdata,
567     )
568   endforeach
569 endif
570
571 if not meson.is_cross_build() or meson.has_exe_wrapper()
572
573   plugin_resources_c = custom_target('plugin-resources.c',
574     input : 'test4.gresource.xml',
575     output : 'plugin-resources.c',
576     command : [glib_compile_resources,
577                '--target=@OUTPUT@',
578                '--sourcedir=' + meson.current_source_dir(),
579                '--generate-source',
580                '--c-name', '_g_plugin',
581                '@INPUT@'])
582
583   shared_module('resourceplugin', 'resourceplugin.c', plugin_resources_c,
584     link_args : export_dynamic_ldflags,
585     dependencies : common_gio_tests_deps,
586     install_dir : installed_tests_execdir,
587     install : installed_tests_enabled
588   )
589
590   # referenced by test2.gresource.xml
591   big_test_resource = custom_target(
592     'gresource-big-test.txt',
593     input : ['gen-big-test-resource.py'],
594     output : ['gresource-big-test.txt'],
595     command : [python, '@INPUT0@', '@OUTPUT@'])
596
597   test_gresource = custom_target('test.gresource',
598     input : 'test.gresource.xml',
599     output : 'test.gresource',
600     command : [glib_compile_resources,
601                '--target=@OUTPUT@',
602                '--sourcedir=' + meson.current_source_dir(),
603                '--sourcedir=' + meson.current_build_dir(),
604                '@INPUT@'],
605     install_dir : installed_tests_execdir,
606     install : installed_tests_enabled)
607
608   test_resources2_c = custom_target('test_resources2.c',
609     input : 'test3.gresource.xml',
610     output : 'test_resources2.c',
611     command : [glib_compile_resources,
612                '--target=@OUTPUT@',
613                '--sourcedir=' + meson.current_source_dir(),
614                '--generate',
615                '--c-name', '_g_test2',
616                '--manual-register',
617                '@INPUT@'])
618
619   test_resources2_h = custom_target('test_resources2.h',
620     input : 'test3.gresource.xml',
621     output : 'test_resources2.h',
622     command : [glib_compile_resources,
623                '--target=@OUTPUT@',
624                '--sourcedir=' + meson.current_source_dir(),
625                '--generate',
626                '--c-name', '_g_test2',
627                '--manual-register',
628                '@INPUT@'])
629
630   test_resources_c = custom_target('test_resources.c',
631     input : 'test2.gresource.xml',
632     depends : big_test_resource,
633     output : 'test_resources.c',
634     command : [glib_compile_resources,
635                '--target=@OUTPUT@',
636                '--sourcedir=' + meson.current_source_dir(),
637                '--sourcedir=' + meson.current_build_dir(),
638                '--generate-source',
639                '--c-name', '_g_test1',
640                '@INPUT@'])
641
642   digit_test_resources_c = custom_target('digit_test_resources.c',
643     input : '111_digit_test.gresource.xml',
644     output : 'digit_test_resources.c',
645     command : [glib_compile_resources,
646                '--target=@OUTPUT@',
647                '--sourcedir=' + meson.current_source_dir(),
648                '--sourcedir=' + meson.current_build_dir(),
649                '--generate-source',
650                '--manual-register',
651                '@INPUT@'])
652
653   digit_test_resources_h = custom_target('digit_test_resources.h',
654     input : '111_digit_test.gresource.xml',
655     output : 'digit_test_resources.h',
656     command : [glib_compile_resources,
657                '--target=@OUTPUT@',
658                '--sourcedir=' + meson.current_source_dir(),
659                '--generate',
660                '--manual-register',
661                '@INPUT@'])
662
663   # referenced by test.gresource.xml
664   test_generated_txt = configure_file(input : 'test1.txt',
665     output : 'test-generated.txt',
666     copy : true,
667   )
668
669   resources_extra_sources = [
670     test_gresource,
671     test_resources_c,
672     test_resources2_c,
673     test_resources2_h,
674     digit_test_resources_c,
675     digit_test_resources_h,
676   ]
677
678   # Create object file containing resource data for testing the --external-data
679   # option. Currently only GNU ld and objcopy, or (as of 2019) LLVM ld and
680   # objcopy, support the right options.
681   objcopy_supports_add_symbol = false
682   objcopy = find_program('objcopy', required : false)
683   if objcopy.found()
684     objcopy_supports_add_symbol = run_command(objcopy, '--help').stdout().contains('--add-symbol')
685   endif
686
687   ld = find_program('ld', required : false)
688
689   if build_machine.system() == 'linux' and objcopy.found() and objcopy_supports_add_symbol and ld.found()
690     test_gresource_binary = custom_target('test5.gresource',
691       input : 'test5.gresource.xml',
692       output : 'test5.gresource',
693       command : [glib_compile_resources,
694                  '--target=@OUTPUT@',
695                  '--sourcedir=' + meson.current_source_dir(),
696                  '--sourcedir=' + meson.current_build_dir(),
697                  '@INPUT@'],
698       install_dir : installed_tests_execdir,
699       install : installed_tests_enabled)
700
701     # Create resource data file
702     test_resources_binary_c = custom_target('test_resources_binary.c',
703       input : 'test5.gresource.xml',
704       output : 'test_resources_binary.c',
705       command : [glib_compile_resources,
706                  '--target=@OUTPUT@',
707                  '--sourcedir=' + meson.current_source_dir(),
708                  '--sourcedir=' + meson.current_build_dir(),
709                  '--generate-source',
710                  '--external-data',
711                  '--c-name', '_g_binary_test1',
712                  '@INPUT@'])
713
714     # Create object file containing resource data
715     test_resources_binary = custom_target('test_resources.o',
716       input : test_gresource_binary,
717       output : 'test_resources.o',
718       command : [ld,
719                  '-r',
720                  '-b','binary',
721                  '@INPUT@',
722                  '-o','@OUTPUT@'])
723
724     # Rename symbol to match the one in the C file
725     test_resources_binary2 = custom_target('test_resources2.o',
726       input : test_resources_binary,
727       output : 'test_resources2.o',
728       command : [objcopy,
729                  '--add-symbol','_g_binary_test1_resource_data=.data:0',
730                  '@INPUT@',
731                  '@OUTPUT@'])
732
733     resources_extra_sources += [
734       test_resources_binary_c,
735       test_resources_binary2,
736     ]
737   endif
738
739   gio_tests += {
740     'resources' : {
741       'extra_sources' : resources_extra_sources,
742     },
743   }
744 endif
745
746 foreach test_name, extra_args : gio_tests
747   source = extra_args.get('source', test_name + '.c')
748   extra_sources = extra_args.get('extra_sources', [])
749   install = installed_tests_enabled and extra_args.get('install', true)
750   installed_tests_env = extra_args.get('installed_tests_env', {})
751
752   if install
753     test_conf = configuration_data()
754     test_conf.set('installed_tests_dir', installed_tests_execdir)
755     test_conf.set('program', test_name)
756     test_env_override = ''
757     if installed_tests_env != {}
758       envs = []
759       foreach var, value : installed_tests_env
760          envs += '@0@=@1@'.format(var, value)
761       endforeach
762       test_env_override = '@0@ @1@ '.format(env_program.path(), ' '.join(envs))
763     endif
764     test_conf.set('env', test_env_override)
765     configure_file(
766       input: installed_tests_template_tap,
767       output: test_name + '.test',
768       install_dir: installed_tests_metadir,
769       configuration: test_conf
770     )
771   endif
772
773   exe = executable(test_name, [source, extra_sources],
774     c_args : test_c_args + extra_args.get('c_args', []),
775     dependencies : common_gio_tests_deps + extra_args.get('dependencies', []),
776     install_rpath : extra_args.get('install_rpath', ''),
777     install_dir: installed_tests_execdir,
778     install: install,
779   )
780
781   suite = ['gio'] + extra_args.get('suite', [])
782   timeout = suite.contains('slow') ? test_timeout_slow : test_timeout
783   local_test_env = test_env
784
785   foreach var, value : extra_args.get('env', {})
786     local_test_env.append(var, value)
787   endforeach
788
789   test(test_name, exe,
790     env : local_test_env,
791     timeout : timeout,
792     suite : suite,
793     is_parallel : extra_args.get('is_parallel', true),
794     depends : extra_args.get('depends', []),
795   )
796 endforeach
797
798 foreach program_name, extra_args : test_extra_programs
799   source = extra_args.get('source', program_name + '.c')
800   extra_sources = extra_args.get('extra_sources', [])
801   install = installed_tests_enabled and extra_args.get('install', true)
802   executable(program_name, [source, extra_sources],
803       c_args : test_c_args,
804       dependencies : common_gio_tests_deps + extra_args.get('dependencies', []),
805       install_dir : installed_tests_execdir,
806       install : install,
807   )
808 endforeach
809
810 foreach test_name : python_tests
811   test(
812     test_name,
813     python,
814     args: ['-B', files(test_name)],
815     env: test_env,
816     suite: ['gio', 'no-valgrind'],
817   )
818
819   if installed_tests_enabled
820     install_data(
821       files(test_name),
822       install_dir: installed_tests_execdir,
823       install_mode: 'rwxr-xr-x',
824     )
825
826     test_conf = configuration_data()
827     test_conf.set('installed_tests_dir', installed_tests_execdir)
828     test_conf.set('program', test_name)
829     test_conf.set('env', '')
830     configure_file(
831       input: installed_tests_template_tap,
832       output: test_name + '.test',
833       install_dir: installed_tests_metadir,
834       configuration: test_conf,
835     )
836   endif
837 endforeach
838
839 # TAP test runner for Python tests
840 if installed_tests_enabled
841   install_data(
842     files('taptestrunner.py'),
843     install_dir: installed_tests_execdir,
844   )
845 endif
846
847 subdir('services')
848 subdir('modules')