DTM Logger Example Using C++
The following C++ code example shows the basics of using the DTM Logger, including how to create and close a log device, how to start and end a test case, and how to log a trace message.
#include "WTTlogger.h"
#include <stdio.h>
int __cdecl main (int argc, char *argv[])
{
HRESULT hr = S_OK;
LONG hDevice = NULL;
CLogger Logger;
//
// Set the outputs
//
hr = Logger.CreateLogDevice(
NULL,
&hDevice
);
//
// Collect machine information
//
hr = Logger.TraceMachineInfo(
hDevice,
NULL
);
//
// Trace some message
//
hr = Logger.Trace(
WTT_LVL_MSG,
hDevice,
L"This is a message"
);
hr = Logger.Trace(
WTT_LVL_MSG,
hDevice,
L"This is a message with parameter %d %s",
1234,
L"string"
);
//
// Trace some message with user-defined XML
//
hr = Logger.TraceEx(
WTT_LVL_MSG,
WTT_PRI_MSG,
hDevice,
L"<MyXML>DTM Logger trace all unit test<MyXML>>",
L"This is a message with user XML"
);
hr = Logger.TraceEx(
WTT_LVL_MSG,
WTT_PRI_MSG,
hDevice,
L"<MyXML>DTM Logger trace all unit test<MyXML>",
L"This is a message with user XML and parameter %d %s",
1234,
L"string"
);
//
// Trace an error
//
hr = Logger.Trace(
WTT_LVL_ERR,
hDevice,
ERROR_FILE_NOT_FOUND,
WTT_ERROR_TYPE_WIN32,
__WFILE__,
__LINE__,
L"This is a Win32 error"
);
hr = Logger.Trace(
WTT_LVL_ERR,
hDevice,
FALSE,
WTT_ERROR_TYPE_BOOL,
__WFILE__,
__LINE__,
L"This is a boolean error"
);
hr = Logger.Trace(
WTT_LVL_ERR,
hDevice,
E_ACCESSDENIED,
WTT_ERROR_TYPE_HRESULT,
__WFILE__,
__LINE__,
L"This is a HRESULT error"
);
hr = Logger.Trace(
WTT_LVL_ERR,
hDevice,
STATUS_ACCESS_VIOLATION,
WTT_ERROR_TYPE_NTSTATUS,
__WFILE__,
__LINE__,
L"This is a NTSTATUS error"
);
//
// Trace an assert
//
hr = Logger.Trace(
WTT_LVL_ASSERT,
hDevice,
__WFILE__,
__LINE__,
L"This is an assert"
);
//
// Trace a warning
//
hr = Logger.Trace(
WTT_LVL_WARN,
hDevice,
__WFILE__,
__LINE__,
L"This is a warning"
);
//
// Trace a bug
//
hr = Logger.Trace(
WTT_LVL_BUG,
hDevice,
L"WTT",
12345,
WTT_BUG_TYPE_NONBLOCKING
);
hr = Logger.Trace(
WTT_LVL_BUG,
hDevice,
L"WTT",
12345,
WTT_BUG_TYPE_BLOCKING
);
//
// Trace a user-defined trace
//
DWORD dwBaseLevel = WTT_LVL_MSG;
DWORD dwPriority = WTT_TRACE_PRIORITY_MEDIUM_CLASS;
hr = Logger.UserDefinedTrace(
L"MPSTRACE3469856450648956845068459860549864586",
hDevice,
dwBaseLevel,
dwPriority,
L"Hello World...! %d", 1
);
//
// Start the test
//
hr = Logger.StartTestEx(
L"9b18233d-10c4-4491-ae70-1f89b00402a0",
L"StartTestEx and EndTestExDemo",
WTTLOG_TESTCASE_TYPE_NOPARENT,
NULL,
NULL,
hDevice
);
//
// Mark the end of the test
//
hr = Logger.EndTestEx(
WTT_TESTCASE_RESULT_PASS,
L"9b18233d-10c4-4491-ae70-1f89b00402a0",
L"StartTestEx and EndTestExDemo",
NULL,
NULL,
hDevice
);
//
// Trace out the test roll up information
//
hr = Logger.Trace(
WTT_LVL_ROLLUP,
NULL,
0,
0,
0,
0,
0
);
//
// Close all the outputs
//
hr = Logger.CloseLogDevice(
NULL,
hDevice
);
return 1;
} // main
See Also
Send feedback on this topic
Built on December 10, 2009