Skip to content

Commit

Permalink
Merge pull request CxxTest#86 from kindkaktus/master
Browse files Browse the repository at this point in the history
Fixed compilation error on Windows (MSVC) in XmlFormatter.h
  • Loading branch information
whart222 committed Aug 8, 2013
2 parents 53bdc0b + 3590a77 commit c8788ba
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
6 changes: 3 additions & 3 deletions cxxtest/StdValueTraits.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class ValueTraits<const CXXTEST_STD(string)> : public StdTraitsBase
{
static bool mb_partial(char ch)
{
return ch & 0x80;
return !!(ch & 0x80);
}
static bool mb_start(char ch)
{
Expand All @@ -80,7 +80,7 @@ class ValueTraits<const CXXTEST_STD(string)> : public StdTraitsBase
{
return false;
}
for (unsigned len = mb_length(s[i]); len > 0; -- len, ++ i)
for (size_t len = mb_length(s[i]); len > 0; -- len, ++ i)
{
if (!mb_partial(s[i]))
{
Expand All @@ -98,7 +98,7 @@ class ValueTraits<const CXXTEST_STD(string)> : public StdTraitsBase
{
if (is_mb(s, i))
{
for (unsigned len = mb_length(s[i]); len > 0; -- len, ++ i)
for (size_t len = mb_length(s[i]); len > 0; -- len, ++ i)
{
char c[2] = { s[i], '\0' };
*this << c;
Expand Down
34 changes: 25 additions & 9 deletions cxxtest/XmlFormatter.h
Original file line number Diff line number Diff line change
Expand Up @@ -383,18 +383,11 @@ class XmlFormatter : public TestListener
void leaveWorld(const WorldDescription& desc)
{
std::ostringstream os;
const time_t current_date(time(0));
char current_date_string[27];
const size_t n = strlen(ctime_r(&current_date,current_date_string));
if (n) {
current_date_string[n-1] = '\0'; // remove the ending \n
} else {
current_date_string[0] = '\0'; // just in case...
}
const std::string currentDateTime = currentDateTimeStr();
os << totaltime;
(*_o) << "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" << endl;
(*_o) << "<testsuite name=\"" << desc.worldName() << "\" ";
(*_o) << "date=\"" << current_date_string;
(*_o) << "date=\"" << currentDateTime.c_str();
(*_o) << "\" tests=\"" << ntests
<< "\" errors=\"" << nerror
<< "\" failures=\"" << nfail
Expand Down Expand Up @@ -592,6 +585,29 @@ class XmlFormatter : public TestListener
return elt->value;
}

std::string currentDateTimeStr()
{
std::string retVal;
const time_t now(time(NULL));
char current_date_string[27];

#ifdef WIN32
if (ctime_s(current_date_string, sizeof(current_date_string)-1, &now) == 0)
{
retVal = current_date_string;
retVal.erase(retVal.find_last_not_of(" \n\r\t")+1); // trim trailing whitespace
}
#else
const size_t n = strlen(ctime_r(&now, current_date_string));
if (n)
{
current_date_string[n-1] = '\0'; // remove the ending \n
retVal = current_date_string;
}
#endif
return retVal;
}

#if 0
void attributeBinary(const char* name, const void *value, unsigned size)
{
Expand Down

0 comments on commit c8788ba

Please sign in to comment.