mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-25 22:01:30 +00:00
Beefed up buffer/pipe tests.
This commit is contained in:
parent
0117937f12
commit
b686fa2108
@ -18,6 +18,7 @@
|
||||
|
||||
#include "nsIBuffer.h"
|
||||
#include "nsIThread.h"
|
||||
#include "nsIBaseStream.h"
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsAutoLock.h"
|
||||
@ -28,6 +29,8 @@
|
||||
#include "prinrval.h"
|
||||
#include <stdio.h>
|
||||
|
||||
PRBool gVerbose = PR_FALSE;
|
||||
|
||||
class Reader : public nsIRunnable {
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
@ -56,12 +59,15 @@ public:
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
else {
|
||||
// buf[readCnt] = 0;
|
||||
// printf(buf);
|
||||
if (gVerbose) {
|
||||
buf[readCnt] = 0;
|
||||
printf(buf);
|
||||
}
|
||||
mBytesRead += readCnt;
|
||||
}
|
||||
}
|
||||
// printf("reader done\n");
|
||||
if (gVerbose)
|
||||
printf("reader done\n");
|
||||
return rv;
|
||||
}
|
||||
|
||||
@ -73,7 +79,8 @@ public:
|
||||
|
||||
virtual ~Reader() {
|
||||
NS_RELEASE(mReadBuffer);
|
||||
printf("bytes read = %d\n", mBytesRead);
|
||||
if (gVerbose)
|
||||
printf("bytes read = %d\n", mBytesRead);
|
||||
}
|
||||
|
||||
void SetEOF() {
|
||||
@ -251,15 +258,109 @@ TestSearch(const char* delim, PRUint32 segDataSize)
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
NS_METHOD
|
||||
FailingReader(void* closure,
|
||||
char* toRawSegment,
|
||||
PRUint32 fromOffset,
|
||||
PRUint32 count,
|
||||
PRUint32 *readCount)
|
||||
{
|
||||
nsresult* rv = (nsresult*)closure;
|
||||
*readCount = 0;
|
||||
return *rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
TestWriteSegments(nsresult error)
|
||||
{
|
||||
nsresult rv;
|
||||
nsIBuffer* buffer;
|
||||
printf("WriteSegments Test: error %x\n", error);
|
||||
rv = NS_NewBuffer(&buffer, 10, 10, nsnull);
|
||||
if (NS_FAILED(rv)) {
|
||||
printf("failed to create buffer\n");
|
||||
return rv;
|
||||
}
|
||||
|
||||
PRUint32 writeCount;
|
||||
rv = buffer->WriteSegments(FailingReader, &error, 1, &writeCount);
|
||||
NS_ASSERTION(rv == error, "WriteSegments failed");
|
||||
|
||||
NS_RELEASE(buffer);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
NS_METHOD
|
||||
FailingWriter(void* closure,
|
||||
const char* fromRawSegment,
|
||||
PRUint32 toOffset,
|
||||
PRUint32 count,
|
||||
PRUint32 *writeCount)
|
||||
{
|
||||
nsresult* rv = (nsresult*)closure;
|
||||
*writeCount = 0;
|
||||
return *rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
TestReadSegments(nsresult error)
|
||||
{
|
||||
nsresult rv;
|
||||
nsIBuffer* buffer;
|
||||
printf("ReadSegments Test: error %x\n", error);
|
||||
rv = NS_NewBuffer(&buffer, 10, 10, nsnull);
|
||||
if (NS_FAILED(rv)) {
|
||||
printf("failed to create buffer\n");
|
||||
return rv;
|
||||
}
|
||||
|
||||
PRUint32 writeCount;
|
||||
rv = buffer->Write("x", 1, &writeCount);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv) && writeCount == 1, "Write failed");
|
||||
|
||||
PRUint32 readCount;
|
||||
rv = buffer->ReadSegments(FailingWriter, &error, 1, &readCount);
|
||||
NS_ASSERTION(rv == error, "ReadSegments failed");
|
||||
|
||||
NS_RELEASE(buffer);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int
|
||||
main()
|
||||
main(int argc, char* argv[])
|
||||
{
|
||||
nsresult rv;
|
||||
nsIServiceManager* servMgr;
|
||||
|
||||
if (argc >= 2 && nsCRT::strcmp(argv[1], "-verbose") == 0) {
|
||||
gVerbose = PR_TRUE;
|
||||
}
|
||||
|
||||
rv = NS_InitXPCOM(&servMgr);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = TestWriteSegments(NS_OK);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "TestWriteSegments failed");
|
||||
rv = TestWriteSegments(NS_ERROR_FAILURE);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "TestWriteSegments failed");
|
||||
rv = TestWriteSegments(NS_BASE_STREAM_EOF);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "TestWriteSegments failed");
|
||||
rv = TestWriteSegments(NS_BASE_STREAM_WOULD_BLOCK);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "TestWriteSegments failed");
|
||||
|
||||
rv = TestReadSegments(NS_OK);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "TestReadSegments failed");
|
||||
rv = TestReadSegments(NS_ERROR_FAILURE);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "TestReadSegments failed");
|
||||
// rv = TestReadSegments(NS_BASE_STREAM_EOF);
|
||||
// NS_ASSERTION(NS_SUCCEEDED(rv), "TestReadSegments failed");
|
||||
rv = TestReadSegments(NS_BASE_STREAM_WOULD_BLOCK);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "TestReadSegments failed");
|
||||
|
||||
rv = TestMallocBuffers(1, 1);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "TestMallocBuffers failed");
|
||||
|
||||
|
@ -164,7 +164,7 @@ main(int argc, char* argv[])
|
||||
}
|
||||
#endif
|
||||
// test for small buffers
|
||||
rv = NS_NewPipe(&in, &out, 12, 24, PR_TRUE, nsnull);
|
||||
rv = NS_NewPipe(&in, &out, 4096, 4096*16, PR_TRUE, nsnull);
|
||||
if (NS_FAILED(rv)) {
|
||||
printf("NewPipe failed\n");
|
||||
return -1;
|
||||
|
@ -91,7 +91,7 @@ include <$(DEPTH)\config\rules.mak>
|
||||
install:: $(PROGRAMS)
|
||||
-for %p in ($(PROGRAMS)) do $(MAKE_INSTALL) %p $(DIST)\bin
|
||||
|
||||
xoclobber::
|
||||
clobber::
|
||||
-for %p in ($(PROGRAMS)) do $(RM) %p $(DIST)\bin\%p
|
||||
|
||||
$(PROG1): $(OBJDIR) TestFactory.cpp
|
||||
|
Loading…
Reference in New Issue
Block a user