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