Commit 1f60d564 authored by Peio Rigaux's avatar Peio Rigaux

fixed the bug preventing assert message to be present in 'message' attribute...

fixed the bug preventing assert message to be present in 'message' attribute of a 'testcase' in xml report
parent 0ee569b9
...@@ -83,6 +83,16 @@ CU_EXPORT size_t CU_translate_special_characters(const char *szSrc, char *szDest ...@@ -83,6 +83,16 @@ CU_EXPORT size_t CU_translate_special_characters(const char *szSrc, char *szDest
* szDest did not have enough room to hold converted string). * szDest did not have enough room to hold converted string).
*/ */
/*=================================================================
* Time management, prevents to add a dependency towards bctoolbox
*=================================================================*/
CU_EXPORT double CU_get_wall_time(void);
/**<
* Gets the actual time. It is used to compute tests elapsed time
* @returns The actual time as a double, in format seconds.milliseconds
*/
CU_EXPORT size_t CU_translated_strlen(const char *szSrc); CU_EXPORT size_t CU_translated_strlen(const char *szSrc);
/**< /**<
* Calculates the length of a translated string. * Calculates the length of a translated string.
......
...@@ -83,7 +83,10 @@ static CU_BOOL bPartialSuiteJUnitReport = CU_FALSE; /** Flag for toggling engl ...@@ -83,7 +83,10 @@ static CU_BOOL bPartialSuiteJUnitReport = CU_FALSE; /** Flag for toggling engl
static char _gPackageName[50] = ""; static char _gPackageName[50] = "";
static time_t f_testStartTime = 0; /**< Start time of current running test suite. */ //static time_t f_testStartTime = 0; /**< Start time of current running test suite. */
double startTime = 0.0;
double endTime = 0.0;
/*================================================================= /*=================================================================
* Static function forward declarations * Static function forward declarations
...@@ -268,7 +271,12 @@ static void automated_test_start_message_handler(const CU_pTest pTest, const CU_ ...@@ -268,7 +271,12 @@ static void automated_test_start_message_handler(const CU_pTest pTest, const CU_
char *szTempName = NULL; char *szTempName = NULL;
size_t szTempName_len = 0; size_t szTempName_len = 0;
f_testStartTime = time(NULL); //Gathering information about current time for the suite start time
time_t suiteStartTime = time(NULL);
struct tm tm = *localtime(&suiteStartTime);
//Getting the start time of the test to compute test duration
startTime = CU_get_wall_time();
if( test_start_handler ){ if( test_start_handler ){
(*test_start_handler)(pTest, pSuite); (*test_start_handler)(pTest, pSuite);
...@@ -301,11 +309,18 @@ static void automated_test_start_message_handler(const CU_pTest pTest, const CU_ ...@@ -301,11 +309,18 @@ static void automated_test_start_message_handler(const CU_pTest pTest, const CU_
if (bJUnitXmlOutput == CU_TRUE) { if (bJUnitXmlOutput == CU_TRUE) {
fprintf(f_pTestResultFile, fprintf(f_pTestResultFile,
" <testsuite name=\"%s\" tests=\"%u\" time=\"0\" failures=\"%u\" errors=\"%u\" skipped=\"0\"> \n", " <testsuite name=\"%s\" tests=\"%u\" time=\"0\" failures=\"%u\" errors=\"%u\" skipped=\"0\" timestamp=\"%d-%02d-%02dT%02d:%02d:%02d\"> \n",
(NULL != szTempName) ? szTempName : "", /* Name */ (NULL != szTempName) ? szTempName : "", /* Name */
pSuite->uiNumberOfTests, /* Tests */ pSuite->uiNumberOfTests, /* Tests */
pSuite->uiNumberOfTestsFailed, /* Tests failure */ pSuite->uiNumberOfTestsFailed, /* Tests failure */
0); /* Errors */ 0,
tm.tm_year + 1900,
tm.tm_mon + 1,
tm.tm_mday,
tm.tm_hour,
tm.tm_min,
tm.tm_sec
); /* Errors */
} else { } else {
fprintf(f_pTestResultFile, fprintf(f_pTestResultFile,
" <BCUNIT_RUN_SUITE> \n" " <BCUNIT_RUN_SUITE> \n"
...@@ -339,6 +354,9 @@ static void automated_test_complete_message_handler(const CU_pTest pTest, ...@@ -339,6 +354,9 @@ static void automated_test_complete_message_handler(const CU_pTest pTest,
CU_pFailureRecord pTempFailure = pFailure; CU_pFailureRecord pTempFailure = pFailure;
const char *pPackageName = CU_automated_package_name_get(); const char *pPackageName = CU_automated_package_name_get();
//Getting the end time of the test to compute test duration
endTime = CU_get_wall_time();
if( test_complete_handler ){ if( test_complete_handler ){
(*test_complete_handler)(pTest, pSuite, pFailure); (*test_complete_handler)(pTest, pSuite, pFailure);
} }
...@@ -359,19 +377,30 @@ static void automated_test_complete_message_handler(const CU_pTest pTest, ...@@ -359,19 +377,30 @@ static void automated_test_complete_message_handler(const CU_pTest pTest,
assert((NULL != pTempFailure->pTest) && (pTempFailure->pTest == pTest)); assert((NULL != pTempFailure->pTest) && (pTempFailure->pTest == pTest));
if (NULL != pTempFailure->strCondition) { if (NULL != pTempFailure->strCondition) {
szTemp = (char *)CU_MALLOC(CU_translated_strlen(pTempFailure->strCondition)); szTemp_len = CU_translated_strlen(pTempFailure->strCondition) + 1;
CU_translate_special_characters(pTempFailure->strCondition, szTemp, sizeof(szTemp)); szTemp = (char *)CU_MALLOC(szTemp_len);
size_t test = CU_translate_special_characters(pTempFailure->strCondition, szTemp, szTemp_len);
} }
else { else {
//!!!!!!
szTemp[0] = '\0'; szTemp[0] = '\0';
} }
fprintf(f_pTestResultFile, " <testcase classname=\"%s.%s\" name=\"%s\" time=\"%ld\">\n", fprintf(f_pTestResultFile, " <testcase classname=\"%s.%s\" name=\"%s\" time=\"%f\">\n",
pPackageName, pPackageName,
pSuite->pName, pSuite->pName,
(NULL != pTest->pName) ? pTest->pName : "", (NULL != pTest->pName) ? pTest->pName : "",
(long)(time(NULL) - f_testStartTime)); endTime - startTime
);
if(NULL != pTempFailure->pNext) {
fprintf(f_pTestResultFile, " <failure message=\"Multiple asserts failed ...\" type=\"Failure\">\n");
}
else {
fprintf(f_pTestResultFile, " <failure message=\"%s\" type=\"Failure\">\n", szTemp); fprintf(f_pTestResultFile, " <failure message=\"%s\" type=\"Failure\">\n", szTemp);
}
} /* if */ } /* if */
} }
...@@ -432,11 +461,12 @@ static void automated_test_complete_message_handler(const CU_pTest pTest, ...@@ -432,11 +461,12 @@ static void automated_test_complete_message_handler(const CU_pTest pTest,
} }
else { else {
if (bJUnitXmlOutput == CU_TRUE) { if (bJUnitXmlOutput == CU_TRUE) {
fprintf(f_pTestResultFile, " <testcase classname=\"%s.%s\" name=\"%s\" time=\"%ld\"/>\n", fprintf(f_pTestResultFile, " <testcase classname=\"%s.%s\" name=\"%s\" time=\"%f\"/>\n",
pPackageName, pPackageName,
pSuite->pName, pSuite->pName,
(NULL != pTest->pName) ? pTest->pName : "", (NULL != pTest->pName) ? pTest->pName : "",
(long)(time(NULL) - f_testStartTime)); endTime - startTime
);
} else { } else {
fprintf(f_pTestResultFile, fprintf(f_pTestResultFile,
" <BCUNIT_RUN_TEST_RECORD> \n" " <BCUNIT_RUN_TEST_RECORD> \n"
......
...@@ -59,7 +59,6 @@ extern bcunit_trace_handler_t CU_trace_handler; ...@@ -59,7 +59,6 @@ extern bcunit_trace_handler_t CU_trace_handler;
#include <stdarg.h> #include <stdarg.h>
#include <winsock2.h> #include <winsock2.h>
void OutputDebugStringPrintf(FILE *file, const char *fmt, ...) { void OutputDebugStringPrintf(FILE *file, const char *fmt, ...) {
va_list args; va_list args;
...@@ -123,6 +122,40 @@ void otherPrintf(FILE *file, const char *fmt, ...){ ...@@ -123,6 +122,40 @@ void otherPrintf(FILE *file, const char *fmt, ...){
#endif #endif
/*=================================================================
* Time management, prevents to add a dependency towards bctoolbox
*=================================================================*/
// Windows
#ifdef _WIN32
#include <Windows.h>
double CU_get_wall_time(void){
LARGE_INTEGER time,freq;
if (!QueryPerformanceFrequency(&freq)) {
// Handle error
return 0;
}
else if (!QueryPerformanceCounter(&time)) {
// Handle error
return 0;
}
else {
return (double)time.QuadPart / freq.QuadPart;
}
}
#else
//#include <time.h>
#include <sys/time.h>
double CU_get_wall_time(void) {
struct timeval time;
if (gettimeofday(&time,NULL)) {
// Handle error
return 0;
}
//tv_usec is divided by a million to get as a double [seconds].[milliseconds]
return (double)time.tv_sec + (double)time.tv_usec * .000001;
}
#endif
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment