1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set ts=2 sw=2 sts=2 et cindent tw=79 ft=cpp: */
4 * Copyright (C) 2010 Sergey Yanovich <ynvich@gmail.com>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public
17 * License along with this program; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
22 #include "xpcom-config.h"
27 /* Unfrozen interfaces */
29 #include "nsIConsoleService.h"
30 #include "nsIConsoleMessage.h"
31 #include "nsServiceManagerUtils.h"
33 /* Project includes */
34 #include "nsTestResult.h"
35 #include "nsTestFailure.h"
37 /******************** nsTestResult ************************************/
38 nsTestResult::nsTestResult()
40 , mLock("nsTestResult Lock")
45 mStartTime
= PR_IntervalNow();
49 nsTestResult::~nsTestResult()
51 nsTestFailure
*failure
;
53 while ( mFailureList
.GetSize() ) {
54 if ( (failure
= (nsTestFailure
*) mFailureList
.PopFront()) ) {
60 NS_IMPL_ISUPPORTS1(nsTestResult
,
64 nsTestResult::MarkTestStart()
66 mozilla::MutexAutoLock
lock(mLock
);
77 nsTestResult::AddFailure(const char *aFile
, PRUint32 aLine
, const char *aText
,
80 mozilla::MutexAutoLock
lock(mLock
);
81 nsTestFailure
*failure
= new nsTestFailure(aFile
, aLine
, aText
, aError
);
82 NS_ENSURE_TRUE(failure
, NS_ERROR_OUT_OF_MEMORY
);
83 mFailureList
.Push( (void *) failure
);
112 nsTestResult::printFailures()
114 nsTestFailure
*failure
;
115 const static char *kFailureMessage
= "test failed";
116 const static char *kFailureHeader
= " failure:";
117 const static char *kErrorMessages
[] = {
118 "cxxunit: message: %s\n"
119 ,"cxxunit: error: component \"%s\" failed to load\n"
121 ,"cxxunit: error: failed to open main window\n"
122 ,"cxxunit: error: component \"%s\" failed to complete async test\n"
126 while ( mFailureList
.GetSize() ) {
127 if ( ! (failure
= (nsTestFailure
*) mFailureList
.PopFront()) )
129 if ( failure
->getFile()[0] ){
130 const char *msg
= kFailureMessage
;
131 if ( failure
->getText()[0] ) {
132 msg
= failure
->getText();
134 printf_stderr("%s:%u:%s %s\n", failure
->getFile(), failure
->getLine(),
135 failure
->isError() ? "" : kFailureHeader
, msg
);
137 printf_stderr( kErrorMessages
[ failure
->getLine() ],
138 failure
->getText() );
145 nsTestResult::printTime()
147 PRInt32 runTime
, msec
, sec
;
149 runTime
= PR_IntervalToMilliseconds(PR_IntervalNow() - mStartTime
);
150 sec
= runTime
/ 1000;
151 msec
= runTime
% 1000;
152 printf_stderr("Time: %u.%03u\n\n", sec
, msec
);
156 nsTestResult::printHeadline()
158 if (!mFailureCount
&& !mErrorCount
) {
159 printf_stderr("OK (%u tests)\n", mCount
);
162 printf_stderr("Failures!!!\n Test run: %u Failures: %u Errors: %u\n",
163 mCount
, mFailureCount
, mErrorCount
);