[Spice-devel] [spice-common v3 3/7] log: Add test case for logging code
Christophe Fergeau
cfergeau at redhat.com
Fri Dec 18 02:40:51 PST 2015
On Thu, Dec 17, 2015 at 10:43:05PM +0100, Victor Toso wrote:
> > +/* Checks that spice_return_if_fail() aborts by default */
> > +static void test_spice_fatal_return_if_fail(void)
> > +{
> > + if (g_test_subprocess()) {
> > + spice_return_if_fail(FALSE);
> > + return;
> > + }
> > + g_test_trap_subprocess(NULL, 0, 0);
> > + g_test_trap_assert_failed();
> > +}
> > +
> > +/* Checks that g_return_if_fail() does not abort by default */
> > +static void test_spice_non_fatal_g_return_if_fail(void)
> > +{
> > + char *pattern = g_strconcat ("*", G_STRFUNC, "*", NULL);
> > + g_test_log_set_fatal_handler(non_fatal_warnings_criticals, pattern);
> > +
> > + if (g_test_subprocess()) {
> > + g_return_if_fail(FALSE);
>
> pattern leaks here
I know, but I don't think I can easily free it unless I move the
g_return_if_fail() to a separate helper function. If
g_test_log_set_fatal_handler() is not called, then g_return_if_fail()
will abort. I did not manage to find some preprocessor magic to build
a compile-time string (rather than an allocated one) with the content I
want. I can add a comment making it explicit that the leak is on
purpose. The g_return_if_fail() runs in a subprocess which will end
right after that call, so in my opinion this leak is acceptable.
Christophe
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/spice-devel/attachments/20151218/57ec2642/attachment.sig>
More information about the Spice-devel
mailing list