Bug 1330857 - remove unused files in netwerk/test. r=mcmanus

MozReview-Commit-ID: 2cuuTblXXZh

--HG--
extra : rebase_source : 993427f73998d4e08e1ca0e44efd9c6328fe87c3
This commit is contained in:
Shih-Chiang Chien 2017-01-13 11:37:15 +08:00
Родитель c7e5802273
Коммит 22af8c1003
19 изменённых файлов: 0 добавлений и 3536 удалений

Просмотреть файл

@ -1,23 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef NetwerkTestLogging_h
#define NetwerkTestLogging_h
#include "mozilla/Logging.h"
// The netwerk standalone cpp unit tests will just use PR_LogPrint as they don't
// have access to mozilla::detail::log_print. To support that MOZ_LOG is
// redefined.
#undef MOZ_LOG
#define MOZ_LOG(_module,_level,_args) \
PR_BEGIN_MACRO \
if (MOZ_LOG_TEST(_module,_level)) { \
PR_LogPrint _args; \
} \
PR_END_MACRO
#endif

Просмотреть файл

@ -1,873 +0,0 @@
/*
TestCacheBlockFiles.cpp
*/
#include <stdio.h>
#include <stdlib.h>
#include <utime.h>
#include <Files.h>
#include <Strings.h>
#include <Errors.h>
#include <Resources.h>
#include <Aliases.h>
#include "nsCOMPtr.h"
#include "nsCRT.h"
#include "nsDirectoryServiceDefs.h"
#include "nsError.h"
#include "nsIComponentManager.h"
#include "nsIComponentRegistrar.h"
#include "nsIFile.h"
#include "nsIFileStreams.h"
#include "nsMemory.h"
#include "nsIComponentRegistrar.h"
#include "nsANSIFileStreams.h"
#include "nsDiskCacheBlockFile.h"
#include "prclist.h"
/**
* StressTest()
*/
typedef struct Allocation {
int32_t start;
int32_t count;
} Allocation;
nsresult
StressTest(nsIFile * localFile, int32_t testNumber, bool readWrite)
{
nsresult rv = NS_OK;
#define ITERATIONS 1024
#define MAX_ALLOCATIONS 256
Allocation block[MAX_ALLOCATIONS];
int32_t currentAllocations = 0;
int32_t i;
uint32_t a;
char * writeBuf[4];
char readBuf[256 * 4];
if (readWrite) {
for (i = 0; i < 4; i++) {
writeBuf[i] = new char[256 * i];
if (!writeBuf[i]) {
printf("Test %d: failed - out of memory\n", testNumber);
rv = NS_ERROR_OUT_OF_MEMORY;
goto exit;
}
memset(writeBuf[i], i, 256 * i);
}
}
nsDiskCacheBlockFile * blockFile = new nsDiskCacheBlockFile;
if (!blockFile) {
printf("Test %d failed (unable to allocate nsDiskCacheBlockFile", testNumber);
rv = NS_ERROR_OUT_OF_MEMORY;
goto exit;
}
rv = blockFile->Open(localFile, 256);
if (NS_FAILED(rv)) {
printf("Test %d: failed (Open returned: 0x%.8x)\n", testNumber, rv);
goto exit;
}
i = ITERATIONS;
while (i > 0) {
if ((currentAllocations >= MAX_ALLOCATIONS) ||
((currentAllocations > 0) && (rand() % 4 == 0))) {
// deallocate if we've reached the limit, or 25% of the time we have allocations
a = rand() % currentAllocations;
if (readWrite) {
// read verify deallocation
rv = blockFile->ReadBlocks(readBuf, block[a].start, block[a].count);
if (NS_FAILED(rv)) {
printf("Test %d: failed (ReadBlocks() returned 0x%.8x)\n", testNumber, rv);
goto exit;
}
// Verify buffer
for (i = 0; i < 256 * block[a].count; i++) {
if (readBuf[i] != block[a].count) {
printf("Test %d: failed (verifying buffer 1)\n", testNumber);
rv = NS_ERROR_FAILURE;
goto exit;
}
}
}
rv = blockFile->DeallocateBlocks(block[a].start, block[a].count);
if (NS_FAILED(rv)) {
printf("Test %d: failed (DeallocateBlocks() returned %d)\n", testNumber, rv);
goto exit;
}
--currentAllocations;
if (currentAllocations > 0)
block[a] = block[currentAllocations];
} else {
// allocate blocks
--i;
a = currentAllocations++;
block[a].count = rand() % 4 + 1; // allocate 1 to 4 blocks
block[a].start = blockFile->AllocateBlocks(block[a].count);
if (block[a].start < 0) {
printf("Test %d: failed (AllocateBlocks() failed.)\n", testNumber);
goto exit;
}
if (readWrite) {
// write buffer
rv = blockFile->WriteBlocks(writeBuf[block[a].count], block[a].start, block[a].count);
if (NS_FAILED(rv)) {
printf("Test %d: failed (WriteBlocks() returned 0x%.8x)\n",testNumber, rv);
goto exit;
}
}
}
}
// now deallocate remaining allocations
i = currentAllocations;
while (i--) {
if (readWrite) {
// read verify deallocation
rv = blockFile->ReadBlocks(readBuf, block[a].start, block[a].count);
if (NS_FAILED(rv)) {
printf("Test %d: failed (ReadBlocks(1) returned 0x%.8x)\n", testNumber, rv);
goto exit;
}
// Verify buffer
for (i = 0; i < 256 * block[a].count; i++) {
if (readBuf[i] != block[a].count) {
printf("Test %d: failed (verifying buffer 1)\n", testNumber);
rv = NS_ERROR_FAILURE;
goto exit;
}
}
}
rv = blockFile->DeallocateBlocks(block[i].start, block[i].count);
if (NS_FAILED(rv)) {
printf("Test %d: failed (DeallocateBlocks() returned %d)\n", testNumber, rv);
goto exit;
}
}
exit:
nsresult rv2 = blockFile->Close();
if (NS_FAILED(rv2)) {
printf("Test %d: failed (Close returned: 0x%.8x)\n", testNumber, rv2);
}
return rv ? rv : rv2;
}
/**
* main()
*/
int
main(void)
{
// OSErr err;
printf("hello world\n");
unsigned long now = time(0);
srand(now);
nsCOMPtr<nsIFile> file;
nsCOMPtr<nsIFile> localFile;
nsresult rv = NS_OK;
{
// Start up XPCOM
nsCOMPtr<nsIServiceManager> servMan;
NS_InitXPCOM2(getter_AddRefs(servMan), nullptr, nullptr);
nsCOMPtr<nsIComponentRegistrar> registrar = do_QueryInterface(servMan);
NS_ASSERTION(registrar, "Null nsIComponentRegistrar");
if (registrar)
registrar->AutoRegister(nullptr);
// Get default directory
rv = NS_GetSpecialDirectory(NS_XPCOM_CURRENT_PROCESS_DIR,
getter_AddRefs(file));
if (NS_FAILED(rv)) {
printf("NS_GetSpecialDirectory() failed : 0x%.8x\n", rv);
goto exit;
}
char * currentDirPath;
rv = file->GetPath(&currentDirPath);
if (NS_FAILED(rv)) {
printf("currentProcessDir->GetPath() failed : 0x%.8x\n", rv);
goto exit;
}
printf("Current Process Directory: %s\n", currentDirPath);
// Generate name for cache block file
rv = file->Append("_CACHE_001_");
if (NS_FAILED(rv)) goto exit;
// Delete existing file
rv = file->Delete(false);
if (NS_FAILED(rv) && rv != NS_ERROR_FILE_NOT_FOUND) goto exit;
// Need nsIFile to open
localFile = do_QueryInterface(file, &rv);
if (NS_FAILED(rv)) {
printf("do_QueryInterface(file) failed : 0x%.8x\n", rv);
goto exit;
}
nsDiskCacheBlockFile * blockFile = new nsDiskCacheBlockFile;
if (!blockFile) {
rv = NS_ERROR_OUT_OF_MEMORY;
goto exit;
}
//----------------------------------------------------------------
// local variables used in tests
//----------------------------------------------------------------
uint32_t bytesWritten = 0;
int32_t startBlock;
int32_t i = 0;
//----------------------------------------------------------------
// Test 1: Open nonexistent file
//----------------------------------------------------------------
rv = blockFile->Open(localFile, 256);
if (NS_FAILED(rv)) {
printf("Test 1: failed (Open returned: 0x%.8x)\n", rv);
goto exit;
}
rv = blockFile->Close();
if (NS_FAILED(rv)) {
printf("Test 1: failed (Close returned: 0x%.8x)\n", rv);
goto exit;
}
printf("Test 1: passed\n");
//----------------------------------------------------------------
// Test 2: Open existing file (with no allocation)
//----------------------------------------------------------------
rv = blockFile->Open(localFile, 256);
if (NS_FAILED(rv)) {
printf("Test 2: failed (Open returned: 0x%.8x)\n", rv);
goto exit;
}
rv = blockFile->Close();
if (NS_FAILED(rv)) {
printf("Test 2: failed (Close returned: 0x%.8x)\n", rv);
goto exit;
}
printf("Test 2: passed\n");
//----------------------------------------------------------------
// Test 3: Open existing file (bad format) size < kBitMapBytes
//----------------------------------------------------------------
// Delete existing file
rv = localFile->Delete(false);
if (NS_FAILED(rv)) {
printf("Test 3 failed (Delete returned: 0x%.8x)\n", rv);
goto exit;
}
// write < kBitMapBytes to file
nsANSIFileStream * stream = new nsANSIFileStream;
if (!stream) {
printf("Test 3 failed (unable to allocate stream\n", rv);
goto exit;
}
NS_ADDREF(stream);
rv = stream->Open(localFile);
if (NS_FAILED(rv)) {
NS_RELEASE(stream);
printf("Test 3 failed (stream->Open returned: 0x%.8x)\n", rv);
goto exit;
}
bytesWritten = 0;
rv = stream->Write("Tell me something good.\n", 24, &bytesWritten);
if (NS_FAILED(rv)) {
NS_RELEASE(stream);
printf("Test 3 failed (stream->Write returned: 0x%.8x)\n", rv);
goto exit;
}
rv = stream->Close();
if (NS_FAILED(rv)) {
NS_RELEASE(stream);
printf("Test 3 failed (stream->Close returned: 0x%.8x)\n", rv);
goto exit;
}
NS_RELEASE(stream);
rv = blockFile->Open(localFile, 256);
if (NS_SUCCEEDED(rv)) {
printf("Test 3: failed (Open erroneously succeeded)\n", rv);
(void) blockFile->Close();
goto exit;
}
printf("Test 3: passed\n");
//----------------------------------------------------------------
// Test 4: Open nonexistent file (again)
//----------------------------------------------------------------
// Delete existing file
rv = localFile->Delete(false);
if (NS_FAILED(rv)) {
printf("Test 4 failed (Delete returned: 0x%.8x)\n", rv);
goto exit;
}
rv = blockFile->Open(localFile, 256);
if (NS_FAILED(rv)) {
printf("Test 4: failed (Open returned: 0x%.8x)\n", rv);
goto exit;
}
printf("Test 4: passed\n");
//----------------------------------------------------------------
// Test 5: AllocateBlocks: invalid block count (0, 5)
//----------------------------------------------------------------
startBlock = blockFile->AllocateBlocks(0);
if (startBlock > -1) {
printf("Test 5: failed (AllocateBlocks(0) erroneously succeeded)\n");
goto exit;
}
startBlock = blockFile->AllocateBlocks(5);
if (startBlock > -1) {
printf("Test 5: failed (AllocateBlocks(5) erroneously succeeded)\n");
goto exit;
}
printf("Test 5: passed\n");
//----------------------------------------------------------------
// Test 6: AllocateBlocks: valid block count (1, 2, 3, 4)
//----------------------------------------------------------------
startBlock = blockFile->AllocateBlocks(1);
if (startBlock != 0) {
printf("Test 6: failed (AllocateBlocks(1) failed)\n");
goto exit;
}
startBlock = blockFile->AllocateBlocks(2);
if (startBlock != 1) {
printf("Test 6: failed (AllocateBlocks(2) failed)\n");
goto exit;
}
startBlock = blockFile->AllocateBlocks(3);
if (startBlock != 4) {
printf("Test 6: failed (AllocateBlocks(3) failed)\n");
goto exit;
}
startBlock = blockFile->AllocateBlocks(4);
if (startBlock != 8) {
printf("Test 6: failed (AllocateBlocks(4) failed)\n");
goto exit;
}
// blocks allocated should be 1220 3330 4444
printf("Test 6: passed\n"); // but bits could be mis-allocated
//----------------------------------------------------------------
// Test 7: VerifyAllocation
//----------------------------------------------------------------
rv = blockFile->VerifyAllocation(0,1);
if (NS_FAILED(rv)) {
printf("Test 7: failed (VerifyAllocation(0,1) returned: 0x%.8x)\n", rv);
goto exit;
}
rv = blockFile->VerifyAllocation(1,2);
if (NS_FAILED(rv)) {
printf("Test 7: failed (VerifyAllocation(1,2) returned: 0x%.8x)\n", rv);
goto exit;
}
rv = blockFile->VerifyAllocation(4,3);
if (NS_FAILED(rv)) {
printf("Test 7: failed (VerifyAllocation(4,3) returned: 0x%.8x)\n", rv);
goto exit;
}
rv = blockFile->VerifyAllocation(8,4);
if (NS_FAILED(rv)) {
printf("Test 7: failed (VerifyAllocation(8,4) returned: 0x%.8x)\n", rv);
goto exit;
}
printf("Test 7: passed\n");
//----------------------------------------------------------------
// Test 8: LastBlock
//----------------------------------------------------------------
int32_t lastBlock = blockFile->LastBlock();
if (lastBlock != 11) {
printf("Test 8: failed (LastBlock() returned: %d)\n", lastBlock);
goto exit;
}
printf("Test 8: passed\n");
//----------------------------------------------------------------
// Test 9: DeallocateBlocks: bad startBlock ( < 0)
//----------------------------------------------------------------
rv = blockFile->DeallocateBlocks(-1, 4);
if (NS_SUCCEEDED(rv)) {
printf("Test 9: failed (DeallocateBlocks(-1, 4) erroneously succeeded)\n");
goto exit;
}
printf("Test 9: passed\n");
//----------------------------------------------------------------
// Test 10: DeallocateBlocks: bad numBlocks (0, 5)
//----------------------------------------------------------------
rv = blockFile->DeallocateBlocks(0, 0);
if (NS_SUCCEEDED(rv)) {
printf("Test 10: failed (DeallocateBlocks(0, 0) erroneously succeeded)\n");
goto exit;
}
rv = blockFile->DeallocateBlocks(0, 5);
if (NS_SUCCEEDED(rv)) {
printf("Test 10: failed (DeallocateBlocks(0, 5) erroneously succeeded)\n");
goto exit;
}
printf("Test 10: passed\n");
//----------------------------------------------------------------
// Test 11: DeallocateBlocks: unallocated blocks
//----------------------------------------------------------------
rv = blockFile->DeallocateBlocks(12, 1);
if (NS_SUCCEEDED(rv)) {
printf("Test 11: failed (DeallocateBlocks(12, 1) erroneously succeeded)\n");
goto exit;
}
printf("Test 11: passed\n");
//----------------------------------------------------------------
// Test 12: DeallocateBlocks: 1, 2, 3, 4 (allocated in Test 6)
//----------------------------------------------------------------
rv = blockFile->DeallocateBlocks(0, 1);
if (NS_FAILED(rv)) {
printf("Test 12: failed (DeallocateBlocks(12, 1) returned: 0x%.8x)\n", rv);
goto exit;
}
rv = blockFile->DeallocateBlocks(1, 2);
if (NS_FAILED(rv)) {
printf("Test 12: failed (DeallocateBlocks(1, 2) returned: 0x%.8x)\n", rv);
goto exit;
}
rv = blockFile->DeallocateBlocks(4, 3);
if (NS_FAILED(rv)) {
printf("Test 12: failed (DeallocateBlocks(4, 3) returned: 0x%.8x)\n", rv);
goto exit;
}
rv = blockFile->DeallocateBlocks(8, 4);
if (NS_FAILED(rv)) {
printf("Test 12: failed (DeallocateBlocks(8, 4) returned: 0x%.8x)\n", rv);
goto exit;
}
// zero blocks should be allocated
rv = blockFile->Close();
if (NS_FAILED(rv)) {
printf("Test 12: failed (Close returned: 0x%.8x)\n", rv);
goto exit;
}
printf("Test 12: passed\n");
//----------------------------------------------------------------
// Test 13: Allocate/Deallocate boundary test
//----------------------------------------------------------------
rv = blockFile->Open(localFile, 256);
if (NS_FAILED(rv)) {
printf("Test 13: failed (Open returned: 0x%.8x)\n", rv);
goto exit;
}
// fully allocate, 1 block at a time
for (i=0; i< kBitMapBytes * 8; ++i) {
startBlock = blockFile->AllocateBlocks(1);
if (startBlock < 0) {
printf("Test 13: failed (AllocateBlocks(1) failed on i=%d)\n", i);
goto exit;
}
}
// attempt allocation with full bit map
startBlock = blockFile->AllocateBlocks(1);
if (startBlock >= 0) {
printf("Test 13: failed (AllocateBlocks(1) erroneously succeeded i=%d)\n", i);
goto exit;
}
// deallocate all the bits
for (i=0; i< kBitMapBytes * 8; ++i) {
rv = blockFile->DeallocateBlocks(i,1);
if (NS_FAILED(rv)) {
printf("Test 13: failed (DeallocateBlocks(%d,1) returned: 0x%.8x)\n", i,rv);
goto exit;
}
}
// attempt deallocation beyond end of bit map
rv = blockFile->DeallocateBlocks(i,1);
if (NS_SUCCEEDED(rv)) {
printf("Test 13: failed (DeallocateBlocks(%d,1) erroneously succeeded)\n", i);
goto exit;
}
// bit map should be empty
// fully allocate, 2 block at a time
for (i=0; i< kBitMapBytes * 8; i+=2) {
startBlock = blockFile->AllocateBlocks(2);
if (startBlock < 0) {
printf("Test 13: failed (AllocateBlocks(2) failed on i=%d)\n", i);
goto exit;
}
}
// attempt allocation with full bit map
startBlock = blockFile->AllocateBlocks(2);
if (startBlock >= 0) {
printf("Test 13: failed (AllocateBlocks(2) erroneously succeeded i=%d)\n", i);
goto exit;
}
// deallocate all the bits
for (i=0; i< kBitMapBytes * 8; i+=2) {
rv = blockFile->DeallocateBlocks(i,2);
if (NS_FAILED(rv)) {
printf("Test 13: failed (DeallocateBlocks(%d,2) returned: 0x%.8x)\n", i,rv);
goto exit;
}
}
// bit map should be empty
// fully allocate, 4 block at a time
for (i=0; i< kBitMapBytes * 8; i+=4) {
startBlock = blockFile->AllocateBlocks(4);
if (startBlock < 0) {
printf("Test 13: failed (AllocateBlocks(4) failed on i=%d)\n", i);
goto exit;
}
}
// attempt allocation with full bit map
startBlock = blockFile->AllocateBlocks(4);
if (startBlock >= 0) {
printf("Test 13: failed (AllocateBlocks(4) erroneously succeeded i=%d)\n", i);
goto exit;
}
// deallocate all the bits
for (i=0; i< kBitMapBytes * 8; i+=4) {
rv = blockFile->DeallocateBlocks(i,4);
if (NS_FAILED(rv)) {
printf("Test 13: failed (DeallocateBlocks(%d,4) returned: 0x%.8x)\n", i,rv);
goto exit;
}
}
// bit map should be empty
// allocate as many triple-blocks as possible
for (i=0; i< kBitMapBytes * 8; i+=4) {
startBlock = blockFile->AllocateBlocks(3);
if (startBlock < 0) {
printf("Test 13: failed (AllocateBlocks(3) failed on i=%d)\n", i);
goto exit;
}
}
// attempt allocation with "full" bit map
startBlock = blockFile->AllocateBlocks(3);
if (startBlock >= 0) {
printf("Test 13: failed (AllocateBlocks(3) erroneously succeeded i=%d)\n", i);
goto exit;
}
// leave some blocks allocated
rv = blockFile->Close();
if (NS_FAILED(rv)) {
printf("Test 13: failed (Close returned: 0x%.8x)\n", rv);
goto exit;
}
printf("Test 13: passed\n");
//----------------------------------------------------------------
// Test 14: ValidateFile (open existing file w/size < allocated blocks
//----------------------------------------------------------------
rv = blockFile->Open(localFile, 256);
if (NS_SUCCEEDED(rv)) {
printf("Test 14: failed (Open erroneously succeeded)\n");
goto exit;
}
// Delete existing file
rv = localFile->Delete(false);
if (NS_FAILED(rv)) {
printf("Test 14 failed (Delete returned: 0x%.8x)\n", rv);
goto exit;
}
printf("Test 14: passed\n");
//----------------------------------------------------------------
// Test 15: Allocate/Deallocate stress test
//----------------------------------------------------------------
rv = StressTest(localFile, 15, false);
if (NS_FAILED(rv))
goto exit;
printf("Test 15: passed\n");
//----------------------------------------------------------------
// Test 16: WriteBlocks
//----------------------------------------------------------------
rv = blockFile->Open(localFile, 256);
if (NS_FAILED(rv)) {
printf("Test 16: failed (Open returned: 0x%.8x)\n", rv);
goto exit;
}
char * one = new char[256 * 1];
char * two = new char[256 * 2];
char * three = new char[256 * 3];
char * four = new char[256 * 4];
if (!one || !two || !three || !four) {
printf("Test 16: failed - out of memory\n");
rv = NS_ERROR_OUT_OF_MEMORY;
goto exit;
}
memset(one, 1, 256);
memset(two, 2, 256 * 2);
memset(three, 3, 256 * 3);
memset(four, 4, 256 * 4);
startBlock = blockFile->AllocateBlocks(1);
if (startBlock != 0) {
printf("Test 16: failed (AllocateBlocks(1) failed)\n");
goto exit;
}
rv = blockFile->WriteBlocks(one, startBlock, 1);
if (NS_FAILED(rv)) {
printf("Test 16: failed (WriteBlocks(1) returned 0x%.8x)\n", rv);
goto exit;
}
startBlock = blockFile->AllocateBlocks(2);
if (startBlock != 1) { // starting with empy map, this allocation should begin at block 1
printf("Test 16: failed (AllocateBlocks(2) failed)\n");
goto exit;
}
rv = blockFile->WriteBlocks(two, startBlock, 2);
if (NS_FAILED(rv)) {
printf("Test 16: failed (WriteBlocks(2) returned 0x%.8x)\n", rv);
goto exit;
}
startBlock = blockFile->AllocateBlocks(3);
if (startBlock != 4) { // starting with empy map, this allocation should begin at block 4
printf("Test 16: failed (AllocateBlocks(3) failed)\n");
goto exit;
}
rv = blockFile->WriteBlocks(three, startBlock, 3);
if (NS_FAILED(rv)) {
printf("Test 16: failed (WriteBlocks(3) returned 0x%.8x)\n", rv);
goto exit;
}
startBlock = blockFile->AllocateBlocks(4);
if (startBlock != 8) { // starting with empy map, this allocation should begin at block 8
printf("Test 16: failed (AllocateBlocks(4) failed)\n");
goto exit;
}
rv = blockFile->WriteBlocks(four, startBlock, 4);
if (NS_FAILED(rv)) {
printf("Test 16: failed (WriteBlocks(4) returned 0x%.8x)\n", rv);
goto exit;
}
printf("Test 16: passed\n");
//----------------------------------------------------------------
// Test 17: ReadBlocks
//----------------------------------------------------------------
rv = blockFile->ReadBlocks(one, 0, 1);
if (NS_FAILED(rv)) {
printf("Test 17: failed (ReadBlocks(1) returned 0x%.8x)\n", rv);
goto exit;
}
// Verify buffer
for (i = 0; i < 256; i++) {
if (one[i] != 1) {
printf("Test 17: failed (verifying buffer 1)\n");
rv = NS_ERROR_FAILURE;
goto exit;
}
}
rv = blockFile->ReadBlocks(two, 1, 2);
if (NS_FAILED(rv)) {
printf("Test 17: failed (ReadBlocks(2) returned 0x%.8x)\n", rv);
goto exit;
}
// Verify buffer
for (i = 0; i < 256 * 2; i++) {
if (two[i] != 2) {
printf("Test 17: failed (verifying buffer 2)\n");
rv = NS_ERROR_FAILURE;
goto exit;
}
}
rv = blockFile->ReadBlocks(three, 4, 3);
if (NS_FAILED(rv)) {
printf("Test 17: failed (ReadBlocks(3) returned 0x%.8x)\n", rv);
goto exit;
}
// Verify buffer
for (i = 0; i < 256 * 3; i++) {
if (three[i] != 3) {
printf("Test 17: failed (verifying buffer 3)\n");
rv = NS_ERROR_FAILURE;
goto exit;
}
}
rv = blockFile->ReadBlocks(four, 8, 4);
if (NS_FAILED(rv)) {
printf("Test 17: failed (ReadBlocks(4) returned 0x%.8x)\n", rv);
goto exit;
}
// Verify buffer
for (i = 0; i < 256 * 4; i++) {
if (four[i] != 4) {
printf("Test 17: failed (verifying buffer 4)\n");
rv = NS_ERROR_FAILURE;
goto exit;
}
}
rv = blockFile->Close();
if (NS_FAILED(rv)) {
printf("Test 17: failed (Close returned: 0x%.8x)\n", rv);
goto exit;
}
printf("Test 17: passed\n");
//----------------------------------------------------------------
// Test 18: ValidateFile (open existing file with blocks allocated)
//----------------------------------------------------------------
rv = blockFile->Open(localFile, 256);
if (NS_FAILED(rv)) {
printf("Test 18: failed (Open returned: 0x%.8x)\n", rv);
goto exit;
}
rv = blockFile->Close();
if (NS_FAILED(rv)) {
printf("Test 18: failed (Close returned: 0x%.8x)\n", rv);
goto exit;
}
printf("Test 18: passed\n");
//----------------------------------------------------------------
// Test 19: WriteBlocks/ReadBlocks stress
//----------------------------------------------------------------
rv = StressTest(localFile, 19, false);
if (NS_FAILED(rv))
goto exit;
printf("Test 19: passed\n");
exit:
if (currentDirPath)
free(currentDirPath);
} // this scopes the nsCOMPtrs
// no nsCOMPtrs are allowed to be alive when you call NS_ShutdownXPCOM
if (NS_FAILED(rv))
printf("Test failed: 0x%.8x\n", rv);
rv = NS_ShutdownXPCOM(nullptr);
NS_ASSERTION(NS_SUCCEEDED(rv), "NS_ShutdownXPCOM failed");
printf("XPCOM shut down.\n\n");
return 0;
}

