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