зеркало из https://github.com/mozilla/pjs.git
Adding TestUpload to windows. Also reordering tests to follow hex numbering.
This commit is contained in:
Родитель
5959e028cf
Коммит
448b866d61
|
@ -0,0 +1,203 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#ifdef WIN32
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#include "nsIEventQueueService.h"
|
||||
#include "nsIIOService.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsNetUtil.h"
|
||||
|
||||
#include "nsIFTPChannel.h"
|
||||
|
||||
static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID);
|
||||
static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
|
||||
|
||||
|
||||
static int gKeepRunning = 1;
|
||||
static nsIEventQueue* gEventQ = nsnull;
|
||||
|
||||
|
||||
nsresult NS_AutoregisterComponents()
|
||||
{
|
||||
nsresult rv = nsComponentManager::AutoRegister(nsIComponentManager::NS_Startup, NULL /* default */);
|
||||
return rv;
|
||||
}
|
||||
//-----------------------------------------------------------------------------
|
||||
// InputTestConsumer
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class InputTestConsumer : public nsIStreamListener
|
||||
{
|
||||
public:
|
||||
|
||||
InputTestConsumer();
|
||||
virtual ~InputTestConsumer();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIREQUESTOBSERVER
|
||||
NS_DECL_NSISTREAMLISTENER
|
||||
};
|
||||
|
||||
InputTestConsumer::InputTestConsumer()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
InputTestConsumer::~InputTestConsumer()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(InputTestConsumer,NS_GET_IID(nsIStreamListener));
|
||||
|
||||
NS_IMETHODIMP
|
||||
InputTestConsumer::OnStartRequest(nsIRequest *request, nsISupports* context)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
InputTestConsumer::OnDataAvailable(nsIRequest *request,
|
||||
nsISupports* context,
|
||||
nsIInputStream *aIStream,
|
||||
PRUint32 aSourceOffset,
|
||||
PRUint32 aLength)
|
||||
{
|
||||
char buf[1025];
|
||||
PRUint32 amt, size;
|
||||
nsresult rv;
|
||||
|
||||
while (aLength) {
|
||||
size = PR_MIN(aLength, sizeof(buf));
|
||||
rv = aIStream->Read(buf, size, &amt);
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_ASSERTION((NS_BASE_STREAM_WOULD_BLOCK != rv),
|
||||
"The stream should never block.");
|
||||
return rv;
|
||||
}
|
||||
aLength -= amt;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
InputTestConsumer::OnStopRequest(nsIRequest *request, nsISupports* context,
|
||||
nsresult aStatus)
|
||||
{
|
||||
gKeepRunning = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
main(int argc, char* argv[])
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
if (argc < 2) {
|
||||
printf("usage: %s <url> <file-to-upload>\n", argv[0]);
|
||||
return -1;
|
||||
}
|
||||
char* uriSpec = argv[1];
|
||||
char* fileName = argv[2];
|
||||
|
||||
|
||||
|
||||
rv = NS_AutoregisterComponents();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// Create the Event Queue for this thread...
|
||||
nsCOMPtr<nsIEventQueueService> eventQService =
|
||||
do_GetService(kEventQueueServiceCID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = eventQService->CreateThreadEventQueue();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
eventQService->GetThreadEventQueue(NS_CURRENT_THREAD, &gEventQ);
|
||||
|
||||
|
||||
|
||||
nsCOMPtr<nsIIOService> ioService(do_GetService(kIOServiceCID, &rv));
|
||||
// first thing to do is create ourselves a stream that
|
||||
// is to be uploaded.
|
||||
nsCOMPtr<nsIInputStream> uploadStream;
|
||||
rv = NS_NewPostDataStream(getter_AddRefs(uploadStream),
|
||||
PR_TRUE,
|
||||
fileName,
|
||||
0, ioService);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// create our url.
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
rv = NS_NewURI(getter_AddRefs(uri), uriSpec);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIChannel> channel;
|
||||
rv = ioService->NewChannelFromURI(uri, getter_AddRefs(channel));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// since we are testing now, we know it is a ftp url.
|
||||
// QI and set the upload stream
|
||||
nsCOMPtr<nsIFTPChannel> ftpChannel(do_QueryInterface(channel));
|
||||
ftpChannel->SetUploadStream(uploadStream);
|
||||
|
||||
// create a dummy listener
|
||||
InputTestConsumer* listener;
|
||||
|
||||
listener = new InputTestConsumer;
|
||||
NS_IF_ADDREF(listener);
|
||||
if (!listener) {
|
||||
NS_ERROR("Failed to create a new stream listener!");
|
||||
return -1;;
|
||||
}
|
||||
|
||||
channel->AsyncOpen(listener, nsnull);
|
||||
|
||||
while ( 1 ) {
|
||||
#ifdef WIN32
|
||||
MSG msg;
|
||||
|
||||
if (GetMessage(&msg, NULL, 0, 0)) {
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessage(&msg);
|
||||
} else {
|
||||
gKeepRunning = 0;
|
||||
}
|
||||
#else
|
||||
#ifdef XP_MAC
|
||||
/* Mac stuff is missing here! */
|
||||
#else
|
||||
PLEvent *gEvent;
|
||||
rv = gEventQ->WaitForEvent(&gEvent);
|
||||
rv = gEventQ->HandleEvent(gEvent);
|
||||
#endif /* XP_UNIX */
|
||||
#endif /* !WIN32 */
|
||||
}
|
||||
NS_ShutdownXPCOM(nsnull);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -31,14 +31,16 @@ PROG6 = .\$(OBJDIR)\urltest.exe
|
|||
PROG7 = .\$(OBJDIR)\TestFileInput2.exe
|
||||
PROG8 = .\$(OBJDIR)\TestFileTransport.exe
|
||||
PROG9 = .\$(OBJDIR)\TestRes.exe
|
||||
PROGA = .\$(OBJDIR)\TestUpload.exe
|
||||
PROGB = .\$(OBJDIR)\TestPageLoad.exe
|
||||
PROGC = .\$(OBJDIR)\TestWriteStream.exe
|
||||
PROGD = .\$(OBJDIR)\TestWriteSpeed.exe
|
||||
PROGE = .\$(OBJDIR)\TestCallbacks.exe
|
||||
PROGF = .\$(OBJDIR)\TestHttp.exe
|
||||
PROGG = .\$(OBJDIR)\TestPageLoad.exe
|
||||
|
||||
PROGRAMS = \
|
||||
$(PROG1) $(PROG2) $(PROG3) $(PROG4) $(PROG5) $(PROG6) $(PROG7) $(PROG8) $(PROG9)\
|
||||
$(PROGC) $(PROGD) $(PROGE) $(PROGF) $(PROGG)
|
||||
$(PROGA) $(PROGB) $(PROGC) $(PROGD) $(PROGE) $(PROGF) $(PROGG)
|
||||
|
||||
LCFLAGS=-DUSE_NSREG -GX
|
||||
|
||||
|
@ -78,6 +80,10 @@ $(PROG8): $(OBJDIR) TestFileTransport.cpp
|
|||
|
||||
$(PROG9): $(OBJDIR) TestRes.cpp
|
||||
|
||||
$(PROGA): $(OBJDIR) TestUpload.cpp
|
||||
|
||||
$(PROGB): $(OBJDIR) TestPageLoad.cpp
|
||||
|
||||
$(PROGC): $(OBJDIR) TestWriteStream.cpp
|
||||
|
||||
$(PROGD): $(OBJDIR) TestWriteSpeed.cpp
|
||||
|
@ -86,4 +92,8 @@ $(PROGE): $(OBJDIR) TestCallbacks.cpp
|
|||
|
||||
$(PROGF): $(OBJDIR) TestHttp.cpp
|
||||
|
||||
$(PROGG): $(OBJDIR) TestPageLoad.cpp
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче