CfixPeGetValue
CfixPeGetValue retrieves a user-defined value associated with the currently executing fixture. The visibility of the value is restricted to the current thread and (as of cfix 1.5) its child threads created by CfixCreateThread2 or CfixCreateSystemThread.
With CfixPeGetValue and CfixPeSetValue, access is provided to a piece of memory that behaves similar to TLS. Unlike TLS, however, the memory is also visible to child threads.
In order to limit the usage of global or static variables, authors of test suites are encouraged to store fixture-specific data using these functions.
Note, however, that such fixture-specific data should be maintained and accessed by before-, after and test-routines only. Setup- and teardown-routines, in contrast, should only be used to maintain global and static variables.
// // Structure containing all fixture-specific data. // typedef struct _FIXTURE_DATA { HANDLE File; ... } FIXTURE_DATA, *PFIXTURE_DATA; static void Before() { PFIXTURE_DATA FixtureData = ( PFIXTURE_DATA ) malloc( sizeof( FIXTURE_DATA ) ); CFIX_ASSERT( FixtureData != NULL ); FixtureData->File = CreateFile( ... ); CfixPeSetValue( 0, FixtureData ); } static void Test() { PFIXTURE_DATA FixtureData = ( PFIXTURE_DATA ) CfixPeGetValue( 0 ); ... // // Use members of FixtureData. // } static void After() { PFIXTURE_DATA FixtureData = ( PFIXTURE_DATA ) CfixPeGetValue( 0 ); CloseHandle( FixtureData->File ); free( FixtureData ); // // This is optional: // CfixPeSetValue( 0, NULL ); } CFIX_BEGIN_FIXTURE( Example ) CFIX_FIXTURE_BEFORE( Before ) CFIX_FIXTURE_AFTER( After ) CFIX_FIXTURE_ENTRY( Test ) CFIX_END_FIXTURE()