Imported Upstream version 2.58.2
[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   '-DTEST_SERVICES="@0@/gio/tests/services"'.format(meson.build_root()),
11   '-DGLIB_MKENUMS="@0@"'.format(glib_mkenums),
12   '-DGLIB_COMPILE_SCHEMAS="@0@"'.format(glib_compile_schemas.full_path()),
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 # FIXME: We are using list of dictionnaries until we can depend on Meson 0.48.0
30 # that supports '+=' operator on dictionnaries.
31 gio_tests = [{
32   'appmonitor' : {},
33   'async-close-output-stream' : {},
34   'async-splice-output-stream' : {},
35   'buffered-input-stream' : {},
36   'buffered-output-stream' : {},
37   'cancellable' : {},
38   'contexts' : {},
39   'contenttype' : {},
40   'converter-stream' : {},
41   'credentials' : {},
42   'data-input-stream' : {},
43   'data-output-stream' : {},
44   'defaultvalue' : {'extra_sources' : [giotypefuncs_inc]},
45   'fileattributematcher' : {},
46   'filter-streams' : {},
47   'giomodule' : {},
48   'gsubprocess' : {},
49   'g-file' : {},
50   'g-file-info' : {},
51   'g-icon' : {},
52   'gdbus-addresses' : {},
53   'gdbus-message' : {},
54   'inet-address' : {},
55   'io-stream' : {},
56   'memory-input-stream' : {},
57   'memory-output-stream' : {},
58   'monitor' : {},
59   'mount-operation' : {},
60   'network-address' : {},
61   'network-monitor' : {},
62   'network-monitor-race' : {},
63   'permission' : {},
64   'pollable' : {},
65   'proxy-test' : {},
66   'readwrite' : {},
67   'simple-async-result' : {},
68   'simple-proxy' : {},
69   'sleepy-stream' : {},
70   'socket' : {},
71   'socket-listener' : {},
72   'socket-service' : {},
73   'srvtarget' : {},
74   'task' : {},
75   'vfs' : {},
76   'volumemonitor' : {},
77   'glistmodel' : {},
78   'testfilemonitor' : {'suite' : ['slow']},
79   'thumbnail-verification' : {},
80   'tls-certificate' : {'extra_sources' : ['gtesttlsbackend.c']},
81   'tls-interaction' : {'extra_sources' : ['gtesttlsbackend.c']},
82 }]
83
84 # FIXME: We are using list of dictionnaries until we can depend on Meson 0.48.0
85 # that supports '+=' operator on dictionnaries.
86 test_extra_programs = [{
87   'gdbus-connection-flush-helper' : {},
88   'gdbus-testserver' : {},
89   'gsubprocess-testprog' : {},
90 }]
91
92 test_env = environment()
93 test_env.set('G_TEST_SRCDIR', meson.current_source_dir())
94 test_env.set('G_TEST_BUILDDIR', meson.current_build_dir())
95 test_env.set('GIO_MODULE_DIR', '')
96 test_env.set('GIO_LAUNCH_DESKTOP', meson.build_root() + '/gio/gio-launch-desktop')
97
98 # Check for libdbus1 - Optional - is only used in the GDBus test cases
99 # 1.2.14 required for dbus_message_set_serial
100 dbus1_dep = dependency('dbus-1', required : false, version : '>= 1.2.14')
101 if not dbus1_dep.found()
102   if cc.get_id() == 'msvc'
103     # MSVC: Search for the DBus library by the configuration, which corresponds
104     # to the output of CMake builds of DBus.  Note that debugoptimized
105     # is really a Release build with .PDB files.
106     if buildtype == 'debug'
107       dbus1_dep = cc.find_library('dbus-1d', required : false)
108     else
109       dbus1_dep = cc.find_library('dbus-1', required : false)
110     endif
111   endif
112 endif
113 if dbus1_dep.found()
114   glib_conf.set('HAVE_DBUS1', 1)
115
116   gio_tests += [{
117     'gdbus-serialization' : {
118       'extra_sources' : ['gdbus-tests.c'],
119       'dependencies' : [dbus1_dep],
120     }
121   }]
122 endif
123
124 #  Test programs buildable on UNIX only
125 if host_machine.system() != 'windows'
126   gio_tests += [{
127     'file' : {},
128     'gdbus-peer' : {
129       'dependencies' : [libgdbus_example_objectmanager_dep],
130       'install_rpath' : installed_tests_execdir
131     },
132     'gdbus-peer-object-manager' : {},
133     'live-g-file' : {},
134     'socket-address' : {},
135     'stream-rw_all' : {},
136     'unix-fd' : {},
137     'unix-mounts' : {},
138     'unix-streams' : {},
139     'g-file-info-filesystem-readonly' : {},
140     'gschema-compile' : {'install' : false},
141     'trash' : {},
142   }]
143
144   # Uninstalled because of the check-for-executable logic in DesktopAppInfo
145   # unable to find the installed executable
146   if not glib_have_cocoa
147     gio_tests += [{
148       'appinfo' : {
149         'install' : false,
150         'is_parallel' : false,
151       },
152       'desktop-app-info' : {
153         'install' : false,
154         'is_parallel' : false,
155       },
156     }]
157   endif
158
159   test_extra_programs += [{
160     'basic-application' : {},
161     'dbus-launch' : {},
162     'appinfo-test' : {},
163   }]
164
165   if not glib_have_cocoa
166     test_extra_programs += [{
167       'apps' : {},
168     }]
169     gio_tests += [{
170       'mimeapps' : {},
171     }]
172   endif
173
174   #  Test programs that need to bring up a session bus (requires dbus-daemon)
175   have_dbus_daemon = find_program('dbus-daemon', required : false).found()
176   if have_dbus_daemon
177     annotate_args = [
178       '--annotate', 'org.project.Bar', 'Key1', 'Value1',
179       '--annotate', 'org.project.Bar', 'org.gtk.GDBus.Internal', 'Value2',
180       '--annotate', 'org.project.Bar.HelloWorld()', 'Key3', 'Value3',
181       '--annotate', 'org.project.Bar::TestSignal', 'Key4', 'Value4',
182       '--annotate', 'org.project.Bar:ay', 'Key5', 'Value5',
183       '--annotate', 'org.project.Bar.TestPrimitiveTypes()[val_int32]', 'Key6', 'Value6',
184       '--annotate', 'org.project.Bar.TestPrimitiveTypes()[ret_uint32]', 'Key7', 'Value7',
185       '--annotate', 'org.project.Bar::TestSignal[array_of_strings]', 'Key8', 'Value8',
186     ]
187     # Generate gdbus-test-codegen-generated.{c,h}
188     gdbus_test_codegen_generated = custom_target('gdbus-test-codegen-generated',
189         input :   ['test-codegen.xml'],
190         output :  ['gdbus-test-codegen-generated.h',
191                    'gdbus-test-codegen-generated.c'],
192         depend_files : gdbus_codegen_built_files,
193         command : [python, gdbus_codegen,
194                    '--interface-prefix', 'org.project.',
195                    '--output-directory', '@OUTDIR@',
196                    '--generate-c-code', 'gdbus-test-codegen-generated',
197                    '--c-generate-object-manager',
198                    '--c-generate-autocleanup', 'all',
199                    '--c-namespace', 'Foo_iGen',
200                    '--generate-docbook', 'gdbus-test-codegen-generated-doc',
201                    annotate_args,
202                    '@INPUT@'])
203
204     gdbus_test_codegen_generated_interface_info = [
205       custom_target('gdbus-test-codegen-generated-interface-info-h',
206           input :   ['test-codegen.xml'],
207           output :  ['gdbus-test-codegen-generated-interface-info.h'],
208           depend_files : gdbus_codegen_built_files,
209           command : [python, gdbus_codegen,
210                      '--interface-info-header',
211                      annotate_args,
212                      '--output', '@OUTPUT@',
213                      '@INPUT@']),
214       custom_target('gdbus-test-codegen-generated-interface-info-c',
215           input :   ['test-codegen.xml'],
216           output :  ['gdbus-test-codegen-generated-interface-info.c'],
217           depend_files : gdbus_codegen_built_files,
218           command : [python, gdbus_codegen,
219                      '--interface-info-body',
220                      annotate_args,
221                      '--output', '@OUTPUT@',
222                      '@INPUT@']),
223     ]
224
225     extra_sources = ['gdbus-sessionbus.c', 'gdbus-tests.c']
226
227     gio_tests += [{
228       'actions' : {
229         'extra_sources' : extra_sources,
230         'suite' : ['slow'],
231       },
232       'gdbus-auth' : {'extra_sources' : extra_sources},
233       'gdbus-bz627724' : {'extra_sources' : extra_sources},
234       'gdbus-close-pending' : {'extra_sources' : extra_sources},
235       'gdbus-connection' : {'extra_sources' : extra_sources},
236       'gdbus-connection-loss' : {'extra_sources' : extra_sources},
237       'gdbus-connection-slow' : {'extra_sources' : extra_sources},
238       'gdbus-error' : {'extra_sources' : extra_sources},
239       'gdbus-exit-on-close' : {'extra_sources' : extra_sources},
240       'gdbus-export' : {
241         'extra_sources' : extra_sources,
242         'suite' : ['slow'],
243       },
244       'gdbus-introspection' : {'extra_sources' : extra_sources},
245       'gdbus-names' : {'extra_sources' : extra_sources},
246       'gdbus-proxy' : {'extra_sources' : extra_sources},
247       'gdbus-proxy-threads' : {
248         'extra_sources' : extra_sources,
249         'dependencies' : [dbus1_dep],
250       },
251       'gdbus-proxy-well-known-name' : {'extra_sources' : extra_sources},
252       'gdbus-test-codegen' : {
253         'extra_sources' : [extra_sources, gdbus_test_codegen_generated, gdbus_test_codegen_generated_interface_info],
254       },
255       'gdbus-threading' : {
256         'extra_sources' : extra_sources,
257         'suite' : ['slow'],
258       },
259       'gmenumodel' : {
260         'extra_sources' : extra_sources,
261         'suite' : ['slow'],
262       },
263       'gnotification' : {
264         'extra_sources' : [extra_sources, 'gnotification-server.c'],
265       },
266       'gdbus-test-codegen-old' : {
267         'source' : 'gdbus-test-codegen.c',
268         'extra_sources' : [extra_sources, gdbus_test_codegen_generated, gdbus_test_codegen_generated_interface_info],
269         'c_args' : ['-DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_2_36',
270                     '-DGLIB_VERSION_MAX_ALLOWED=GLIB_VERSION_2_36'],
271       },
272       'gapplication' : {'extra_sources' : extra_sources},
273       'gdbus-unix-addresses' : {},
274     }]
275
276     if not glib_have_cocoa
277       gio_tests += [{
278         'dbus-appinfo' : {
279           'extra_sources' : extra_sources,
280         },
281       }]
282     endif
283   endif # have_dbus_daemon
284
285   # This test is currently unreliable
286   executable('gdbus-overflow', 'gdbus-overflow.c',
287       c_args : test_c_args,
288       dependencies : common_gio_tests_deps,
289       install_dir : installed_tests_execdir,
290       install : installed_tests_enabled)
291
292   gio_tests += [{
293     'gdbus-connection-flush' : {
294       'extra_sources' : ['test-io-stream.c', 'test-pipe-unix.c'],
295     },
296     'gdbus-non-socket' : {
297       'extra_sources' : ['gdbus-tests.c', 'test-io-stream.c', 'test-pipe-unix.c'],
298     },
299   }]
300
301   # Generate test.mo from de.po using msgfmt
302   msgfmt = find_program('msgfmt', required : false)
303   if msgfmt.found()
304     subdir('de/LC_MESSAGES')
305     gio_tests += [{
306       'gsettings' : {
307         'extra_sources' : [test_mo],
308         'c_args' : ['-DSRCDIR="@0@"'.format(meson.current_source_dir()),
309                     '-DTEST_LOCALE_PATH="@0@"'.format(test_mo_dir)],
310         'install' : false,
311       },
312     }]
313   endif
314 endif # unix
315
316 #  Test programs buildable on Windows only
317 if host_machine.system() == 'windows'
318   gio_tests += [{'win32-streams' : {}}]
319 endif
320
321 if cc.get_id() != 'msvc'
322   gio_tests += [{
323     'autoptr-gio' : {
324       'source' : 'autoptr.c',
325     },
326   }]
327 endif
328
329 test_extra_programs += [{
330   'gio-du' : {'install' : false},
331   'echo-server' : {'install' : false},
332   'filter-cat' : {'install' : false},
333   'gapplication-example-actions' : {'install' : false},
334   'gapplication-example-cmdline' : {'install' : false},
335   'gapplication-example-cmdline2' : {'install' : false},
336   'gapplication-example-cmdline3' : {'install' : false},
337   'gapplication-example-cmdline4' : {'install' : false},
338   'gapplication-example-dbushooks' : {'install' : false},
339   'gapplication-example-open' : {'install' : false},
340   'gdbus-daemon' : {
341     'extra_sources' : gdbus_daemon_sources,
342     'install' : false,
343   },
344   'gdbus-example-export' : {'install' : false},
345   'gdbus-example-own-name' : {'install' : false},
346   'gdbus-example-peer' : {'install' : false},
347   'gdbus-example-proxy-subclass' : {'install' : false},
348   'gdbus-example-server' : {'install' : false},
349   'gdbus-example-subtree' : {'install' : false},
350   'gdbus-example-watch-name' : {'install' : false},
351   'gdbus-example-watch-proxy' : {'install' : false},
352   'httpd' : {'install' : false},
353   'proxy' : {'install' : false},
354   'resolver' : {'install' : false},
355   'send-data' : {'install' : false},
356   'socket-server' : {'install' : false},
357   'socket-client' : {
358     'extra_sources' : ['gtlsconsoleinteraction.c'],
359     'install' : false,
360   },
361 }]
362
363 if cc.get_id() != 'msvc'
364   test_extra_programs += [{
365     # These three are manual-run tests because they need a session bus but don't bring one up themselves
366     # FIXME: these build but don't seem to work!
367     'gdbus-example-objectmanager-client' : {
368       'dependencies' : [libgdbus_example_objectmanager_dep],
369       'install' : false,
370     },
371     'gdbus-example-objectmanager-server' : {
372       'dependencies' : [libgdbus_example_objectmanager_dep],
373       'install' : false,
374     },
375     'gdbus-test-fixture' : {
376       'dependencies' : [libgdbus_example_objectmanager_dep],
377       'install' : false,
378     },
379   }]
380 endif
381
382 if host_machine.system() != 'windows'
383   test_extra_programs += [{
384     'gdbus-example-unix-fd-client' : {
385       'install' : false,
386     },
387   }]
388 endif
389
390 if installed_tests_enabled
391   install_data(
392     'contexts.c',
393     'g-icon.c',
394     'appinfo-test-actions.desktop',
395     'appinfo-test-gnome.desktop',
396     'appinfo-test-notgnome.desktop',
397     'appinfo-test.desktop',
398     'appinfo-test2.desktop',
399     'file.c',
400     'org.gtk.test.dbusappinfo.desktop',
401     install_dir : installed_tests_execdir,
402   )
403   install_subdir('x-content', install_dir : installed_tests_execdir)
404   install_subdir('desktop-files', install_dir : installed_tests_execdir)
405   install_subdir('thumbnails', install_dir : installed_tests_execdir)
406   install_subdir('cert-tests', install_dir : installed_tests_execdir)
407 endif
408
409 if not meson.is_cross_build() or meson.has_exe_wrapper()
410
411   plugin_resources_c = custom_target('plugin-resources.c',
412     input : 'test4.gresource.xml',
413     output : 'plugin-resources.c',
414     command : [glib_compile_resources,
415                '--target=@OUTPUT@',
416                '--sourcedir=' + meson.current_source_dir(),
417                '--generate-source',
418                '--c-name', '_g_plugin',
419                '@INPUT@'])
420
421   shared_module('resourceplugin', 'resourceplugin.c', plugin_resources_c,
422     link_args : export_dynamic_ldflags,
423     dependencies : common_gio_tests_deps,
424     install_dir : installed_tests_execdir,
425     install : installed_tests_enabled
426   )
427
428   test_gresource = custom_target('test.gresource',
429     input : 'test.gresource.xml',
430     output : 'test.gresource',
431     command : [glib_compile_resources,
432                '--target=@OUTPUT@',
433                '--sourcedir=' + meson.current_source_dir(),
434                '--sourcedir=' + meson.current_build_dir(),
435                '@INPUT@'],
436     install_dir : installed_tests_execdir,
437     install : installed_tests_enabled)
438
439   test_resources2_c = custom_target('test_resources2.c',
440     input : 'test3.gresource.xml',
441     output : 'test_resources2.c',
442     command : [glib_compile_resources,
443                '--target=@OUTPUT@',
444                '--sourcedir=' + meson.current_source_dir(),
445                '--generate',
446                '--c-name', '_g_test2',
447                '--manual-register',
448                '@INPUT@'])
449
450   test_resources2_h = custom_target('test_resources2.h',
451     input : 'test3.gresource.xml',
452     output : 'test_resources2.h',
453     command : [glib_compile_resources,
454                '--target=@OUTPUT@',
455                '--sourcedir=' + meson.current_source_dir(),
456                '--generate',
457                '--c-name', '_g_test2',
458                '--manual-register',
459                '@INPUT@'])
460
461   test_resources_c = custom_target('test_resources.c',
462     input : 'test2.gresource.xml',
463     output : 'test_resources.c',
464     command : [glib_compile_resources,
465                '--target=@OUTPUT@',
466                '--sourcedir=' + meson.current_source_dir(),
467                '--generate-source',
468                '--c-name', '_g_test1',
469                '@INPUT@'])
470
471   # referenced by test.gresource.xml
472   test_generated_txt = configure_file(input : 'test1.txt',
473     output : 'test-generated.txt',
474     copy : true,
475     install : false)
476
477   gio_tests += [{
478     'resources' : {
479       'extra_sources' : [test_gresource, test_resources_c, test_resources2_c,
480                          test_resources2_h],
481     },
482   }]
483 endif
484
485 foreach test_dict : gio_tests
486   foreach test_name, extra_args : test_dict
487     source = extra_args.get('source', test_name + '.c')
488     extra_sources = extra_args.get('extra_sources', [])
489     install = installed_tests_enabled and extra_args.get('install', true)
490
491     if install
492       test_conf = configuration_data()
493       test_conf.set('installed_tests_dir', installed_tests_execdir)
494       test_conf.set('program', test_name)
495       configure_file(
496         input: installed_tests_template_tap,
497         output: test_name + '.test',
498         install_dir: installed_tests_metadir,
499         configuration: test_conf
500       )
501     endif
502
503     exe = executable(test_name, [source, extra_sources],
504       c_args : test_c_args + extra_args.get('c_args', []),
505       dependencies : common_gio_tests_deps + extra_args.get('dependencies', []),
506       install_rpath : extra_args.get('install_rpath', ''),
507       install_dir: installed_tests_execdir,
508       install: install,
509     )
510
511     suite = ['gio'] + extra_args.get('suite', [])
512     timeout = suite.contains('slow') ? test_timeout_slow : test_timeout
513     test(test_name, exe,
514       env : test_env,
515       timeout : timeout,
516       suite : suite,
517       args : ['--tap'],
518       is_parallel : extra_args.get('is_parallel', true),
519     )
520   endforeach
521 endforeach
522
523 foreach program_dict : test_extra_programs
524   foreach program_name, extra_args : program_dict
525     source = extra_args.get('source', program_name + '.c')
526     extra_sources = extra_args.get('extra_sources', [])
527     install = installed_tests_enabled and extra_args.get('install', true)
528     executable(program_name, [source, extra_sources],
529         c_args : test_c_args,
530         dependencies : common_gio_tests_deps + extra_args.get('dependencies', []),
531         install_dir : installed_tests_execdir,
532         install : install,
533     )
534   endforeach
535 endforeach
536
537 # FIXME: subdir('services')
538 subdir('modules')