Imported Upstream version 2.59.0
[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 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-output-stream' : {},
56   'monitor' : {},
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']},
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 }
82
83 test_extra_programs = {
84   'gdbus-connection-flush-helper' : {},
85   'gdbus-testserver' : {},
86   'gsubprocess-testprog' : {},
87 }
88
89 test_env = environment()
90 test_env.set('G_TEST_SRCDIR', meson.current_source_dir())
91 test_env.set('G_TEST_BUILDDIR', meson.current_build_dir())
92 test_env.set('GIO_MODULE_DIR', '')
93 test_env.set('GIO_LAUNCH_DESKTOP', meson.build_root() + '/gio/gio-launch-desktop')
94
95 # Check for libdbus1 - Optional - is only used in the GDBus test cases
96 # 1.2.14 required for dbus_message_set_serial
97 dbus1_dep = dependency('dbus-1', required : false, version : '>= 1.2.14')
98 if not dbus1_dep.found()
99   if cc.get_id() == 'msvc'
100     # MSVC: Search for the DBus library by the configuration, which corresponds
101     # to the output of CMake builds of DBus.  Note that debugoptimized
102     # is really a Release build with .PDB files.
103     if buildtype == 'debug'
104       dbus1_dep = cc.find_library('dbus-1d', required : false)
105     else
106       dbus1_dep = cc.find_library('dbus-1', required : false)
107     endif
108   endif
109 endif
110 if dbus1_dep.found()
111   glib_conf.set('HAVE_DBUS1', 1)
112
113   gio_tests += {
114     'gdbus-serialization' : {
115       'extra_sources' : ['gdbus-tests.c'],
116       'dependencies' : [dbus1_dep],
117     }
118   }
119 endif
120
121 #  Test programs buildable on UNIX only
122 if host_machine.system() != 'windows'
123   gio_tests += {
124     'file' : {},
125     'gdbus-peer' : {
126       'dependencies' : [libgdbus_example_objectmanager_dep],
127       'install_rpath' : installed_tests_execdir
128     },
129     'gdbus-peer-object-manager' : {},
130     'live-g-file' : {},
131     'socket-address' : {},
132     'stream-rw_all' : {},
133     'unix-fd' : {},
134     'unix-mounts' : {},
135     'unix-streams' : {},
136     'g-file-info-filesystem-readonly' : {},
137     'gsocketclient-slow' : {
138       'depends' : [
139         shared_library('slow-connect-preload',
140           'slow-connect-preload.c',
141           name_prefix : '',
142           dependencies: cc.find_library('dl'),
143         )
144       ],
145       'env' : {
146         'LD_PRELOAD': '@0@/slow-connect-preload.so'.format(meson.current_build_dir())
147       }
148     },
149     'gschema-compile' : {'install' : false},
150     'trash' : {},
151   }
152
153   # Uninstalled because of the check-for-executable logic in DesktopAppInfo
154   # unable to find the installed executable
155   if not glib_have_cocoa
156     gio_tests += {
157       'appinfo' : {
158         'install' : false,
159       },
160       'desktop-app-info' : {
161         'install' : false,
162       },
163     }
164   endif
165
166   test_extra_programs += {
167     'basic-application' : {},
168     'dbus-launch' : {},
169     'appinfo-test' : {},
170   }
171
172   if not glib_have_cocoa
173     test_extra_programs += {
174       'apps' : {},
175     }
176     gio_tests += {
177       'mimeapps' : {},
178     }
179   endif
180
181   #  Test programs that need to bring up a session bus (requires dbus-daemon)
182   have_dbus_daemon = find_program('dbus-daemon', required : false).found()
183   if have_dbus_daemon
184     annotate_args = [
185       '--annotate', 'org.project.Bar', 'Key1', 'Value1',
186       '--annotate', 'org.project.Bar', 'org.gtk.GDBus.Internal', 'Value2',
187       '--annotate', 'org.project.Bar.HelloWorld()', 'Key3', 'Value3',
188       '--annotate', 'org.project.Bar::TestSignal', 'Key4', 'Value4',
189       '--annotate', 'org.project.Bar:ay', 'Key5', 'Value5',
190       '--annotate', 'org.project.Bar.TestPrimitiveTypes()[val_int32]', 'Key6', 'Value6',
191       '--annotate', 'org.project.Bar.TestPrimitiveTypes()[ret_uint32]', 'Key7', 'Value7',
192       '--annotate', 'org.project.Bar::TestSignal[array_of_strings]', 'Key8', 'Value8',
193     ]
194     # Generate gdbus-test-codegen-generated.{c,h}
195     gdbus_test_codegen_generated = custom_target('gdbus-test-codegen-generated',
196         input :   ['test-codegen.xml'],
197         output :  ['gdbus-test-codegen-generated.h',
198                    'gdbus-test-codegen-generated.c'],
199         depend_files : gdbus_codegen_built_files,
200         command : [python, gdbus_codegen,
201                    '--interface-prefix', 'org.project.',
202                    '--output-directory', '@OUTDIR@',
203                    '--generate-c-code', 'gdbus-test-codegen-generated',
204                    '--c-generate-object-manager',
205                    '--c-generate-autocleanup', 'all',
206                    '--c-namespace', 'Foo_iGen',
207                    '--generate-docbook', 'gdbus-test-codegen-generated-doc',
208                    annotate_args,
209                    '@INPUT@'])
210
211     gdbus_test_codegen_generated_interface_info = [
212       custom_target('gdbus-test-codegen-generated-interface-info-h',
213           input :   ['test-codegen.xml'],
214           output :  ['gdbus-test-codegen-generated-interface-info.h'],
215           depend_files : gdbus_codegen_built_files,
216           command : [python, gdbus_codegen,
217                      '--interface-info-header',
218                      annotate_args,
219                      '--output', '@OUTPUT@',
220                      '@INPUT@']),
221       custom_target('gdbus-test-codegen-generated-interface-info-c',
222           input :   ['test-codegen.xml'],
223           output :  ['gdbus-test-codegen-generated-interface-info.c'],
224           depend_files : gdbus_codegen_built_files,
225           command : [python, gdbus_codegen,
226                      '--interface-info-body',
227                      annotate_args,
228                      '--output', '@OUTPUT@',
229                      '@INPUT@']),
230     ]
231
232     extra_sources = ['gdbus-sessionbus.c', 'gdbus-tests.c']
233
234     gio_tests += {
235       'actions' : {
236         'extra_sources' : extra_sources,
237         'suite' : ['slow'],
238       },
239       'gdbus-auth' : {'extra_sources' : extra_sources},
240       'gdbus-bz627724' : {'extra_sources' : extra_sources},
241       'gdbus-close-pending' : {'extra_sources' : extra_sources},
242       'gdbus-connection' : {'extra_sources' : extra_sources},
243       'gdbus-connection-loss' : {'extra_sources' : extra_sources},
244       'gdbus-connection-slow' : {'extra_sources' : extra_sources},
245       'gdbus-error' : {'extra_sources' : extra_sources},
246       'gdbus-exit-on-close' : {'extra_sources' : extra_sources},
247       'gdbus-export' : {
248         'extra_sources' : extra_sources,
249         'suite' : ['slow'],
250       },
251       'gdbus-introspection' : {'extra_sources' : extra_sources},
252       'gdbus-names' : {'extra_sources' : extra_sources},
253       'gdbus-proxy' : {'extra_sources' : extra_sources},
254       'gdbus-proxy-threads' : {
255         'extra_sources' : extra_sources,
256         'dependencies' : [dbus1_dep],
257       },
258       'gdbus-proxy-unique-name' : {'extra_sources' : extra_sources},
259       'gdbus-proxy-well-known-name' : {'extra_sources' : extra_sources},
260       'gdbus-test-codegen' : {
261         'extra_sources' : [extra_sources, gdbus_test_codegen_generated, gdbus_test_codegen_generated_interface_info],
262       },
263       'gdbus-threading' : {
264         'extra_sources' : extra_sources,
265         'suite' : ['slow'],
266       },
267       'gmenumodel' : {
268         'extra_sources' : extra_sources,
269         'suite' : ['slow'],
270       },
271       'gnotification' : {
272         'extra_sources' : [extra_sources, 'gnotification-server.c'],
273       },
274       'gdbus-test-codegen-old' : {
275         'source' : 'gdbus-test-codegen.c',
276         'extra_sources' : [extra_sources, gdbus_test_codegen_generated, gdbus_test_codegen_generated_interface_info],
277         'c_args' : ['-DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_2_36',
278                     '-DGLIB_VERSION_MAX_ALLOWED=GLIB_VERSION_2_36'],
279       },
280       'gapplication' : {'extra_sources' : extra_sources},
281       'gdbus-unix-addresses' : {},
282     }
283
284     if not glib_have_cocoa
285       gio_tests += {
286         'dbus-appinfo' : {
287           'extra_sources' : extra_sources,
288         },
289       }
290     endif
291   endif # have_dbus_daemon
292
293   # This test is currently unreliable
294   executable('gdbus-overflow', 'gdbus-overflow.c',
295       c_args : test_c_args,
296       dependencies : common_gio_tests_deps,
297       install_dir : installed_tests_execdir,
298       install : installed_tests_enabled)
299
300   gio_tests += {
301     'gdbus-connection-flush' : {
302       'extra_sources' : ['test-io-stream.c', 'test-pipe-unix.c'],
303     },
304     'gdbus-non-socket' : {
305       'extra_sources' : ['gdbus-tests.c', 'test-io-stream.c', 'test-pipe-unix.c'],
306     },
307   }
308
309   # Generate test.mo from de.po using msgfmt
310   msgfmt = find_program('msgfmt', required : false)
311   if msgfmt.found()
312     subdir('de/LC_MESSAGES')
313     gio_tests += {
314       'gsettings' : {
315         'extra_sources' : [test_mo],
316         'c_args' : ['-DSRCDIR="@0@"'.format(meson.current_source_dir()),
317                     '-DTEST_LOCALE_PATH="@0@"'.format(test_mo_dir)],
318         'install' : false,
319       },
320     }
321   endif
322 endif # unix
323
324 #  Test programs buildable on Windows only
325 if host_machine.system() == 'windows'
326   gio_tests += {'win32-streams' : {}}
327 endif
328
329 if cc.get_id() != 'msvc'
330   gio_tests += {
331     'autoptr-gio' : {
332       'source' : 'autoptr.c',
333     },
334   }
335 endif
336
337 test_extra_programs += {
338   'gio-du' : {'install' : false},
339   'echo-server' : {'install' : false},
340   'filter-cat' : {'install' : false},
341   'gapplication-example-actions' : {'install' : false},
342   'gapplication-example-cmdline' : {'install' : false},
343   'gapplication-example-cmdline2' : {'install' : false},
344   'gapplication-example-cmdline3' : {'install' : false},
345   'gapplication-example-cmdline4' : {'install' : false},
346   'gapplication-example-dbushooks' : {'install' : false},
347   'gapplication-example-open' : {'install' : false},
348   'gdbus-daemon' : {
349     'extra_sources' : gdbus_daemon_sources,
350     'install' : false,
351   },
352   'gdbus-example-export' : {'install' : false},
353   'gdbus-example-own-name' : {'install' : false},
354   'gdbus-example-peer' : {'install' : false},
355   'gdbus-example-proxy-subclass' : {'install' : false},
356   'gdbus-example-server' : {'install' : false},
357   'gdbus-example-subtree' : {'install' : false},
358   'gdbus-example-watch-name' : {'install' : false},
359   'gdbus-example-watch-proxy' : {'install' : false},
360   'httpd' : {'install' : false},
361   'proxy' : {'install' : false},
362   'resolver' : {'install' : false},
363   'send-data' : {'install' : false},
364   'socket-server' : {'install' : false},
365   'socket-client' : {
366     'extra_sources' : ['gtlsconsoleinteraction.c'],
367     'install' : false,
368   },
369 }
370
371 if cc.get_id() != 'msvc'
372   test_extra_programs += {
373     # These three are manual-run tests because they need a session bus but don't bring one up themselves
374     # FIXME: these build but don't seem to work!
375     'gdbus-example-objectmanager-client' : {
376       'dependencies' : [libgdbus_example_objectmanager_dep],
377       'install' : false,
378     },
379     'gdbus-example-objectmanager-server' : {
380       'dependencies' : [libgdbus_example_objectmanager_dep],
381       'install' : false,
382     },
383     'gdbus-test-fixture' : {
384       'dependencies' : [libgdbus_example_objectmanager_dep],
385       'install' : false,
386     },
387   }
388 endif
389
390 if host_machine.system() != 'windows'
391   test_extra_programs += {
392     'gdbus-example-unix-fd-client' : {
393       'install' : false,
394     },
395   }
396 endif
397
398 appinfo_test_desktop_files = [
399   'appinfo-test-gnome.desktop',
400   'appinfo-test-notgnome.desktop',
401   'appinfo-test.desktop',
402   'appinfo-test2.desktop',
403 ]
404
405 cdata = configuration_data()
406 if installed_tests_enabled
407   cdata.set('installed_tests_dir', installed_tests_execdir)
408 else
409   cdata.set('installed_tests_dir', meson.current_build_dir())
410 endif
411
412 foreach appinfo_test_desktop_file : appinfo_test_desktop_files
413   configure_file(
414     input: appinfo_test_desktop_file + '.in',
415     output: appinfo_test_desktop_file,
416     install_dir: installed_tests_execdir,
417     install: installed_tests_enabled,
418     configuration: cdata,
419   )
420 endforeach
421
422 if installed_tests_enabled
423   install_data(
424     'contexts.c',
425     'g-icon.c',
426     'appinfo-test-actions.desktop',
427     'appinfo-test-static.desktop',
428     'file.c',
429     'org.gtk.test.dbusappinfo.desktop',
430     install_dir : installed_tests_execdir,
431   )
432   install_subdir('x-content', install_dir : installed_tests_execdir)
433   install_subdir('desktop-files', install_dir : installed_tests_execdir)
434   install_subdir('thumbnails', install_dir : installed_tests_execdir)
435   install_subdir('cert-tests', install_dir : installed_tests_execdir)
436
437   cdata = configuration_data()
438   cdata.set('installed_tests_dir', installed_tests_execdir)
439   cdata.set('program', 'static-link.py ' + glib_pkgconfigreldir)
440   configure_file(
441     input: installed_tests_template,
442     output: 'static-link.test',
443     install_dir: installed_tests_metadir,
444     configuration: cdata
445   )
446   install_subdir('static-link', install_dir : installed_tests_execdir)
447   install_data('static-link.py', install_dir : installed_tests_execdir)
448 endif
449
450 if not meson.is_cross_build() or meson.has_exe_wrapper()
451
452   plugin_resources_c = custom_target('plugin-resources.c',
453     input : 'test4.gresource.xml',
454     output : 'plugin-resources.c',
455     command : [glib_compile_resources,
456                '--target=@OUTPUT@',
457                '--sourcedir=' + meson.current_source_dir(),
458                '--generate-source',
459                '--c-name', '_g_plugin',
460                '@INPUT@'])
461
462   shared_module('resourceplugin', 'resourceplugin.c', plugin_resources_c,
463     link_args : export_dynamic_ldflags,
464     dependencies : common_gio_tests_deps,
465     install_dir : installed_tests_execdir,
466     install : installed_tests_enabled
467   )
468
469   # referenced by test2.gresource.xml
470   big_test_resource = custom_target(
471     'gresource-big-test.txt',
472     input : ['gen-big-test-resource.py'],
473     output : ['gresource-big-test.txt'],
474     command : [python, '@INPUT0@', '@OUTPUT@'])
475
476   test_gresource = custom_target('test.gresource',
477     input : 'test.gresource.xml',
478     output : 'test.gresource',
479     command : [glib_compile_resources,
480                '--target=@OUTPUT@',
481                '--sourcedir=' + meson.current_source_dir(),
482                '--sourcedir=' + meson.current_build_dir(),
483                '@INPUT@'],
484     install_dir : installed_tests_execdir,
485     install : installed_tests_enabled)
486
487   test_resources2_c = custom_target('test_resources2.c',
488     input : 'test3.gresource.xml',
489     output : 'test_resources2.c',
490     command : [glib_compile_resources,
491                '--target=@OUTPUT@',
492                '--sourcedir=' + meson.current_source_dir(),
493                '--generate',
494                '--c-name', '_g_test2',
495                '--manual-register',
496                '@INPUT@'])
497
498   test_resources2_h = custom_target('test_resources2.h',
499     input : 'test3.gresource.xml',
500     output : 'test_resources2.h',
501     command : [glib_compile_resources,
502                '--target=@OUTPUT@',
503                '--sourcedir=' + meson.current_source_dir(),
504                '--generate',
505                '--c-name', '_g_test2',
506                '--manual-register',
507                '@INPUT@'])
508
509   test_resources_c = custom_target('test_resources.c',
510     input : 'test2.gresource.xml',
511     depends : big_test_resource,
512     output : 'test_resources.c',
513     command : [glib_compile_resources,
514                '--target=@OUTPUT@',
515                '--sourcedir=' + meson.current_source_dir(),
516                '--sourcedir=' + meson.current_build_dir(),
517                '--generate-source',
518                '--c-name', '_g_test1',
519                '@INPUT@'])
520
521   # referenced by test.gresource.xml
522   test_generated_txt = configure_file(input : 'test1.txt',
523     output : 'test-generated.txt',
524     copy : true,
525     install : false)
526
527   # Create object file containing resource data
528   # for testing the external data option
529   if build_machine.system() == 'linux'
530     test_gresource_binary = custom_target('test5.gresource',
531       input : 'test5.gresource.xml',
532       output : 'test5.gresource',
533       command : [glib_compile_resources,
534                  '--target=@OUTPUT@',
535                  '--sourcedir=' + meson.current_source_dir(),
536                  '--sourcedir=' + meson.current_build_dir(),
537                  '@INPUT@'],
538       install_dir : installed_tests_execdir,
539       install : installed_tests_enabled)
540
541         # Create resource data file
542     test_resources_binary_c = custom_target('test_resources_binary.c',
543       input : 'test5.gresource.xml',
544       output : 'test_resources_binary.c',
545       command : [glib_compile_resources,
546                  '--target=@OUTPUT@',
547                  '--sourcedir=' + meson.current_source_dir(),
548                  '--sourcedir=' + meson.current_build_dir(),
549                  '--generate-source',
550                  '--external-data',
551                  '--c-name', '_g_binary_test1',
552                  '@INPUT@'])
553
554         # Create object file containing resource data
555     test_resources_binary = custom_target('test_resources.o',
556       input : test_gresource_binary,
557       output : 'test_resources.o',
558       command : ['ld',
559                  '-r',
560                  '-b','binary',
561                  '@INPUT@',
562                  '-o','@OUTPUT@'])
563
564         # Rename symbol to match the one in the C file
565     test_resources_binary2 = custom_target('test_resources2.o',
566       input : test_resources_binary,
567       output : 'test_resources2.o',
568       command : ['objcopy',
569                  '--add-symbol','_g_binary_test1_resource_data=.data:0',
570                  '@INPUT@',
571                  '@OUTPUT@'])
572
573     gio_tests += {
574       'resources' : {
575         'extra_sources' : [test_gresource, test_resources_c, test_resources2_c,
576                            test_resources2_h, test_resources_binary_c,
577                            test_resources_binary2],
578       },
579     }
580   else
581     gio_tests += {
582       'resources' : {
583         'extra_sources' : [test_gresource, test_resources_c, test_resources2_c,
584                            test_resources2_h],
585       },
586     }
587   endif
588 endif
589
590 foreach test_name, extra_args : gio_tests
591   source = extra_args.get('source', test_name + '.c')
592   extra_sources = extra_args.get('extra_sources', [])
593   install = installed_tests_enabled and extra_args.get('install', true)
594
595   if install
596     test_conf = configuration_data()
597     test_conf.set('installed_tests_dir', installed_tests_execdir)
598     test_conf.set('program', test_name)
599     configure_file(
600       input: installed_tests_template_tap,
601       output: test_name + '.test',
602       install_dir: installed_tests_metadir,
603       configuration: test_conf
604     )
605   endif
606
607   exe = executable(test_name, [source, extra_sources],
608     c_args : test_c_args + extra_args.get('c_args', []),
609     dependencies : common_gio_tests_deps + extra_args.get('dependencies', []),
610     install_rpath : extra_args.get('install_rpath', ''),
611     install_dir: installed_tests_execdir,
612     install: install,
613   )
614
615   suite = ['gio'] + extra_args.get('suite', [])
616   timeout = suite.contains('slow') ? test_timeout_slow : test_timeout
617   local_test_env = test_env
618
619   foreach var, value : extra_args.get('env', {})
620     local_test_env.append(var, value)
621   endforeach
622
623   test(test_name, exe,
624     env : local_test_env,
625     timeout : timeout,
626     suite : suite,
627     args : ['--tap'],
628     is_parallel : extra_args.get('is_parallel', true),
629     depends : extra_args.get('depends', []),
630   )
631 endforeach
632
633 foreach program_name, extra_args : test_extra_programs
634   source = extra_args.get('source', program_name + '.c')
635   extra_sources = extra_args.get('extra_sources', [])
636   install = installed_tests_enabled and extra_args.get('install', true)
637   executable(program_name, [source, extra_sources],
638       c_args : test_c_args,
639       dependencies : common_gio_tests_deps + extra_args.get('dependencies', []),
640       install_dir : installed_tests_execdir,
641       install : install,
642   )
643 endforeach
644
645 # FIXME: subdir('services')
646 subdir('modules')