cfix cfix 1.2 introduces improved C++ support

cfix 1.2, which has been released today, introduces a number of new features, the most prominent being improved support for C++ and additional execution options.

New C++ API

To date, cfix has primarily focussed on C as the programming language to write unit tests in. Although C++ has always been supported, cfix has not made use of the additional capabilities C++ provides. With version 1.2, cfix makes C++ a first class citizen and introduces an additional API that leverages the benefits of C++ and allows writing test cases in a more convenient manner.

Being implemented on top of the existing C API, the C++ API is not a replacement, but rather an addition to the existing API set.

As the following example suggests, fixtures can now be written as classes, with test cases being implemented as methods:

    #include <cfixcc.h>
    
    class ExampleTest : public <a href="http://cfix.sourceforge.net/doc/TestFixture.html" title="TestFixture">cfixcc::TestFixture</a>
    {
    public:
      void TestOne() 
      {}
      
      void TestTwo() 
      {}
    };
    
    <a href="http://cfix.sourceforge.net/doc/CFIXCC_BEGIN_CLASS.html" title="CFIXCC_BEGIN_CLASS">CFIXCC_BEGIN_CLASS</a>( ExampleTest )
      <a href="http://cfix.sourceforge.net/doc/CFIXCC_METHOD.html" title="CFIXCC_METHOD">CFIXCC_METHOD</a>( TestOne )
      <a href="http://cfix.sourceforge.net/doc/CFIXCC_METHOD.html" title="CFIXCC_METHOD">CFIXCC_METHOD</a>( TestTwo )
    <a href="http://cfix.sourceforge.net/doc/CFIXCC_END_CLASS.html" title="CFIXCC_END_CLASS">CFIXCC_END_CLASS</a>()
    

To learn more about the definition of fixtures, have a look at the respective TestFixture chapter in the cfix documentation.

Regarding the implementation of test cases, cfix adds a new set of type-safe, template-driven assertions that, for instance, allow convenient equality checks:

    void TestOne() 
    {
      const wchar_t* testString = L"test";
      
      //
      // Use typesafe assertions...
      //
      <a href="http://cfix.sourceforge.net/doc/CFIXCC_ASSERT_EQUALS.html" title="CFIXCC_ASSERT_EQUALS">CFIXCC_ASSERT_EQUALS</a>( 1, 1 );
      <a href="http://cfix.sourceforge.net/doc/CFIXCC_ASSERT_EQUALS.html" title="CFIXCC_ASSERT_EQUALS">CFIXCC_ASSERT_EQUALS</a>( L"test", testString );
      <a href="http://cfix.sourceforge.net/doc/CFIXCC_ASSERT_EQUALS.html" title="CFIXCC_ASSERT_EQUALS">CFIXCC_ASSERT_EQUALS</a>( wcslen( testString ), ( size_t ) 4 );
      
      //
      // ...log messages...
      //
      <a href="http://cfix.sourceforge.net/doc/CFIX_LOG.html" title="http://cfix.sourceforge.net/doc/CFIX_LOG">CFIX_LOG</a>( L"Test string is %s", testString );
      
      //
      // ...or use the existing "C" assertions.
      //
      <a href="http://cfix.sourceforge.net/doc/CFIX_ASSERT.html" title="CFIX_ASSERT">CFIX_ASSERT</a>( wcslen( testString ) == 4 );
      <a href="http://cfix.sourceforge.net/doc/CFIX_ASSERT_MESSAGE.html" title="CFIX_ASSERT_MESSAGE">CFIX_ASSERT_MESSAGE</a>( testString[ 0 ] == 't', 
        L"Test string should start with a 't'" );
    }
    

Again, have a look at the updated API reference for an overview of the new API additions.

Customizing Test Runs

Another important new feature is the addition of the new switches -fsf (Shortcut Fixture), -fsr (Shortcut Run), and -fss (Shortcut Run On Failing Setup). Using these switches allows you to specify how a test run should resume when a test case fails.

When a test case fails, the default behavior of cfix is to report the failure, and resume at the next test case. By specifying -fsf, however, the remaining test cases of the same fixture will be skipped and execution resumes at the next fixture. With -fsr, cfix can be requirested to abort the entire run as soon as a single test case fails.

What else is new in 1.2?

Download

As always, cfix 1.2 is source and binary compatible to previous versions. The new MSI package and source code can now be downloaded on Sourceforge.

cfix is open source and licensed under the GNU Lesser General Public License.

Any opinions expressed on this blog are Johannes' own. Refer to the respective vendor’s product documentation for authoritative information.
« Back to home