Lhaz
読み取り中…
検索中…
一致する文字列を見つけられません
関数 | 変数
Implementing a Custom Logger

関数

 WINUNIT_LOGGER_FUNCTION (void, Initialize)(const wchar_t *initializationString)
 < String for initializing this logger.
 
 WINUNIT_LOGGER_FUNCTION (void, OutputTestExecutableNamePreTest)(const wchar_t *fullPath
 
 WINUNIT_LOGGER_FUNCTION (void, OutputTestExecutableNamePostTest)(const wchar_t *fullPath
 
 WINUNIT_LOGGER_FUNCTION (void, OutputTestNamePreTest)(const char *testName)
 < Name of test about to be run.
 
 WINUNIT_LOGGER_FUNCTION (void, OutputTestNamePostTest)(const char *testName
 
 WINUNIT_LOGGER_FUNCTION (void, OutputTrace)(const wchar_t *message)
 < Informational message to be output.
 
 WINUNIT_LOGGER_FUNCTION (void, OutputTestError)(const wchar_t *message)
 < Message indicating details about failure.
 
 WINUNIT_LOGGER_FUNCTION (void, OutputProgramErrorLine)(const wchar_t *message)
 
 WINUNIT_LOGGER_FUNCTION (void, OutputFinalResults)(unsigned int succeeded
 
 WINUNIT_LOGGER_FUNCTION (void, SetVerbosity)(unsigned int verbosity)
 

変数

const wchar_t * nameOfExecutable
 < Full path to the executable whose tests are to be run.
 
const wchar_t unsigned int succeeded
 Number of tests succeeded.
 
const wchar_t unsigned int unsigned int totalRun
 < Number of tests run.
 
bool passed
 < Name of test that was just run.
 

詳解

To implement a custom logger, create a DLL that implements and exports one or more of the following functions. A very simple example would be a logger that writes out the results the end of a test run, to stdout if no failures, and to stderr if there were failures.

注釈
The functions must be exported by the exact names shown. This can be accomplished by using a .def file or by using the WINUNIT_LOGGER_FUNCTION macro to prepend 'extern "C" __declspec(dllexport)'.
Example:
(See GettingStarted for how to build MyTests.dll.)
// ResultsLogger.cpp
// Build with: cl [/I includePath] /LD ResultsLogger.cpp
// Run with: WinUnit -q -l ResultsLogger.dll MyTests.dll
#include "WinUnitLogger.h"
#include <stdio.h>
WINUNIT_LOGGER_FUNCTION(void, OutputFinalResults)(
unsigned int succeeded,
unsigned int totalRun)
{
{
fprintf(stderr, "There were %d failures out of %d tests run.¥n", totalRun - succeeded, totalRun);
}
else
{
printf("There were no failures out of %d tests run.¥n", totalRun);
}
}
#define WINUNIT_LOGGER_FUNCTION(returntype, func)
Definition WinUnitLogger.h:11
const wchar_t unsigned int unsigned int totalRun
< Number of tests run.
Definition WinUnitLogger.h:76
const wchar_t unsigned int succeeded
Number of tests succeeded.
Definition WinUnitLogger.h:74

関数詳解

◆ WINUNIT_LOGGER_FUNCTION() [1/10]

WINUNIT_LOGGER_FUNCTION ( void  ,
Initialize   
) const

< String for initializing this logger.

Initialize the logger with any required data.

注釈
The initialization string can be any string, and should be parsed appropriately in this function. It is the string passed in on the command line after the name of this DLL and a colon. Consider outputting usage information to stderr if an invalid string is passed in (or NULL).

◆ WINUNIT_LOGGER_FUNCTION() [2/10]

WINUNIT_LOGGER_FUNCTION ( void  ,
OutputFinalResults   
)

Output final results from all tests run.

注釈
This can be treated as an "Uninitialize" function. You can expect it will be the last function to be called, and cleanup can be done here.

◆ WINUNIT_LOGGER_FUNCTION() [3/10]

WINUNIT_LOGGER_FUNCTION ( void  ,
OutputProgramErrorLine   
) const

Output an error message that describes an unexpected occurrence in the program (e.g. file not found).

注釈
The line passed in will be a complete error message, but does not include a newline.

◆ WINUNIT_LOGGER_FUNCTION() [4/10]

WINUNIT_LOGGER_FUNCTION ( void  ,
OutputTestError   
) const

< Message indicating details about failure.

Output a message from a failed test.

注釈
This will occur after OutputTestNamePreTest has been called but before OutputTestNamePostTest, for the test in question. You can expect that the message will end with a period, but not a newline.

◆ WINUNIT_LOGGER_FUNCTION() [5/10]

WINUNIT_LOGGER_FUNCTION ( void  ,
OutputTestExecutableNamePostTest   
) const

Outputs the full path and just the name of the executable tests are being run from, after running the tests.

◆ WINUNIT_LOGGER_FUNCTION() [6/10]

WINUNIT_LOGGER_FUNCTION ( void  ,
OutputTestExecutableNamePreTest   
) const

Outputs the full path and just the name of the executable tests are being run from, before running the tests.

◆ WINUNIT_LOGGER_FUNCTION() [7/10]

WINUNIT_LOGGER_FUNCTION ( void  ,
OutputTestNamePostTest   
) const

Outputs the name of the test after it has been run, and whether or not it passed.

注釈
The only reason this would not be called after a test would be if an unrecoverable error had occurred during the test and the application was being shut down.

◆ WINUNIT_LOGGER_FUNCTION() [8/10]

WINUNIT_LOGGER_FUNCTION ( void  ,
OutputTestNamePreTest   
) const

< Name of test about to be run.

Outputs the name of the test about to be run.

注釈
You can expect that before each test is run, this function will be called, followed by any traces or errors that came from the test, followed by OutputTestNamePostTest.

◆ WINUNIT_LOGGER_FUNCTION() [9/10]

WINUNIT_LOGGER_FUNCTION ( void  ,
OutputTrace   
) const

< Informational message to be output.

Output a trace message. This comes from any OutputDebugString calls that have been made in the test executable.

注釈
Messages are expected to contain newlines where appropriate. Message may be a continuation of a previous message.

◆ WINUNIT_LOGGER_FUNCTION() [10/10]

WINUNIT_LOGGER_FUNCTION ( void  ,
SetVerbosity   
)

Set verbosity level.

注釈
This can be ignored or stored and used to decide how to handle output sent to the other (output) functions. This is set by the user on the command line. The default is 1.

変数詳解

◆ nameOfExecutable

const wchar_t * nameOfExecutable

< Full path to the executable whose tests are to be run.

< Full path to the executable whose tests were run.

< Name of executable.

Name of executable.

◆ passed

bool passed

< Name of test that was just run.

< True if test passed.

◆ succeeded

const wchar_t unsigned int succeeded

Number of tests succeeded.

◆ totalRun

unsigned int totalRun

< Number of tests run.

< Total number of tests that succeeded.

< Total number of tests that were run.