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