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