Просмотреть файл

@ -1,78 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "TestHarness.h"
#include "nsILoadContextInfo.h"
#include "../cache2/CacheFileUtils.h"
int
main(int32_t argc, char *argv[])
{
nsCOMPtr<nsILoadContextInfo> info;
nsAutoCString key, enh;
#define CHECK(a) MOZ_ASSERT(a)
info = ParseKey(NS_LITERAL_CSTRING(""));
CHECK(info && !info->IsPrivate() && !info->IsAnonymous() && !info->IsInBrowserElement() && info->AppId() == 0);
info = ParseKey(NS_LITERAL_CSTRING(":"));
CHECK(info && !info->IsPrivate() && !info->IsAnonymous() && !info->IsInBrowserElement() && info->AppId() == 0);
info = ParseKey(NS_LITERAL_CSTRING("a,"));
CHECK(info && !info->IsPrivate() && info->IsAnonymous() && !info->IsInBrowserElement() && info->AppId() == 0);
info = ParseKey(NS_LITERAL_CSTRING("a,:"));
CHECK(info && !info->IsPrivate() && info->IsAnonymous() && !info->IsInBrowserElement() && info->AppId() == 0);
info = ParseKey(NS_LITERAL_CSTRING("a,:xxx"), &enh, &key);
CHECK(info && !info->IsPrivate() && info->IsAnonymous() && !info->IsInBrowserElement() && info->AppId() == 0);
CHECK(NS_LITERAL_CSTRING("xxx").Equals(key));
info = ParseKey(NS_LITERAL_CSTRING("b,:xxx"));
CHECK(info && !info->IsPrivate() && !info->IsAnonymous() && info->IsInBrowserElement() && info->AppId() == 0);
info = ParseKey(NS_LITERAL_CSTRING("a,b,:xxx"), &enh, &key);
CHECK(info && !info->IsPrivate() && info->IsAnonymous() && info->IsInBrowserElement() && info->AppId() == 0);
CHECK(NS_LITERAL_CSTRING("xxx").Equals(key));
CHECK(enh.IsEmpty());
info = ParseKey(NS_LITERAL_CSTRING("a,b,i123,:xxx"));
CHECK(info && !info->IsPrivate() && info->IsAnonymous() && info->IsInBrowserElement() && info->AppId() == 123);
info = ParseKey(NS_LITERAL_CSTRING("a,b,c,h***,i123,:xxx"), &enh, &key);
CHECK(info && !info->IsPrivate() && info->IsAnonymous() && info->IsInBrowserElement() && info->AppId() == 123);
CHECK(NS_LITERAL_CSTRING("xxx").Equals(key));
info = ParseKey(NS_LITERAL_CSTRING("a,b,c,h***,i123,~enh,:xxx"), &enh, &key);
CHECK(info && !info->IsPrivate() && info->IsAnonymous() && info->IsInBrowserElement() && info->AppId() == 123);
CHECK(NS_LITERAL_CSTRING("xxx").Equals(key));
CHECK(NS_LITERAL_CSTRING("enh").Equals(enh));
info = ParseKey(NS_LITERAL_CSTRING("0x,1,a,b,i123,:xxx"));
CHECK(info && !info->IsPrivate() && info->IsAnonymous() && info->IsInBrowserElement() && info->AppId() == 123);
nsAutoCString test;
AppendTagWithValue(test, '~', NS_LITERAL_CSTRING("e,nh,"));
info = ParseKey(test, &enh, &key);
CHECK(info && !info->IsPrivate() && !info->IsAnonymous() && !info->IsInBrowserElement() && info->AppId() == 0);
CHECK(NS_LITERAL_CSTRING("e,nh,").Equals(enh));
info = ParseKey(NS_LITERAL_CSTRING("a,i123,b,:xxx"));
CHECK(!info);
info = ParseKey(NS_LITERAL_CSTRING("a"));
CHECK(!info);
info = ParseKey(NS_LITERAL_CSTRING("a:"));
CHECK(!info);
info = ParseKey(NS_LITERAL_CSTRING("a:xxx"));
CHECK(!info);
info = ParseKey(NS_LITERAL_CSTRING("i123"));
CHECK(!info);
info = ParseKey(NS_LITERAL_CSTRING("i123:"));
CHECK(!info);
info = ParseKey(NS_LITERAL_CSTRING("i123:xxx"));
CHECK(!info);
info = ParseKey(NS_LITERAL_CSTRING("i123,x:"));
CHECK(!info);
info = ParseKey(NS_LITERAL_CSTRING("i,x,:"));
CHECK(!info);
info = ParseKey(NS_LITERAL_CSTRING("i:"));
CHECK(!info);
#undef CHECK
passed("ok");
return 0;
}

