From e74c1e869fa95097624a4fd58f0c70b709d90a39 Mon Sep 17 00:00:00 2001 From: Sergey Gaychuk Date: Fri, 12 Nov 2010 17:50:43 +0200 Subject: [PATCH] xpunit: fix sync bug in OneLineDiff --- abstract/xpunit/nsICompareListener.idl | 1 + transport/base/aaTransportUtils.h | 5 +++-- xpunit/nsOneLineDiff.cpp | 21 ++++++++++++++------- xpunit/nsTestRunner.cpp | 26 +++++++++++++++++++++++++- 4 files changed, 43 insertions(+), 10 deletions(-) diff --git a/abstract/xpunit/nsICompareListener.idl b/abstract/xpunit/nsICompareListener.idl index b901e79..9eaf74e 100644 --- a/abstract/xpunit/nsICompareListener.idl +++ b/abstract/xpunit/nsICompareListener.idl @@ -30,6 +30,7 @@ interface nsICompareListener : nsISupports { void onError(in ACString aText, in unsigned long aLine); + void onMismatch(in ACString aText, in unsigned long aLine); void onSuccess(); }; diff --git a/transport/base/aaTransportUtils.h b/transport/base/aaTransportUtils.h index bae5ff3..9be036a 100644 --- a/transport/base/aaTransportUtils.h +++ b/transport/base/aaTransportUtils.h @@ -30,7 +30,8 @@ inline nsresult AA_CreatePipe(nsIInputStream **pipeIn, - nsIOutputStream **pipeOut) + nsIOutputStream **pipeOut, + PRBool nonBlockingIn = PR_TRUE) { nsresult rv; @@ -40,7 +41,7 @@ AA_CreatePipe(nsIInputStream **pipeIn, = do_CreateInstance("@mozilla.org/pipe;1", &rv); NS_ENSURE_SUCCESS(rv, rv); - rv = pipe->Init(PR_FALSE, PR_FALSE, 0, 0, nsnull); + rv = pipe->Init(nonBlockingIn, PR_FALSE, 0, 0, nsnull); NS_ENSURE_SUCCESS(rv, rv); rv = pipe->GetInputStream(getter_AddRefs(in)); diff --git a/xpunit/nsOneLineDiff.cpp b/xpunit/nsOneLineDiff.cpp index 98e3ff5..ede66bc 100644 --- a/xpunit/nsOneLineDiff.cpp +++ b/xpunit/nsOneLineDiff.cpp @@ -69,10 +69,19 @@ nsOneLineDiff::OnDataAvailable(nsIRequest *aRequest, nsISupports *aContext, nsCAutoString ref; PRBool hasMore = PR_FALSE; do { + rv = NS_ReadLine(aInputStream, mBuffer, data, &hasMore); + if (NS_FAILED(rv)) + hasMore = PR_FALSE; + + if (!data.Length()) + return NS_OK; + if (!mRefHasMore) { mIsErrorCalled = PR_TRUE; - mListener->OnError(NS_LITERAL_CSTRING(""), mLine); + nsCAutoString error("text after EOF:"); + error.Append(ref); + mListener->OnError(error, mLine); return NS_ERROR_FAILURE; } @@ -81,13 +90,10 @@ nsOneLineDiff::OnDataAvailable(nsIRequest *aRequest, nsISupports *aContext, ++mLine; - rv = NS_ReadLine(aInputStream, mBuffer, data, &hasMore); - NS_ENSURE_SUCCESS(rv, rv); - if (!ref.Equals(data)) { mIsErrorCalled = PR_TRUE; - mListener->OnError(data, mLine); + mListener->OnMismatch(data, mLine); return NS_ERROR_FAILURE; } } while(hasMore); @@ -109,9 +115,10 @@ nsOneLineDiff::OnStopRequest(nsIRequest *aRequest, nsISupports *aContext, mBuffer = nsnull; mReference = nsnull; - if (mRefHasMore) + if (!mIsErrorCalled && mRefHasMore) { - rv = mListener->OnError(NS_LITERAL_CSTRING(""), mLine); + rv = mListener->OnError(NS_LITERAL_CSTRING("unexpected end of file"), + mLine++); NS_ENSURE_SUCCESS(rv, rv); mIsErrorCalled = PR_TRUE; } diff --git a/xpunit/nsTestRunner.cpp b/xpunit/nsTestRunner.cpp index 765c95e..09fea35 100644 --- a/xpunit/nsTestRunner.cpp +++ b/xpunit/nsTestRunner.cpp @@ -733,7 +733,7 @@ nsTestRunner::OnSecurityChange(nsIWebProgress *aWebProgress, } NS_IMETHODIMP -nsTestRunner::OnError(const nsACString& aText, PRUint32 aLine) +nsTestRunner::OnMismatch(const nsACString& aText, PRUint32 aLine) { nsresult rv = NS_OK; nsCOMPtr reference = mCompareURI; @@ -759,6 +759,30 @@ nsTestRunner::OnError(const nsACString& aText, PRUint32 aLine) } NS_IMETHODIMP +nsTestRunner::OnError(const nsACString& aText, PRUint32 aLine) +{ + nsresult rv = NS_OK; + nsCOMPtr reference = mCompareURI; + + mCompareURI = nsnull; + + nsCAutoString spec; + rv = reference->GetSpec(spec); + NS_ENSURE_SUCCESS(rv, rv); + + nsCAutoString message; + message.Append(aText); + rv = AddFailure(spec.get(), aLine, message.get()); + NS_ENSURE_SUCCESS(rv, rv); + rv = AddFailure(mCompareFile, mCompareLine, "included from here"); + NS_ENSURE_SUCCESS(rv, rv); + mCompareFile = nsnull; + mCompareLine = 0; + + return NS_OK; +} + +NS_IMETHODIMP nsTestRunner::OnSuccess() { mCompareURI = nsnull; -- 2.11.4.GIT