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