예제 #1
0
int
main(int argc, char* argv[])
{
    nsresult rv;
    {
        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);

        NS_ASSERTION(NS_SUCCEEDED(rv), "AutoregisterComponents failed");

        if (argc < 2) {
            printf("usage: %s resource://foo/<path-to-resolve>\n", argv[0]);
            return -1;
        }

        rv = SetupMapping();
        NS_ASSERTION(NS_SUCCEEDED(rv), "SetupMapping failed");
        if (NS_FAILED(rv)) return rv;

        rv = TestOpenInputStream(argv[1]);
        NS_ASSERTION(NS_SUCCEEDED(rv), "TestOpenInputStream failed");

        rv = TestAsyncRead(argv[1]);
        NS_ASSERTION(NS_SUCCEEDED(rv), "TestAsyncRead failed");
    } // 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 rv;
}
예제 #2
0
int
main(int argc, char* argv[])
{
    nsresult rv;

#if defined(PR_LOGGING)
    gTestFileTransportLog = PR_NewLogModule("TestFileTransport");
#endif

    if (argc < 2) {
        printf("usage: %s <file-to-read>\n", argv[0]);
        return -1;
    }
    char* fileName = argv[1];
    {
        nsCOMPtr<nsIServiceManager> servMan;
        NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull);
        nsCOMPtr<nsIComponentRegistrar> registrar = do_QueryInterface(servMan);
        NS_ASSERTION(registrar, "Null nsIComponentRegistrar");
        if (registrar)
            registrar->AutoRegister(nsnull);

        nsCOMPtr<nsIEventQueueService> eventQService =
                 do_GetService(kEventQueueServiceCID, &rv);
        if (NS_FAILED(rv)) return rv;

        rv = eventQService->GetThreadEventQueue(NS_CURRENT_THREAD, &gEventQ);
        if (NS_FAILED(rv)) return rv;

        rv = TestAsyncRead(fileName, 0, -1);
        NS_ASSERTION(NS_SUCCEEDED(rv), "TestAsyncRead failed");

        rv = TestAsyncWrite(fileName, 0, -1);
        NS_ASSERTION(NS_SUCCEEDED(rv), "TestAsyncWrite failed");

        rv = TestAsyncRead(fileName, 10, 100);
        NS_ASSERTION(NS_SUCCEEDED(rv), "TestAsyncRead failed");

        NS_RELEASE(gEventQ);
    } // this scopes the nsCOMPtrs
    // no nsCOMPtrs are allowed to be alive when you call NS_ShutdownXPCOM
    rv = NS_ShutdownXPCOM(nsnull);
    NS_ASSERTION(NS_SUCCEEDED(rv), "NS_ShutdownXPCOM failed");
    return NS_OK;
}