Просмотреть файл

@ -1,274 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <unistd.h>
#include <errno.h>
#if defined(AIX) || defined(__linux)
#include <sys/select.h> // for fd_set
#endif
#if defined(__linux)
// Didn't find gettdtablehi() or gettdtablesize() on linux. Using FD_SETSIZE
#define getdtablehi() FD_SETSIZE
#else
#define getdtablehi() getdtablesize()
// If you find a system doesn't have getdtablesize try #define getdtablesize
// to FD_SETSIZE. And if you encounter a system that doesn't even have
// FD_SETSIZE, just grab your ankles and use 255.
#endif
#include "nspr.h"
#include "nsCRT.h"
#include "unix_dns.h"
struct sockaddr_un unix_addr;
int async_dns_lookup(char* hostName)
{
fprintf(stderr, "start async_dns_lookup\n");
int socket_fd = socket(PF_UNIX, SOCK_STREAM, 0);
if (socket_fd == -1) {
fprintf(stderr, "socket returned error.\n");
return -1;
}
unix_addr.sun_family = AF_UNIX;
strcpy(unix_addr.sun_path, DNS_SOCK_NAME);
int err = connect(socket_fd,(struct sockaddr*)&unix_addr, sizeof(unix_addr));
if (err == -1) {
fprintf(stderr, "connect failed (errno = %d).\n",errno);
close(socket_fd);
return -1;
}
char buf[256];
strcpy(buf, "lookup: ");
strcpy(&buf[8], hostName);
err = send(socket_fd, buf, strlen(buf)+1, 0);
if (err < 0)
fprintf(stderr, "send(%s) returned error (errno=%d).\n",buf, errno);
// receive 4 byte ID
err = recv(socket_fd, buf, 256, 0);
if (err < 0)
fprintf(stderr, "recv() returned error (errno=%d).\n", errno);
else
{
// printf("recv() returned %d bytes.");
int id = *(int *)buf;
fprintf(stderr, "id: %d\n", id);
}
return socket_fd;
}
static char *
string_trim(char *s)
{
char *s2;
if (!s) return 0;
s2 = s + strlen(s) - 1;
while (s2 > s && (*s2 == '\n' || *s2 == '\r' || *s2 == ' ' || *s2 == '\t'))
*s2-- = 0;
while (*s == ' ' || *s == '\t' || *s == '\n' || *s == '\r')
s++;
return s;
}
hostent *
bytesToHostent(char *buf)
{
int i;
// int size = 0;
int len, aliasCount, addressCount;
int addrtype, addrlength;
char* p = buf;
char s[1024];
len = *(int *)p; // length of name
p += sizeof(int); // advance past name length
memcpy(s, p, len); s[len] = 0;
fprintf(stderr, "hostname: %s\n", s);
p += len; // advance past name
aliasCount = *(int *)p; // number of aliases
p += sizeof(int); // advance past alias count
for (i=0; i<aliasCount; i++) {
len = *(int *)p; // length of alias name
p += sizeof(int); // advance past alias name length
memcpy(s, p, len); s[len] = 0;
fprintf(stderr, "alias: %s\n", s);
p += len; // advance past alias name
}
addrtype = *(int *)p;
fprintf(stderr, "addrtype: %d\n", addrtype);
p += sizeof(int);
addrlength = *(int *)p;
fprintf(stderr, "addrlength: %d\n", addrlength);
p += sizeof(int);
addressCount = *(int *)p;
p += sizeof(int);
for (i=0; i<addressCount; i++) {
len = *(int *)p;
p += sizeof(int);
fprintf(stderr, "addr len: %d\n", len);
fprintf(stderr, "addr : %x\n", *(int *)p);
p += len;
}
// size = p - buf;
// size += 1 + aliasCount;
return 0;
}
int
main(int argc, char* argv[])
{
PRStatus status;
// launch daemon
printf("### launch daemon...\n");
PRProcessAttr *attributes = PR_NewProcessAttr();
if (attributes == nullptr) {
printf("PR_NewProcessAttr() failed.\n");
return -1;
}
PRProcess *daemon = PR_CreateProcess("nsDnsAsyncLookup", nullptr, nullptr, attributes);
if (daemon == nullptr) {
printf("PR_CreateProcess failed.\n");
} else {
// status = PR_DetachProcess(daemon);
//if (status != 0)
// printf("PR_DetachProcess returned %d\n", status);
//daemon = nullptr;
}
PR_DestroyProcessAttr(attributes);
// create socket and connect to daemon
int socket_fd = 0;
bool notDone = true;
char buf[1024];
while(notDone) {
int status = 0;
fd_set fdset;
FD_ZERO(&fdset);
FD_SET(fileno(stdin), &fdset);
if (socket_fd > 0)
FD_SET(socket_fd, &fdset);
status = select(getdtablehi(), &fdset, 0, 0, 0);
if (status <= 0)
{
fprintf(stderr, "%s: select() returned %d\n", argv[0], status);
exit(-1);
}
// which fd is set?
if (FD_ISSET(fileno(stdin), &fdset))
{
char *line = fgets(buf, sizeof(buf)-1, stdin);
line = string_trim(line);
if(!strcmp(line, "quit") || !strcmp(line, "exit"))
{
fprintf(stderr, "bye now.\n");
notDone = false;
}
else if (!strncmp(line, "abort ", 6))
{
// abort id
}
else if (strchr(line, ' ') || strchr(line, '\t'))
{
fprintf(stderr, "%s: unrecognized command %s.\n", argv[0], line);
}
else
{
fprintf(stderr, "%s: looking up %s...\n", argv[0], line);
// initiate dns lookup
socket_fd = async_dns_lookup(line);
}
}
if (socket_fd && FD_ISSET(socket_fd, &fdset))
{
// read from socket, parse results
int size = read(socket_fd, buf, 1024);
if (size > 0)
{
// parse buffer into hostent
char *p = buf;
fprintf(stderr, "bytes read: %d\n", size);
fprintf(stderr, "response code: %d\n", *(int *)p);
p += sizeof(int);
for (int i=0; i < size; i++) {
if (!(i%8))
fprintf(stderr, "\n");
fprintf(stderr, "%2.2x ",(unsigned char)buf[i]);
}
fprintf(stderr, "\n");
hostent *h;
h = bytesToHostent(p);
}
close(socket_fd);
socket_fd = 0;
}
}
return 0;
}
/*
buffer
int nameLen;
if (nameLen > 0)
char [nameLen+1] name
int aliasCount
for each alias
int aliasNameLen
char [aliasNameLen+1] aliasName
int h_addrtype
int h_length
int addrCount
for each addr
char[h_length] addr
*/

Просмотреть файл

