diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-29 04:41:38 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-29 04:41:38 +0000 |
commit | 7b6e527f440cd7e6f8be2b07cee320ee6ca18786 (patch) | |
tree | 4a2738d69fa2814659fdadddf5826282e73d81f4 /test cases/vala | |
parent | Initial commit. (diff) | |
download | meson-7b6e527f440cd7e6f8be2b07cee320ee6ca18786.tar.xz meson-7b6e527f440cd7e6f8be2b07cee320ee6ca18786.zip |
Adding upstream version 1.0.1.upstream/1.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'test cases/vala')
119 files changed, 1325 insertions, 0 deletions
diff --git a/test cases/vala/1 basic/meson.build b/test cases/vala/1 basic/meson.build new file mode 100644 index 0000000..d1bfabd --- /dev/null +++ b/test cases/vala/1 basic/meson.build @@ -0,0 +1,7 @@ +# Language are case unsensitive, check here that capital C works too. +project('valatest', 'vala', 'C') + +valadeps = [dependency('glib-2.0'), dependency('gobject-2.0')] + +e = executable('valaprog', 'prog.vala', dependencies : valadeps) +test('valatest', e) diff --git a/test cases/vala/1 basic/prog.vala b/test cases/vala/1 basic/prog.vala new file mode 100644 index 0000000..638e776 --- /dev/null +++ b/test cases/vala/1 basic/prog.vala @@ -0,0 +1,7 @@ +class MainProg : GLib.Object { + + public static int main(string[] args) { + stdout.printf("Vala is working.\n"); + return 0; + } +} diff --git a/test cases/vala/10 mixed sources/c/foo.c b/test cases/vala/10 mixed sources/c/foo.c new file mode 100644 index 0000000..f3c6fb8 --- /dev/null +++ b/test cases/vala/10 mixed sources/c/foo.c @@ -0,0 +1,5 @@ +int retval (void); + +int test (void) { + return retval (); +} diff --git a/test cases/vala/10 mixed sources/c/meson.build b/test cases/vala/10 mixed sources/c/meson.build new file mode 100644 index 0000000..ead0575 --- /dev/null +++ b/test cases/vala/10 mixed sources/c/meson.build @@ -0,0 +1,5 @@ +writec = find_program('writec.py') + +retval = custom_target('writec', + output : 'retval.c', + command : [writec, '@OUTPUT@']) diff --git a/test cases/vala/10 mixed sources/c/writec.py b/test cases/vala/10 mixed sources/c/writec.py new file mode 100644 index 0000000..2cc822b --- /dev/null +++ b/test cases/vala/10 mixed sources/c/writec.py @@ -0,0 +1,12 @@ +#!/usr/bin/env python3 + +import sys + +c = '''int +retval(void) { + return 0; +} +''' + +with open(sys.argv[1], 'w') as f: + f.write(c) diff --git a/test cases/vala/10 mixed sources/meson.build b/test cases/vala/10 mixed sources/meson.build new file mode 100644 index 0000000..75b8ecd --- /dev/null +++ b/test cases/vala/10 mixed sources/meson.build @@ -0,0 +1,7 @@ +project('foo', 'c', 'vala') + +glib = dependency('glib-2.0') + +subdir('c') +e = executable('foo', 'c/foo.c', retval, 'vala/bar.vala', dependencies: [glib]) +test('test foo', e) diff --git a/test cases/vala/10 mixed sources/vala/bar.vala b/test cases/vala/10 mixed sources/vala/bar.vala new file mode 100644 index 0000000..0772f3e --- /dev/null +++ b/test cases/vala/10 mixed sources/vala/bar.vala @@ -0,0 +1,5 @@ +extern int test (); + +public int main (string[] args) { + return test (); +} diff --git a/test cases/vala/11 generated vapi/libbar/bar.c b/test cases/vala/11 generated vapi/libbar/bar.c new file mode 100644 index 0000000..3037141 --- /dev/null +++ b/test cases/vala/11 generated vapi/libbar/bar.c @@ -0,0 +1,29 @@ +#include "bar.h" +#include "foo.h" + +struct _BarBar +{ + GObject parent_instance; +}; + +G_DEFINE_TYPE (BarBar, bar_bar, G_TYPE_OBJECT) + +static void +bar_bar_class_init (BarBarClass *klass) +{ +} + +static void +bar_bar_init (BarBar *self) +{ +} + +/** + * bar_bar_return_success: + * + * Returns 0 + */ +int bar_bar_return_success(void) +{ + return foo_foo_return_success(); +} diff --git a/test cases/vala/11 generated vapi/libbar/bar.h b/test cases/vala/11 generated vapi/libbar/bar.h new file mode 100644 index 0000000..4ca7270 --- /dev/null +++ b/test cases/vala/11 generated vapi/libbar/bar.h @@ -0,0 +1,9 @@ +#include <glib-object.h> + +#pragma once + +#define BAR_TYPE_BAR (bar_bar_get_type()) + +G_DECLARE_FINAL_TYPE (BarBar, bar_bar, BAR, BAR, GObject) + +int bar_bar_return_success(void); diff --git a/test cases/vala/11 generated vapi/libbar/meson.build b/test cases/vala/11 generated vapi/libbar/meson.build new file mode 100644 index 0000000..0bf7d5c --- /dev/null +++ b/test cases/vala/11 generated vapi/libbar/meson.build @@ -0,0 +1,32 @@ +libbar_sources = [ + 'bar.c', + 'bar.h', +] + +libbar_deps = [ + dependency('gobject-2.0'), + libfoo_dep, +] + +libbar = shared_library('bar', libbar_sources, + dependencies: libbar_deps, + install: true, +) + +libbar_api_ver = '1.0' + +libbar_gir = gnome.generate_gir(libbar, + sources: libbar_sources, + namespace: 'Bar', + nsversion: libbar_api_ver, + symbol_prefix: 'bar', + extra_args: [ + '--c-include=bar.h', + ], +) + +libbar_vapi = gnome.generate_vapi('bar-' + libbar_api_ver, + sources: libbar_gir[0], + packages: libfoo_vapi, + install: true, +) diff --git a/test cases/vala/11 generated vapi/libfoo/foo.c b/test cases/vala/11 generated vapi/libfoo/foo.c new file mode 100644 index 0000000..dd2b891 --- /dev/null +++ b/test cases/vala/11 generated vapi/libfoo/foo.c @@ -0,0 +1,28 @@ +#include "foo.h" + +struct _FooFoo +{ + GObject parent_instance; +}; + +G_DEFINE_TYPE (FooFoo, foo_foo, G_TYPE_OBJECT) + +static void +foo_foo_class_init (FooFooClass *klass) +{ +} + +static void +foo_foo_init (FooFoo *self) +{ +} + +/** + * foo_foo_return_success: + * + * Returns 0 + */ +int foo_foo_return_success(void) +{ + return 0; +} diff --git a/test cases/vala/11 generated vapi/libfoo/foo.h b/test cases/vala/11 generated vapi/libfoo/foo.h new file mode 100644 index 0000000..e1887d8 --- /dev/null +++ b/test cases/vala/11 generated vapi/libfoo/foo.h @@ -0,0 +1,9 @@ +#include <glib-object.h> + +#pragma once + +#define FOO_TYPE_FOO (foo_foo_get_type()) + +G_DECLARE_FINAL_TYPE (FooFoo, foo_foo, Foo, FOO, GObject) + +int foo_foo_return_success(void); diff --git a/test cases/vala/11 generated vapi/libfoo/foo.metadata b/test cases/vala/11 generated vapi/libfoo/foo.metadata new file mode 100644 index 0000000..e208fe3 --- /dev/null +++ b/test cases/vala/11 generated vapi/libfoo/foo.metadata @@ -0,0 +1 @@ +Foo.bar nullable diff --git a/test cases/vala/11 generated vapi/libfoo/meson.build b/test cases/vala/11 generated vapi/libfoo/meson.build new file mode 100644 index 0000000..ee425f2 --- /dev/null +++ b/test cases/vala/11 generated vapi/libfoo/meson.build @@ -0,0 +1,42 @@ +libfoo_sources = [ + 'foo.c', + 'foo.h', +] + +libfoo_deps = [ + dependency('gobject-2.0') +] + +libfoo = shared_library('foo', libfoo_sources, + dependencies: libfoo_deps, + install: true, +) + +libfoo_api_ver = '1.0' + +libfoo_gir = gnome.generate_gir(libfoo, + sources: libfoo_sources, + namespace: 'Foo', + nsversion: libfoo_api_ver, + symbol_prefix: 'foo', + extra_args: [ + '--c-include=foo.h', + ], +) + +configure_file( + input: 'foo.metadata', + output: 'Foo-@0@.metadata'.format(libfoo_api_ver), + copy: true +) + +libfoo_vapi = gnome.generate_vapi('foo-' + libfoo_api_ver, + metadata_dirs: meson.current_build_dir(), + sources: libfoo_gir[0], + install: true, +) + +libfoo_dep = declare_dependency( + link_with: libfoo, + include_directories: include_directories('.'), +) diff --git a/test cases/vala/11 generated vapi/main.vala b/test cases/vala/11 generated vapi/main.vala new file mode 100644 index 0000000..d61fba0 --- /dev/null +++ b/test cases/vala/11 generated vapi/main.vala @@ -0,0 +1,9 @@ +using Foo; +using Bar; + +class Main : GLib.Object { + public static int main(string[] args) { + var ignore = Foo.Foo.return_success(); + return Bar.Bar.return_success(); + } +} diff --git a/test cases/vala/11 generated vapi/meson.build b/test cases/vala/11 generated vapi/meson.build new file mode 100644 index 0000000..d5f38ca --- /dev/null +++ b/test cases/vala/11 generated vapi/meson.build @@ -0,0 +1,13 @@ +project('vapi-test', ['c', 'vala']) + +gnome = import('gnome') +subdir('libfoo') +subdir('libbar') + +vapiexe = executable('vapigen-test', + 'main.vala', + dependencies: [dependency('gobject-2.0'), libfoo_vapi, libbar_vapi], + install: true, +) + +test('vapigen-test', vapiexe) diff --git a/test cases/vala/11 generated vapi/test.json b/test cases/vala/11 generated vapi/test.json new file mode 100644 index 0000000..1a742aa --- /dev/null +++ b/test cases/vala/11 generated vapi/test.json @@ -0,0 +1,13 @@ +{ + "installed": [ + {"type": "exe", "file": "usr/bin/vapigen-test"}, + {"type": "expr", "file": "usr/lib/?libfoo.so"}, + {"type": "file", "platform": "cygwin", "file": "usr/lib/libfoo.dll.a"}, + {"type": "expr", "file": "usr/lib/?libbar.so"}, + {"type": "file", "platform": "cygwin", "file": "usr/lib/libbar.dll.a"}, + {"type": "file", "file": "usr/share/vala/vapi/foo-1.0.vapi"}, + {"type": "file", "file": "usr/share/vala/vapi/foo-1.0.deps"}, + {"type": "file", "file": "usr/share/vala/vapi/bar-1.0.vapi"}, + {"type": "file", "file": "usr/share/vala/vapi/bar-1.0.deps"} + ] +} diff --git a/test cases/vala/12 custom output/bar.vala b/test cases/vala/12 custom output/bar.vala new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/test cases/vala/12 custom output/bar.vala diff --git a/test cases/vala/12 custom output/foo.vala b/test cases/vala/12 custom output/foo.vala new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/test cases/vala/12 custom output/foo.vala diff --git a/test cases/vala/12 custom output/meson.build b/test cases/vala/12 custom output/meson.build new file mode 100644 index 0000000..c328959 --- /dev/null +++ b/test cases/vala/12 custom output/meson.build @@ -0,0 +1,13 @@ +project('valatest', 'c', 'vala') + +glib = dependency('glib-2.0') +gobject = dependency('gobject-2.0') + +foo_lib = library('foo-1.0', 'foo.vala', + vala_header: 'foo.h', + vala_vapi: 'foo.vapi', + dependencies: [glib, gobject]) + +library('bar', 'bar.vala', + link_with: [foo_lib], + dependencies: [glib, gobject]) diff --git a/test cases/vala/13 find library/meson.build b/test cases/vala/13 find library/meson.build new file mode 100644 index 0000000..03054d2 --- /dev/null +++ b/test cases/vala/13 find library/meson.build @@ -0,0 +1,9 @@ +project('find vala library', 'vala', 'c') + +valac = meson.get_compiler('vala') + +gobject = dependency('gobject-2.0') +zlib = valac.find_library('zlib') + +e = executable('zlibtest', 'test.vala', dependencies : [gobject, zlib]) +test('testzlib', e) diff --git a/test cases/vala/13 find library/test.vala b/test cases/vala/13 find library/test.vala new file mode 100644 index 0000000..b087cfb --- /dev/null +++ b/test cases/vala/13 find library/test.vala @@ -0,0 +1,6 @@ +using ZLib; + +public static int main(string[] args) { + stdout.printf("ZLIB_VERSION is: %s\n", ZLib.VERSION.STRING); + return 0; +} diff --git a/test cases/vala/14 target glib version and gresources/gres/meson.build b/test cases/vala/14 target glib version and gresources/gres/meson.build new file mode 100644 index 0000000..f222a00 --- /dev/null +++ b/test cases/vala/14 target glib version and gresources/gres/meson.build @@ -0,0 +1,3 @@ +res = gnome.compile_resources('testui', + 'test-resources.xml', + source_dir : '.') diff --git a/test cases/vala/14 target glib version and gresources/gres/test-resources.xml b/test cases/vala/14 target glib version and gresources/gres/test-resources.xml new file mode 100644 index 0000000..4e8a73f --- /dev/null +++ b/test cases/vala/14 target glib version and gresources/gres/test-resources.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<gresources> + <gresource prefix="/org/Meson"> + <file compressed="true" preprocess="xml-stripblanks">test.ui</file> + </gresource> +</gresources> diff --git a/test cases/vala/14 target glib version and gresources/gres/test.ui b/test cases/vala/14 target glib version and gresources/gres/test.ui new file mode 100644 index 0000000..f90d941 --- /dev/null +++ b/test cases/vala/14 target glib version and gresources/gres/test.ui @@ -0,0 +1,19 @@ +<?xml version="1.0" encoding="UTF-8"?> +<interface> + <!-- interface-requires gtk+ 3.8 --> + <template class="TestWidget" parent="GtkBox"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="orientation">vertical</property> + <property name="spacing">4</property> + <child> + <object class="GtkEntry" id="entry"> + <property name="visible">True</property> + <property name="can_focus">True</property> + </object> + <packing> + <property name="position">0</property> + </packing> + </child> + </template> +</interface> diff --git a/test cases/vala/14 target glib version and gresources/meson.build b/test cases/vala/14 target glib version and gresources/meson.build new file mode 100644 index 0000000..dee2627 --- /dev/null +++ b/test cases/vala/14 target glib version and gresources/meson.build @@ -0,0 +1,12 @@ +project('test glib target version and gresources', 'c', 'vala') + +gnome = import('gnome') + +glib = dependency('glib-2.0', version : '>=2.38') +gtk = dependency('gtk+-3.0') + +subdir('gres') + +e = executable('gtktemplate', 'test.vala', res, dependencies : [glib, gtk]) +# No X on the CI, so disable this for now +#test('test-target-glib', e) diff --git a/test cases/vala/14 target glib version and gresources/test.vala b/test cases/vala/14 target glib version and gresources/test.vala new file mode 100644 index 0000000..f10bbe4 --- /dev/null +++ b/test cases/vala/14 target glib version and gresources/test.vala @@ -0,0 +1,37 @@ +using Gtk; +using GLib; + +[GtkTemplate (ui = "/org/Meson/test.ui")] +public class TestWidget : Box { + public string text { + get { return entry.text; } + set { entry.text = value; } + } + + [GtkChild] + private unowned Entry entry; + + public TestWidget (string text) { + this.text = text; + } +} + +void main(string[] args) { + Gtk.init (ref args); + var win = new Window(); + win.destroy.connect (Gtk.main_quit); + + var widget = new TestWidget ("SOME TEXT HERE"); + + win.add (widget); + win.show_all (); + + /* Exit immediately */ + Timeout.add_full (Priority.DEFAULT_IDLE, 1, () => + { + Gtk.main_quit(); + return false; + }); + + Gtk.main (); +} diff --git a/test cases/vala/15 static vapi in source tree/meson.build b/test cases/vala/15 static vapi in source tree/meson.build new file mode 100644 index 0000000..44bea48 --- /dev/null +++ b/test cases/vala/15 static vapi in source tree/meson.build @@ -0,0 +1,13 @@ +project('static vapi', 'c', 'vala') + +glib = dependency('glib-2.0') + +conf = configuration_data() +conf.set_quoted('VERSION', '1.0.0') +config_h = configure_file(output : 'config.h', + configuration : conf) + +e = executable('static-vapi', 'vapi/config.vapi', 'test.vala', + dependencies : glib) + +test('test-config', e) diff --git a/test cases/vala/15 static vapi in source tree/test.vala b/test cases/vala/15 static vapi in source tree/test.vala new file mode 100644 index 0000000..06f2d59 --- /dev/null +++ b/test cases/vala/15 static vapi in source tree/test.vala @@ -0,0 +1,6 @@ +using GLib; +using Config; + +public int main (string[] args) { + return GLib.strcmp(VERSION, "1.0.0"); +} diff --git a/test cases/vala/15 static vapi in source tree/vapi/config.vapi b/test cases/vala/15 static vapi in source tree/vapi/config.vapi new file mode 100644 index 0000000..71bcc6e --- /dev/null +++ b/test cases/vala/15 static vapi in source tree/vapi/config.vapi @@ -0,0 +1,4 @@ +[CCode (cprefix = "", lower_case_cprefix = "", cheader_filename = "config.h")] +namespace Config { + public const string VERSION; +} diff --git a/test cases/vala/16 mixed dependence/app.vala b/test cases/vala/16 mixed dependence/app.vala new file mode 100644 index 0000000..5b54543 --- /dev/null +++ b/test cases/vala/16 mixed dependence/app.vala @@ -0,0 +1,7 @@ +namespace App { + public static int main(string[] args) { + var mixer = new Mixer(); + print("Current volume is %u\n", mixer.get_volume()); + return 0; + } +} diff --git a/test cases/vala/16 mixed dependence/meson.build b/test cases/vala/16 mixed dependence/meson.build new file mode 100644 index 0000000..b44b47b --- /dev/null +++ b/test cases/vala/16 mixed dependence/meson.build @@ -0,0 +1,16 @@ +project('mixed dependence', 'vala', 'c') + +cc = meson.get_compiler('c') + +deps = [dependency('glib-2.0'), dependency('gobject-2.0'), + # Should be ignored, see https://github.com/mesonbuild/meson/issues/1939 + cc.find_library('z')] + +mixer = static_library('mixer', 'mixer.vala', 'mixer-glue.c', + dependencies : deps) + +app = executable('app', 'app.vala', + link_with : mixer, + dependencies : deps) + +test('valamixeddependencetest', app) diff --git a/test cases/vala/16 mixed dependence/mixer-glue.c b/test cases/vala/16 mixed dependence/mixer-glue.c new file mode 100644 index 0000000..d6c0c37 --- /dev/null +++ b/test cases/vala/16 mixed dependence/mixer-glue.c @@ -0,0 +1,5 @@ +#include "mixer.h" + +guint mixer_get_volume(Mixer *mixer) { + return 11; +} diff --git a/test cases/vala/16 mixed dependence/mixer.vala b/test cases/vala/16 mixed dependence/mixer.vala new file mode 100644 index 0000000..f207132 --- /dev/null +++ b/test cases/vala/16 mixed dependence/mixer.vala @@ -0,0 +1,3 @@ +public class Mixer : Object { + public extern uint get_volume(); +} diff --git a/test cases/vala/17 plain consumer/app.c b/test cases/vala/17 plain consumer/app.c new file mode 100644 index 0000000..c8d0010 --- /dev/null +++ b/test cases/vala/17 plain consumer/app.c @@ -0,0 +1,11 @@ +#include "badger.h" + +int main(int argc, char *argv[]) { + Badger *badger; + + badger = g_object_new(TYPE_BADGER, NULL); + g_print("Badger whose name is '%s'\n", badger_get_name(badger)); + g_object_unref(badger); + + return 0; +} diff --git a/test cases/vala/17 plain consumer/badger.vala b/test cases/vala/17 plain consumer/badger.vala new file mode 100644 index 0000000..1aaeda6 --- /dev/null +++ b/test cases/vala/17 plain consumer/badger.vala @@ -0,0 +1,10 @@ +public class Badger : Object { + public string name { + get; + construct; + } + + Badger() { + Object(name: "Joe"); + } +} diff --git a/test cases/vala/17 plain consumer/meson.build b/test cases/vala/17 plain consumer/meson.build new file mode 100644 index 0000000..e98bca1 --- /dev/null +++ b/test cases/vala/17 plain consumer/meson.build @@ -0,0 +1,12 @@ +project('plain consumer', 'vala', 'c') + +deps = [dependency('glib-2.0'), dependency('gobject-2.0')] + +badger = static_library('badger', 'badger.vala', + dependencies : deps) + +app = executable('app', 'app.c', + link_with : badger, + dependencies : deps) + +test('valaplainconsumertest', app) diff --git a/test cases/vala/18 vapi consumed twice/app.vala b/test cases/vala/18 vapi consumed twice/app.vala new file mode 100644 index 0000000..cd94a42 --- /dev/null +++ b/test cases/vala/18 vapi consumed twice/app.vala @@ -0,0 +1,11 @@ +namespace App { + public static int main(string[] args) { + var person = new Person(); + print("Favorite beer of \"%s\" is %s\n", person.name, person.favorite_beer.flavor); + + var beer = new Beer("tasty"); + print("This beer is %s\n", beer.flavor); + + return 0; + } +} diff --git a/test cases/vala/18 vapi consumed twice/beer.vala b/test cases/vala/18 vapi consumed twice/beer.vala new file mode 100644 index 0000000..cee38ad --- /dev/null +++ b/test cases/vala/18 vapi consumed twice/beer.vala @@ -0,0 +1,10 @@ +public class Beer : Object { + public string flavor { + get; + construct; + } + + public Beer(string flavor) { + Object(flavor: flavor); + } +} diff --git a/test cases/vala/18 vapi consumed twice/meson.build b/test cases/vala/18 vapi consumed twice/meson.build new file mode 100644 index 0000000..6a7f5eb --- /dev/null +++ b/test cases/vala/18 vapi consumed twice/meson.build @@ -0,0 +1,15 @@ +project('vapi consumed twice', 'vala', 'c') + +base_deps = [dependency('glib-2.0'), dependency('gobject-2.0')] + +beer = library('beer', 'beer.vala', dependencies : base_deps) +beer_dep = declare_dependency(link_with : beer) + +person = library('person', 'person.vala', link_with : beer, + dependencies : base_deps) +person_dep = declare_dependency(link_with : person, dependencies : [beer_dep]) + +app = executable('app', 'app.vala', + dependencies : base_deps + [person_dep, beer_dep]) + +test('valavapiconsumedtwicetest', app) diff --git a/test cases/vala/18 vapi consumed twice/person.vala b/test cases/vala/18 vapi consumed twice/person.vala new file mode 100644 index 0000000..36b0025 --- /dev/null +++ b/test cases/vala/18 vapi consumed twice/person.vala @@ -0,0 +1,16 @@ +public class Person : Object { + public string name { + get { + return "Joe Badger"; + } + } + + public Beer favorite_beer { + get; + construct; + } + + public Person() { + Object(favorite_beer: new Beer("smooth")); + } +} diff --git a/test cases/vala/19 genie/meson.build b/test cases/vala/19 genie/meson.build new file mode 100644 index 0000000..2bdb185 --- /dev/null +++ b/test cases/vala/19 genie/meson.build @@ -0,0 +1,6 @@ +project('genietest', 'vala', 'c') + +valadeps = [dependency('glib-2.0'), dependency('gobject-2.0')] + +e = executable('genieprog', 'prog.gs', dependencies : valadeps) +test('genietest', e) diff --git a/test cases/vala/19 genie/prog.gs b/test cases/vala/19 genie/prog.gs new file mode 100644 index 0000000..f206b09 --- /dev/null +++ b/test cases/vala/19 genie/prog.gs @@ -0,0 +1,2 @@ +init + print ("Genie is working.") diff --git a/test cases/vala/2 multiple files/class1.vala b/test cases/vala/2 multiple files/class1.vala new file mode 100644 index 0000000..7072101 --- /dev/null +++ b/test cases/vala/2 multiple files/class1.vala @@ -0,0 +1,7 @@ +class Class1 : GLib.Object { + + public void hello() { + var c2 = new Class2(); + c2.hello(); + } +} diff --git a/test cases/vala/2 multiple files/class2.vala b/test cases/vala/2 multiple files/class2.vala new file mode 100644 index 0000000..ad76cc1 --- /dev/null +++ b/test cases/vala/2 multiple files/class2.vala @@ -0,0 +1,6 @@ +class Class2 : GLib.Object { + + public void hello() { + stdout.printf("Multiple file Vala project is working.\n"); + } +} diff --git a/test cases/vala/2 multiple files/main.vala b/test cases/vala/2 multiple files/main.vala new file mode 100644 index 0000000..6de0fa3 --- /dev/null +++ b/test cases/vala/2 multiple files/main.vala @@ -0,0 +1,8 @@ +class MainProg : GLib.Object { + + public static int main(string[] args) { + var c1 = new Class1(); + c1.hello(); + return 0; + } +} diff --git a/test cases/vala/2 multiple files/meson.build b/test cases/vala/2 multiple files/meson.build new file mode 100644 index 0000000..dc36073 --- /dev/null +++ b/test cases/vala/2 multiple files/meson.build @@ -0,0 +1,10 @@ +# adding 'c' shouldn't be required +project('multiple files') +add_languages('vala') + +glib = dependency('glib-2.0') +gobject = dependency('gobject-2.0') + +e = executable('prog', 'main.vala', 'class1.vala', 'class2.vala', +dependencies : [glib, gobject]) +test('multiple file test', e) diff --git a/test cases/vala/20 genie multiple mixed sources/c_test_one.c b/test cases/vala/20 genie multiple mixed sources/c_test_one.c new file mode 100644 index 0000000..d0b7e05 --- /dev/null +++ b/test cases/vala/20 genie multiple mixed sources/c_test_one.c @@ -0,0 +1,5 @@ +#include <glib.h> + +gboolean c_test_one_is_true (void) { + return TRUE; +} diff --git a/test cases/vala/20 genie multiple mixed sources/c_test_two.c b/test cases/vala/20 genie multiple mixed sources/c_test_two.c new file mode 100644 index 0000000..596928b --- /dev/null +++ b/test cases/vala/20 genie multiple mixed sources/c_test_two.c @@ -0,0 +1,5 @@ +#include <glib.h> + +gboolean c_test_two_is_true (void) { + return TRUE; +} diff --git a/test cases/vala/20 genie multiple mixed sources/init.gs b/test cases/vala/20 genie multiple mixed sources/init.gs new file mode 100644 index 0000000..1564403 --- /dev/null +++ b/test cases/vala/20 genie multiple mixed sources/init.gs @@ -0,0 +1,10 @@ +def extern c_test_one_is_true():bool +def extern c_test_two_is_true():bool + +init + assert( new Genie.TestOne().is_true() ) + assert( new Genie.TestTwo().is_true() ) + assert( new Vala.TestOne().is_true() ) + assert( new Vala.TestTwo().is_true() ) + assert( c_test_one_is_true() ) + assert( c_test_two_is_true() ) diff --git a/test cases/vala/20 genie multiple mixed sources/meson.build b/test cases/vala/20 genie multiple mixed sources/meson.build new file mode 100644 index 0000000..148ce0e --- /dev/null +++ b/test cases/vala/20 genie multiple mixed sources/meson.build @@ -0,0 +1,19 @@ +project( 'Genie multiple and mixed sources', 'vala', 'c' ) + +genie_deps = [ + dependency( 'glib-2.0' ), + dependency( 'gobject-2.0' ), +] + +sources = [ + 'init.gs', + 'test_one.gs', + 'test_two.gs', + 'vala_test_one.vala', + 'vala_test_two.vala', + 'c_test_one.c', + 'c_test_two.c', +] + +prog = executable( 'genie_prog', sources, dependencies: genie_deps ) +test( 'Given a Genie program when it is compiled from multiple mixed sources then it should work', prog ) diff --git a/test cases/vala/20 genie multiple mixed sources/test_one.gs b/test cases/vala/20 genie multiple mixed sources/test_one.gs new file mode 100644 index 0000000..af3b1ec --- /dev/null +++ b/test cases/vala/20 genie multiple mixed sources/test_one.gs @@ -0,0 +1,5 @@ +namespace Genie + + class TestOne + def is_true():bool + return true diff --git a/test cases/vala/20 genie multiple mixed sources/test_two.gs b/test cases/vala/20 genie multiple mixed sources/test_two.gs new file mode 100644 index 0000000..0a0e03c --- /dev/null +++ b/test cases/vala/20 genie multiple mixed sources/test_two.gs @@ -0,0 +1,5 @@ +namespace Genie + + class TestTwo + def is_true():bool + return true diff --git a/test cases/vala/20 genie multiple mixed sources/vala_test_one.vala b/test cases/vala/20 genie multiple mixed sources/vala_test_one.vala new file mode 100644 index 0000000..7044bc8 --- /dev/null +++ b/test cases/vala/20 genie multiple mixed sources/vala_test_one.vala @@ -0,0 +1,7 @@ +namespace Vala { + public class TestOne { + public bool is_true() { + return true; + } + } +} diff --git a/test cases/vala/20 genie multiple mixed sources/vala_test_two.vala b/test cases/vala/20 genie multiple mixed sources/vala_test_two.vala new file mode 100644 index 0000000..b530efb --- /dev/null +++ b/test cases/vala/20 genie multiple mixed sources/vala_test_two.vala @@ -0,0 +1,7 @@ +namespace Vala { + public class TestTwo { + public bool is_true() { + return true; + } + } +} diff --git a/test cases/vala/21 type module/foo.vala b/test cases/vala/21 type module/foo.vala new file mode 100644 index 0000000..0a63225 --- /dev/null +++ b/test cases/vala/21 type module/foo.vala @@ -0,0 +1,17 @@ +public extern const string FOO_PLUGIN_PATH; + +Foo.PluginModule plugin_module; + +public int main () { + plugin_module = new Foo.PluginModule (FOO_PLUGIN_PATH, "bar"); + + if (!plugin_module.load ()) { + return 1; + } + + var plugin = Object.new (plugin_module.plugin_type) as Foo.Plugin; + + assert ("bar" == plugin.bar ()); + + return 0; +} diff --git a/test cases/vala/21 type module/meson.build b/test cases/vala/21 type module/meson.build new file mode 100644 index 0000000..9bd26e3 --- /dev/null +++ b/test cases/vala/21 type module/meson.build @@ -0,0 +1,20 @@ +project('valatest', 'c', 'vala') + +glib_dep = dependency('glib-2.0') +gobject_dep = dependency('gobject-2.0') +gmodule_dep = dependency('gmodule-2.0') + +foo_sources = ['plugin.vala', 'plugin-module.vala'] +foo_lib = shared_library('foo', foo_sources, + dependencies: [glib_dep, gobject_dep, gmodule_dep]) + +shared_module('bar', 'plugin-bar.vala', + dependencies: [glib_dep, gobject_dep], + link_with: foo_lib) + +foo_bin = executable('foo', 'foo.vala', + c_args: ['-DFOO_PLUGIN_PATH="@0@"'.format(meson.current_build_dir())], + dependencies: [glib_dep, gobject_dep], + link_with: foo_lib) + +test('shared module', foo_bin) diff --git a/test cases/vala/21 type module/plugin-bar.vala b/test cases/vala/21 type module/plugin-bar.vala new file mode 100644 index 0000000..ff6e334 --- /dev/null +++ b/test cases/vala/21 type module/plugin-bar.vala @@ -0,0 +1,11 @@ +[ModuleInit] +public GLib.Type plugin_init (GLib.TypeModule tm) { + return typeof (Bar.Plugin); +} + +public class Bar.Plugin : Foo.Plugin, GLib.Object { + + public string bar () { + return "bar"; + } +} diff --git a/test cases/vala/21 type module/plugin-module.vala b/test cases/vala/21 type module/plugin-module.vala new file mode 100644 index 0000000..1c3aeca --- /dev/null +++ b/test cases/vala/21 type module/plugin-module.vala @@ -0,0 +1,54 @@ +public class Foo.PluginModule : TypeModule { + + [CCode (has_target = false)] + private delegate Type PluginInit (TypeModule type_module); + + public string? directory { get; construct; default = null; } + + public string name { get; construct; } + + public string path { get; construct; } + + public Type plugin_type { get; private set; } + + private Module? module = null; + + public PluginModule (string? directory, string name) { + Object (directory: directory, name: name); + } + + construct { + path = Module.build_path (directory, name); + } + + public override bool load () { + module = Module.open (path, ModuleFlags.BIND_LAZY); + + if (module == null) { + critical (Module.error ()); + return false; + } + + void* plugin_init; + if (!module.symbol ("plugin_init", out plugin_init)){ + critical (Module.error ()); + return false; + } + + if (plugin_init == null) { + return false; + } + + plugin_type = ((PluginInit) plugin_init) (this); + + if (!plugin_type.is_a (typeof (Plugin))) { + return false; + } + + return true; + } + + public override void unload () { + module = null; + } +} diff --git a/test cases/vala/21 type module/plugin.vala b/test cases/vala/21 type module/plugin.vala new file mode 100644 index 0000000..3d0ea4c --- /dev/null +++ b/test cases/vala/21 type module/plugin.vala @@ -0,0 +1,4 @@ +public interface Foo.Plugin : GLib.Object { + + public abstract string bar (); +} diff --git a/test cases/vala/22 same target in directories/Subdir/Subdir2/Test.vala b/test cases/vala/22 same target in directories/Subdir/Subdir2/Test.vala new file mode 100644 index 0000000..94e5cbc --- /dev/null +++ b/test cases/vala/22 same target in directories/Subdir/Subdir2/Test.vala @@ -0,0 +1,5 @@ +public class Subdir.Subdir2.Test : GLib.Object { + construct { + stdout.printf("Test from Subdir/Subdir2/\n"); + } +} diff --git a/test cases/vala/22 same target in directories/Subdir/Test.vala b/test cases/vala/22 same target in directories/Subdir/Test.vala new file mode 100644 index 0000000..02143c4 --- /dev/null +++ b/test cases/vala/22 same target in directories/Subdir/Test.vala @@ -0,0 +1,5 @@ +public class Subdir.Test : GLib.Object { + construct { + stdout.printf("Test from Subdir/\n"); + } +} diff --git a/test cases/vala/22 same target in directories/Subdir2/Test.vala b/test cases/vala/22 same target in directories/Subdir2/Test.vala new file mode 100644 index 0000000..4a2d61f --- /dev/null +++ b/test cases/vala/22 same target in directories/Subdir2/Test.vala @@ -0,0 +1,5 @@ +public class Subdir2.Test : GLib.Object { + construct { + stdout.printf("Test from Subdir2/\n"); + } +} diff --git a/test cases/vala/22 same target in directories/Test.vala b/test cases/vala/22 same target in directories/Test.vala new file mode 100644 index 0000000..9154e22 --- /dev/null +++ b/test cases/vala/22 same target in directories/Test.vala @@ -0,0 +1,5 @@ +public class Test : GLib.Object { + construct { + stdout.printf("Test from main directory\n"); + } +} diff --git a/test cases/vala/22 same target in directories/meson.build b/test cases/vala/22 same target in directories/meson.build new file mode 100644 index 0000000..6785f73 --- /dev/null +++ b/test cases/vala/22 same target in directories/meson.build @@ -0,0 +1,13 @@ +project('valatest', 'vala', 'c') + +valadeps = [dependency('glib-2.0'), dependency('gobject-2.0')] +valafiles = files( + 'prog.vala', + 'Test.vala', + 'Subdir/Test.vala', + 'Subdir/Subdir2/Test.vala', + 'Subdir2/Test.vala', +) + +e = executable('multidir_prog', valafiles, dependencies : valadeps) +test('valatest', e) diff --git a/test cases/vala/22 same target in directories/prog.vala b/test cases/vala/22 same target in directories/prog.vala new file mode 100644 index 0000000..37cbf7a --- /dev/null +++ b/test cases/vala/22 same target in directories/prog.vala @@ -0,0 +1,8 @@ +int main() { + var test1 = new Test (); + var test2 = new Subdir.Test (); + var test3 = new Subdir2.Test (); + var test4 = new Subdir.Subdir2.Test (); + stdout.printf("Vala is working.\n"); + return 0; +} diff --git a/test cases/vala/23 thread flags/meson.build b/test cases/vala/23 thread flags/meson.build new file mode 100644 index 0000000..3b385df --- /dev/null +++ b/test cases/vala/23 thread flags/meson.build @@ -0,0 +1,7 @@ +project('thread flags', 'c', 'vala') + +glib = dependency('glib-2.0') +gobject = dependency('gobject-2.0') +threads = dependency('threads') + +e = executable('valaprog', 'prog.vala', dependencies: [glib, gobject, threads]) diff --git a/test cases/vala/23 thread flags/prog.vala b/test cases/vala/23 thread flags/prog.vala new file mode 100644 index 0000000..0b2c54c --- /dev/null +++ b/test cases/vala/23 thread flags/prog.vala @@ -0,0 +1,2 @@ +void main () { +} diff --git a/test cases/vala/24 export dynamic shared module/app.vala b/test cases/vala/24 export dynamic shared module/app.vala new file mode 100644 index 0000000..e016ecd --- /dev/null +++ b/test cases/vala/24 export dynamic shared module/app.vala @@ -0,0 +1,21 @@ +const string MODULE_LIB = "libapp_module.so"; + +delegate int ModuleFunc (); + +public int app_func () { + return 41; +} + +int main () { + Module module; + void *func; + unowned ModuleFunc mfunc; + + module = Module.open (MODULE_LIB, ModuleFlags.BIND_LAZY); + module.symbol ("module_func", out func); + mfunc = (ModuleFunc) func; + + print ("%d\n", mfunc ()); + + return 0; +} diff --git a/test cases/vala/24 export dynamic shared module/meson.build b/test cases/vala/24 export dynamic shared module/meson.build new file mode 100644 index 0000000..9aa9fd9 --- /dev/null +++ b/test cases/vala/24 export dynamic shared module/meson.build @@ -0,0 +1,20 @@ +project ('test', ['c', 'vala'], version: '0.1') + +deps = [ + dependency ('glib-2.0'), + dependency ('gmodule-2.0'), +] + +app = executable ( + 'app', + ['app.vala'], + dependencies: deps, + export_dynamic: true +) + +shared_module ( + 'app_module', + ['module.vala'], + link_with: app, + dependencies : deps, +) diff --git a/test cases/vala/24 export dynamic shared module/module.vala b/test cases/vala/24 export dynamic shared module/module.vala new file mode 100644 index 0000000..5553727 --- /dev/null +++ b/test cases/vala/24 export dynamic shared module/module.vala @@ -0,0 +1,3 @@ +public int module_func () { + return app_func() + 1; +} diff --git a/test cases/vala/25 extract_all_objects/meson.build b/test cases/vala/25 extract_all_objects/meson.build new file mode 100644 index 0000000..a1a4ebc --- /dev/null +++ b/test cases/vala/25 extract_all_objects/meson.build @@ -0,0 +1,11 @@ +project('valatest', 'vala', 'c') + +valadeps = [dependency('glib-2.0'), dependency('gobject-2.0')] + +# A dummy target, just so that we can check that extract_all_objects() works +# properly for Vala sources. Due to a bug, Vala's .c.o files weren't included +# which would cause the "e" executable below to have no "main" and fail to link. +dummy = executable('valaprog_dummy', 'prog.vala', dependencies : valadeps, build_by_default: false) + +objs = dummy.extract_all_objects() +e = executable('valaprog', objects: objs, dependencies : valadeps) diff --git a/test cases/vala/25 extract_all_objects/prog.vala b/test cases/vala/25 extract_all_objects/prog.vala new file mode 100644 index 0000000..638e776 --- /dev/null +++ b/test cases/vala/25 extract_all_objects/prog.vala @@ -0,0 +1,7 @@ +class MainProg : GLib.Object { + + public static int main(string[] args) { + stdout.printf("Vala is working.\n"); + return 0; + } +} diff --git a/test cases/vala/26 vala and asm/meson.build b/test cases/vala/26 vala and asm/meson.build new file mode 100644 index 0000000..4e662e7 --- /dev/null +++ b/test cases/vala/26 vala and asm/meson.build @@ -0,0 +1,23 @@ +project('vala and asm', 'vala', 'c') + +cpu = host_machine.cpu_family() +cc = meson.get_compiler('c') + +supported_cpus = ['arm', 'x86', 'x86_64'] + +if not supported_cpus.contains(cpu) + error('MESON_SKIP_TEST unsupported cpu:' + cpu) +endif + +if meson.get_compiler('c').get_id() == 'msvc' + error('MESON_SKIP_TEST MSVC can\'t compile assembly') +endif + +if cc.symbols_have_underscore_prefix() + add_project_arguments('-DMESON_TEST__UNDERSCORE_SYMBOL', language: 'c') +endif + +valadeps = [dependency('glib-2.0'), dependency('gobject-2.0')] +e = executable('vala-asm', ['prog.vala', 'retval-' + cpu + '.S'], + dependencies: valadeps) +test('test-vala-asm', e) diff --git a/test cases/vala/26 vala and asm/prog.vala b/test cases/vala/26 vala and asm/prog.vala new file mode 100644 index 0000000..d5f89a4 --- /dev/null +++ b/test cases/vala/26 vala and asm/prog.vala @@ -0,0 +1,9 @@ +extern int get_retval(); + +class MainProg : GLib.Object { + + public static int main(string[] args) { + stdout.printf("Vala is working.\n"); + return get_retval(); + } +} diff --git a/test cases/vala/26 vala and asm/retval-arm.S b/test cases/vala/26 vala and asm/retval-arm.S new file mode 100644 index 0000000..a892362 --- /dev/null +++ b/test cases/vala/26 vala and asm/retval-arm.S @@ -0,0 +1,11 @@ +#include "symbol-underscore.h" + +.text +.globl SYMBOL_NAME(get_retval) +# ifdef __linux__ +.type get_retval, %function +#endif + +SYMBOL_NAME(get_retval): + mov r0, #0 + mov pc, lr diff --git a/test cases/vala/26 vala and asm/retval-x86.S b/test cases/vala/26 vala and asm/retval-x86.S new file mode 100644 index 0000000..3cb0237 --- /dev/null +++ b/test cases/vala/26 vala and asm/retval-x86.S @@ -0,0 +1,12 @@ +#include "symbol-underscore.h" + +.text +.globl SYMBOL_NAME(get_retval) +/* Only supported on Linux with GAS */ +# ifdef __linux__ +.type get_retval, %function +#endif + +SYMBOL_NAME(get_retval): + xorl %eax, %eax + retl diff --git a/test cases/vala/26 vala and asm/retval-x86_64.S b/test cases/vala/26 vala and asm/retval-x86_64.S new file mode 100644 index 0000000..1a5f3eb --- /dev/null +++ b/test cases/vala/26 vala and asm/retval-x86_64.S @@ -0,0 +1,11 @@ +#include "symbol-underscore.h" + +.text +.globl SYMBOL_NAME(get_retval) +# ifdef __linux__ +.type get_retval, %function +#endif + +SYMBOL_NAME(get_retval): + xorl %eax, %eax + retq diff --git a/test cases/vala/26 vala and asm/symbol-underscore.h b/test cases/vala/26 vala and asm/symbol-underscore.h new file mode 100644 index 0000000..d0f3ef9 --- /dev/null +++ b/test cases/vala/26 vala and asm/symbol-underscore.h @@ -0,0 +1,5 @@ +#if defined(MESON_TEST__UNDERSCORE_SYMBOL) +# define SYMBOL_NAME(name) _##name +#else +# define SYMBOL_NAME(name) name +#endif diff --git a/test cases/vala/3 dep/gioprog.vala b/test cases/vala/3 dep/gioprog.vala new file mode 100644 index 0000000..969aa97 --- /dev/null +++ b/test cases/vala/3 dep/gioprog.vala @@ -0,0 +1,8 @@ +class GioProg { + + public static int main(string[] args) { + var homedir = File.new_for_path(Environment.get_home_dir()); + stdout.printf("Home directory as told by gio is " + homedir.get_path() + "\n"); + return 0; + } +} diff --git a/test cases/vala/3 dep/meson.build b/test cases/vala/3 dep/meson.build new file mode 100644 index 0000000..c3563b1 --- /dev/null +++ b/test cases/vala/3 dep/meson.build @@ -0,0 +1,12 @@ +project('giotest', 'vala', 'c') + +glib = dependency('glib-2.0') +gobject = dependency('gobject-2.0') +gio = [dependency('gio-2.0'), + # https://github.com/mesonbuild/meson/issues/1484 + dependency('gio-unix-2.0', required : false), + dependency('gio-windows-2.0', required : false)] + +e = executable('gioprog', 'gioprog.vala', +dependencies : [glib, gobject, gio]) +test('giotest', e) diff --git a/test cases/vala/4 config/config.vapi b/test cases/vala/4 config/config.vapi new file mode 100644 index 0000000..6845417 --- /dev/null +++ b/test cases/vala/4 config/config.vapi @@ -0,0 +1 @@ +public const string DATA_DIRECTORY; diff --git a/test cases/vala/4 config/meson-something-else.vapi b/test cases/vala/4 config/meson-something-else.vapi new file mode 100644 index 0000000..ce2b83a --- /dev/null +++ b/test cases/vala/4 config/meson-something-else.vapi @@ -0,0 +1 @@ +public const string SOMETHING_ELSE; diff --git a/test cases/vala/4 config/meson.build b/test cases/vala/4 config/meson.build new file mode 100644 index 0000000..7cb93cf --- /dev/null +++ b/test cases/vala/4 config/meson.build @@ -0,0 +1,15 @@ +project('valatest', 'vala', 'c') + +valac = meson.get_compiler('vala') +# Try to find our library +valadeps = [valac.find_library('meson-something-else', dirs : meson.current_source_dir())] +valadeps += [dependency('glib-2.0'), dependency('gobject-2.0')] + +e = executable( +'valaprog', +sources : ['config.vapi', 'prog.vala'], +dependencies : valadeps, +c_args : ['-DDATA_DIRECTORY="@0@"'.format(meson.current_source_dir()), + '-DSOMETHING_ELSE="Out of this world!"'] +) +test('valatest', e) diff --git a/test cases/vala/4 config/prog.vala b/test cases/vala/4 config/prog.vala new file mode 100644 index 0000000..2b08dad --- /dev/null +++ b/test cases/vala/4 config/prog.vala @@ -0,0 +1,8 @@ +class MainProg : GLib.Object { + + public static int main(string[] args) { + stdout.printf("DATA_DIRECTORY is: %s.\n", DATA_DIRECTORY); + stdout.printf("SOMETHING_ELSE is: %s.\n", SOMETHING_ELSE); + return 0; + } +} diff --git a/test cases/vala/5 target glib/GLib.Thread.vala b/test cases/vala/5 target glib/GLib.Thread.vala new file mode 100644 index 0000000..fc82919 --- /dev/null +++ b/test cases/vala/5 target glib/GLib.Thread.vala @@ -0,0 +1,43 @@ +extern void * get_ret_code (); + +public class MyThread : Object { + public int x_times { get; private set; } + + public MyThread (int times) { + this.x_times = times; + } + + public int run () { + for (int i = 0; i < this.x_times; i++) { + stdout.printf ("ping! %d/%d\n", i + 1, this.x_times); + Thread.usleep (10000); + } + + // return & exit have the same effect + Thread.exit (get_ret_code ()); + return 43; + } +} + +public static int main (string[] args) { + // Check whether threads are supported: + if (Thread.supported () == false) { + stderr.printf ("Threads are not supported!\n"); + return -1; + } + + try { + // Start a thread: + MyThread my_thread = new MyThread (10); + Thread<int> thread = new Thread<int>.try ("My fst. thread", my_thread.run); + + // Wait until thread finishes: + int result = thread.join (); + // Output: `Thread stopped! Return value: 42` + stdout.printf ("Thread stopped! Return value: %d\n", result); + } catch (Error e) { + stdout.printf ("Error: %s\n", e.message); + } + + return 0; +} diff --git a/test cases/vala/5 target glib/meson.build b/test cases/vala/5 target glib/meson.build new file mode 100644 index 0000000..f285d9f --- /dev/null +++ b/test cases/vala/5 target glib/meson.build @@ -0,0 +1,10 @@ +project('valatest', 'vala', 'c') + +if not meson.is_unity() + add_global_arguments('-Werror', language : 'c') +endif + +valadeps = [dependency('glib-2.0', version : '>=2.32'), dependency('gobject-2.0')] + +e = executable('valaprog', 'GLib.Thread.vala', 'retcode.c', dependencies : valadeps) +test('valatest', e) diff --git a/test cases/vala/5 target glib/retcode.c b/test cases/vala/5 target glib/retcode.c new file mode 100644 index 0000000..df44de5 --- /dev/null +++ b/test cases/vala/5 target glib/retcode.c @@ -0,0 +1,5 @@ +void * +get_ret_code (void) +{ + return (void *) (int) 42; +} diff --git a/test cases/vala/6 static library/meson.build b/test cases/vala/6 static library/meson.build new file mode 100644 index 0000000..c74bdf8 --- /dev/null +++ b/test cases/vala/6 static library/meson.build @@ -0,0 +1,17 @@ +project('valastatic', 'vala', 'c') + +valadeps = [dependency('glib-2.0'), dependency('gobject-2.0')] + +l = static_library('valalib', 'mylib.vala', dependencies : valadeps) +# NOTE: This static library is not usable from Vala because it does not carry +# forward the .vapi and .h files generated by Valac to the next BuildTarget. +# Will have to be fixed with https://github.com/mesonbuild/meson/issues/891 +m = static_library('extractedlib', + objects : l.extract_all_objects(), + install : true) + +e = executable('valaprog', 'prog.vala', +link_with : l, +dependencies : valadeps) + +test('valastatictest', e) diff --git a/test cases/vala/6 static library/mylib.vala b/test cases/vala/6 static library/mylib.vala new file mode 100644 index 0000000..5cc903b --- /dev/null +++ b/test cases/vala/6 static library/mylib.vala @@ -0,0 +1,5 @@ +public class LibraryObject : Object { + public void func() { + stdout.printf("Method in library called."); + } +} diff --git a/test cases/vala/6 static library/prog.vala b/test cases/vala/6 static library/prog.vala new file mode 100644 index 0000000..3c4a017 --- /dev/null +++ b/test cases/vala/6 static library/prog.vala @@ -0,0 +1,7 @@ +class MainApp : Object { + public static int main(string[] args) { + var l = new LibraryObject(); + l.func(); + return 0; + } +} diff --git a/test cases/vala/6 static library/test.json b/test cases/vala/6 static library/test.json new file mode 100644 index 0000000..d85ef6d --- /dev/null +++ b/test cases/vala/6 static library/test.json @@ -0,0 +1,5 @@ +{ + "installed": [ + {"type": "file", "file": "usr/lib/libextractedlib.a"} + ] +} diff --git a/test cases/vala/7 shared library/lib/meson.build b/test cases/vala/7 shared library/lib/meson.build new file mode 100644 index 0000000..edeeb96 --- /dev/null +++ b/test cases/vala/7 shared library/lib/meson.build @@ -0,0 +1,35 @@ +args = [] +# https://github.com/mesonbuild/meson/issues/1969 +if get_option('unity') == 'on' + vala_args = ['-H', 'mylib.h'] +endif + +l = shared_library('valalib', 'mylib.vala', + vala_args : args, + dependencies : valadeps) + +shared_library('installed_vala_lib', 'mylib.vala', + dependencies : valadeps, + install : true) + +shared_library('installed_vala_all', 'mylib.vala', + dependencies : valadeps, + install : true, + install_dir : [true, true, true]) + +shared_library('installed_vala_all_nolib', 'mylib.vala', + dependencies : valadeps, + install : true, + install_dir : [false, + join_paths(get_option('includedir'), 'valah'), + join_paths(get_option('datadir'), 'vala-1.0', 'vapi')]) + +shared_library('installed_vala_onlyh', 'mylib.vala', + dependencies : valadeps, + install : true, + install_dir : [false, get_option('includedir'), false]) + +shared_library('installed_vala_onlyvapi', 'mylib.vala', + dependencies : valadeps, + install : true, + install_dir : [false, false, join_paths(get_option('datadir'), 'vala', 'vapi')]) diff --git a/test cases/vala/7 shared library/lib/mylib.vala b/test cases/vala/7 shared library/lib/mylib.vala new file mode 100644 index 0000000..5cc903b --- /dev/null +++ b/test cases/vala/7 shared library/lib/mylib.vala @@ -0,0 +1,5 @@ +public class LibraryObject : Object { + public void func() { + stdout.printf("Method in library called."); + } +} diff --git a/test cases/vala/7 shared library/meson.build b/test cases/vala/7 shared library/meson.build new file mode 100644 index 0000000..9c56f14 --- /dev/null +++ b/test cases/vala/7 shared library/meson.build @@ -0,0 +1,10 @@ +project('shared library', 'vala', 'c') + +valadeps = [dependency('glib-2.0'), dependency('gobject-2.0')] + +libinc = include_directories('lib') + +subdir('lib') +subdir('prog') + +test('valasharedtest', e) diff --git a/test cases/vala/7 shared library/prog/meson.build b/test cases/vala/7 shared library/prog/meson.build new file mode 100644 index 0000000..2b842ea --- /dev/null +++ b/test cases/vala/7 shared library/prog/meson.build @@ -0,0 +1,4 @@ +e = executable('valaprog', 'prog.vala', + link_with : l, + include_directories : libinc, + dependencies : valadeps) diff --git a/test cases/vala/7 shared library/prog/prog.vala b/test cases/vala/7 shared library/prog/prog.vala new file mode 100644 index 0000000..3c4a017 --- /dev/null +++ b/test cases/vala/7 shared library/prog/prog.vala @@ -0,0 +1,7 @@ +class MainApp : Object { + public static int main(string[] args) { + var l = new LibraryObject(); + l.func(); + return 0; + } +} diff --git a/test cases/vala/7 shared library/test.json b/test cases/vala/7 shared library/test.json new file mode 100644 index 0000000..eee3c3d --- /dev/null +++ b/test cases/vala/7 shared library/test.json @@ -0,0 +1,14 @@ +{ + "installed": [ + {"type": "expr", "file": "usr/lib/?libinstalled_vala_lib.so"}, + {"type": "file", "platform": "cygwin", "file": "usr/lib/libinstalled_vala_lib.dll.a"}, + {"type": "expr", "file": "usr/lib/?libinstalled_vala_all.so"}, + {"type": "file", "platform": "cygwin", "file": "usr/lib/libinstalled_vala_all.dll.a"}, + {"type": "file", "file": "usr/include/installed_vala_all.h"}, + {"type": "file", "file": "usr/include/valah/installed_vala_all_nolib.h"}, + {"type": "file", "file": "usr/include/installed_vala_onlyh.h"}, + {"type": "file", "file": "usr/share/vala/vapi/installed_vala_all.vapi"}, + {"type": "file", "file": "usr/share/vala-1.0/vapi/installed_vala_all_nolib.vapi"}, + {"type": "file", "file": "usr/share/vala/vapi/installed_vala_onlyvapi.vapi"} + ] +} diff --git a/test cases/vala/8 generated sources/dependency-generated/enum-types.c.template b/test cases/vala/8 generated sources/dependency-generated/enum-types.c.template new file mode 100644 index 0000000..9d45a93 --- /dev/null +++ b/test cases/vala/8 generated sources/dependency-generated/enum-types.c.template @@ -0,0 +1,43 @@ +/*** BEGIN file-header ***/ + +#include "enum-types.h" + +/*** END file-header ***/ + +/*** BEGIN file-production ***/ +/* enumerations from "@filename@" */ +#include "@filename@" +/*** END file-production ***/ + + +/*** BEGIN value-header ***/ +GType +@enum_name@_get_type (void) +{ + static gsize static_g_define_type_id = 0; + + if (g_once_init_enter (&static_g_define_type_id)) { + static const G@Type@Value values[] = { +/*** END value-header ***/ + +/*** BEGIN value-production ***/ + { @VALUENAME@, "@VALUENAME@", "@valuenick@" }, +/*** END value-production ***/ + +/*** BEGIN value-tail ***/ + { 0, NULL, NULL } + }; + GType g_define_type_id = + g_@type@_register_static (g_intern_static_string ("@EnumName@"), values); + + g_once_init_leave (&static_g_define_type_id, g_define_type_id); + } + + return static_g_define_type_id; +} + +/*** END value-tail ***/ + +/*** BEGIN file-tail ***/ + +/*** END file-tail ***/ diff --git a/test cases/vala/8 generated sources/dependency-generated/enum-types.h.template b/test cases/vala/8 generated sources/dependency-generated/enum-types.h.template new file mode 100644 index 0000000..e5478ab --- /dev/null +++ b/test cases/vala/8 generated sources/dependency-generated/enum-types.h.template @@ -0,0 +1,26 @@ +/*** BEGIN file-header ***/ + +#ifndef __EXAMPLE_ENUMS_TYPES_H__ +#define __EXAMPLE_ENUMS_TYPES_H__ + +#include <glib-object.h> +#include "enums.h" + +G_BEGIN_DECLS +/*** END file-header ***/ + +/*** BEGIN file-production ***/ + +/* enumerations from "@filename@" */ +/*** END file-production ***/ + +/*** BEGIN value-header ***/ +GType @enum_name@_get_type (void) G_GNUC_CONST; +#define EXAMPLE_TYPE_@ENUMSHORT@ (@enum_name@_get_type ()) +/*** END value-header ***/ + +/*** BEGIN file-tail ***/ +G_END_DECLS + +#endif /* __EXAMPLE_ENUMS_TYPES_H__ */ +/*** END file-tail ***/ diff --git a/test cases/vala/8 generated sources/dependency-generated/enums.h b/test cases/vala/8 generated sources/dependency-generated/enums.h new file mode 100644 index 0000000..3fb621e --- /dev/null +++ b/test cases/vala/8 generated sources/dependency-generated/enums.h @@ -0,0 +1,15 @@ +#ifndef __EXAMPLE_ENUMS_H__ +#define __EXAMPLE_ENUMS_H__ + +G_BEGIN_DECLS + +typedef enum { + EXAMPLE_VERBOSITY_ERRORS, + EXAMPLE_VERBOSITY_MINIMAL, + EXAMPLE_VERBOSITY_DETAILED, + EXAMPLE_VERBOSITY_DEBUG, +} ExampleVerbosity; + +G_END_DECLS + +#endif /* __EXAMPLE_ENUMS_H__ */ diff --git a/test cases/vala/8 generated sources/dependency-generated/lib.vala b/test cases/vala/8 generated sources/dependency-generated/lib.vala new file mode 100644 index 0000000..3fcbb7f --- /dev/null +++ b/test cases/vala/8 generated sources/dependency-generated/lib.vala @@ -0,0 +1,3 @@ +int whatever() { + return 0; +} diff --git a/test cases/vala/8 generated sources/dependency-generated/main.vala b/test cases/vala/8 generated sources/dependency-generated/main.vala new file mode 100644 index 0000000..33c14ce --- /dev/null +++ b/test cases/vala/8 generated sources/dependency-generated/main.vala @@ -0,0 +1,3 @@ +int main() { + return 0; +} diff --git a/test cases/vala/8 generated sources/dependency-generated/meson.build b/test cases/vala/8 generated sources/dependency-generated/meson.build new file mode 100644 index 0000000..a1895b4 --- /dev/null +++ b/test cases/vala/8 generated sources/dependency-generated/meson.build @@ -0,0 +1,44 @@ +# Test that dependencies with their own generated sources don't +# confuse the Vala build instruction generator. + +# Test case for https://github.com/mesonbuild/meson/issues/1084 + +gnome = import('gnome') + +gobject = dependency('gobject-2.0') + +enums = gnome.mkenums('enum-types', + sources: 'enums.h', + c_template: 'enum-types.c.template', + h_template: 'enum-types.h.template', +) + +libcommon = library('common', + enums[0], enums[1], + dependencies: gobject) + +common_dep = declare_dependency( + # This is required so that whoever depends on this also depends + # on the generated header; that won't happen implicitly. + # See: https://github.com/mesonbuild/meson/issues/1084 + sources: enums[1], + link_with: libcommon, +) + +libplover_vala = library('plover', + 'lib.vala', + dependencies: [common_dep, gobject] +) + +plover_dep = declare_dependency( + link_with: libplover_vala, + dependencies: common_dep +) + +vala_prog = executable('hello', + 'main.vala', + link_with: libplover_vala, + # There's no need to specify common_dep here since plover_dep pulls it + # in, but it should be harmless to do so. + dependencies: [common_dep, plover_dep, gobject] +) diff --git a/test cases/vala/8 generated sources/dependency-generated/null.c b/test cases/vala/8 generated sources/dependency-generated/null.c new file mode 100644 index 0000000..8337712 --- /dev/null +++ b/test cases/vala/8 generated sources/dependency-generated/null.c @@ -0,0 +1 @@ +// diff --git a/test cases/vala/8 generated sources/meson.build b/test cases/vala/8 generated sources/meson.build new file mode 100644 index 0000000..711a93a --- /dev/null +++ b/test cases/vala/8 generated sources/meson.build @@ -0,0 +1,14 @@ +project('mytest', 'vala', 'c') + +cd = configuration_data() +cd.set('x', 'y') + +subdir('src') + +executable('generatedtestparent', [src, config, returncode, wrapper], + install : true, + dependencies: [dependency('glib-2.0'), dependency('gobject-2.0')]) + +subdir('tools') +subdir('onlygen') +subdir('dependency-generated') diff --git a/test cases/vala/8 generated sources/onlygen/maingen.in b/test cases/vala/8 generated sources/onlygen/maingen.in new file mode 100644 index 0000000..33c14ce --- /dev/null +++ b/test cases/vala/8 generated sources/onlygen/maingen.in @@ -0,0 +1,3 @@ +int main() { + return 0; +} diff --git a/test cases/vala/8 generated sources/onlygen/meson.build b/test cases/vala/8 generated sources/onlygen/meson.build new file mode 100644 index 0000000..f48e0b8 --- /dev/null +++ b/test cases/vala/8 generated sources/onlygen/meson.build @@ -0,0 +1,7 @@ +onlygen = generator(copy, + output : '@BASENAME@.vala', + arguments : ['@INPUT@', '@OUTPUT@']) + +executable('onlygentest', onlygen.process('maingen.in'), + install : true, + dependencies: [dependency('glib-2.0'), dependency('gobject-2.0')]) diff --git a/test cases/vala/8 generated sources/src/config.vala.in b/test cases/vala/8 generated sources/src/config.vala.in new file mode 100644 index 0000000..a5196fd --- /dev/null +++ b/test cases/vala/8 generated sources/src/config.vala.in @@ -0,0 +1,3 @@ +namespace Config { + public static const string x = "@x@"; +} diff --git a/test cases/vala/8 generated sources/src/copy_file.py b/test cases/vala/8 generated sources/src/copy_file.py new file mode 100644 index 0000000..ff42ac3 --- /dev/null +++ b/test cases/vala/8 generated sources/src/copy_file.py @@ -0,0 +1,6 @@ +#!/usr/bin/env python3 + +import sys +import shutil + +shutil.copyfile(sys.argv[1], sys.argv[2]) diff --git a/test cases/vala/8 generated sources/src/meson.build b/test cases/vala/8 generated sources/src/meson.build new file mode 100644 index 0000000..06515c1 --- /dev/null +++ b/test cases/vala/8 generated sources/src/meson.build @@ -0,0 +1,17 @@ +config = configure_file(input: 'config.vala.in', + output: 'config.vala', + configuration: cd) + +print = find_program('write_wrapper.py') +wrapper = custom_target('wrapper', + output : 'print_wrapper.vala', + command : [print, '@OUTPUT@']) + +copy = find_program('copy_file.py') +gen = generator(copy, + output : '@BASENAME@.vala', + arguments : ['@INPUT@', '@OUTPUT@']) + +returncode = gen.process('returncode.in') + +src = files('test.vala') diff --git a/test cases/vala/8 generated sources/src/returncode.in b/test cases/vala/8 generated sources/src/returncode.in new file mode 100644 index 0000000..e3d3ea6 --- /dev/null +++ b/test cases/vala/8 generated sources/src/returncode.in @@ -0,0 +1,3 @@ +int return_code() { + return 0; +} diff --git a/test cases/vala/8 generated sources/src/test.vala b/test cases/vala/8 generated sources/src/test.vala new file mode 100644 index 0000000..ca27676 --- /dev/null +++ b/test cases/vala/8 generated sources/src/test.vala @@ -0,0 +1,4 @@ +int main() { + print_wrapper (Config.x); + return return_code (); +} diff --git a/test cases/vala/8 generated sources/src/write_wrapper.py b/test cases/vala/8 generated sources/src/write_wrapper.py new file mode 100644 index 0000000..b5608f7 --- /dev/null +++ b/test cases/vala/8 generated sources/src/write_wrapper.py @@ -0,0 +1,12 @@ +#!/usr/bin/env python3 + +import sys + +contents = ''' +void print_wrapper(string arg) { + print (arg); +} +''' + +with open(sys.argv[1], 'w') as f: + f.write(contents) diff --git a/test cases/vala/8 generated sources/test.json b/test cases/vala/8 generated sources/test.json new file mode 100644 index 0000000..d99a6ce --- /dev/null +++ b/test cases/vala/8 generated sources/test.json @@ -0,0 +1,7 @@ +{ + "installed": [ + {"type": "exe", "file": "usr/bin/generatedtestparent"}, + {"type": "exe", "file": "usr/bin/generatedtest"}, + {"type": "exe", "file": "usr/bin/onlygentest"} + ] +} diff --git a/test cases/vala/8 generated sources/tools/meson.build b/test cases/vala/8 generated sources/tools/meson.build new file mode 100644 index 0000000..303468e --- /dev/null +++ b/test cases/vala/8 generated sources/tools/meson.build @@ -0,0 +1,3 @@ +executable('generatedtest', [src, config, returncode, wrapper], + install : true, + dependencies: [dependency('glib-2.0'), dependency('gobject-2.0')]) diff --git a/test cases/vala/9 gir/foo.vala b/test cases/vala/9 gir/foo.vala new file mode 100644 index 0000000..bb6da10 --- /dev/null +++ b/test cases/vala/9 gir/foo.vala @@ -0,0 +1,7 @@ +namespace Foo +{ + public int bar () + { + return 0; + } +} diff --git a/test cases/vala/9 gir/meson.build b/test cases/vala/9 gir/meson.build new file mode 100644 index 0000000..3320527 --- /dev/null +++ b/test cases/vala/9 gir/meson.build @@ -0,0 +1,17 @@ +project('foo', 'c', 'vala') + +glib = dependency('glib-2.0') +gobject = dependency('gobject-2.0') +g_ir_compiler = find_program('g-ir-compiler') + +foo = shared_library('foo', 'foo.vala', + install : true, + install_dir : [true, false, false, true], + vala_gir: 'Foo-1.0.gir', + dependencies: [glib, gobject]) + +custom_target('foo-typelib', + command: [g_ir_compiler, '--output', '@OUTPUT@', '@INPUT@'], + input: meson.current_build_dir() + '/Foo-1.0.gir', + output: 'Foo-1.0.typelib', + depends: foo) diff --git a/test cases/vala/9 gir/test.json b/test cases/vala/9 gir/test.json new file mode 100644 index 0000000..add1d71 --- /dev/null +++ b/test cases/vala/9 gir/test.json @@ -0,0 +1,7 @@ +{ + "installed": [ + {"type": "expr", "platform": "gcc", "file": "usr/lib/?libfoo.so"}, + {"type": "file", "platform": "cygwin", "file": "usr/lib/libfoo.dll.a"}, + {"type": "file", "file": "usr/share/gir-1.0/Foo-1.0.gir"} + ] +} |