From 58ab818708127f74c509727642413fa00f1748aa Mon Sep 17 00:00:00 2001 From: Anton Gorenko Date: Sun, 12 Sep 2010 23:08:52 +0600 Subject: [PATCH] gobject-introspection: add new tests --- basis/gobject-introspection/ffi/ffi.factor | 5 +- .../tests/codegen.factor | 267 ++ .../tests/everything/Everything-1.0.gir | 2340 +++++++++++++++++ .../tests/everything/everything.factor | 5 + .../tests/everything/ffi/ffi.factor | 19 + 5 files changed, 2635 insertions(+), 1 deletion(-) create mode 100644 basis/gobject-introspection/tests/codegen.factor create mode 100644 basis/gobject-introspection/tests/everything/Everything-1.0.gir create mode 100644 basis/gobject-introspection/tests/everything/everything.factor create mode 100644 basis/gobject-introspection/tests/everything/ffi/ffi.factor diff --git a/basis/gobject-introspection/ffi/ffi.factor b/basis/gobject-introspection/ffi/ffi.factor index fb58ede1f6..1328bdc787 100644 --- a/basis/gobject-introspection/ffi/ffi.factor +++ b/basis/gobject-introspection/ffi/ffi.factor @@ -161,7 +161,8 @@ IN: gobject-introspection.ffi [ define-ffi-interface-content ] each ; : get-type-invoker ( name -- quot ) - [ "GType" current-lib get-global ] dip + ! hack + [ "GType" "glib.ffi" lookup current-lib get-global ] dip { } \ alien-invoke 5 narray >quotation ; : define-ffi-class ( class -- word ) @@ -230,6 +231,8 @@ IN: gobject-introspection.ffi [ classes>> define-ffi-classes-content ] [ interfaces>> define-ffi-interfaces-content ] [ functions>> define-ffi-functions ] + + [ define-get-types ] } cleave ; : define-ffi-repository ( repository -- ) diff --git a/basis/gobject-introspection/tests/codegen.factor b/basis/gobject-introspection/tests/codegen.factor new file mode 100644 index 0000000000..0a28b68174 --- /dev/null +++ b/basis/gobject-introspection/tests/codegen.factor @@ -0,0 +1,267 @@ +! Copyright (C) 2010 Anton Gorenko. +! See http://factorcode.org/license.txt for BSD license. +USING: glib.ffi gobject-introspection.tests.everything.ffi +io.streams.string see tools.test ; +IN: gobject-introspection.tests.godegen + +! Constants + +[ "IN: glib.ffi +CONSTANT: G_ASCII_DTOSTR_BUF_SIZE 39 inline +" ] [ + [ \ G_ASCII_DTOSTR_BUF_SIZE see ] with-string-writer +] unit-test + +[ "IN: glib.ffi +CONSTANT: G_CSET_a_2_z \"abcdefghijklmnopqrstuvwxyz\" inline +" ] [ + [ \ G_CSET_a_2_z see ] with-string-writer +] unit-test + +[ "IN: glib.ffi +CONSTANT: G_E 2.71828182846 inline +" ] [ + [ \ G_E see ] with-string-writer +] unit-test + +! Enumerations + +[ "USING: alien.c-types alien.syntax ; +IN: gobject-introspection.tests.everything.ffi +TYPEDEF: int TestEnum +" ] [ + [ \ TestEnum see ] with-string-writer +] unit-test + +[ "IN: gobject-introspection.tests.everything.ffi +CONSTANT: TEST_VALUE1 0 inline +" ] [ + [ \ TEST_VALUE1 see ] with-string-writer +] unit-test + +[ "IN: gobject-introspection.tests.everything.ffi +CONSTANT: TEST_VALUE3 42 inline +" ] [ + [ \ TEST_VALUE3 see ] with-string-writer +] unit-test + +! Bitfields + +[ "USING: alien.c-types alien.syntax ; +IN: gobject-introspection.tests.everything.ffi +TYPEDEF: int TestFlags +" ] [ + [ \ TestFlags see ] with-string-writer +] unit-test + +[ "IN: gobject-introspection.tests.everything.ffi +CONSTANT: TEST_FLAG2 2 inline +" ] [ + [ \ TEST_FLAG2 see ] with-string-writer +] unit-test + +! Functions + +[ "USING: alien.syntax glib.ffi ; +IN: gobject-introspection.tests.everything.ffi +LIBRARY: gobject-introspection.tests.everything FUNCTION: + gint test_int ( gint in ) ; +" ] [ + [ \ test_int see ] with-string-writer +] unit-test + +! - throws + +[ "USING: alien.c-types alien.syntax glib.ffi ; +IN: gobject-introspection.tests.everything.ffi +LIBRARY: gobject-introspection.tests.everything FUNCTION: + gboolean test_torture_signature_1 + ( int x, double* y, int* z, char* foo, int* q, guint m, + GError** error ) ; +" ] [ + [ \ test_torture_signature_1 see ] with-string-writer +] unit-test + +! Records + +[ "USING: alien.syntax ; +IN: gobject-introspection.tests.everything.ffi +C-TYPE: TestSimpleBoxedA +" ] [ + [ \ TestSimpleBoxedA see ] with-string-writer +] unit-test + +[ "USING: classes.struct glib.ffi ; +IN: gobject-introspection.tests.everything.ffi +STRUCT: TestBoxed + { some_int8 gint8 initial: 0 } + { nested_a TestSimpleBoxedA } { priv TestBoxedPrivate* } ; +" ] [ + [ \ TestBoxed see ] with-string-writer +] unit-test + +! - constructors + +[ "USING: alien.syntax ; +IN: gobject-introspection.tests.everything.ffi +LIBRARY: gobject-introspection.tests.everything FUNCTION: + TestBoxed* test_boxed_new ( ) ; +" ] [ + [ \ test_boxed_new see ] with-string-writer +] unit-test + +[ "USING: alien.c-types alien.syntax ; +IN: gobject-introspection.tests.everything.ffi +LIBRARY: gobject-introspection.tests.everything FUNCTION: + TestBoxed* test_boxed_new_alternative_constructor1 + ( int i ) ; +" ] [ + [ \ test_boxed_new_alternative_constructor1 see ] with-string-writer +] unit-test + +! - functions + +! - methods + +[ "USING: alien.syntax ; +IN: gobject-introspection.tests.everything.ffi +LIBRARY: gobject-introspection.tests.everything FUNCTION: + TestBoxed* test_boxed_copy ( TestBoxed* self ) ; +" ] [ + [ \ test_boxed_copy see ] with-string-writer +] unit-test + +[ "USING: alien.c-types alien.syntax ; +IN: gobject-introspection.tests.everything.ffi +LIBRARY: gobject-introspection.tests.everything FUNCTION: + void test_struct_a_clone + ( TestStructA* self, TestStructA* a_out ) ; +" ] [ + [ \ test_struct_a_clone see ] with-string-writer +] unit-test + +! Classes + +[ "USING: alien.syntax ; +IN: gobject-introspection.tests.everything.ffi +C-TYPE: TestObj +" ] [ + [ \ TestObj see ] with-string-writer +] unit-test + +! - get_type + +[ "USING: alien.syntax glib.ffi ; +IN: gobject-introspection.tests.everything.ffi +LIBRARY: gobject-introspection.tests.everything FUNCTION: + GType test_obj_get_type ( ) ; +" ] [ + [ \ test_obj_get_type see ] with-string-writer +] unit-test + +! - constructors + +[ "USING: alien.c-types alien.syntax glib.ffi ; +IN: gobject-introspection.tests.everything.ffi +LIBRARY: gobject-introspection.tests.everything FUNCTION: + TestObj* test_obj_new_from_file ( char* x, GError** error ) + ; +" ] [ + [ \ test_obj_new_from_file see ] with-string-writer +] unit-test + +[ "USING: alien.syntax glib.ffi ; +IN: gobject-introspection.tests.everything.ffi +LIBRARY: gobject-introspection.tests.everything FUNCTION: + TestObj* test_obj_new_callback + ( TestCallbackUserData callback, gpointer user_data, + GDestroyNotify notify ) ; +" ] [ + [ \ test_obj_new_callback see ] with-string-writer +] unit-test + +! - functions + +[ "USING: alien.c-types alien.syntax ; +IN: gobject-introspection.tests.everything.ffi +LIBRARY: gobject-introspection.tests.everything FUNCTION: + double test_obj_static_method ( int x ) ; +" ] [ + [ \ test_obj_static_method see ] with-string-writer +] unit-test + +[ "USING: alien.c-types alien.syntax ; +IN: gobject-introspection.tests.everything.ffi +LIBRARY: gobject-introspection.tests.everything FUNCTION: + void test_obj_static_method_callback + ( TestCallback callback ) ; +" ] [ + [ \ test_obj_static_method_callback see ] with-string-writer +] unit-test + +! - methods + +[ "USING: alien.c-types alien.syntax gobject.ffi ; +IN: gobject-introspection.tests.everything.ffi +LIBRARY: gobject-introspection.tests.everything FUNCTION: + void test_obj_set_bare ( TestObj* self, GObject* bare ) ; +" ] [ + [ \ test_obj_set_bare see ] with-string-writer +] unit-test + +[ "USING: alien.c-types alien.syntax ; +IN: gobject-introspection.tests.everything.ffi +LIBRARY: gobject-introspection.tests.everything FUNCTION: + int test_obj_instance_method ( TestObj* self ) ; +" ] [ + [ \ test_obj_instance_method see ] with-string-writer +] unit-test + +[ "USING: alien.c-types alien.syntax glib.ffi ; +IN: gobject-introspection.tests.everything.ffi +LIBRARY: gobject-introspection.tests.everything FUNCTION: + gboolean test_obj_torture_signature_1 + ( TestObj* self, int x, double* y, int* z, char* foo, int* + q, guint m, GError** error ) ; +" ] [ + [ \ test_obj_torture_signature_1 see ] with-string-writer +] unit-test + +! - signals + +[ "USING: alien.c-types alien.syntax glib.ffi ; +IN: gobject-introspection.tests.everything.ffi +LIBRARY: gobject-introspection.tests.everything CALLBACK: + void TestObj:test ( TestObj* sender, gpointer user_data ) ; +" ] [ + [ \ TestObj:test see ] with-string-writer +] unit-test + +[ "USING: alien.c-types alien.syntax glib.ffi ; +IN: gobject-introspection.tests.everything.ffi +LIBRARY: gobject-introspection.tests.everything CALLBACK: + void TestObj:test-with-static-scope-arg + ( TestObj* sender, TestSimpleBoxedA* object, gpointer + user_data ) ; +" ] [ + [ \ TestObj:test-with-static-scope-arg see ] with-string-writer +] unit-test + +! Callbacks + +[ "USING: alien.c-types alien.syntax ; +IN: gobject-introspection.tests.everything.ffi +LIBRARY: gobject-introspection.tests.everything CALLBACK: + int TestCallback ( ) ; +" ] [ + [ \ TestCallback see ] with-string-writer +] unit-test + +[ "USING: alien.c-types alien.syntax glib.ffi ; +IN: gobject-introspection.tests.everything.ffi +LIBRARY: gobject-introspection.tests.everything CALLBACK: + int TestCallbackUserData ( gpointer user_data ) ; +" ] [ + [ \ TestCallbackUserData see ] with-string-writer +] unit-test + diff --git a/basis/gobject-introspection/tests/everything/Everything-1.0.gir b/basis/gobject-introspection/tests/everything/Everything-1.0.gir new file mode 100644 index 0000000000..aa7de3b4b6 --- /dev/null +++ b/basis/gobject-introspection/tests/everything/Everything-1.0.gir @@ -0,0 +1,2340 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + This method is virtual. Notably its name differs from the virtual +slot name, which makes it useful for testing bindings handle this +case. + + + + + + Meaningless string + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + This function throws an error if m is odd. + + + + + + + + + + + + + + + + + + + + + + + + + + This method is virtual. Notably its name differs from the virtual +slot name, which makes it useful for testing bindings handle this +case. + + + + + + Meaningless string + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Meaningless string + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Make a copy of a TestStructA + + + + + + the cloned structure + + + + + + + + + + + + + + Make a copy of a TestStructB + + + + + + the cloned structure + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + the sum of the items in @ints + + + + + a list of 5 integers + + + + + + + + + + + + + a list of 5 integers ranging from 0 to 4 + + + + + + + + + a list of 5 integers ranging from 0 to 4 + + + + + + + + + + + + + + + List of ints + + + + + + + + + + + + + + + + List of ints + + + + + + + + + + + + + + + + List of ints + + + + + + + + + + + + + + + + List of ints + + + + + + + + + string representation of provided types + + + + + + + + List of types + + + + + + + + + a new array of integers. + + + + + + + length of the returned array. + + + + + + + + + + + + + + List of ints + + + + + + + + + + + + + + + + List of ints + + + + + + + + + + + + + the length of @ints + + + + a list of integers whose items will be increased by 1, except the first that will be dropped + + + + + + + + + a static array of integers. + + + + + + + length of the returned array. + + + + + + + + + + + + + + + + length + + + + + + + + + + + + + + + + length + + + + + + + + + + + the length of @ints + + + + a list of 5 integers, from 0 to 4 in consecutive order + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Notified - callback persists until a DestroyNotify delegate +is invoked. + + + + + + + + + + + + + + + + + + + + + + Invokes all callbacks installed by #test_callback_destroy_notify(), +adding up their return values, and removes them, invoking the +corresponding destroy notfications. + + Sum of the return values of the invoked callbacks. + + + + + Call - callback parameter persists for the duration of the method +call and can be released on return. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + list of strings + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Specify nested parameterized types directly with the (type ) annotation. + + + + + + + + + + + + element-type annotation. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + A #TestObj + + + + + + + + + + + A #TestObj + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + No annotations here. We want the default to Do The Right Thing. + + + + + + + + No annotations here. We want the default to Do The Right Thing. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + This function throws an error if m is odd. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + <const char*> UTF-8 string + + + + + + + + + + + + + + + + + + + + + + + + + + <char*> UTF-8 string + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + a copy of "first" + + + + + a copy of "second" + + + + + + + + + + + a copy of "first" + + + + a copy of "second" + + + + + + + + + + + + + + + + + the int wrapped in a GValue. + + + + + an int + + + + + + + + + + + + + + + + + + + diff --git a/basis/gobject-introspection/tests/everything/everything.factor b/basis/gobject-introspection/tests/everything/everything.factor new file mode 100644 index 0000000000..bfb94a842c --- /dev/null +++ b/basis/gobject-introspection/tests/everything/everything.factor @@ -0,0 +1,5 @@ +! Copyright (C) 2010 Anton Gorenko. +! See http://factorcode.org/license.txt for BSD license. +USING: gobject-introspection.tests.everything.ffi ; +IN: gobject-introspection.tests.everything + diff --git a/basis/gobject-introspection/tests/everything/ffi/ffi.factor b/basis/gobject-introspection/tests/everything/ffi/ffi.factor new file mode 100644 index 0000000000..d4a7c2ff34 --- /dev/null +++ b/basis/gobject-introspection/tests/everything/ffi/ffi.factor @@ -0,0 +1,19 @@ +! Copyright (C) 2010 Anton Gorenko. +! See http://factorcode.org/license.txt for BSD license. +USING: alien alien.c-types alien.libraries combinators kernel +system +gobject-introspection cairo.ffi gio.ffi glib.ffi gobject.ffi ; +IN: gobject-introspection.tests.everything.ffi + +<< +"gobject-introspection.tests.everything" { + { [ os winnt? ] [ drop ] } + { [ os macosx? ] [ drop ] } + { [ os unix? ] [ "libgirepository-everything-1.0.so" cdecl add-library ] } +} cond +>> + +IMPLEMENT-STRUCTS: TestBoxed ; + +GIR: vocab:gobject-introspection/tests/everything/Everything-1.0.gir +