diff options
author | Jussi Pakkanen <jpakkane@gmail.com> | 2016-10-03 19:07:42 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-10-03 19:07:42 +0300 |
commit | 7256e109bf93d9a7de3802c6df01b0e728c4511c (patch) | |
tree | 63c6b8bf815f0e01f0472f2894e94382448bfc58 /test cases/frameworks | |
parent | efc986ee93c4a509ce087370d645a816393b7966 (diff) | |
parent | 2840539a08ff03aa33ecc4f1cd7e64cc12791ae1 (diff) | |
download | meson-7256e109bf93d9a7de3802c6df01b0e728c4511c.zip meson-7256e109bf93d9a7de3802c6df01b0e728c4511c.tar.gz meson-7256e109bf93d9a7de3802c6df01b0e728c4511c.tar.bz2 |
Merge pull request #718 from QuLogic/glib-mkenums-genmarshal
glib-mkenums and glib-genmarshal support
Diffstat (limited to 'test cases/frameworks')
-rw-r--r-- | test cases/frameworks/7 gnome/genmarshal/main.c | 102 | ||||
-rw-r--r-- | test cases/frameworks/7 gnome/genmarshal/marshaller.list | 3 | ||||
-rw-r--r-- | test cases/frameworks/7 gnome/genmarshal/meson.build | 11 | ||||
-rw-r--r-- | test cases/frameworks/7 gnome/installed_files.txt | 4 | ||||
-rw-r--r-- | test cases/frameworks/7 gnome/meson.build | 3 | ||||
-rw-r--r-- | test cases/frameworks/7 gnome/mkenums/enums.c.in | 41 | ||||
-rw-r--r-- | test cases/frameworks/7 gnome/mkenums/enums.h.in | 24 | ||||
-rw-r--r-- | test cases/frameworks/7 gnome/mkenums/enums2.c.in | 41 | ||||
-rw-r--r-- | test cases/frameworks/7 gnome/mkenums/enums2.h.in | 24 | ||||
-rw-r--r-- | test cases/frameworks/7 gnome/mkenums/main.c | 30 | ||||
-rw-r--r-- | test cases/frameworks/7 gnome/mkenums/meson-sample.h | 18 | ||||
-rw-r--r-- | test cases/frameworks/7 gnome/mkenums/meson.build | 118 |
12 files changed, 418 insertions, 1 deletions
diff --git a/test cases/frameworks/7 gnome/genmarshal/main.c b/test cases/frameworks/7 gnome/genmarshal/main.c new file mode 100644 index 0000000..83b08af --- /dev/null +++ b/test cases/frameworks/7 gnome/genmarshal/main.c @@ -0,0 +1,102 @@ +#include<stdio.h> +#include<stdlib.h> +#include<glib-object.h> +#include"marshaller.h" + +static int singleton = 42; + +void foo(gpointer user_data, gpointer data) { + if (user_data != &singleton) { + fprintf(stderr, "Invoked foo function was passed incorrect user data.\n"); + exit(1); + } +} + +void bar(gpointer user_data, gint param1, gpointer data) { + if (param1 != singleton) { + fprintf(stderr, "Invoked bar function was passed incorrect param1, but %d.\n", param1); + exit(2); + } + if (user_data != &singleton) { + fprintf(stderr, "Invoked bar function was passed incorrect user data.\n"); + exit(3); + } +} + +gfloat baz(gpointer user_data, gboolean param1, guchar param2, gpointer data) { + if (param1 != TRUE) { + fprintf(stderr, "Invoked baz function was passed incorrect param1.\n"); + exit(4); + } + if (param2 != singleton) { + fprintf(stderr, "Invoked baz function was passed incorrect param2.\n"); + exit(5); + } + if (user_data != &singleton) { + fprintf(stderr, "Invoked baz function was passed incorrect user data.\n"); + exit(6); + } + return (gfloat)param2; +} + +int main(int argc, char **argv) { + GClosure *cc_foo, *cc_bar, *cc_baz; + GValue return_value = G_VALUE_INIT; + GValue param_values[3] = {G_VALUE_INIT, G_VALUE_INIT, G_VALUE_INIT}; + + fprintf(stderr, "Invoking foo function.\n"); + cc_foo = g_cclosure_new(G_CALLBACK(foo), NULL, NULL); + g_closure_set_marshal(cc_foo, g_cclosure_user_marshal_VOID__VOID); + g_value_init(¶m_values[0], G_TYPE_POINTER); + g_value_set_pointer(¶m_values[0], &singleton); + g_closure_invoke(cc_foo, &return_value, 1, param_values, NULL); + if (G_VALUE_TYPE(&return_value) != G_TYPE_INVALID) { + fprintf(stderr, "Invoked foo function did not return empty value, but %s.\n", + G_VALUE_TYPE_NAME(&return_value)); + return 7; + } + g_value_unset(¶m_values[0]); + g_value_unset(&return_value); + g_closure_unref(cc_foo); + + fprintf(stderr, "Invoking bar function.\n"); + cc_bar = g_cclosure_new(G_CALLBACK(bar), NULL, NULL); + g_closure_set_marshal(cc_bar, g_cclosure_user_marshal_VOID__INT); + g_value_init(¶m_values[0], G_TYPE_POINTER); + g_value_set_pointer(¶m_values[0], &singleton); + g_value_init(¶m_values[1], G_TYPE_INT); + g_value_set_int(¶m_values[1], 42); + g_closure_invoke(cc_bar, &return_value, 2, param_values, NULL); + if (G_VALUE_TYPE(&return_value) != G_TYPE_INVALID) { + fprintf(stderr, "Invoked bar function did not return empty value.\n"); + return 8; + } + g_value_unset(¶m_values[0]); + g_value_unset(¶m_values[1]); + g_value_unset(&return_value); + g_closure_unref(cc_bar); + + fprintf(stderr, "Invoking baz function.\n"); + cc_baz = g_cclosure_new(G_CALLBACK(baz), NULL, NULL); + g_closure_set_marshal(cc_baz, g_cclosure_user_marshal_FLOAT__BOOLEAN_UCHAR); + g_value_init(¶m_values[0], G_TYPE_POINTER); + g_value_set_pointer(¶m_values[0], &singleton); + g_value_init(¶m_values[1], G_TYPE_BOOLEAN); + g_value_set_boolean(¶m_values[1], TRUE); + g_value_init(¶m_values[2], G_TYPE_UCHAR); + g_value_set_uchar(¶m_values[2], 42); + g_value_init(&return_value, G_TYPE_FLOAT); + g_closure_invoke(cc_baz, &return_value, 3, param_values, NULL); + if (g_value_get_float(&return_value) != 42.0f) { + fprintf(stderr, "Invoked baz function did not return expected value.\n"); + return 9; + } + g_value_unset(¶m_values[0]); + g_value_unset(¶m_values[1]); + g_value_unset(¶m_values[2]); + g_value_unset(&return_value); + g_closure_unref(cc_baz); + + fprintf(stderr, "All ok.\n"); + return 0; +} diff --git a/test cases/frameworks/7 gnome/genmarshal/marshaller.list b/test cases/frameworks/7 gnome/genmarshal/marshaller.list new file mode 100644 index 0000000..a29f6c9 --- /dev/null +++ b/test cases/frameworks/7 gnome/genmarshal/marshaller.list @@ -0,0 +1,3 @@ +VOID:VOID +VOID:INT +FLOAT:BOOLEAN,UCHAR diff --git a/test cases/frameworks/7 gnome/genmarshal/meson.build b/test cases/frameworks/7 gnome/genmarshal/meson.build new file mode 100644 index 0000000..4a1a7f9 --- /dev/null +++ b/test cases/frameworks/7 gnome/genmarshal/meson.build @@ -0,0 +1,11 @@ +marshallers = gnome.genmarshal('marshaller', +sources : 'marshaller.list', +install_header : true, +install_dir : get_option('includedir')) + +marshaller_c = marshallers[0] +marshaller_h = marshallers[1] + +genmarshalexe = executable('genmarshalprog', 'main.c', marshaller_c, marshaller_h, +dependencies : gobj) +test('genmarshal test', genmarshalexe) diff --git a/test cases/frameworks/7 gnome/installed_files.txt b/test cases/frameworks/7 gnome/installed_files.txt index 741d9b8..c922f8b 100644 --- a/test cases/frameworks/7 gnome/installed_files.txt +++ b/test cases/frameworks/7 gnome/installed_files.txt @@ -1,3 +1,7 @@ +usr/include/enums.h +usr/include/enums2.h +usr/include/enums3.h +usr/include/marshaller.h usr/lib/girepository-1.0/Meson-1.0.typelib usr/lib/libgirlib.so usr/share/gir-1.0/Meson-1.0.gir diff --git a/test cases/frameworks/7 gnome/meson.build b/test cases/frameworks/7 gnome/meson.build index 6afe508..2c2e953 100644 --- a/test cases/frameworks/7 gnome/meson.build +++ b/test cases/frameworks/7 gnome/meson.build @@ -13,4 +13,5 @@ subdir('resources') subdir('gir') subdir('schemas') subdir('gdbus') - +subdir('mkenums') +subdir('genmarshal') diff --git a/test cases/frameworks/7 gnome/mkenums/enums.c.in b/test cases/frameworks/7 gnome/mkenums/enums.c.in new file mode 100644 index 0000000..62e1adc --- /dev/null +++ b/test cases/frameworks/7 gnome/mkenums/enums.c.in @@ -0,0 +1,41 @@ +/*** BEGIN file-header ***/ + +#include "enums.h" + +/*** END file-header ***/ +/*** BEGIN file-production ***/ + +/* enumerations from "@basename@" */ +#include "@basename@" + +/*** END file-production ***/ + +/*** BEGIN value-header ***/ +GType +@enum_name@_get_type(void) { + static volatile gsize g_define_type_id__volatile = 0; + + if(g_once_init_enter(&g_define_type_id__volatile)) { + 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(&g_define_type_id__volatile, g_define_type_id); + } + + return g_define_type_id__volatile; +} + +/*** END value-tail ***/ + +/*** BEGIN file-tail ***/ +/*** END file-tail ***/ diff --git a/test cases/frameworks/7 gnome/mkenums/enums.h.in b/test cases/frameworks/7 gnome/mkenums/enums.h.in new file mode 100644 index 0000000..479867f --- /dev/null +++ b/test cases/frameworks/7 gnome/mkenums/enums.h.in @@ -0,0 +1,24 @@ +/*** BEGIN file-header ***/ +#ifndef MESON_ENUMS_H +#define MESON_ENUMS_H + +#include <glib-object.h> + +G_BEGIN_DECLS +/*** END file-header ***/ + +/*** BEGIN file-production ***/ + +/* enumerations from "@basename@" */ +/*** END file-production ***/ +/*** BEGIN value-header ***/ +GType @enum_name@_get_type(void) G_GNUC_CONST; +#define @ENUMPREFIX@_TYPE_@ENUMSHORT@ (@enum_name@_get_type()) +/*** END value-header ***/ + +/*** BEGIN file-tail ***/ + +G_END_DECLS + +#endif /* MESON_ENUMS_H */ +/*** END file-tail ***/ diff --git a/test cases/frameworks/7 gnome/mkenums/enums2.c.in b/test cases/frameworks/7 gnome/mkenums/enums2.c.in new file mode 100644 index 0000000..62e1adc --- /dev/null +++ b/test cases/frameworks/7 gnome/mkenums/enums2.c.in @@ -0,0 +1,41 @@ +/*** BEGIN file-header ***/ + +#include "enums.h" + +/*** END file-header ***/ +/*** BEGIN file-production ***/ + +/* enumerations from "@basename@" */ +#include "@basename@" + +/*** END file-production ***/ + +/*** BEGIN value-header ***/ +GType +@enum_name@_get_type(void) { + static volatile gsize g_define_type_id__volatile = 0; + + if(g_once_init_enter(&g_define_type_id__volatile)) { + 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(&g_define_type_id__volatile, g_define_type_id); + } + + return g_define_type_id__volatile; +} + +/*** END value-tail ***/ + +/*** BEGIN file-tail ***/ +/*** END file-tail ***/ diff --git a/test cases/frameworks/7 gnome/mkenums/enums2.h.in b/test cases/frameworks/7 gnome/mkenums/enums2.h.in new file mode 100644 index 0000000..479867f --- /dev/null +++ b/test cases/frameworks/7 gnome/mkenums/enums2.h.in @@ -0,0 +1,24 @@ +/*** BEGIN file-header ***/ +#ifndef MESON_ENUMS_H +#define MESON_ENUMS_H + +#include <glib-object.h> + +G_BEGIN_DECLS +/*** END file-header ***/ + +/*** BEGIN file-production ***/ + +/* enumerations from "@basename@" */ +/*** END file-production ***/ +/*** BEGIN value-header ***/ +GType @enum_name@_get_type(void) G_GNUC_CONST; +#define @ENUMPREFIX@_TYPE_@ENUMSHORT@ (@enum_name@_get_type()) +/*** END value-header ***/ + +/*** BEGIN file-tail ***/ + +G_END_DECLS + +#endif /* MESON_ENUMS_H */ +/*** END file-tail ***/ diff --git a/test cases/frameworks/7 gnome/mkenums/main.c b/test cases/frameworks/7 gnome/mkenums/main.c new file mode 100644 index 0000000..d257185 --- /dev/null +++ b/test cases/frameworks/7 gnome/mkenums/main.c @@ -0,0 +1,30 @@ +#include<stdio.h> +#include<string.h> +#include<glib-object.h> +#include"meson-sample.h" +#include"@ENUM_FILE@" + +int main(int argc, char **argv) { + GEnumClass *xenum = g_type_class_ref(MESON_TYPE_THE_XENUM); + GFlagsClass *flags_enum = g_type_class_ref(MESON_TYPE_THE_FLAGS_ENUM); + if (g_enum_get_value_by_name(xenum, "MESON_THE_XVALUE")->value != MESON_THE_XVALUE) { + fprintf(stderr, "Get MESON_THE_XVALUE by name failed.\n"); + return 1; + } + if (g_enum_get_value_by_nick(xenum, "the-xvalue")->value != MESON_THE_XVALUE) { + fprintf(stderr, "Get MESON_THE_XVALUE by nick failed.\n"); + return 2; + } + if (g_flags_get_value_by_name(flags_enum, "MESON_THE_FIRST_VALUE")->value != MESON_THE_FIRST_VALUE) { + fprintf(stderr, "Get MESON_THE_FIRST_VALUE by name failed.\n"); + return 3; + } + if (g_flags_get_value_by_nick(flags_enum, "the-first-value")->value != MESON_THE_FIRST_VALUE) { + fprintf(stderr, "Get MESON_THE_FIRST_VALUE by nick failed.\n"); + return 4; + } + g_type_class_unref(xenum); + g_type_class_unref(flags_enum); + fprintf(stderr, "All ok.\n"); + return 0; +} diff --git a/test cases/frameworks/7 gnome/mkenums/meson-sample.h b/test cases/frameworks/7 gnome/mkenums/meson-sample.h new file mode 100644 index 0000000..51e5421 --- /dev/null +++ b/test cases/frameworks/7 gnome/mkenums/meson-sample.h @@ -0,0 +1,18 @@ +typedef enum +{ + MESON_THE_XVALUE, + MESON_ANOTHER_VALUE +} MesonTheXEnum; + +typedef enum /*< skip >*/ +{ + MESON_FOO +} MesonThisEnumWillBeSkipped; + +typedef enum /*< flags,prefix=MESON >*/ +{ + MESON_THE_ZEROTH_VALUE, /*< skip >*/ + MESON_THE_FIRST_VALUE, + MESON_THE_SECOND_VALUE, + MESON_THE_THIRD_VALUE, /*< nick=the-last-value >*/ +} MesonTheFlagsEnum; diff --git a/test cases/frameworks/7 gnome/mkenums/meson.build b/test cases/frameworks/7 gnome/mkenums/meson.build new file mode 100644 index 0000000..f0989cf --- /dev/null +++ b/test cases/frameworks/7 gnome/mkenums/meson.build @@ -0,0 +1,118 @@ +# Generate both header and source via template together. + +myenums = gnome.mkenums('abc1', + sources : 'meson-sample.h', + h_template : 'enums.h.in', + c_template : 'enums.c.in', + install_header : true, + install_dir : get_option('includedir')) + +enums_c1 = myenums[0] +enums_h1 = myenums[1] + +conf = configuration_data() +conf.set('ENUM_FILE', 'enums.h') +main = configure_file( + input : 'main.c', + output : 'main1.c', + configuration : conf) + +enumexe1 = executable('enumprog1', main, enums_c1, enums_h1, +dependencies : gobj) +test('enum test 1', enumexe1) + +# Generate both header and source via template individually and overriding. + +enums_c2 = gnome.mkenums('abc2', + sources : 'meson-sample.h', + c_template : 'enums2.c.in', + ftail : '/* trailing source file info */', + install_header : true, + install_dir : get_option('includedir')) + +enums_h2 = gnome.mkenums('abc2', + sources : 'meson-sample.h', + h_template : 'enums2.h.in', + ftail : '/* trailing header file info */', + install_header : true, + install_dir : get_option('includedir')) + +conf = configuration_data() +conf.set('ENUM_FILE', 'enums2.h') +main = configure_file( + input : 'main.c', + output : 'main2.c', + configuration : conf) + +enumexe2 = executable('enumprog2', main, enums_c2, enums_h2, +dependencies : gobj) +test('enum test 2', enumexe2) + +# Generate both header and source by options only. +# These are specified in a way that should produce the same result as above +# (modulo any filename changes.) + +enums_h3 = gnome.mkenums('enums3.h', + sources : 'meson-sample.h', + fhead : '''#ifndef MESON_ENUMS_H +#define MESON_ENUMS_H + +#include <glib-object.h> + +G_BEGIN_DECLS +''', + fprod : ''' +/* enumerations from "@basename@" */ +''', + vhead : '''GType @enum_name@_get_type(void) G_GNUC_CONST; +#define @ENUMPREFIX@_TYPE_@ENUMSHORT@ (@enum_name@_get_type()) +''', + ftail : ''' +G_END_DECLS + +#endif /* MESON_ENUMS_H */ +''', + install_header : true, + install_dir : get_option('includedir')) + +enums_c3 = gnome.mkenums('enums3.c', + sources : 'meson-sample.h', + depends : enums_h3, + fhead : '''#include "enums3.h" +''', + fprod : ''' + +/* enumerations from "@basename@" */ +#include "@basename@" +''', + vhead : ''' +GType +@enum_name@_get_type(void) { + static volatile gsize g_define_type_id__volatile = 0; + + if(g_once_init_enter(&g_define_type_id__volatile)) { + static const G@Type@Value values [] = { +''', + vprod : ''' { @VALUENAME@, "@VALUENAME@", "@valuenick@" },''', + vtail : ''' { 0, NULL, NULL } + }; + + GType g_define_type_id = + g_@type@_register_static(g_intern_static_string("@EnumName@"), values); + g_once_init_leave(&g_define_type_id__volatile, g_define_type_id); + } + + return g_define_type_id__volatile; +} +''') + +conf = configuration_data() +conf.set('ENUM_FILE', 'enums3.h') +main = configure_file( + input : 'main.c', + output : 'main3.c', + configuration : conf) + +enumexe3 = executable('enumprog3', main, enums_c3, enums_h3, +dependencies : gobj) +test('enum test 3', enumexe3) |