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