Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Please use <a href="http://cppunit.sourceforge.net/doc/lastest/group___assertions.html#ga3" rel="nofollow"><code>CPPUNIT_ASSERT_EQUAL</code></a>, which takes an actual and expected value. This pretty much eliminates the need for formatting a string, as the actual and expected values will be printed in the failure message.</p> <p>You could also copy the implementation of this macro and the function it invokes and add additional macros for other types of comparisons. Another idea I tried out would be to use operator overloading to capture the value out of an expression. This (ab)uses operator overloading to capture the expression, but it seems perhaps a bit too hackish. I have included it to give you an idea of what is possible, but would not recommend its use:</p> <pre><code>#include &lt;iostream&gt; #include &lt;sstream&gt; class ExpressionPrinter { public: std::ostringstream result; template&lt;typename T&gt; ExpressionPrinter&amp; operator&lt;&lt;(const T&amp; other) { result &lt;&lt; other; return *this; } template&lt;typename T&gt; ExpressionPrinter&amp; operator&lt;(const T&amp; other) { result &lt;&lt; " &lt; "; result &lt;&lt; other; return *this; } template&lt;typename T&gt; ExpressionPrinter&amp; operator&lt;=(const T&amp; other) { result &lt;&lt; " &lt;= "; result &lt;&lt; other; return *this; } template&lt;typename T&gt; ExpressionPrinter&amp; operator&gt;(const T&amp; other) { result &lt;&lt; " &gt; "; result &lt;&lt; other; return *this; } template&lt;typename T&gt; ExpressionPrinter&amp; operator&gt;=(const T&amp; other) { result &lt;&lt; " &gt;= "; result &lt;&lt; other; return *this; } template&lt;typename T&gt; ExpressionPrinter&amp; operator==(const T&amp; other) { result &lt;&lt; " == "; result &lt;&lt; other; return *this; } template&lt;typename T&gt; ExpressionPrinter&amp; operator!=(const T&amp; other) { result &lt;&lt; " != "; result &lt;&lt; other; return *this; } }; #define ASSERT(X) doAssert((X), (ExpressionPrinter() &lt;&lt; X)); void doAssert(bool result, const ExpressionPrinter&amp; message) { std::cout &lt;&lt; "Result: " &lt;&lt; result &lt;&lt; ", Expression: " &lt;&lt; message.result.str() &lt;&lt; std::endl; } int main() { int i = 1, j = 2; ASSERT(i &lt; j); return 0; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload