]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
tests: Add [Profile] method test to increase coverage
authorRico Tzschichholz <ricotz@ubuntu.com>
Wed, 24 Nov 2021 20:26:03 +0000 (21:26 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Wed, 24 Nov 2021 20:26:03 +0000 (21:26 +0100)
tests/Makefile.am
tests/methods/profile.c-expected [new file with mode: 0644]
tests/methods/profile.vala [new file with mode: 0644]

index b7b1b9f26ddc09ad29dac9964eb0c1ebe36814d5..d795b2623b77de7233a56927b6f26124c1b02018 100644 (file)
@@ -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 (file)
index 0000000..0245456
--- /dev/null
@@ -0,0 +1,114 @@
+/* methods_profile.c generated by valac, the Vala compiler
+ * generated from methods_profile.vala, do not modify */
+
+#include <stdio.h>
+#include <glib.h>
+
+#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 (file)
index 0000000..a99b377
--- /dev/null
@@ -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);
+}