mirror of
https://github.com/boostorg/test.git
synced 2026-01-27 07:22:11 +00:00
62 lines
3.0 KiB
HTML
62 lines
3.0 KiB
HTML
<HTML>
|
|
<HEAD>
|
|
<TITLE>The Test Tools</TITLE>
|
|
<LINK rel="stylesheet" type="text/css" href="../../../style/btl.css" media="screen">
|
|
<LINK rel="stylesheet" type="text/css" href="../../../style/btl-print.css" media="print">
|
|
<META http-equiv="Content-Language" content="en-us">
|
|
<META http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
|
<STYLE type="text/css">
|
|
H4
|
|
{
|
|
margin: 0px;
|
|
}
|
|
</STYLE>
|
|
</HEAD>
|
|
<BODY>
|
|
<DIV class="body">
|
|
<H3>BOOST_CHECK_PREDICATE( predicate, predicate_arity, arguments_list ) </H3>
|
|
<P class="first_line_indented">This tool is used to validate the supplied predicate functor. This test
|
|
tool is generic. It allows to validate arbitrary one or two arity predicate. To validate zero or more
|
|
then two arity predicate use <A href="BOOST_CHECK.html" target="descr">BOOST_CHECK</A> tool. The advantage
|
|
of this tool is that shows arguments values in case of predicate failure.</P>
|
|
<P class="first_line_indented">If predicate produces <I>true</I> value, the tool produces a conformation
|
|
message (note: to manage what messages appear in the test output stream set the proper log level),
|
|
in other case it produces an error message in a form "error in ...: test <predicate>( arguments
|
|
list ) fail for (arguments values)".</P>
|
|
<P class="first_line_indented">The tools first parameter is the predicate itself. The tools second parameter
|
|
the predicate arity. The last third argument is wrapped in round brackets, comma separated list of
|
|
predicate arguments.</P>
|
|
<H4>Example: test.cpp</H4>
|
|
<PRE class="code"><SPAN class="cpp-type">bool</SPAN> is_even( <SPAN class="cpp-type">int</SPAN> i ) {
|
|
<SPAN class="reserv-word">return</SPAN> i%<SPAN class="literal">2</SPAN> == <SPAN class="literal">0</SPAN>;
|
|
}
|
|
|
|
<SPAN class="cpp-type">int</SPAN> test.cpp( <SPAN class="cpp-type">int</SPAN>, <SPAN class="cpp-type">char</SPAN>* [] ) {
|
|
<SPAN class="cpp-type">int</SPAN> i = <SPAN class="literal">17</SPAN>;
|
|
BOOST_CHECK_PREDICATE( &is_even, <SPAN class="literal">1</SPAN>, (i) );
|
|
|
|
<SPAN class="reserv-word">return</SPAN> <SPAN class="literal">0</SPAN>;
|
|
}
|
|
</PRE>
|
|
<H4>Output:</H4>
|
|
<P class="test-output">test.cpp(3) : error in test_main: test &is_even(i) failed for 17 </P>
|
|
<H4>Example: test.cpp</H4>
|
|
<PRE class="code"><SPAN class="cpp-type">int</SPAN> test.cpp( <SPAN class="cpp-type">int</SPAN>, <SPAN class="cpp-type">char</SPAN>* [] ) {
|
|
<SPAN class="cpp-type">int</SPAN> i = <SPAN class="literal">17</SPAN>;
|
|
|
|
BOOST_CHECK_PREDICATE( std::not_equal_to<<SPAN class="cpp-type">int</SPAN>>(), <SPAN class="literal">2</SPAN>, (i,<SPAN class="literal">17</SPAN>) );
|
|
|
|
<SPAN class="reserv-word">return</SPAN> <SPAN class="literal">0</SPAN>;
|
|
}
|
|
</PRE>
|
|
<H4>Output:</H4>
|
|
<P class="test-output">test.cpp(3) : error in test_main: test std::not_equal_to<int>()(i, 17)
|
|
failed for (17, 17) </P>
|
|
<DIV class="see_also">
|
|
<H4>See Also</H4>
|
|
<P class="see_also_content"><A href="BOOST_CHECK.html" target="descr">BOOST_CHECK</A></P>
|
|
</DIV>
|
|
</DIV>
|
|
</BODY>
|
|
</HTML>
|