From: Rico Tzschichholz Date: Wed, 24 Nov 2021 20:26:03 +0000 (+0100) Subject: tests: Add [Profile] method test to increase coverage X-Git-Tag: 0.55.1~63 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0f493a1d0e67f480cfa979fd5a4f254659b2c869;p=thirdparty%2Fvala.git tests: Add [Profile] method test to increase coverage --- diff --git a/tests/Makefile.am b/tests/Makefile.am index b7b1b9f26..d795b2623 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -247,6 +247,7 @@ TESTS = \ methods/printf-invalid.test \ methods/printf-constructor.vala \ methods/printf-constructor-invalid.test \ + methods/profile.vala \ methods/varargs-delegate.vala \ methods/varargs-delegate-without-target.vala \ methods/varargs-gvalue.vala \ diff --git a/tests/methods/profile.c-expected b/tests/methods/profile.c-expected new file mode 100644 index 000000000..024545610 --- /dev/null +++ b/tests/methods/profile.c-expected @@ -0,0 +1,114 @@ +/* methods_profile.c generated by valac, the Vala compiler + * generated from methods_profile.vala, do not modify */ + +#include +#include + +#if !defined(VALA_EXTERN) +#if defined(_MSC_VER) +#define VALA_EXTERN __declspec(dllexport) extern +#elif __GNUC__ >= 4 +#define VALA_EXTERN __attribute__((visibility("default"))) extern +#else +#define VALA_EXTERN extern +#endif +#endif + +#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); +#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return; } +#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return val; } +#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); + +static gint _vala_prof_foo_counter; +static gint _vala_prof_foo_level; +static GTimer * _vala_prof_foo_timer; +static gint _vala_prof_bar_counter; +static gint _vala_prof_bar_level; +static GTimer * _vala_prof_bar_timer; + +VALA_EXTERN void foo (void); +static void _vala_prof_foo_init (void) __attribute__((constructor)); +static void _vala_prof_foo_exit (void) __attribute__((destructor)); +VALA_EXTERN gint bar (gboolean b); +static void _vala_prof_bar_init (void) __attribute__((constructor)); +static void _vala_prof_bar_exit (void) __attribute__((destructor)); +static void _vala_main (void); + +static void +_vala_prof_foo_init (void) +{ + _vala_prof_foo_timer = g_timer_new (); + g_timer_stop (_vala_prof_foo_timer); +} + +static void +_vala_prof_foo_exit (void) +{ + fprintf (stderr, "foo: %gs (%d calls)\n", g_timer_elapsed (_vala_prof_foo_timer, NULL), _vala_prof_foo_counter); +} + +void +foo (void) +{ + if (!(_vala_prof_foo_level++)) { + _vala_prof_foo_counter++; + g_timer_continue (_vala_prof_foo_timer); + } + g_usleep ((gulong) 4000); + if (!(--_vala_prof_foo_level)) { + g_timer_stop (_vala_prof_foo_timer); + } +} + +static void +_vala_prof_bar_init (void) +{ + _vala_prof_bar_timer = g_timer_new (); + g_timer_stop (_vala_prof_bar_timer); +} + +static void +_vala_prof_bar_exit (void) +{ + fprintf (stderr, "bar: %gs (%d calls)\n", g_timer_elapsed (_vala_prof_bar_timer, NULL), _vala_prof_bar_counter); +} + +gint +bar (gboolean b) +{ + gint result = 0; + if (!(_vala_prof_bar_level++)) { + _vala_prof_bar_counter++; + g_timer_continue (_vala_prof_bar_timer); + } + g_usleep ((gulong) 4000); + if (b) { + result = 42; + if (!(--_vala_prof_bar_level)) { + g_timer_stop (_vala_prof_bar_timer); + } + return result; + } + result = 23; + if (!(--_vala_prof_bar_level)) { + g_timer_stop (_vala_prof_bar_timer); + } + return result; +} + +static void +_vala_main (void) +{ + foo (); + _vala_assert (bar (FALSE) == 23, "bar (false) == 23"); + _vala_assert (bar (TRUE) == 42, "bar (true) == 42"); +} + +int +main (int argc, + char ** argv) +{ + _vala_main (); + return 0; +} + diff --git a/tests/methods/profile.vala b/tests/methods/profile.vala new file mode 100644 index 000000000..a99b377c9 --- /dev/null +++ b/tests/methods/profile.vala @@ -0,0 +1,19 @@ +[Profile] +void foo () { + Thread.usleep (4000); +} + +[Profile] +int bar (bool b) { + Thread.usleep (4000); + if (b) { + return 42; + } + return 23; +} + +void main () { + foo (); + assert (bar (false) == 23); + assert (bar (true) == 42); +}