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