Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Functions | Variables
TestJarCache.cpp File Reference
#include "nsISupports.h"
#include "nsIServiceManager.h"
#include "nsCRT.h"
#include "nsMemory.h"
#include "nsAutoLock.h"
#include "nsIRunnable.h"
#include "nsIThread.h"
#include "nsIZipReader.h"
#include "nsILocalFile.h"
#include <stdio.h>
#include <stdlib.h>

Go to the source code of this file.

Classes

class  TestThread

Defines

#define ZIP_COUNT   8
#define CACHE_SIZE   4
#define THREAD_COUNT   6
#define THREAD_LOOP_COUNT   1000

Functions

static nsIZipReaderGetZipReader (nsILocalFile *file)
int main (int argc, char **argv)
 The Xalan testcases app.

Variables

static char ** filenames
static nsCOMPtr< nsILocalFilefiles [ZIP_COUNT]
static const char gCacheContractID [] = "@mozilla.org/libjar/zip-reader-cache;1"
static const PRUint32 gCacheSize = 4
nsCOMPtr< nsIZipReaderCachegCache = nsnull

Define Documentation

#define CACHE_SIZE   4

Definition at line 64 of file TestJarCache.cpp.

Definition at line 65 of file TestJarCache.cpp.

Definition at line 66 of file TestJarCache.cpp.

#define ZIP_COUNT   8

Definition at line 63 of file TestJarCache.cpp.


Function Documentation

static nsIZipReader* GetZipReader ( nsILocalFile file) [static]

Definition at line 75 of file TestJarCache.cpp.

{
    if(!gCache)
    {
        gCache = do_CreateInstance(gCacheContractID);
        if(!gCache || NS_FAILED(gCache->Init(CACHE_SIZE)))
            return nsnull;
    }

    nsIZipReader* reader = nsnull;

    if(!file || NS_FAILED(gCache->GetZip(file, &reader)))
        return nsnull;

    return reader;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int main ( int  argc,
char **  argv 
)

The Xalan testcases app.

Definition at line 155 of file TestJarCache.cpp.

{
    nsresult rv;
    int i;

    if (ZIP_COUNT != (argc - 1)) 
    {
        printf("usage: TestJarCache ");
        for ( i = 0; i < ZIP_COUNT; i++)
            printf("file%1d ",i + 1);
        printf("\n");
        return 1;
    }
    filenames = argv + 1;

    rv = NS_InitXPCOM2(nsnull, nsnull, nsnull);
    if(NS_FAILED(rv)) 
    {
        printf("NS_InitXPCOM failed!\n");
        return 1;
    }

    // construct the cache
    nsIZipReader* bogus = GetZipReader(nsnull);


    for(i = 0; i < ZIP_COUNT; i++)
    {
        PRBool exists;
        rv = NS_NewLocalFile(filenames[i], PR_FALSE, getter_AddRefs(files[i]));
        if(NS_FAILED(rv) || NS_FAILED(files[i]->Exists(&exists)) || !exists) 
        {   
            printf("Couldn't find %s\n", filenames[i]);
            return 1;
        }
    }

    nsCOMPtr<nsIThread> threads[THREAD_COUNT];

    for(i = 0; i < THREAD_COUNT; i++)
    {
        rv = NS_NewThread(getter_AddRefs(threads[i]),
                          new TestThread(), 
                          0, PR_JOINABLE_THREAD);
        if(NS_FAILED(rv)) 
        {
            printf("NS_NewThread failed!\n");
            return 1;
        }
        PR_Sleep(10);
    }

    printf("all threads created\n");

    for(i = 0; i < THREAD_COUNT; i++)
    {
        if(threads[i])
        {
            threads[i]->Join();
            threads[i] = nsnull;
        }
    }

    for(i = 0; i < ZIP_COUNT; i++)
        files[i] = nsnull;

    // kill the cache
    gCache = nsnull;

    rv = NS_ShutdownXPCOM(nsnull);
    if(NS_FAILED(rv)) 
    {
        printf("NS_ShutdownXPCOM failed!\n");
        return 1;
    }

    printf("done\n");

    return 0;
}    

Here is the call graph for this function:


Variable Documentation

char** filenames [static]

Definition at line 61 of file TestJarCache.cpp.

Definition at line 68 of file TestJarCache.cpp.

Definition at line 73 of file TestJarCache.cpp.

const char gCacheContractID[] = "@mozilla.org/libjar/zip-reader-cache;1" [static]

Definition at line 70 of file TestJarCache.cpp.

const PRUint32 gCacheSize = 4 [static]

Definition at line 71 of file TestJarCache.cpp.