@ -1,483 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsIServiceManager.h"
#include "nsIComponentRegistrar.h"
#include "nsIInputStream.h"
#include "nsIOutputStream.h"
#include "nsIRunnable.h"
#include "nsIThread.h"
#include "nsCOMArray.h"
#include "nsISimpleEnumerator.h"
#include "prinrval.h"
#include "nsIFileStreams.h"
#include "nsIFileChannel.h"
#include "nsIFile.h"
#include "nsNetUtil.h"
#include <stdio.h>
////////////////////////////////////////////////////////////////////////////////
#include <math.h>
#include "prprf.h"
#include "nsAutoLock.h"
class nsTimeSampler {
public:
nsTimeSampler();
void Reset();
void StartTime();
void EndTime();
void AddTime(PRIntervalTime time);
PRIntervalTime LastInterval() { return mLastInterval; }
char* PrintStats();
protected:
PRIntervalTime mStartTime;
double mSquares;
double mTotalTime;
uint32_t mCount;
PRIntervalTime mLastInterval;
};
nsTimeSampler::nsTimeSampler()
{
Reset();
}
void
nsTimeSampler::Reset()
{
mStartTime = 0;
mSquares = 0;
mTotalTime = 0;
mCount = 0;
mLastInterval = 0;
}
void
nsTimeSampler::StartTime()
{
mStartTime = PR_IntervalNow();
}
void
nsTimeSampler::EndTime()
{
NS_ASSERTION(mStartTime != 0, "Forgot to call StartTime");
PRIntervalTime endTime = PR_IntervalNow();
mLastInterval = endTime - mStartTime;
AddTime(mLastInterval);
mStartTime = 0;
}
void
nsTimeSampler::AddTime(PRIntervalTime time)
{
nsAutoCMonitor mon(this);
mTotalTime += time;
mSquares += (double)time * (double)time;
mCount++;
}
char*
nsTimeSampler::PrintStats()
{
double mean = mTotalTime / mCount;
double variance = fabs(mSquares / mCount - mean * mean);
double stddev = sqrt(variance);
uint32_t imean = (uint32_t)mean;
uint32_t istddev = (uint32_t)stddev;
return PR_smprintf("%d +/- %d ms",
PR_IntervalToMilliseconds(imean),
PR_IntervalToMilliseconds(istddev));
}
////////////////////////////////////////////////////////////////////////////////
nsTimeSampler gTimeSampler;
typedef nsresult (*CreateFun)(nsIRunnable* *result,
nsIFile* inPath,
nsIFile* outPath,
uint32_t bufferSize);
////////////////////////////////////////////////////////////////////////////////
nsresult
Copy(nsIInputStream* inStr, nsIOutputStream* outStr,
char* buf, uint32_t bufSize, uint32_t *copyCount)
{
nsresult rv;
while (true) {
uint32_t count;
rv = inStr->Read(buf, bufSize, &count);
if (NS_FAILED(rv)) return rv;
if (count == 0) break;
uint32_t writeCount;
rv = outStr->Write(buf, count, &writeCount);
if (NS_FAILED(rv)) return rv;
NS_ASSERTION(writeCount == count, "didn't write all the data");
*copyCount += writeCount;
}
rv = outStr->Flush();
return rv;
}
////////////////////////////////////////////////////////////////////////////////
class FileSpecWorker : public nsIRunnable {
public:
NS_IMETHOD Run() override {
nsresult rv;
PRIntervalTime startTime = PR_IntervalNow();
PRIntervalTime endTime;
nsCOMPtr<nsIInputStream> inStr;
nsCOMPtr<nsIOutputStream> outStr;
uint32_t copyCount = 0;
// Open the input stream:
nsCOMPtr<nsIInputStream> fileIn;
rv = NS_NewLocalFileInputStream(getter_AddRefs(fileIn), mInPath);
if (NS_FAILED(rv)) return rv;
rv = NS_NewBufferedInputStream(getter_AddRefs(inStr), fileIn, 65535);
if (NS_FAILED(rv)) return rv;
// Open the output stream:
nsCOMPtr<nsIOutputStream> fileOut;
rv = NS_NewLocalFileOutputStream(getter_AddRefs(fileOut),
mOutPath,
PR_CREATE_FILE | PR_WRONLY | PR_TRUNCATE,
0664);
if (NS_FAILED(rv)) return rv;
rv = NS_NewBufferedOutputStream(getter_AddRefs(outStr), fileOut, 65535);
if (NS_FAILED(rv)) return rv;
// Copy from one to the other
rv = Copy(inStr, outStr, mBuffer, mBufferSize, &copyCount);
if (NS_FAILED(rv)) return rv;
endTime = PR_IntervalNow();
gTimeSampler.AddTime(endTime - startTime);
return rv;
}
NS_DECL_ISUPPORTS
FileSpecWorker()
: mInPath(nullptr), mOutPath(nullptr), mBuffer(nullptr),
mBufferSize(0)
{
}
nsresult Init(nsIFile* inPath, nsIFile* outPath,
uint32_t bufferSize)
{
mInPath = inPath;
mOutPath = outPath;
mBuffer = new char[bufferSize];
mBufferSize = bufferSize;
return (mInPath && mOutPath && mBuffer)
? NS_OK : NS_ERROR_OUT_OF_MEMORY;
}
static nsresult Create(nsIRunnable* *result,
nsIFile* inPath,
nsIFile* outPath,
uint32_t bufferSize)
{
FileSpecWorker* worker = new FileSpecWorker();
if (worker == nullptr)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(worker);
nsresult rv = worker->Init(inPath, outPath, bufferSize);
if (NS_FAILED(rv)) {
NS_RELEASE(worker);
return rv;
}
*result = worker;
return NS_OK;
}
virtual ~FileSpecWorker() {
delete[] mBuffer;
}
protected:
nsCOMPtr<nsIFile> mInPath;
nsCOMPtr<nsIFile> mOutPath;
char* mBuffer;
uint32_t mBufferSize;
};
NS_IMPL_ISUPPORTS(FileSpecWorker, nsIRunnable)
////////////////////////////////////////////////////////////////////////////////
#include "nsIIOService.h"
#include "nsIChannel.h"
class FileChannelWorker : public nsIRunnable {
public:
NS_IMETHOD Run() override {
nsresult rv;
PRIntervalTime startTime = PR_IntervalNow();
PRIntervalTime endTime;
uint32_t copyCount = 0;
nsCOMPtr<nsIFileChannel> inCh;
nsCOMPtr<nsIFileChannel> outCh;
nsCOMPtr<nsIInputStream> inStr;
nsCOMPtr<nsIOutputStream> outStr;
rv = NS_NewLocalFileChannel(getter_AddRefs(inCh), mInPath);
if (NS_FAILED(rv)) return rv;
rv = inCh->Open(getter_AddRefs(inStr));
if (NS_FAILED(rv)) return rv;
//rv = NS_NewLocalFileChannel(getter_AddRefs(outCh), mOutPath);
//if (NS_FAILED(rv)) return rv;
//rv = outCh->OpenOutputStream(0, -1, 0, getter_AddRefs(outStr));
//if (NS_FAILED(rv)) return rv;
// Copy from one to the other
rv = Copy(inStr, outStr, mBuffer, mBufferSize, &copyCount);
if (NS_FAILED(rv)) return rv;
endTime = PR_IntervalNow();
gTimeSampler.AddTime(endTime - startTime);
return rv;
}
NS_DECL_ISUPPORTS
FileChannelWorker()
: mInPath(nullptr), mOutPath(nullptr), mBuffer(nullptr),
mBufferSize(0)
{
}
nsresult Init(nsIFile* inPath, nsIFile* outPath,
uint32_t bufferSize)
{
mInPath = inPath;
mOutPath = outPath;
mBuffer = new char[bufferSize];
mBufferSize = bufferSize;
return (mInPath && mOutPath && mBuffer)
? NS_OK : NS_ERROR_OUT_OF_MEMORY;
}
static nsresult Create(nsIRunnable* *result,
nsIFile* inPath,
nsIFile* outPath,
uint32_t bufferSize)
{
FileChannelWorker* worker = new FileChannelWorker();
if (worker == nullptr)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(worker);
nsresult rv = worker->Init(inPath, outPath, bufferSize);
if (NS_FAILED(rv)) {
NS_RELEASE(worker);
return rv;
}
*result = worker;
return NS_OK;
}
virtual ~FileChannelWorker() {
delete[] mBuffer;
}
protected:
nsCOMPtr<nsIFile> mInPath;
nsCOMPtr<nsIFile> mOutPath;
char* mBuffer;
uint32_t mBufferSize;
};
NS_IMPL_ISUPPORTS(FileChannelWorker, nsIRunnable)
////////////////////////////////////////////////////////////////////////////////
void
Test(CreateFun create, const char* name, uint32_t count,
nsIFile* inDirSpec, nsIFile* outDirSpec, uint32_t bufSize)
{
nsresult rv;
uint32_t i;
nsAutoCString inDir;
nsAutoCString outDir;
(void)inDirSpec->GetNativePath(inDir);
(void)outDirSpec->GetNativePath(outDir);
printf("###########\nTest: from %s to %s, bufSize = %d\n",
inDir.get(), outDir.get(), bufSize);
gTimeSampler.Reset();
nsTimeSampler testTime;
testTime.StartTime();
nsCOMArray<nsIThread> threads;
nsCOMPtr<nsISimpleEnumerator> entries;
rv = inDirSpec->GetDirectoryEntries(getter_AddRefs(entries));
NS_ASSERTION(NS_SUCCEEDED(rv), "GetDirectoryEntries failed");
i = 0;
bool hasMore;
while (i < count && NS_SUCCEEDED(entries->HasMoreElements(&hasMore)) && hasMore) {
nsCOMPtr<nsISupports> next;
rv = entries->GetNext(getter_AddRefs(next));
if (NS_FAILED(rv)) goto done;
nsCOMPtr<nsIFile> inSpec = do_QueryInterface(next, &rv);
if (NS_FAILED(rv)) goto done;
nsCOMPtr<nsIFile> outSpec;
rv = outDirSpec->Clone(getter_AddRefs(outSpec)); // don't munge the original
if (NS_FAILED(rv)) goto done;
nsAutoCString leafName;
rv = inSpec->GetNativeLeafName(leafName);
if (NS_FAILED(rv)) goto done;
rv = outSpec->AppendNative(leafName);
if (NS_FAILED(rv)) goto done;
bool exists;
rv = outSpec->Exists(&exists);
if (NS_FAILED(rv)) goto done;
if (exists) {
rv = outSpec->Remove(false);
if (NS_FAILED(rv)) goto done;
}
nsCOMPtr<nsIThread> thread;
nsCOMPtr<nsIRunnable> worker;
rv = create(getter_AddRefs(worker),
inSpec,
outSpec,
bufSize);
if (NS_FAILED(rv)) goto done;
rv = NS_NewNamedThread(name, getter_AddRefs(thread),
worker, 0, PR_JOINABLE_THREAD);
if (NS_FAILED(rv)) goto done;
bool inserted = threads.InsertObjectAt(thread, i);
NS_ASSERTION(inserted, "not inserted");
i++;
}
uint32_t j;
for (j = 0; j < i; j++) {
nsIThread* thread = threads.ObjectAt(j);
thread->Join();
}
done:
NS_ASSERTION(rv == NS_OK, "failed");
testTime.EndTime();
char* testStats = testTime.PrintStats();
char* workerStats = gTimeSampler.PrintStats();
printf(" threads = %d\n work time = %s,\n test time = %s\n",
i, workerStats, testStats);
PR_smprintf_free(workerStats);
PR_smprintf_free(testStats);
}
////////////////////////////////////////////////////////////////////////////////
int
main(int argc, char* argv[])
{
nsresult rv;
if (argc < 2) {
printf("usage: %s <in-dir> <out-dir>\n", argv[0]);
return -1;
}
char* inDir = argv[1];
char* outDir = argv[2];
{
nsCOMPtr<nsIServiceManager> servMan;
NS_InitXPCOM2(getter_AddRefs(servMan), nullptr, nullptr);
nsCOMPtr<nsIComponentRegistrar> registrar = do_QueryInterface(servMan);
NS_ASSERTION(registrar, "Null nsIComponentRegistrar");
if (registrar)
registrar->AutoRegister(nullptr);
nsCOMPtr<nsIFile> inDirFile;
rv = NS_NewNativeLocalFile(nsDependentCString(inDir), false, getter_AddRefs(inDirFile));
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIFile> outDirFile;
rv = NS_NewNativeLocalFile(nsDependentCString(outDir), false, getter_AddRefs(outDirFile));
if (NS_FAILED(rv)) return rv;
CreateFun create = FileChannelWorker::Create;
const char* name = "FileChannelWorker";
Test(create, 1, inDirFile, outDirFile, 16 * 1024);
#if 1
printf("FileChannelWorker *****************************\n");
Test(create, name, 20, inDirFile, outDirFile, 16 * 1024);
Test(create, name, 20, inDirFile, outDirFile, 16 * 1024);
Test(create, name, 20, inDirFile, outDirFile, 16 * 1024);
Test(create, name, 20, inDirFile, outDirFile, 16 * 1024);
Test(create, name, 20, inDirFile, outDirFile, 16 * 1024);
Test(create, name, 20, inDirFile, outDirFile, 16 * 1024);
Test(create, name, 20, inDirFile, outDirFile, 16 * 1024);
Test(create, name, 20, inDirFile, outDirFile, 16 * 1024);
Test(create, name, 20, inDirFile, outDirFile, 16 * 1024);
#endif
create = FileSpecWorker::Create;
name = "FileSpecWorker";
printf("FileSpecWorker ********************************\n");
#if 1
Test(create, name, 20, inDirFile, outDirFile, 16 * 1024);
Test(create, name, 20, inDirFile, outDirFile, 16 * 1024);
Test(create, name, 20, inDirFile, outDirFile, 16 * 1024);
Test(create, name, 20, inDirFile, outDirFile, 16 * 1024);
Test(create, name, 20, inDirFile, outDirFile, 16 * 1024);
Test(create, name, 20, inDirFile, outDirFile, 16 * 1024);
Test(create, name, 20, inDirFile, outDirFile, 16 * 1024);
Test(create, name, 20, inDirFile, outDirFile, 16 * 1024);
Test(create, name, 20, inDirFile, outDirFile, 16 * 1024);
#endif
#if 1
Test(create, name, 20, inDirFile, outDirFile, 4 * 1024);
Test(create, name, 20, inDirFile, outDirFile, 4 * 1024);
Test(create, name, 20, inDirFile, outDirFile, 4 * 1024);
Test(create, name, 20, inDirFile, outDirFile, 4 * 1024);
Test(create, name, 20, inDirFile, outDirFile, 4 * 1024);
Test(create, name, 20, inDirFile, outDirFile, 4 * 1024);
Test(create, name, 20, inDirFile, outDirFile, 4 * 1024);
Test(create, name, 20, inDirFile, outDirFile, 4 * 1024);
Test(create, name, 20, inDirFile, outDirFile, 4 * 1024);
#endif
} // this scopes the nsCOMPtrs
// no nsCOMPtrs are allowed to be alive when you call NS_ShutdownXPCOM
rv = NS_ShutdownXPCOM(nullptr);
NS_ASSERTION(NS_SUCCEEDED(rv), "NS_ShutdownXPCOM failed");
return 0;
}
////////////////////////////////////////////////////////////////////////////////

Просмотреть файл

@ -1,69 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nspr.h"
#include "nscore.h"
#include "nsCOMPtr.h"
#include "nsIIOService.h"
#include "nsIServiceManager.h"
#include "nsIComponentRegistrar.h"
#include "nsIURI.h"
static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
nsresult ServiceMakeAbsolute(nsIURI *baseURI, char *relativeInfo, char **_retval) {
nsresult rv;
nsCOMPtr<nsIIOService> serv(do_GetService(kIOServiceCID, &rv));
if (NS_FAILED(rv)) return rv;
return serv->MakeAbsolute(relativeInfo, baseURI, _retval);
}
nsresult URLMakeAbsolute(nsIURI *baseURI, char *relativeInfo, char **_retval) {
return baseURI->MakeAbsolute(relativeInfo, _retval);
}
int
main(int argc, char* argv[])
{
nsresult rv = NS_OK;
if (argc < 4) {
printf("usage: %s int (loop count) baseURL relativeSpec\n", argv[0]);
return -1;
}
uint32_t cycles = atoi(argv[1]);
char *base = argv[2];
char *rel = argv[3];
{
nsCOMPtr<nsIServiceManager> servMan;
NS_InitXPCOM2(getter_AddRefs(servMan), nullptr, nullptr);
nsCOMPtr<nsIComponentRegistrar> registrar = do_QueryInterface(servMan);
NS_ASSERTION(registrar, "Null nsIComponentRegistrar");
if (registrar)
registrar->AutoRegister(nullptr);
nsCOMPtr<nsIIOService> serv(do_GetService(kIOServiceCID, &rv));
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIURI> uri;
rv = serv->NewURI(base, nullptr, getter_AddRefs(uri));
if (NS_FAILED(rv)) return rv;
char *absURLString;
uint32_t i = 0;
while (i++ < cycles) {
rv = ServiceMakeAbsolute(uri, rel, &absURLString);
if (NS_FAILED(rv)) return rv;
free(absURLString);
rv = URLMakeAbsolute(uri, rel, &absURLString);
free(absURLString);
}
} // this scopes the nsCOMPtrs
// no nsCOMPtrs are allowed to be alive when you call NS_ShutdownXPCOM
NS_ShutdownXPCOM(nullptr);
return rv;
}

Просмотреть файл

@ -1,313 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include <stdio.h>
#include <signal.h>
#include <algorithm>
#ifdef WIN32
#include <windows.h>
#endif
#include "nspr.h"
#include "nscore.h"
#include "nsISocketTransportService.h"
#include "nsIEventQueueService.h"
#include "nsIServiceManager.h"
#include "nsITransport.h"
#include "nsIRequest.h"
#include "nsIStreamProvider.h"
#include "nsIStreamListener.h"
#include "nsIPipe.h"
#include "nsIOutputStream.h"
#include "nsIInputStream.h"
#include "nsCRT.h"
#include "nsCOMPtr.h"
#include "nsIByteArrayInputStream.h"
static PRLogModuleInfo *gTestSocketIOLog;
#define LOG(args) MOZ_LOG(gTestSocketIOLog, mozilla::LogLevel::Debug, args)
static NS_DEFINE_CID(kSocketTransportServiceCID, NS_SOCKETTRANSPORTSERVICE_CID);
static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID);
static PRTime gElapsedTime;
static int gKeepRunning = 1;
static nsIEventQueue* gEventQ = nullptr;
//
//----------------------------------------------------------------------------
// Test Listener
//----------------------------------------------------------------------------
//
class TestListener : public nsIStreamListener
{
public:
TestListener() { }
virtual ~TestListener() {}
NS_DECL_ISUPPORTS
NS_DECL_NSIREQUESTOBSERVER
NS_DECL_NSISTREAMLISTENER
};
NS_IMPL_ISUPPORTS(TestListener,
nsIRequestObserver,
nsIStreamListener);
NS_IMETHODIMP
TestListener::OnStartRequest(nsIRequest* request, nsISupports* context)
{
LOG(("TestListener::OnStartRequest\n"));
return NS_OK;
}
NS_IMETHODIMP
TestListener::OnDataAvailable(nsIRequest* request,
nsISupports* context,
nsIInputStream *aIStream,
uint64_t aSourceOffset,
uint32_t aLength)
{
LOG(("TestListener::OnDataAvailable [offset=%llu length=%u]\n",
aSourceOffset, aLength));
char buf[1025];
uint32_t amt;
while (1) {
aIStream->Read(buf, 1024, &amt);
if (amt == 0)
break;
buf[amt] = '\0';
//puts(buf);
printf("read %d bytes\n", amt);
}
return NS_OK;
}
NS_IMETHODIMP
TestListener::OnStopRequest(nsIRequest* request, nsISupports* context,
nsresult aStatus)
{
LOG(("TestListener::OnStopRequest [aStatus=%x]\n", aStatus));
//gKeepRunning = 0;
return NS_OK;
}
//
//----------------------------------------------------------------------------
// Test Provider
//----------------------------------------------------------------------------
//
class TestProvider : public nsIStreamProvider
{
public:
TestProvider(char *data);
virtual ~TestProvider();
NS_DECL_ISUPPORTS
NS_DECL_NSIREQUESTOBSERVER
NS_DECL_NSISTREAMPROVIDER
protected:
char *mData;
uint32_t mOffset;
uint32_t mDataLen;
uint32_t mRequestCount;
};
NS_IMPL_ISUPPORTS(TestProvider,
nsIStreamProvider,
nsIRequestObserver)
TestProvider::TestProvider(char *data)
{
mData = data;
mDataLen = strlen(data);
mOffset = 0;
mRequestCount = 0;
LOG(("Constructing TestProvider [this=%p]\n", this));
}
TestProvider::~TestProvider()
{
LOG(("Destroying TestProvider [this=%p]\n", this));
}
NS_IMETHODIMP
TestProvider::OnStartRequest(nsIRequest* request, nsISupports* context)
{
LOG(("TestProvider::OnStartRequest [this=%p]\n", this));
return NS_OK;
}
NS_IMETHODIMP
TestProvider::OnStopRequest(nsIRequest* request, nsISupports* context,
nsresult aStatus)
{
LOG(("TestProvider::OnStopRequest [status=%x]\n", aStatus));
return NS_OK;
}
NS_IMETHODIMP
TestProvider::OnDataWritable(nsIRequest *request, nsISupports *context,
nsIOutputStream *output, uint32_t offset, uint32_t count)
{
LOG(("TestProvider::OnDataWritable [offset=%u, count=%u]\n", offset, count));
// Stop at 5 requests
if (mRequestCount == 5)
return NS_BASE_STREAM_CLOSED;
uint32_t writeCount, amount;
amount = std::min(count, mDataLen - mOffset);
nsresult rv = output->Write(mData + mOffset, amount, &writeCount);
if (NS_SUCCEEDED(rv)) {
printf("wrote %u bytes\n", writeCount);
mOffset += writeCount;
if (mOffset == mDataLen) {
printf("done sending packet %u\n", mRequestCount);
mOffset = 0;
mRequestCount++;
}
}
return NS_OK;
}
//
//----------------------------------------------------------------------------
// Synchronous IO
//----------------------------------------------------------------------------
//
nsresult
WriteRequest(nsIOutputStream *os, const char *request)
{
LOG(("WriteRequest [request=%s]\n", request));
uint32_t n;
return os->Write(request, strlen(request), &n);
}
nsresult
ReadResponse(nsIInputStream *is)
{
uint32_t bytesRead;
char buf[2048];
do {
is->Read(buf, sizeof(buf), &bytesRead);
if (bytesRead > 0)
fwrite(buf, 1, bytesRead, stdout);
} while (bytesRead > 0);
return NS_OK;
}
//
//----------------------------------------------------------------------------
// Startup...
//----------------------------------------------------------------------------
//
void
sighandler(int sig)
{
LOG(("got signal: %d\n", sig));
NS_BREAK();
}
void
usage(char **argv)
{
printf("usage: %s <host> <path>\n", argv[0]);
exit(1);
}
int
main(int argc, char* argv[])
{
nsresult rv;
signal(SIGSEGV, sighandler);
gTestSocketIOLog = PR_NewLogModule("TestSocketIO");
if (argc < 3)
usage(argv);
char *hostName = argv[1];
char *fileName = argv[2];
int port = 80;
// Create the Event Queue for this thread...
nsCOMPtr<nsIEventQueueService> eventQService =
do_GetService(kEventQueueServiceCID, &rv);
if (NS_FAILED(rv)) {
NS_WARNING("failed to create: event queue service!");
return rv;
}
rv = eventQService->CreateMonitoredThreadEventQueue();
if (NS_FAILED(rv)) {
NS_WARNING("failed to create: thread event queue!");
return rv;
}
eventQService->GetThreadEventQueue(NS_CURRENT_THREAD, &gEventQ);
// Create the Socket transport service...
nsCOMPtr<nsISocketTransportService> sts =
do_GetService(kSocketTransportServiceCID, &rv);
if (NS_FAILED(rv)) {
NS_WARNING("failed to create: socket transport service!");
return rv;
}
char *buffer = PR_smprintf("GET %s HTTP/1.1" CRLF
"host: %s" CRLF
"user-agent: Mozilla/5.0 (X11; N; Linux 2.2.16-22smp i686; en-US; m18) Gecko/20001220" CRLF
"accept: */*" CRLF
"accept-language: en" CRLF
"accept-encoding: gzip,deflate,compress,identity" CRLF
"keep-alive: 300" CRLF
"connection: keep-alive" CRLF
CRLF,
fileName, hostName);
LOG(("Request [\n%s]\n", buffer));
// Create the socket transport...
nsCOMPtr<nsITransport> transport;
rv = sts->CreateTransport(hostName, port, nullptr, -1, 0, 0, getter_AddRefs(transport));
if (NS_FAILED(rv)) {
NS_WARNING("failed to create: socket transport!");
return rv;
}
gElapsedTime = PR_Now();
nsCOMPtr<nsIRequest> writeRequest, readRequest;
rv = transport->AsyncWrite(new TestProvider(buffer), nullptr, 0, 0, 0, getter_AddRefs(writeRequest));
if (NS_FAILED(rv)) {
NS_WARNING("failed calling: AsyncWrite!");
return rv;
}
rv = transport->AsyncRead(new TestListener(), nullptr, 0, 0, 0, getter_AddRefs(readRequest));
if (NS_FAILED(rv)) {
NS_WARNING("failed calling: AsyncWrite!");
return rv;
}
// Enter the message pump
while ( gKeepRunning ) {
PLEvent *gEvent;
gEventQ->WaitForEvent(&gEvent);
gEventQ->HandleEvent(gEvent);
}
PRTime endTime;
endTime = PR_Now();
LOG(("Elapsed time: %d\n", (int32_t)(endTime/1000UL - gElapsedTime/1000UL)));
sts->Shutdown();
return 0;
}

Просмотреть файл

@ -1,164 +0,0 @@
/* vim:set ts=2 sw=2 et: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/*
* To use try out this JS server socket implementation, just copy this file
* into the "components" directory of a Mozilla build. Then load the URL
* http://localhost:4444/ in the browser. You should see a page get loaded
* that was served up by this component :-)
*
* This code requires Mozilla 1.6 or better.
*/
const kTESTSERV_CONTRACTID = "@mozilla.org/network/test-serv;1";
const kTESTSERV_CID = Components.ID("{a741fcd5-9695-42e8-a7f7-14f9a29f8200}");
const nsISupports = Components.interfaces.nsISupports;
const nsIObserver = Components.interfaces.nsIObserver;
const nsIServerSocket = Components.interfaces.nsIServerSocket;
const nsIServerSocketListener = Components.interfaces.nsIServerSocketListener;
const nsITransport = Components.interfaces.nsITransport;
const nsIScriptableInputStream = Components.interfaces.nsIScriptableInputStream;
/** we'll listen on this port for HTTP requests **/
const kPORT = 4444;
function nsTestServ() { dump(">>> creating nsTestServ instance\n"); };
nsTestServ.prototype =
{
QueryInterface: function(iid)
{
if (iid.equals(nsIObserver) ||
iid.equals(nsIServerSocketListener) ||
iid.equals(nsISupports))
return this;
throw Components.results.NS_ERROR_NO_INTERFACE;
},
observe: function(subject, topic, data)
{
dump(">>> observe [" + topic + "]\n");
this.startListening();
},
/* this function is called when we receive a new connection */
onSocketAccepted: function(serverSocket, clientSocket)
{
dump(">>> accepted connection on "+clientSocket.host+":"+clientSocket.port+"\n");
var input = clientSocket.openInputStream(nsITransport.OPEN_BLOCKING, 0, 0);
var output = clientSocket.openOutputStream(nsITransport.OPEN_BLOCKING, 0, 0);
this.consumeInput(input);
const fixedResponse =
"HTTP/1.0 200 OK\r\nContent-Type: text/plain\r\n\r\nFooooopy!!\r\n";
var response = fixedResponse + "\r\n" + new Date().toString() + "\r\n";
var n = output.write(response, response.length);
dump(">>> wrote "+n+" bytes\n");
input.close();
output.close();
},
onStopListening: function(serverSocket, status)
{
dump(">>> shutting down server socket\n");
},
startListening: function()
{
const SERVERSOCKET_CONTRACTID = "@mozilla.org/network/server-socket;1";
var socket = Components.classes[SERVERSOCKET_CONTRACTID].createInstance(nsIServerSocket);
socket.init(kPORT, true /* loopback only */, 5);
dump(">>> listening on port "+socket.port+"\n");
socket.asyncListen(this);
},
consumeInput: function(input)
{
/* use nsIScriptableInputStream to consume all of the data on the stream */
var sin = Components.classes["@mozilla.org/scriptableinputstream;1"]
.createInstance(nsIScriptableInputStream);
sin.init(input);
/* discard all data */
while (sin.available() > 0)
sin.read(512);
}
}
/**
* JS XPCOM component registration goop:
*
* We set ourselves up to observe the xpcom-startup category. This provides
* us with a starting point.
*/
var servModule = new Object();
servModule.registerSelf =
function (compMgr, fileSpec, location, type)
{
compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
compMgr.registerFactoryLocation(kTESTSERV_CID,
"nsTestServ",
kTESTSERV_CONTRACTID,
fileSpec,
location,
type);
const CATMAN_CONTRACTID = "@mozilla.org/categorymanager;1";
const nsICategoryManager = Components.interfaces.nsICategoryManager;
var catman = Components.classes[CATMAN_CONTRACTID].getService(nsICategoryManager);
catman.addCategoryEntry("xpcom-startup",
"TestServ",
kTESTSERV_CONTRACTID,
true,
true);
}
servModule.getClassObject =
function (compMgr, cid, iid)
{
if (!cid.equals(kTESTSERV_CID))
throw Components.results.NS_ERROR_NO_INTERFACE;
if (!iid.equals(Components.interfaces.nsIFactory))
throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
return servFactory;
}
servModule.canUnload =
function (compMgr)
{
dump(">>> unloading test serv.\n");
return true;
}
var servFactory = new Object();
servFactory.createInstance =
function (outer, iid)
{
if (outer != null)
throw Components.results.NS_ERROR_NO_AGGREGATION;
if (!iid.equals(nsIObserver) &&
!iid.equals(nsISupports))
throw Components.results.NS_ERROR_NO_INTERFACE;
return TestServ;
}
function NSGetModule(compMgr, fileSpec)
{
return servModule;
}
var TestServ = new nsTestServ();

Просмотреть файл

@ -1,343 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include <stdio.h>
#include <signal.h>
#ifdef WIN32
#include <windows.h>
#endif
#include "nspr.h"
#include "nscore.h"
#include "nsISocketTransportService.h"
#include "nsIEventQueueService.h"
#include "nsIServiceManager.h"
#include "nsITransport.h"
#include "nsIRequest.h"
#include "nsIStreamProvider.h"
#include "nsIStreamListener.h"
#include "nsIPipe.h"
#include "nsIOutputStream.h"
#include "nsIInputStream.h"
#include "nsCRT.h"
#include "nsCOMPtr.h"
#include "nsIByteArrayInputStream.h"
static PRLogModuleInfo *gTestSocketIOLog;
#define LOG(args) MOZ_LOG(gTestSocketIOLog, mozilla::LogLevel::Debug, args)
static NS_DEFINE_CID(kSocketTransportServiceCID, NS_SOCKETTRANSPORTSERVICE_CID);
static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID);
static PRTime gElapsedTime;
static int gKeepRunning = 1;
static nsIEventQueue* gEventQ = nullptr;
//
//----------------------------------------------------------------------------
// Test Listener
//----------------------------------------------------------------------------
//
class TestListener : public nsIStreamListener
{
public:
TestListener() {}
virtual ~TestListener() {}
NS_DECL_ISUPPORTS
NS_DECL_NSIREQUESTOBSERVER
NS_DECL_NSISTREAMLISTENER
};
NS_IMPL_ISUPPORTS(TestListener,
nsIRequestObserver,
nsIStreamListener);
NS_IMETHODIMP
TestListener::OnStartRequest(nsIRequest* request, nsISupports* context)
{
LOG(("TestListener::OnStartRequest\n"));
return NS_OK;
}
NS_IMETHODIMP
TestListener::OnDataAvailable(nsIRequest* request,
nsISupports* context,
nsIInputStream *aIStream,
uint32_t aSourceOffset,
uint32_t aLength)
{
LOG(("TestListener::OnDataAvailable [offset=%u length=%u]\n",
aSourceOffset, aLength));
char buf[1025];
uint32_t amt;
while (1) {
aIStream->Read(buf, 1024, &amt);
if (amt == 0)
break;
buf[amt] = '\0';
puts(buf);
}
return NS_OK;
}
NS_IMETHODIMP
TestListener::OnStopRequest(nsIRequest* request, nsISupports* context,
nsresult aStatus)
{
LOG(("TestListener::OnStopRequest [aStatus=%x]\n", aStatus));
gKeepRunning = 0;
return NS_OK;
}
//
//----------------------------------------------------------------------------
// Test Provider
//----------------------------------------------------------------------------
//
class TestProvider : public nsIStreamProvider
{
public:
TestProvider(char *data);
virtual ~TestProvider();
NS_DECL_ISUPPORTS
NS_DECL_NSIREQUESTOBSERVER
NS_DECL_NSISTREAMPROVIDER
protected:
nsCOMPtr<nsIByteArrayInputStream> mData;
};
NS_IMPL_ISUPPORTS(TestProvider,
nsIStreamProvider,
nsIRequestObserver)
TestProvider::TestProvider(char *data)
{
NS_NewByteArrayInputStream(getter_AddRefs(mData), data, strlen(data));
LOG(("Constructing TestProvider [this=%p]\n", this));
}
TestProvider::~TestProvider()
{
LOG(("Destroying TestProvider [this=%p]\n", this));
}
NS_IMETHODIMP
TestProvider::OnStartRequest(nsIRequest* request, nsISupports* context)
{
LOG(("TestProvider::OnStartRequest [this=%p]\n", this));
return NS_OK;
}
NS_IMETHODIMP
TestProvider::OnStopRequest(nsIRequest* request, nsISupports* context,
nsresult aStatus)
{
LOG(("TestProvider::OnStopRequest [status=%x]\n", aStatus));
nsCOMPtr<nsIStreamListener> listener = do_QueryInterface(new TestListener());
if (NS_SUCCEEDED(aStatus)) {
nsCOMPtr<nsITransportRequest> treq = do_QueryInterface(request);
nsCOMPtr<nsITransport> transport;
treq->GetTransport(getter_AddRefs(transport));
if (transport) {
nsCOMPtr<nsIRequest> readRequest;
transport->AsyncRead(listener, nullptr, 0, 0, 0, getter_AddRefs(readRequest));
}
} else
gKeepRunning = 0;
return NS_OK;
}
NS_IMETHODIMP
TestProvider::OnDataWritable(nsIRequest *request, nsISupports *context,
nsIOutputStream *output, uint32_t offset, uint32_t count)
{
LOG(("TestProvider::OnDataWritable [offset=%u, count=%u]\n", offset, count));
uint32_t writeCount;
nsresult rv = output->WriteFrom(mData, count, &writeCount);
// Zero bytes written on success indicates EOF
if (NS_SUCCEEDED(rv) && (writeCount == 0))
return NS_BASE_STREAM_CLOSED;
return rv;
}
//
//----------------------------------------------------------------------------
// Synchronous IO
//----------------------------------------------------------------------------
//
nsresult
WriteRequest(nsIOutputStream *os, const char *request)
{
LOG(("WriteRequest [request=%s]\n", request));
uint32_t n;
return os->Write(request, strlen(request), &n);
}
nsresult
ReadResponse(nsIInputStream *is)
{
uint32_t bytesRead;
char buf[2048];
do {
is->Read(buf, sizeof(buf), &bytesRead);
if (bytesRead > 0)
fwrite(buf, 1, bytesRead, stdout);
} while (bytesRead > 0);
return NS_OK;
}
//
//----------------------------------------------------------------------------
// Startup...
//----------------------------------------------------------------------------
//
void
sighandler(int sig)
{
LOG(("got signal: %d\n", sig));
NS_BREAK();
}
void
usage(char **argv)
{
printf("usage: %s [-sync] <host> <path>\n", argv[0]);
exit(1);
}
int
main(int argc, char* argv[])
{
nsresult rv;
signal(SIGSEGV, sighandler);
gTestSocketIOLog = PR_NewLogModule("TestSocketIO");
if (argc < 3)
usage(argv);
int i=0;
bool sync = false;
if (nsCRT::strcasecmp(argv[1], "-sync") == 0) {
if (argc < 4)
usage(argv);
sync = true;
i = 1;
}
char *hostName = argv[1+i];
char *fileName = argv[2+i];
int port = 80;
// Create the Event Queue for this thread...
nsCOMPtr<nsIEventQueueService> eventQService =
do_GetService(kEventQueueServiceCID, &rv);
if (NS_FAILED(rv)) {
NS_WARNING("failed to create: event queue service!");
return rv;
}
rv = eventQService->CreateMonitoredThreadEventQueue();
if (NS_FAILED(rv)) {
NS_WARNING("failed to create: thread event queue!");
return rv;
}
eventQService->GetThreadEventQueue(NS_CURRENT_THREAD, &gEventQ);
// Create the Socket transport service...
nsCOMPtr<nsISocketTransportService> sts =
do_GetService(kSocketTransportServiceCID, &rv);
if (NS_FAILED(rv)) {
NS_WARNING("failed to create: socket transport service!");
return rv;
}
char *buffer = PR_smprintf("GET %s HTTP/1.1" CRLF
"host: %s" CRLF
"user-agent: Mozilla/5.0 (X11; N; Linux 2.2.16-22smp i686; en-US; m18) Gecko/20001220" CRLF
"accept: */*" CRLF
"accept-language: en" CRLF
"accept-encoding: gzip,deflate,compress,identity" CRLF
"keep-alive: 300" CRLF
"connection: keep-alive" CRLF
CRLF,
fileName, hostName);
LOG(("Request [\n%s]\n", buffer));
// Create the socket transport...
nsCOMPtr<nsITransport> transport;
rv = sts->CreateTransport(hostName, port, nullptr, 0, 0, getter_AddRefs(transport));
if (NS_FAILED(rv)) {
NS_WARNING("failed to create: socket transport!");
return rv;
}
gElapsedTime = PR_Now();
if (!sync) {
nsCOMPtr<nsIRequest> request;
rv = transport->AsyncWrite(new TestProvider(buffer), nullptr, 0, 0, 0, getter_AddRefs(request));
if (NS_FAILED(rv)) {
NS_WARNING("failed calling: AsyncWrite!");
return rv;
}
// Enter the message pump to allow the URL load to proceed.
while ( gKeepRunning ) {
PLEvent *gEvent;
gEventQ->WaitForEvent(&gEvent);
gEventQ->HandleEvent(gEvent);
}
}
else {
// synchronous write
{
nsCOMPtr<nsIOutputStream> os;
rv = transport->OpenOutputStream(0, 0, 0, getter_AddRefs(os));
if (NS_FAILED(rv)) {
LOG(("OpenOutputStream failed [rv=%x]\n", rv));
return rv;
}
rv = WriteRequest(os, buffer);
if (NS_FAILED(rv)) {
LOG(("WriteRequest failed [rv=%x]\n", rv));
return rv;
}
}
// synchronous read
{
nsCOMPtr<nsIInputStream> is;
rv = transport->OpenInputStream(0, 0, 0, getter_AddRefs(is));
if (NS_FAILED(rv)) {
LOG(("OpenInputStream failed [rv=%x]\n", rv));
return rv;
}
rv = ReadResponse(is);
if (NS_FAILED(rv)) {
LOG(("ReadResponse failed [rv=%x]\n", rv));
return rv;
}
}
}
PRTime endTime;
endTime = PR_Now();
LOG(("Elapsed time: %d\n", (int32_t)(endTime/1000UL - gElapsedTime/1000UL)));
sts->Shutdown();
return 0;
}

Просмотреть файл

@ -1,154 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include <stdio.h>
#ifdef WIN32
#include <windows.h>
#endif
#include "nscore.h"
#include "nsCOMPtr.h"
#include "nsISocketTransportService.h"
#include "nsIEventQueueService.h"
#include "nsIServiceManager.h"
#include "nsIComponentRegistrar.h"
#include "nsITransport.h"
#include "nsIRequest.h"
#include "nsIStreamListener.h"
#include "nsIInputStream.h"
static NS_DEFINE_CID(kSocketTransportServiceCID, NS_SOCKETTRANSPORTSERVICE_CID);
static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID);
static int gKeepRunning = 1;
class InputTestConsumer : public nsIStreamListener
{
public:
InputTestConsumer();
virtual ~InputTestConsumer();
// ISupports interface...
NS_DECL_ISUPPORTS
// IStreamListener interface...
NS_DECL_NSIREQUESTOBSERVER
NS_DECL_NSISTREAMLISTENER
};
InputTestConsumer::InputTestConsumer()
{
}
InputTestConsumer::~InputTestConsumer()
{
}
NS_IMPL_ISUPPORTS(InputTestConsumer, nsIRequestObserver, nsIStreamListener)
NS_IMETHODIMP
InputTestConsumer::OnStartRequest(nsIRequest *request, nsISupports* context)
{
printf("+++ OnStartRequest +++\n");
return NS_OK;
}
NS_IMETHODIMP
InputTestConsumer::OnDataAvailable(nsIRequest *request,
nsISupports* context,
nsIInputStream *aIStream,
uint64_t aSourceOffset,
uint32_t aLength)
{
char buf[1025];
while (aLength > 0) {
uint32_t amt;
aIStream->Read(buf, 1024, &amt);
if (amt == 0) break;
buf[amt] = '\0';
printf(buf);
aLength -= amt;
}
return NS_OK;
}
NS_IMETHODIMP
InputTestConsumer::OnStopRequest(nsIRequest *request, nsISupports* context,
nsresult aStatus)
{
gKeepRunning = 0;
printf("+++ OnStopRequest status %x +++\n", aStatus);
return NS_OK;
}
int
main(int argc, char* argv[])
{
nsresult rv;
if (argc < 2) {
printf("usage: %s <host>\n", argv[0]);
return -1;
}
int port;
char* hostName = argv[1];
//nsString portString(argv[2]);
//port = portString.ToInteger(&rv);
port = 13;
{
nsCOMPtr<nsIServiceManager> servMan;
NS_InitXPCOM2(getter_AddRefs(servMan), nullptr, nullptr);
nsCOMPtr<nsIComponentRegistrar> registrar = do_QueryInterface(servMan);
NS_ASSERTION(registrar, "Null nsIComponentRegistrar");
if (registrar)
registrar->AutoRegister(nullptr);
// Create the Event Queue for this thread...
nsCOMPtr<nsIEventQueueService> eventQService =
do_GetService(kEventQueueServiceCID, &rv);
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIEventQueue> eventQ;
rv = eventQService->GetThreadEventQueue(NS_CURRENT_THREAD, getter_AddRefs(eventQ));
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsISocketTransportService> sts =
do_GetService(kSocketTransportServiceCID, &rv);
if (NS_FAILED(rv)) return rv;
nsITransport* transport;
rv = sts->CreateTransport(hostName, port, nullptr, 0, 0, &transport);
if (NS_SUCCEEDED(rv)) {
nsCOMPtr<nsIRequest> request;
transport->AsyncRead(new InputTestConsumer, nullptr, 0, -1, 0, getter_AddRefs(request));
NS_RELEASE(transport);
}
// Enter the message pump to allow the URL load to proceed.
while ( gKeepRunning ) {
PLEvent *gEvent;
eventQ->WaitForEvent(&gEvent);
eventQ->HandleEvent(gEvent);
}
} // this scopes the nsCOMPtrs
// no nsCOMPtrs are allowed to be alive when you call NS_ShutdownXPCOM
rv = NS_ShutdownXPCOM(nullptr);
NS_ASSERTION(NS_SUCCEEDED(rv), "NS_ShutdownXPCOM failed");
return 0;
}

Просмотреть файл

@ -1,130 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>URL manipulation</title>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
<script type="text/javascript">
var gIOService = null;
function getIOService()
{
if (gIOService)
return gIOService;
try {
gIOService = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService);
} catch(e) { dump("problem creating nsIURL for: "+inURLString+"\n"); }
return gIOService;
}
function getnsIURL(inURLString)
{
var URL = null;
var ioserv = getIOService();
try {
var URI = ioserv.newURI(inURLString, "", null);
URL = URI.QueryInterface(Components.interfaces.nsIURL);
} catch(e) { dump("problem creating nsIURL for: "+inURLString+"\n"); }
return URL;
}
function getCommonSpec()
{
var URL1 = getnsIURL(document.foo.baseEdit.value);
var URL2 = getnsIURL(document.foo.compareEdit.value);
var result = "";
try {
result = URL1.getCommonBaseSpec(URL2);
} catch(e) { dump("problem with getCommonSpec ("+e+")\n"); }
document.foo.resultEdit.value = result;
}
function getRelativeSpec()
{
var URL1 = getnsIURL(document.foo.baseEdit.value);
var URL2 = getnsIURL(document.foo.compareEdit.value);
var result = "";
try {
result = URL1.getRelativeSpec(URL2);
} catch(e) { dump("problem with getRelativeSpec ("+e+")\n"); }
document.foo.resultEdit.value = result;
}
function doResolve()
{
var URL = getnsIURL(document.foo.baseEdit.value);
var result = "";
try {
result = URL.resolve(document.foo.resultEdit.value);
} catch(e) { dump("problem with getRelativeSpec ("+e+")\n"); }
document.foo.compareEdit.value = result;
}
</script>
</head>
<body>
<h1>testing of URL manipulation:</h1>
<p>
<form name="foo">
<p>
<label for="baseEdit">base url (absolute)</label><br>
<input type="input" name="baseEdit" size="80" value="http://www.mozilla.org/">
<p>
<label for="compareEdit">comparison uri (absolute)</label><br>
<input type="input" name="compareEdit" size="80">
<p>
<label for="resultEdit">resolved url</label><br>
<input type="input" name="resultEdit" size="80">
<p>
<input type="button" onclick="getCommonSpec();" value="Get Common Spec">
<input type="button" onclick="getRelativeSpec();" value="Get Relative Spec">
<input type="button" onclick="doResolve();" value="Resolve">
<h5> note: results from "resolve" are placed in "comparison uri" edit field</h5>
</form>
<p>
<br>
<h3>notes for testing</h3>
different types of uris:<br>
<ul>
<li>about:</li>
<li>about:blank</li>
<li>mailbox://nsmail-2.mcom.com/xxx</li>
<li>mailto:brade@netscape.com)</li>
<li>junk</li>
<li>http://foo/</li>
<li>http://foo.com/</li>
<li>https://foo.com/</li>
<li>ftp://ftp.mozilla.org/</li>
<li>http://foo.com:8080/</li>
<li>http://brade@foo.com/</li>
<li>http://brade:password@foo.com/</li>
<li>http://brade:@foo.com:8080/</li>
<li>file:///</li>
<li>file:///Quest/Desktop%20Folder/test.html</li>
</ul>
other variations:<br>
<ul>
<li>sub-directories on above list</li>
<li>files on above list</li>
<li>sub-directories and files on above list<br>
</li>
<li>directories which don't end in a '/'</li>
<li>files with queries</li>
<li>files with no extension</li>
<li>files with references</li>
<li>files with params</li>
<li>other schemes (chrome, ldap, news, finger, etc.)<br>
</li>
</ul>
<br>
This should be true:<br>
&nbsp; resultString = baseURL.getRelativeSpec(URL);<br>
&lt;==&gt;<br>
&nbsp; baseURL.resolve(resultString) == URL.spec;<br>
</body>
</html>

Просмотреть файл

@ -1,116 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "prio.h"
#include "prinrval.h"
#include "prmem.h"
#include <stdio.h>
#include <math.h>
void
NS_MeanAndStdDev(double n, double sumOfValues, double sumOfSquaredValues,
double *meanResult, double *stdDevResult)
{
double mean = 0.0, var = 0.0, stdDev = 0.0;
if (n > 0.0 && sumOfValues >= 0) {
mean = sumOfValues / n;
double temp = (n * sumOfSquaredValues) - (sumOfValues * sumOfValues);
if (temp < 0.0 || n <= 1)
var = 0.0;
else
var = temp / (n * (n - 1));
// for some reason, Windows says sqrt(0.0) is "-1.#J" (?!) so do this:
stdDev = var != 0.0 ? sqrt(var) : 0.0;
}
*meanResult = mean;
*stdDevResult = stdDev;
}
int
Test(const char* filename, int32_t minSize, int32_t maxSize,
int32_t sizeIncrement, int32_t iterations)
{
fprintf(stdout, " size write: mean stddev iters total: mean stddev iters\n");
for (int32_t size = minSize; size <= maxSize; size += sizeIncrement) {
// create a buffer of stuff to write
char* buf = (char*)PR_Malloc(size);
if (buf == nullptr)
return -1;
// initialize it with a pattern
int32_t i;
char hex[] = "0123456789ABCDEF";
for (i = 0; i < size; i++) {
buf[i] = hex[i & 0xF];
}
double writeCount = 0, writeRate = 0, writeRateSquared = 0;
double totalCount = 0, totalRate = 0, totalRateSquared = 0;
for (i = 0; i < iterations; i++) {
PRIntervalTime start = PR_IntervalNow();
char name[1024];
sprintf(name, "%s_%d", filename, i);
PRFileDesc* fd = PR_Open(name, PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE, 0664);
if (fd == nullptr)
return -1;
PRIntervalTime writeStart = PR_IntervalNow();
int32_t rv = PR_Write(fd, buf, size);
if (rv < 0) return rv;
if (rv != size) return -1;
PRIntervalTime writeStop = PR_IntervalNow();
PRStatus st = PR_Close(fd);
if (st == PR_FAILURE) return -1;
PRIntervalTime stop = PR_IntervalNow();
PRIntervalTime writeTime = PR_IntervalToMilliseconds(writeStop - writeStart);
if (writeTime > 0) {
double wr = size / writeTime;
writeRate += wr;
writeRateSquared += wr * wr;
writeCount++;
}
PRIntervalTime totalTime = PR_IntervalToMilliseconds(stop - start);
if (totalTime > 0) {
double t = size / totalTime;
totalRate += t;
totalRateSquared += t * t;
totalCount++;
}
}
PR_Free(buf);
double writeMean, writeStddev;
double totalMean, totalStddev;
NS_MeanAndStdDev(writeCount, writeRate, writeRateSquared,
&writeMean, &writeStddev);
NS_MeanAndStdDev(totalCount, totalRate, totalRateSquared,
&totalMean, &totalStddev);
fprintf(stdout, "%10d %10.2f %10.2f %10d %10.2f %10.2f %10d\n",
size, writeMean, writeStddev, (int32_t)writeCount,
totalMean, totalStddev, (int32_t)totalCount);
}
return 0;
}
int
main(int argc, char* argv[])
{
if (argc != 5) {
printf("usage: %s <min buf size (K)> <max buf size (K)> <size increment (K)> <iterations>\n", argv[0]);
return -1;
}
Test("y:\\foo",
atoi(argv[1]) * 1024,
atoi(argv[2]) * 1024,
atoi(argv[3]) * 1024,
atoi(argv[4]));
return 0;
}

Просмотреть файл

@ -26,11 +26,6 @@ if CONFIG['OS_TARGET'] == 'WINNT':
'TestNamedPipeService.cpp',
]
RESOURCE_FILES += [
'urlparse.dat',
'urlparse_unx.dat',
]
include('/ipc/chromium/chromium-config.mozbuild')
if CONFIG['GNU_CXX']:

Просмотреть файл

@ -1,257 +0,0 @@
http://www.yahoo.com/
http://www.netscape.com/
http://www.microsoft.com/
http://www.excite.com/
http://www.mckinley.com/
http://www.city.net/
http://www.webcrawler.com/
http://www.mirabilis.com/
http://www.infoseek.com/
http://www.pathfinder.com/
http://www.warnerbros.com/
http://www.cnn.com/
http://www.altavista.digital.com/
http://www.altavista.com/
http://www.usatoday.com/
http://www.disney.com/
http://www.starwave.com/
http://www.hotwired.com/
http://www.hotbot.com/
http://www.lycos.com/
http://www.pointcom.com/
http://www.cnet.com/
http://www.search.com/
http://www.news.com/
http://www.download.com/
http://www.geocities.com/
http://www.aol.com/
http://members.aol.com/
http://www.imdb.com/
http://uk.imdb.com/
http://www.macromedia.com/
http://www.infobeat.com/
http://www.fxweb.com/
http://www.whowhere.com/
http://www.real.com/
http://www.sportsline.com/
http://www.dejanews.com/
http://www.the-park.com/
http://www.cmpnet.com/
http://www.go2net.com/
http://www.metacrawler.com/
http://www.playsite.com/
http://www.stocksite.com/
http://www.sony.com/
http://www.music.sony.com/
http://www.station.sony.com/
http://www.scea.sony.com/
http://www.infospace.com/
http://www.zdnet.com/
http://www.hotfiles.com/
http://www.chathouse.com/
http://www.looksmart.com/
http://www.iamginegames.com/
http://www.macaddict.com/
http://www.rsac.org/
http://www.apple.com/
http://www.beseen.com/
http://www.dogpile.com/
http://www.xoom.com/
http://www.tucows.com/
http://www.freethemes.com/
http://www.winfiles.com/
http://www.vservers.com/
http://www.mtv.com/
http://www.the-xfiles.com/
http://www.datek.com/
http://www.cyberthrill.com/
http://www.surplusdirect.com/
http://www.tomshardware.com/
http://www.bigyellow.com/
http://www.100hot.com/
http://www.messagemates.com/
http://www.onelist.com/
http://www.bluemountain.com/
http://www.ea.com/
http://www.bullfrog.co.uk/
http://www.travelocity.com/
http://www.ibm.com/
http://www.bigcharts.com/
http://www.davesclassics.com/
http://www.goto.com/
http://www.weather.com/
http://www.gamespot.com/
http://www.bloomberg.com/
http://www.winzip.com/
http://www.filez.com/
http://www.westwood.com/
http://www.internet.com/
http://www.cardmaster.com/
http://www.creaf.com/
http://netaddress.usa.net/
http://www.occ.com/
http://www.as.org/
http://www.amazon.com/
http://www.drudgereport.com/
http://www.hardradio.com/
http://www.intel.com/
http://www.mp3.com/
http://www.ebay.com/
http://www.msn.com/
http://www.fifa.com/
http://www.attitude.com/
http://www.happypuppy.com/
http://www.gamesdomain.com/
http://www.onsale.com/
http://www.tm.com/
http://www.xlnc1.com/
http://www.greatsports.com/
http://www.discovery.com/
http://www.nai.com/
http://www.nasa.gov/
http://www.ogr.com/
http://www.warzone.com/
http://www.gamestats.com/
http://www.winamp.com/
http://java.sun.com/
http://www.hp.com/
http://www.cdnow.com/
http://www.nytimes.com/
http://www.majorleaguebaseball.com/
http://www.washingtonpost.com/
http://www.planetquake.com/
http://www.wsj.com/
http://www.slashdot.org/
http://www.adobe.com/
http://www.quicken.com/
http://www.talkcity.com/
http://www.developer.com/
http://www.mapquest.com/
http://www.yahoo.com/
http://www.pathfinder.com/
http://www.msn.com/
http://www.fifa.com/
http://www.attitude.com/
http://www.happypuppy.com/
http://www.gamesdomain.com/
http://www.onsale.com/
http://www.tm.com/
http://www.xlnc1.com/
http://www.greatsports.com/
http://www.discovery.com/
http://www.warnerbros.com/
http://www.nai.com/
http://www.nasa.gov/
http://www.ogr.com/
http://www.warzone.com/
http://www.gamestats.com/
http://www.winamp.com/
http://java.sun.com/
http://www.hp.com/
http://www.cdnow.com/
http://www.nytimes.com/
http://www.majorleaguebaseball.com/
http://www.planetquake.com/
http://www.wsj.com/
http://www.slashdot.org/
http://www.adobe.com/
http://www.quicken.com/
http://www.talkcity.com/
http://www.developer.com/
http://www.mapquest.com/
http://www.altavista.digital.com/
http://www.altavista.com/
http://www.usatoday.com/
http://www.disney.com/
http://www.starwave.com/
http://www.hotwired.com/
http://www.hotbot.com/
http://www.netscape.com/
http://www.lycos.com/
http://www.pointcom.com/
http://www.cnet.com/
http://www.search.com/
http://www.news.com/
http://www.download.com/
http://www.geocities.com/
http://www.imdb.com/
http://www.microsoft.com/
http://uk.imdb.com/
http://www.macromedia.com/
http://www.infobeat.com/
http://www.fxweb.com/
http://www.whowhere.com/
http://www.real.com/
http://www.sportsline.com/
http://www.dejanews.com/
http://www.the-park.com/
http://www.cmpnet.com/
http://www.excite.com/
http://www.go2net.com/
http://www.metacrawler.com/
http://www.playsite.com/
http://www.stocksite.com/
http://www.infospace.com/
http://www.zdnet.com/
http://www.mckinley.com/
http://www.hotfiles.com/
http://www.chathouse.com/
http://www.looksmart.com/
http://www.iamginegames.com/
http://www.macaddict.com/
http://www.rsac.org/
http://www.apple.com/
http://www.beseen.com/
http://www.dogpile.com/
http://www.xoom.com/
http://www.city.net/
http://www.tucows.com/
http://www.freethemes.com/
http://www.winfiles.com/
http://www.vservers.com/
http://www.mtv.com/
http://www.the-xfiles.com/
http://www.datek.com/
http://www.cyberthrill.com/
http://www.surplusdirect.com/
http://www.tomshardware.com/
http://www.webcrawler.com/
http://www.bigyellow.com/
http://www.100hot.com/
http://www.messagemates.com/
http://www.onelist.com/
http://www.bluemountain.com/
http://www.ea.com/
http://www.bullfrog.co.uk/
http://www.travelocity.com/
http://www.ibm.com/
http://www.bigcharts.com/
http://www.mirabilis.com/
http://www.davesclassics.com/
http://www.goto.com/
http://www.weather.com/
http://www.gamespot.com/
http://www.bloomberg.com/
http://www.winzip.com/
http://www.filez.com/
http://www.westwood.com/
http://www.internet.com/
http://www.cardmaster.com/
http://www.infoseek.com/
http://www.creaf.com/
http://netaddress.usa.net/
http://www.occ.com/
http://www.as.org/
http://www.amazon.com/
http://www.drudgereport.com/
http://www.hardradio.com/
http://www.intel.com/
http://www.mp3.com/
http://www.ebay.com/
http://www.aol.com/
http://www.cnn.com/
http://www.music.sony.com/
http://www.scea.sony.com/
http://www.sony.com/
http://www.station.sony.com/
http://www.washingtonpost.com/

Просмотреть файл

@ -1,103 +0,0 @@
# Any blank lines and those beginning with # are comments and
# ignored. To add additional test cases that could potentially
# break URL parsing in mozilla add the input URL on a new line
# and follow it with the expected output for the standard URL
# parser and one line for the case when the URL is really
# created. Then run urltest with the -std option and without it
# on this file and hopefully the expected output should match
# the one from the program.
# - Gagan Saksena 03/28/00
#
http://username:password@hostname.com:80/pathname/./more/stuff/../path
http,username,password,hostname.com,80,/pathname/more/,path,,,,,http://username:password@hostname.com:80/pathname/more/path
http,username,password,hostname.com,80,/pathname/more/,path,,,,,http://username:password@hostname.com/pathname/more/path
username@host:8080/path
,username,,host,8080,/,path,,,,,username@host:8080/path
Can not create URL
http://gagan/
http,,,gagan,-1,/,,,,,,http://gagan/
http,,,gagan,-1,/,,,,,,http://gagan/
scheme:host/netlib
scheme,,,host,-1,/,netlib,,,,,scheme://host/netlib
Can not create URL
mailbox:///foo
mailbox,,,,-1,/,foo,,,,,mailbox:///foo
mailbox,,,,-1,/,foo,,,,,mailbox:///foo
scheme:user@hostname.edu:80/pathname
scheme,user,,hostname.edu,80,/,pathname,,,,,scheme://user@hostname.edu:80/pathname
Can not create URL
http://username:password@hostname:80/pathname
http,username,password,hostname,80,/,pathname,,,,,http://username:password@hostname:80/pathname
http,username,password,hostname,80,/,pathname,,,,,http://username:password@hostname/pathname
http://username:password@hostname:8080/path/filebasename.fileextension;param?query#ref
http,username,password,hostname,8080,/path/,filebasename,fileextension,param,query,ref,http://username:password@hostname:8080/path/filebasename.fileextension;param?query#ref
http,username,password,hostname,8080,/path/,filebasename,fileextension,param,query,ref,http://username:password@hostname:8080/path/filebasename.fileextension;param?query#ref
resource:/pathname
resource,,,,-1,/,pathname,,,,,resource:///pathname
resource,,,,-1,/,pathname,,,,,resource:///pathname
ftp://uname%here.com:pwd@there.com/aPath/a.html
ftp,uname%here.com,pwd,there.com,-1,/aPath/,a,html,,,,ftp://uname%here.com:pwd@there.com/aPath/a.html
ftp,uname%here.com,pwd,there.com,-1,/aPath/,a,html,,,,ftp://uname%here.com:pwd@there.com/aPath/a.html
http://www.inf.bme.hu?foo=bar
http,,,www.inf.bme.hu,-1,/,,,,foo=bar,,http://www.inf.bme.hu/?foo=bar
http,,,www.inf.bme.hu,-1,/,,,,foo=bar,,http://www.inf.bme.hu/?foo=bar
http://test.com/aPath/a.html#/1/2
http,,,test.com,-1,/aPath/,a,html,,,/1/2,http://test.com/aPath/a.html#/1/2
http,,,test.com,-1,/aPath/,a,html,,,/1/2,http://test.com/aPath/a.html#/1/2
http://user:pass@ipaddres:2/get?foo/something
http,user,pass,ipaddres,2,/,get,,,foo/something,,http://user:pass@ipaddres:2/get?foo/something
http,user,pass,ipaddres,2,/,get,,,foo/something,,http://user:pass@ipaddres:2/get?foo/something
# testing different versions of http urls
http:www.mozilla.org
http,,,www.mozilla.org,-1,/,,,,,,http://www.mozilla.org/
http,,,www.mozilla.org,-1,/,,,,,,http://www.mozilla.org/
http:/www.mozilla.org
http,,,,-1,/,www.mozilla,org,,,,http:///www.mozilla.org
http,,,www.mozilla.org,-1,/,,,,,,http://www.mozilla.org/
# testing cap letters (23927)
HtTp://wWw.mozilLa.org
http,,,www.mozilla.org,-1,/,,,,,,http://www.mozilla.org/
http,,,www.mozilla.org,-1,/,,,,,,http://www.mozilla.org/
# testing spaces (15150)
go.com.au?mozilla bug reports
,,,go.com.au,-1,/,,,,mozilla%20bug%20reports,,go.com.au/?mozilla%20bug%20reports
Can not create URL
http://go.com.au?mozilla bug reports
http,,,go.com.au,-1,/,,,,mozilla%20bug%20reports,,http://go.com.au/?mozilla%20bug%20reports
http,,,go.com.au,-1,/,,,,mozilla%20bug%20reports,,http://go.com.au/?mozilla%20bug%20reports
# testing for multiple params (14801)
http://ad.doubleclick.net/ad/cbsmw.button.com/SIDEBAR_BUTTONS;sz=88x31;kw=DBCC;tile=4;ord=1864641213378545414
http,,,ad.doubleclick.net,-1,/ad/cbsmw.button.com/,SIDEBAR_BUTTONS,,sz=88x31;kw=DBCC;tile=4;ord=1864641213378545414,,,http://ad.doubleclick.net/ad/cbsmw.button.com/SIDEBAR_BUTTONS;sz=88x31;kw=DBCC;tile=4;ord=1864641213378545414
http,,,ad.doubleclick.net,-1,/ad/cbsmw.button.com/,SIDEBAR_BUTTONS,,sz=88x31;kw=DBCC;tile=4;ord=1864641213378545414,,,http://ad.doubleclick.net/ad/cbsmw.button.com/SIDEBAR_BUTTONS;sz=88x31;kw=DBCC;tile=4;ord=1864641213378545414
fxqn:/us/va/reston/cnri/ietf/24/asdf%*.fred
fxqn,,,,-1,/us/va/reston/cnri/ietf/24/,asdf%*,fred,,,,fxqn:///us/va/reston/cnri/ietf/24/asdf%*.fred
Can not create URL
news:3B5C133C.2080505@foobar.net
news,3B5C133C.2080505,,foobar.net,-1,/,,,,,,news://3B5C133C.2080505@foobar.net/
news,3B5C133C.2080505,,foobar.net,-1,/,,,,,,news://3B5C133C.2080505@foobar.net/
http://host/path/%2E%2E/file%2Ehtml
http,,,host,-1,/,file%2Ehtml,,,,,http://host/file%2Ehtml
http,,,host,-1,/,file%2Ehtml,,,,,http://host/file%2Ehtml

Просмотреть файл

@ -1,14 +0,0 @@
# Any blank lines and those beginning with # are comments and
# ignored. To add additional test cases that could potentially
# break URL parsing in mozilla add the input URL on a new line
# and follow it with the expected output for the standard URL
# parser and one line for the case when the URL is really
# created. Then run urltest with the -std option and without it
# on this file and hopefully the expected output should match
# the one from the program.
# - Gagan Saksena 03/28/00
#
# This version is specifically for the Mac platform.
#
# testing different versions of file urls

Просмотреть файл

@ -1,34 +0,0 @@
# Any blank lines and those beginning with # are comments and
# ignored. To add additional test cases that could potentially
# break URL parsing in mozilla add the input URL on a new line
# and follow it with the expected output for the standard URL
# parser and one line for the case when the URL is really
# created. Then run urltest with the -std option and without it
# on this file and hopefully the expected output should match
# the one from the program.
# - Gagan Saksena 03/28/00
#
# This version is specifically *not* for PC platforms like Windows or OS/2.
# It's testcases for the file protocol target a unix-like filesystem.
# testing different versions of file urls
file:home
file,,,home,-1,/,,,,,,file://home/
file,,,,-1,/,home,,,,,file:///home
file:/home
file,,,,-1,/,home,,,,,file:///home
file,,,,-1,/,home,,,,,file:///home
file://home
file,,,home,-1,/,,,,,,file://home/
file,,,home,-1,/,,,,,,file://home/
file:///home
file,,,,-1,/,home,,,,,file:///home
file,,,,-1,/,home,,,,,file:///home
# testing UNC filepaths
file:////server/path
file,,,,-1,//server/,path,,,,,file:////server/path
file,,,,-1,//server/,path,,,,,file:////server/path

Просмотреть файл

@ -1,60 +0,0 @@
# Any blank lines and those beginning with # are comments and
# ignored. To add additional test cases that could potentially
# break URL parsing in mozilla add the input URL on a new line
# and follow it with the expected output for the standard URL
# parser and one line for the case when the URL is really
# created. Then run urltest with the -std option and without it
# on this file and hopefully the expected output should match
# the one from the program.
# - Gagan Saksena 03/28/00
#
# This version is specifically for PC platforms like Windows or OS/2.
# It has testcases for the file protocol targeting typical
# drive:/path filesystems
#
# testing different versions of file urls
file:c:
file,,,,-1,/,c:,,,,,file:///c%3A
file,,,,-1,/c:/,,,,,,file:///c:/
file:c:/
file,,,,-1,/c:/,,,,,,file:///c:/
file,,,,-1,/c:/,,,,,,file:///c:/
file:/c:/
file,,,,-1,/c:/,,,,,,file:///c:/
file,,,,-1,/c:/,,,,,,file:///c:/
file://c:/
file,,,,-1,/c:/,,,,,,file:///c:/
file,,,,-1,/c:/,,,,,,file:///c:/
file:///c:/
file,,,,-1,/c:/,,,,,,file:///c:/
file,,,,-1,/c:/,,,,,,file:///c:/
# testing UNC filepaths
file:server/path
file,,,server,-1,/,path,,,,,file://server/path
file,,,,-1,///server/,path,,,,,file://///server/path
file:/server/path
file,,,,-1,/server/,path,,,,,file:///server/path
file,,,,-1,///server/,path,,,,,file://///server/path
file://server/path
file,,,server,-1,/,path,,,,,file://server/path
file,,,server,-1,///,path,,,,,file://server///path
file:///server/path
file,,,,-1,/server/,path,,,,,file:///server/path
file,,,,-1,///server/,path,,,,,file://///server/path
file:////server/path
file,,,,-1,//server/,path,,,,,file:////server/path
file,,,,-1,///server/,path,,,,,file://///server/path
file://///server/path
file,,,,-1,///server/,path,,,,,file://///server/path
file,,,,-1,///server/,path,,,,,file://///server/path

Просмотреть файл

@ -1,43 +0,0 @@
# Any blank lines and those beginning with # are comments and
# ignored. To add additional test cases that could potentially
# break URL parsing in mozilla add the input URL on a new line
# and follow it with the expected output. Then run urltest on
# this file and hopefully the expected output should match the
# one from the program.
# - Gagan Saksena 03/28/00
http://username:password@hostname.com:80/pathname/./more/stuff/../path
http,username:password,hostname.com,80,,/pathname/more/path
username@host:8080/path
,username,host,8080,,/path
http://gagan/
http,,gagan,-1,,/
scheme:host/netlib
scheme,,host,-1,,/netlib
mailbox:///foo
mailbox,,,-1,,/foo
scheme:user@hostname.edu:80/pathname
scheme,user,hostname.edu,80,,/pathname
http://username:password@hostname:80/pathname
http,username:password,hostname,80,,/pathname
resource:/pathname
resource,,,-1,,/pathname
ftp://uname%here.com:pwd@there.com/aPath/a.html
ftp,uname%here.com:pwd,there.com,-1,,/aPath/a.html
http://www.inf.bme.hu?foo=bar
http,,www.inf.bme.hu,-1,foo=bar,/?foo=bar
http://test.com/aPath/a.html#/1/2
http,,test.com,-1,,/aPath/a.html#/1/2
http://user:pass@ipaddres:2/get?foo/something
http,user:pass,ipaddres,2,foo/something,/get?foo/something