|
Boost : |
From: Paul A. Bristow (boost_at_[hidden])
Date: 2002-07-26 05:10:39
I have been using Gennadiy Rozental's new and improved Boost Test Tools and
Unit Test Library
to improve my testing.
One feature I believe important is date and time stamping.
But I am unsure what to suggest to him that is portable and Boost approved.
MSVC provides some MACROs which can be used, if available.
Please can you advise which are widely available on other systems.
(The format output is C locale, as is the code below.)
// Date and time information.
#if defined(__FILE__) && defined(__TIMESTAMP__)
// ANSI-Compliant Predefined Macros:
// __DATE__ The compilation date of the current source file.
// The date is a string literal of the form Mmm dd yyyy.
// The month name Mmm is the same as for dates generated by the library
function asctime declared in TIME.H.
// __FILE__ The name of the current source file.
// __FILE__ expands to a string surrounded by double quotation marks.
// __LINE__ The line number in the current source file.
// The line number is a decimal integer constant.
// __TIME__ The most recent compilation time of the current source file.
// The time is a string literal of the form hh:mm:ss.
// __TIMESTAMP__ The date and time of the last modification of the current
source file,
// expressed as a string literal in the form Ddd Mmm Date hh:mm:ss yyyy,
// where Ddd is the abbreviated day of the week and Date is an integer from
1 to 31.
// Available on MSVC but not others?
cout << __FILE__ << space << __TIMESTAMP__ << nl;
#endif
Is this is best code to use?
#include <ctime>
time_t aclock;
time( &aclock ); // Get time in seconds.
cout << "The current date and time are " << asctime(localtime( &aclock ) )
<< endl;
// Outputs "The current date and time are Fri Jul 26 10:32:40 2002"
to log the time & date of the actual test before the tests, for example:
// Examples of using BOOST test tools.
BOOST_MESSAGE("Test BOOST_MESSAGE");
Other suggestions? Views? Thanks.
Paul
Paul A Bristow, Prizet Farmhouse, Kendal, Cumbria, LA8 8AB UK
+44 1539 561830 Mobile +44 7714 33 02 04
Mobile mailto:pabristow_at_[hidden]
mailto:pbristow_at_[hidden]
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk