From: Rico Tzschichholz Date: Wed, 29 Jul 2020 13:14:07 +0000 (+0200) Subject: tests: Add "girwriter" tests to increase coverage X-Git-Tag: 0.40.24~42 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a650efc8a963eedf61504a53bebe7f6179921b2f;p=thirdparty%2Fvala.git tests: Add "girwriter" tests to increase coverage Backported from 0.46 branch Fixes https://gitlab.gnome.org/GNOME/vala/issues/158 --- diff --git a/configure.ac b/configure.ac index adb51dfbd..72b62515b 100644 --- a/configure.ac +++ b/configure.ac @@ -142,6 +142,9 @@ LIBADD="$cgraph_tmp_LIBADD" CFLAGS="$cgraph_tmp_CFLAGS" AM_CONDITIONAL(HAVE_CGRAPH, test "$have_cgraph" = "yes") +AC_PATH_PROG([G_IR_COMPILER], [g-ir-compiler], :) +AM_CONDITIONAL(HAVE_G_IR_COMPILER, test "$G_IR_COMPILER" != :) + AC_PATH_PROG([XSLTPROC], [xsltproc], :) AM_CONDITIONAL(HAVE_XSLTPROC, test "$XSLTPROC" != :) @@ -162,6 +165,7 @@ AC_CONFIG_FILES([Makefile compiler/Makefile vapi/Makefile tests/Makefile + tests/girwriter/Makefile doc/Makefile doc/manual/Makefile doc/manual/version.xml diff --git a/tests/Makefile.am b/tests/Makefile.am index 42e7c95fc..9be7483fc 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,5 +1,9 @@ NULL = +SUBDIRS = \ + girwriter \ + $(NULL) + AM_CPPFLAGS = \ $(GLIB_CFLAGS) \ $(NULL) diff --git a/tests/girwriter/GirTest-1.0.gir-expected b/tests/girwriter/GirTest-1.0.gir-expected new file mode 100644 index 000000000..f26ab9605 --- /dev/null +++ b/tests/girwriter/GirTest-1.0.gir-expected @@ -0,0 +1,1841 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/girwriter/Makefile.am b/tests/girwriter/Makefile.am new file mode 100644 index 000000000..d5c383178 --- /dev/null +++ b/tests/girwriter/Makefile.am @@ -0,0 +1,33 @@ +NULL = + +check-girwriter: $(top_builddir)/compiler/valac + G_DEBUG=fatal-warnings $(top_builddir)/compiler/valac \ + -C \ + --disable-version-header \ + --vapidir $(top_srcdir)/vapi \ + --pkg gio-2.0 \ + --gir GirTest-1.0.gir \ + --library girtest \ + --shared-library girtest \ + $(srcdir)/girtest.vala; \ + tail -n +3 girtest.vapi | diff -wu $(srcdir)/girtest.vapi-expected - || exit 1; \ + tail -n +3 GirTest-1.0.gir | diff -wu $(srcdir)/GirTest-1.0.gir-expected - || exit 1; +if HAVE_G_IR_COMPILER + $(G_IR_COMPILER) -o GirTest-1.0.typelib GirTest-1.0.gir; +endif + rm -f GirTest-1.0.gir GirTest-1.0.typelib girtest.vapi girtest.c + +check: check-girwriter + +EXTRA_DIST = \ + girtest.vala \ + girtest.vapi-expected \ + GirTest-1.0.gir-expected \ + $(NULL) + +CLEANFILES = \ + girtest.c \ + girtest.vapi \ + GirTest-1.0.gir \ + GirTest-1.0.typelib \ + $(NULL) diff --git a/tests/girwriter/girtest.vala b/tests/girwriter/girtest.vala new file mode 100644 index 000000000..9aeeacc4a --- /dev/null +++ b/tests/girwriter/girtest.vala @@ -0,0 +1,349 @@ +[CCode (gir_namespace = "GirTest", gir_version = "1.0")] +namespace GirTest { + public struct BoxedStruct { + public int field_name; + + public BoxedStruct () { + } + + public void inv () { + } + } + + [CCode (has_type_id = false)] + public struct Struct { + public int field_name; + + public Struct () { + } + + public void inv () { + } + } + + [GIR (visible = false)] + public struct SkippedStruct { + public int field_name; + } + + public const int CONSTANT_NUMBER = 42; + public const string CONSTANT_STRING = "const ♥ utf8"; + + public enum EnumTest { + VALUE1, + VALUE2, + VALUE3 = 4711 + } + + [Flags] + public enum FlagsTest { + VALUE1, + VALUE2, + VALUE3 + } + + [CCode (has_type_id = false)] + public enum PlainEnumTest { + VALUE1, + VALUE2, + VALUE3 = 4711 + } + + [GIR (visible = false)] + public enum SkippedEnum { + VALUE1 + } + + [GIR (visible = false)] + public enum SkippedFlags { + VALUE1 + } + + public errordomain ErrorTest { + FAILED, + SMELLY, + FISHY = 23 + } + + public interface InterfaceTest : Object { + public abstract int property { get; construct set; } + public virtual void int8_in (int8 param) { + } + public virtual async void coroutine_async () { + } + public virtual void method_valist (int param, va_list vargs) { + } + [GIR (visible = false)] + public virtual async void skipped_coroutine_method (int param) { + } + } + + [GIR (visible = false)] + public interface SkippedInterface { + } + + public delegate bool DelegateTest (void* a, void* b); + + public delegate bool DelegateErrorTest () throws ErrorTest; + + public delegate bool DelegateGenericsTest (G g, T t); + + [GIR (visible = false)] + public delegate void SkippedDelegate (); + + public class TypeTest { + public string some_property { get; set; } + } + + public class SubTypeTest : TypeTest { + public string[] array_field; + public DelegateTest delegate_field; + } + + public class ObjectTest : Object { + private static ObjectTest global_instance = new ObjectTest (); + + public signal void some_signal (int param); + + [GIR (visible = false)] + public signal void skipped_signal (int param); + + public int field = 42; + + public int fixed_array_field[23]; + + public string? nullable_field; + + public string some_property { get; construct set; } + + public string write_only_property { set; } + + public string construct_only_property { construct; } + + [GIR (visible = false)] + public string skipped_property { get; construct set; } + + public ObjectTest () { + } + public ObjectTest.with_int (int param) { + field = param; + } + public ObjectTest.may_fail (int param) throws ErrorTest { + field = param; + } + public ObjectTest.newv (int param, ...) { + field = param; + } + public ObjectTest.new_valist (int param, va_list vargs) { + field = param; + } + public static void full_inout (ref ObjectTest obj) { + assert (obj.field == 42); + obj = new ObjectTest (); + } + public static void full_out (out ObjectTest obj) { + obj = new ObjectTest (); + } + public static ObjectTest full_return () { + return new ObjectTest (); + } + public static void none_inout (ref unowned ObjectTest obj) { + assert (obj.field == 42); + obj = global_instance; + } + public static void none_out (out unowned ObjectTest obj) { + obj = global_instance; + } + public static unowned ObjectTest none_return () { + return global_instance; + } + + public static void static_method () { + } + + public virtual void method_with_default_impl (int8 param) { + } + + public void int8_in (int8 param) { + } + + public void int8_out (out int8 param) { + param = 42; + } + + public void method () { + } + + public void method_varargs (int param, ...) { + } + + public void method_valist (int param, va_list vargs) { + } + + public void array_in (int[] array) { + } + + public void array_inout (ref int[] array) { + assert (array.length > 0); + array = new int[8]; + } + + public void array_out (out int[] array) { + array = new int[8]; + } + + public int[] array_return () { + return new int[8]; + } + + public void int_in_int_in_array_out (int param1, int param2, out int[] array) { + array = new int[8]; + } + + public int[] int_in_int_in_array_return (int param1, int param2) { + return new int[8]; + } + + public void string_array_out (out string[] array) { + array = { "foo" }; + } + + public string[] string_array_return () { + return { "foo" }; + } + + public void none_in () { + } + + public DelegateTest delegate_return () { + return (val1, val2) => { return (void*)val1 == (void*)val2; }; + } + + public DelegateTest delegate_return_int_in_array_out (int i1, out int[] a) { + a = new int[8]; + return delegate_return (); + } + + public int[] array_return_int_in_delegate_out (int i1, out DelegateTest d) { + d = delegate_return (); + return new int[8]; + } + + public EqualFunc simple_delegate_return () { + return str_equal; + } + + public (unowned string)[] container_return () { + return { "foo", "bar" }; + } + + public GenericArray? generic_array_container_return () { + return null; + } + + public async void coroutine_async () { + } + + public virtual async void coroutine_virtual_async () { + } + + public virtual async void coroutine_method_throw (int i1, out int o1) throws ErrorTest { + o1 = i1; + } + + public void simple_throw () throws ErrorTest { + } + + public virtual void method_throw () throws ErrorTest { + } + + public void method_with_default (int i = Priority.HIGH) { + } + + public virtual signal void signal_with_default_handlder (int i1) { + } + + [GIR (visible = false)] + public void skipped_method () { + } + } + + public abstract class AbstractObjectTest : Object { + public abstract void method_int8_in (int8 param); + + public abstract void method_int8_inout (ref int8 param); + + public abstract void method_int8_out (out int8 param); + + public abstract void method_throw () throws ErrorTest; + + public abstract void method_valist (int param, va_list vargs); + + [GIR (visible = false)] + public abstract async void skipped_coroutine_method (int param); + } + + public interface PrerequisiteTest : InterfaceTest { + } + + public class ImplementionTest : Object, InterfaceTest { + public int property { get; construct set; } + } + + [Compact] + public class CompactClass { + public string s; + public int i; + } + + [GIR (visible = false)] + public class SkippedClass { + } + + [Version (deprecated = true, deprecated_since = "0.1.2", since = "0.1.0")] + public class DeprecatedClassTest { + } + + public class GenericsTest { + public GenericsTest (owned DelegateTest cb) { + } + + public GenericsTest.typed (owned DelegateGenericsTest cb) { + } + + public void method (T param) { + } + } + + public class GenericsObjectTest : Object { + public void method (K[] param) { + } + } +} + +public enum InvalidEnum { + VALUE +} + +public errordomain InvalidError { + FAILED +} + +public class InvalidClass { +} + +public interface InvalidIface { +} + +public struct InvalidStruct { + public int i; +} + +public delegate void InvalidFunc (); + +public const int INVALID_CONST = 0; + +public int invalid_field; + +public void invalid_method () { +} diff --git a/tests/girwriter/girtest.vapi-expected b/tests/girwriter/girtest.vapi-expected new file mode 100644 index 000000000..23ca2a8bd --- /dev/null +++ b/tests/girwriter/girtest.vapi-expected @@ -0,0 +1,221 @@ +[CCode (gir_namespace = "GirTest", gir_version = "1.0")] +namespace GirTest { + [CCode (cheader_filename = "girtest.h")] + public abstract class AbstractObjectTest : GLib.Object { + protected AbstractObjectTest (); + public abstract void method_int8_in (int8 param); + public abstract void method_int8_inout (ref int8 param); + public abstract void method_int8_out (out int8 param); + public abstract void method_throw () throws GirTest.ErrorTest; + public abstract void method_valist (int param, va_list vargs); + [GIR (visible = false)] + public abstract async void skipped_coroutine_method (int param); + } + [CCode (cheader_filename = "girtest.h")] + [Compact] + public class CompactClass { + public int i; + public string s; + public CompactClass (); + } + [CCode (cheader_filename = "girtest.h")] + [Version (deprecated = true, deprecated_since = "0.1.2", since = "0.1.0")] + public class DeprecatedClassTest { + public DeprecatedClassTest (); + } + [CCode (cheader_filename = "girtest.h")] + public class GenericsObjectTest : GLib.Object { + public GenericsObjectTest (); + public void method (K[] param); + } + [CCode (cheader_filename = "girtest.h")] + public class GenericsTest { + public GenericsTest (owned GirTest.DelegateTest cb); + public void method (T param); + public GenericsTest.typed (owned GirTest.DelegateGenericsTest cb); + } + [CCode (cheader_filename = "girtest.h")] + public class ImplementionTest : GLib.Object, GirTest.InterfaceTest { + public ImplementionTest (); + } + [CCode (cheader_filename = "girtest.h")] + public class ObjectTest : GLib.Object { + public int field; + public int fixed_array_field[23]; + public string? nullable_field; + public ObjectTest (); + public void array_in (int[] array); + public void array_inout (ref int[] array); + public void array_out (out int[] array); + public int[] array_return (); + public int[] array_return_int_in_delegate_out (int i1, out GirTest.DelegateTest d); + public (unowned string)[] container_return (); + public async void coroutine_async (); + public virtual async void coroutine_method_throw (int i1, out int o1) throws GirTest.ErrorTest; + public virtual async void coroutine_virtual_async (); + public GirTest.DelegateTest delegate_return (); + public GirTest.DelegateTest delegate_return_int_in_array_out (int i1, out int[] a); + public static void full_inout (ref GirTest.ObjectTest obj); + public static void full_out (out GirTest.ObjectTest obj); + public static GirTest.ObjectTest full_return (); + public GLib.GenericArray? generic_array_container_return (); + public void int8_in (int8 param); + public void int8_out (out int8 param); + public void int_in_int_in_array_out (int param1, int param2, out int[] array); + public int[] int_in_int_in_array_return (int param1, int param2); + public ObjectTest.may_fail (int param) throws GirTest.ErrorTest; + public void method (); + public virtual void method_throw () throws GirTest.ErrorTest; + public void method_valist (int param, va_list vargs); + public void method_varargs (int param, ...); + public void method_with_default (int i = GLib.Priority.HIGH); + public virtual void method_with_default_impl (int8 param); + public ObjectTest.new_valist (int param, va_list vargs); + public ObjectTest.newv (int param, ...); + public void none_in (); + public static void none_inout (ref unowned GirTest.ObjectTest obj); + public static void none_out (out unowned GirTest.ObjectTest obj); + public static unowned GirTest.ObjectTest none_return (); + public GLib.EqualFunc simple_delegate_return (); + public void simple_throw () throws GirTest.ErrorTest; + [GIR (visible = false)] + public void skipped_method (); + public static void static_method (); + public void string_array_out (out string[] array); + public string[] string_array_return (); + public ObjectTest.with_int (int param); + public string construct_only_property { construct; } + [GIR (visible = false)] + public string skipped_property { get; set construct; } + public string some_property { get; set construct; } + public string write_only_property { set; } + public virtual signal void signal_with_default_handlder (int i1); + [GIR (visible = false)] + public signal void skipped_signal (int param); + public signal void some_signal (int param); + } + [CCode (cheader_filename = "girtest.h")] + [GIR (visible = false)] + public class SkippedClass { + public SkippedClass (); + } + [CCode (cheader_filename = "girtest.h")] + public class SubTypeTest : GirTest.TypeTest { + public string[] array_field; + public GirTest.DelegateTest delegate_field; + public SubTypeTest (); + } + [CCode (cheader_filename = "girtest.h")] + public class TypeTest { + public TypeTest (); + public string some_property { get; set; } + } + [CCode (cheader_filename = "girtest.h")] + public interface InterfaceTest : GLib.Object { + public virtual async void coroutine_async (); + public virtual void int8_in (int8 param); + public virtual void method_valist (int param, va_list vargs); + [GIR (visible = false)] + public virtual async void skipped_coroutine_method (int param); + public abstract int property { get; set construct; } + } + [CCode (cheader_filename = "girtest.h")] + public interface PrerequisiteTest : GirTest.InterfaceTest { + } + [CCode (cheader_filename = "girtest.h")] + [GIR (visible = false)] + public interface SkippedInterface { + } + [CCode (cheader_filename = "girtest.h")] + public struct BoxedStruct { + public int field_name; + public BoxedStruct (); + public void inv (); + } + [CCode (cheader_filename = "girtest.h")] + [GIR (visible = false)] + public struct SkippedStruct { + public int field_name; + } + [CCode (cheader_filename = "girtest.h", has_type_id = false)] + public struct Struct { + public int field_name; + public Struct (); + public void inv (); + } + [CCode (cheader_filename = "girtest.h")] + public enum EnumTest { + VALUE1, + VALUE2, + VALUE3 + } + [CCode (cheader_filename = "girtest.h")] + [Flags] + public enum FlagsTest { + VALUE1, + VALUE2, + VALUE3 + } + [CCode (cheader_filename = "girtest.h", has_type_id = false)] + public enum PlainEnumTest { + VALUE1, + VALUE2, + VALUE3 + } + [CCode (cheader_filename = "girtest.h")] + [GIR (visible = false)] + public enum SkippedEnum { + VALUE1 + } + [CCode (cheader_filename = "girtest.h")] + [GIR (visible = false)] + public enum SkippedFlags { + VALUE1 + } + [CCode (cheader_filename = "girtest.h")] + public errordomain ErrorTest { + FAILED, + SMELLY, + FISHY + } + [CCode (cheader_filename = "girtest.h")] + public delegate bool DelegateErrorTest () throws GirTest.ErrorTest; + [CCode (cheader_filename = "girtest.h")] + public delegate bool DelegateGenericsTest (G g, T t); + [CCode (cheader_filename = "girtest.h")] + public delegate bool DelegateTest (void* a, void* b); + [CCode (cheader_filename = "girtest.h")] + [GIR (visible = false)] + public delegate void SkippedDelegate (); + [CCode (cheader_filename = "girtest.h")] + public const int CONSTANT_NUMBER; + [CCode (cheader_filename = "girtest.h")] + public const string CONSTANT_STRING; +} +[CCode (cheader_filename = "girtest.h")] +public enum InvalidEnum { + VALUE +} +[CCode (cheader_filename = "girtest.h")] +public errordomain InvalidError { + FAILED +} +[CCode (cheader_filename = "girtest.h")] +public class InvalidClass { + public InvalidClass (); +} +[CCode (cheader_filename = "girtest.h")] +public interface InvalidIface { +} +[CCode (cheader_filename = "girtest.h")] +public struct InvalidStruct { + public int i; +} +[CCode (cheader_filename = "girtest.h")] +public delegate void InvalidFunc (); +[CCode (cheader_filename = "girtest.h")] +public const int INVALID_CONST; +[CCode (cheader_filename = "girtest.h")] +public static int invalid_field; +[CCode (cheader_filename = "girtest.h")] +public static void invalid_method ();