DTM Logger Example Using C
Note This content applies to the Windows Logo Kit (WLK). For the latest information using the new Windows Hardware Certification Kit (HCK), see Windows HCK User's Guide on the Windows Hardware Dev Center.
The following C language code example logs several different trace levels.
void __cdecl main (int argc, char *argv[])
{
HRESULT hr = S_OK;
LONG hDevice = 0;
hr = WTTLogCreateLogDevice(
L"$LocalPub($LogFile:file=\"foo.xml\",writemode=overwrite;$Console)",
&hDevice
);
hr = WTTLogTrace(
hDevice,
WTT_LVL_FUNCTION_ENTRY,
__WFILE__,
L"main"
);
hr = WTTLogTrace(
hDevice,
WTT_LVL_MACHINEINFO,
NULL, // OS
L"Windows XP", // platform
L"5.1", // version (upgrade path)
L"Main", // VBL
L"3615.00", // build number
L"20050229", // build date
L"EN-US", // language
NULL // config
);
hr = WTTLogTrace(
hDevice,
WTT_LVL_TCMINFO,
-1, // Test case ID
L"$\\\\DTM Logger\\COM Test", // node path
NULL, // Test case title -- set later
NULL, // Hash key
NULL, // Created by
NULL, // Modified by
NULL, // Assigned to
NULL, // Test type
NULL, // Result type
NULL, // Milestone
NULL, // Priority
NULL, // Test time
NULL, // Comments
NULL, // Method
NULL, // Frequency
NULL, // Description
NULL, // Scripts
NULL, // Log file path
NULL, // Suite
NULL, // Area
NULL, // Component
NULL, // Sub component
NULL, // Dev
NULL, // Test lead
FALSE, // Create only
TRUE, // Log only
FALSE // Recursive
);
hr = WTTLogStartTest(
hDevice,
L"DTM Logger Test"
);
hr = WTTLogTrace(
hDevice,
WTT_LVL_MSG,
L"This is a unit test."
);
hr = WTTLogAddErrorToErrorList(
S_OK,
WTT_ERROR_TYPE_HRESULT,
WTT_ERROR_LIST_EXPECTED
);
hr = WTTLogCheckResult(
hDevice,
S_OK,
WTT_ERROR_TYPE_HRESULT,
__WFILE__,
__LINE__,
L"This should pass, and does not log"
);
hr = WTTLogRemoveErrorFromErrorList(
S_OK,
WTT_ERROR_TYPE_HRESULT,
WTT_ERROR_LIST_EXPECTED
);
hr = WTTLogCheckResult(
hDevice,
S_OK,
WTT_ERROR_TYPE_HRESULT,
__WFILE__,
__LINE__,
L"This should fail, and it should log"
);
hr = WTTLogTrace(
hDevice,
WTT_LVL_ERR,
E_POINTER,
WTT_ERROR_TYPE_HRESULT,
__WFILE__,
__LINE__,
L"This is an error"
);
hr = WTTLogTrace(
hDevice,
WTT_LVL_INVALID_PARAM,
__WFILE__,
__LINE__
);
hr = WTTLogTrace(
hDevice,
WTT_LVL_BUG,
L"BugDB",
890403
);
hr = WTTLogTrace(
hDevice,
WTT_LVL_BREAK,
E_POINTER,
WTT_ERROR_TYPE_HRESULT,
__WFILE__,
__LINE__,
L"This is a break"
);
hr = WTTLogTrace(
hDevice,
WTT_LVL_WARN,
__WFILE__,
__LINE__,
L"This is a warning message"
);
hr = WTTLogUserDefinedTrace(
hDevice,
L"MyLvl",
WTT_LVL_MSG,
100000,
L"%s",
L"This is a user defined trace."
);
hr = WTTLogAssert(
hDevice,
FALSE,
__WFILE__,
__LINE__,
L"This is an assert"
);
hr = WTTLogEndTest(
hDevice,
L"DTM Logger COM Test",
WTT_TESTCASE_RESULT_PASS,
L"This is the repro line"
);
hr = WTTLogTrace(
hDevice,
WTT_LVL_FUNCTION_EXIT,
__WFILE__,
L"main"
);
hr = WTTLogPFRollup(
hDevice,
0,
0,
0,
0,
0
);
hr = WTTLogCloseLogDevice(
hDevice,
NULL
);
// Mandatory call to destroy the global Logger
WTTLogUninit();
return;
}
See Also
Build date: 9/14/2012