[prev in list] [next in list] [prev in thread] [next in thread] 

List:       gtk-devel
Subject:    Re: RFC: GLib testing framework
From:       "Mikkel Kamstrup Erlandsen" <mikkel.kamstrup () gmail ! com>
Date:       2007-11-07 20:06:00
Message-ID: 9961daf10711071206l418251ddx3cf07c5aa5c29bab () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


On 07/11/2007, Tim Janik <timj@imendio.com> wrote:
>
> On Wed, 7 Nov 2007, Morten Welinder wrote:
>
> >> nobody has to use this syntax. you can stick to the ever simple:
> >>    g_assert (foo > bar);
> >>
> >> however if you want the value of 'foo' and 'bar' be printed out,
> instead
> >> of just the value of (foo > bar) which would be 0 or 1, then there are
> >> no other means than using something simialr to:
> >>    g_assert_cmpfloat (foo, >, bar);
> >
> > No other way?  You just need to think outside the box^w^wcpp.  How
> > about a pre-cpp filter that looks at the source code, finds the
> g_assert,
> > and does a little creative rewriting?
>
> how about that? bad.
> we don't use a preprocessor like moc before cpp+cc. if we did,
> GObject would look a million times different.
> people are coding such a thing after the fact these days though,
> look at vala to see how it looks like.


How about token concatenation[1]?

#define g_assert_cmp (arg1, cmp_op, arg2) \
    g_assert_cmp_##CMP_OP (arg1, arg2);

Then implement private methods:

g_assert_cmp_G_LESSTHAN
g_assert_cmp_G_EQUALS
...

Then call it like

g_assert_cmp (1, G_EQUALS, 2);

Cheers,
Mikkel

[1]: For the CPP challenged like me:
http://en.wikipedia.org/wiki/C_preprocessor

[Attachment #5 (text/html)]

On 07/11/2007, <b class="gmail_sendername">Tim Janik</b> &lt;<a \
href="mailto:timj@imendio.com">timj@imendio.com</a>&gt; wrote:<div><span \
class="gmail_quote"></span><blockquote class="gmail_quote" style="border-left: 1px \
solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"> On Wed, 7 \
Nov 2007, Morten Welinder wrote:<br><br>&gt;&gt; nobody has to use this syntax. you \
can stick to the ever simple:<br>&gt;&gt;&nbsp;&nbsp;&nbsp;&nbsp;g_assert (foo &gt; \
bar);<br>&gt;&gt;<br>&gt;&gt; however if you want the value of &#39;foo&#39; and \
&#39;bar&#39; be printed out, instead <br>&gt;&gt; of just the value of (foo &gt; \
bar) which would be 0 or 1, then there are<br>&gt;&gt; no other means than using \
something simialr to:<br>&gt;&gt;&nbsp;&nbsp;&nbsp;&nbsp;g_assert_cmpfloat (foo, \
&gt;, bar);<br>&gt;<br>&gt; No other way?&nbsp;&nbsp;You just need to think outside \
the box^w^wcpp.&nbsp;&nbsp;How <br>&gt; about a pre-cpp filter that looks at the \
source code, finds the g_assert,<br>&gt; and does a little creative \
rewriting?<br><br>how about that? bad.<br>we don&#39;t use a preprocessor like moc \
before cpp+cc. if we did, <br>GObject would look a million times different.<br>people \
are coding such a thing after the fact these days though,<br>look at vala to see how \
it looks like.</blockquote><div><br>How about token concatenation[1]?<br><br> #define \
g_assert_cmp (arg1, cmp_op, arg2) \<br>&nbsp;&nbsp;&nbsp; g_assert_cmp_##CMP_OP \
(arg1, arg2);<br><br>Then implement private \
methods:<br><br>g_assert_cmp_G_LESSTHAN<br>g_assert_cmp_G_EQUALS<br>...<br><br>Then \
call it like<br><br> g_assert_cmp (1, G_EQUALS, \
2);<br><br>Cheers,<br>Mikkel<br><br>[1]: For the CPP challenged like me: <a \
href="http://en.wikipedia.org/wiki/C_preprocessor">http://en.wikipedia.org/wiki/C_preprocessor</a><br></div></div>




_______________________________________________
gtk-devel-list mailing list
gtk-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-devel-list


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic