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