From f2a60e78bf43679df3e22b3c3e0f7647582a3a3d Mon Sep 17 00:00:00 2001 From: "gagan%netscape.com" Date: Wed, 2 Jun 1999 23:02:53 +0000 Subject: [PATCH] Test case changes git-svn-id: svn://10.0.0.236/trunk@33434 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/netwerk/test/Makefile.in | 1 + mozilla/netwerk/test/TestProtocols.cpp | 88 +++++++++++++++++++++++--- mozilla/netwerk/test/makefile.win | 1 + 3 files changed, 81 insertions(+), 9 deletions(-) diff --git a/mozilla/netwerk/test/Makefile.in b/mozilla/netwerk/test/Makefile.in index 5844bd1dba5..6f5b7d6744e 100644 --- a/mozilla/netwerk/test/Makefile.in +++ b/mozilla/netwerk/test/Makefile.in @@ -35,6 +35,7 @@ CPPSRCS = \ BASE_LIBS = \ -lreg \ -lxpcom \ + -lraptorbase \ -lnetwerk \ $(NULL) diff --git a/mozilla/netwerk/test/TestProtocols.cpp b/mozilla/netwerk/test/TestProtocols.cpp index a6538ced577..49e4216f9ea 100644 --- a/mozilla/netwerk/test/TestProtocols.cpp +++ b/mozilla/netwerk/test/TestProtocols.cpp @@ -41,6 +41,18 @@ #include "nsCRT.h" #include "nsIProtocolConnection.h" #include "nsIUrl.h" +#include "nsIHTTPConnection.h" +#include "nsIHTTPEventSink.h" + +#ifdef XP_PC +#define XPCOM_DLL "xpcom32.dll" +#else +#ifdef XP_MAC +#include "nsMacRepository.h" +#else +#define XPCOM_DLL "libxpcom.so" +#endif +#endif static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID); static NS_DEFINE_CID(kNetServiceCID, NS_NETSERVICE_CID); @@ -49,7 +61,7 @@ static PRTime gElapsedTime; static int gKeepRunning = 1; static nsIEventQueue* gEventQ = nsnull; -class InputTestConsumer : public nsIStreamListener +class InputTestConsumer : public nsIHTTPEventSink { public: @@ -59,6 +71,19 @@ public: // ISupports interface... NS_DECL_ISUPPORTS + // nsIHTTPEventSink interface... + NS_IMETHOD OnAwaitingInput(nsISupports* i_Context); + + NS_IMETHOD OnHeadersAvailable(nsISupports* i_Context); + + NS_IMETHOD OnProgress(nsISupports* i_Context, + PRUint32 i_Progress, + PRUint32 i_ProgressMax); + + // OnRedirect gets fired only if you have set FollowRedirects on the handler! + NS_IMETHOD OnRedirect(nsISupports* i_Context, + nsIUrl* i_NewLocation); + // IStreamListener interface... NS_IMETHOD OnStartBinding(nsISupports* context); @@ -83,8 +108,8 @@ InputTestConsumer::~InputTestConsumer() } -NS_DEFINE_IID(kIStreamListenerIID, NS_ISTREAMLISTENER_IID); -NS_IMPL_ISUPPORTS(InputTestConsumer,kIStreamListenerIID); +//NS_DEFINE_IID(kIStreamListenerIID, NS_ISTREAMLISTENER_IID); +NS_IMPL_ISUPPORTS(InputTestConsumer,nsIHTTPEventSink::GetIID()); NS_IMETHODIMP @@ -123,6 +148,43 @@ InputTestConsumer::OnStopBinding(nsISupports* context, return NS_OK; } +NS_IMETHODIMP +InputTestConsumer::OnAwaitingInput(nsISupports* context) +{ + printf("\n+++ InputTestConsumer::OnAwaitingInput +++\n"); + return NS_OK; +} + +NS_IMETHODIMP +InputTestConsumer::OnHeadersAvailable(nsISupports* context) +{ + printf("\n+++ InputTestConsumer::OnHeadersAvailable +++\n"); + nsCOMPtr pHTTPCon(do_QueryInterface(context)); + if (pHTTPCon) + { + const char* type; + //optimize later TODO allow atoms here...! intead of just the header strings + pHTTPCon->GetResponseHeader("Content-type", &type); + if (type) + printf("\nRecieving ... %s\n", type); + } + return NS_OK; +} + +NS_IMETHODIMP +InputTestConsumer::OnProgress(nsISupports* context, PRUint32 i_Progress, PRUint32 i_ProgressMax) +{ + printf("\n+++ InputTestConsumer::OnProgress +++\n"); + return NS_OK; +} + +NS_IMETHODIMP +InputTestConsumer::OnRedirect(nsISupports* context, nsIUrl* i_NewLocation) +{ + printf("\n+++ InputTestConsumer::OnRedirect +++\n"); + return NS_OK; +} + int main(int argc, char* argv[]) @@ -143,6 +205,7 @@ main(int argc, char* argv[]) "components"); if (NS_FAILED(rv)) return rv; + // Create the Event Queue for this thread... NS_WITH_SERVICE(nsIEventQueueService, eventQService, kEventQueueServiceCID, &rv); if (NS_FAILED(rv)) return rv; @@ -171,8 +234,8 @@ main(int argc, char* argv[]) if (pURL) { nsCOMPtr pConnection; - if (NS_OK == pService->NewConnection(pURL, nsnull, nsnull, - getter_AddRefs(pConnection))) +#if 0 // remove once the blocking io issues are worked out + if (NS_OK == pService->NewConnection(pURL, nsnull, nsnull, getter_AddRefs(pConnection))) { /* Flavour One! */ // Plain vanilla getting a file... in blocking mode @@ -195,8 +258,15 @@ main(int argc, char* argv[]) } } -#if 0 +#endif +//#if 0 /* Flavour Two */ + InputTestConsumer* pMyConsumer = new InputTestConsumer(); + if (!pMyConsumer) + { + NS_ERROR("Failed to create a new consumer!"); + return -1; + } // Async reading thru the calls of the event sink interface if (NS_OK == pService->NewConnection(pURL, pMyConsumer, nsnull, getter_AddRefs(pConnection))) @@ -208,12 +278,12 @@ main(int argc, char* argv[]) request object. This is done by QI for the specific protocolConnection. */ - nsCOMPtr pHTTPCon(pConnection); + nsCOMPtr pHTTPCon(do_QueryInterface(pConnection)); if (pHTTPCon) { // Setting a sample user agent string. - if (NS_OK == pHTTPCon->SetAgent("Mozilla/5.0 [en] (Win98; U)")) + if (NS_OK == pHTTPCon->SetRequestHeader("User-Agent", "Mozilla/5.0 [en] (Win98; U)")) { } } @@ -222,7 +292,7 @@ main(int argc, char* argv[]) pConnection->Open(); } } -#endif +//#endif } } diff --git a/mozilla/netwerk/test/makefile.win b/mozilla/netwerk/test/makefile.win index 5009623e798..5a0fec95ace 100644 --- a/mozilla/netwerk/test/makefile.win +++ b/mozilla/netwerk/test/makefile.win @@ -35,6 +35,7 @@ LINCS = \ -I$(PUBLIC)\xpcom \ -I$(PUBLIC)\raptor \ -I$(PUBLIC)\netwerk \ + -I$(PUBLIC)\plughttp \ $(NULL) LLIBS= \