Visual Assert – The Unit Testing Add-In for Visual C++
cfix – C/C++ Unit Testing for Win32 and NT
 
 

CfixPeGetValue

CfixPeGetValue

Synopsis

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.

Declaration
PVOID CfixPeGetValue(
	__in ULONG Reserved
	);
				
Parameters

[in] Reserved: must be 0.

Return Value

The user-specified value. If no value has been specified yet, NULL is returned.

Remarks

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.

Usage example
//
// 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()
				
Requirements

Table 7.12. 

 User ModeKernel Mode
Available since1.21.2
HeaderDeclared in cfix.hDeclared in cfix.h
LibraryLink to cfix.libLink to cfixkdrv.lib
DLLcfix.dllN/A
IRQLN/ACallable at any IRQL