rdf/tests/triplescat/triplescat.cpp
author B2G Bumper Bot <release+b2gbumper@mozilla.com>
Tue, 22 Jul 2014 07:30:28 -0700
changeset 195548 b64b42abd5f8282c08fca7ba57a70d26dbda7165
parent 191792 682c3cd67254b1a4c8c7428d6d3c3102cfa764be
child 223398 e381d48c24353d9c0af822f977c331dab48ddd6e
permissions -rw-r--r--
Bumping gaia.json for 8 gaia revision(s) a=gaia-bump ======== https://hg.mozilla.org/integration/gaia-central/rev/383735049e86 Author: Ryan VanderMeulen <rvandermeulen@mozilla.com> Desc: Merge pull request #21846 from svic/Bug_1039239 Bug 1039239 - Better NFC handover error handling ======== https://hg.mozilla.org/integration/gaia-central/rev/b40b6117be3e Author: Arno Puder <arno@puder.org> Desc: Bug 1039239 - Better NFC handover error handling ======== https://hg.mozilla.org/integration/gaia-central/rev/8eba7c0e50e3 Author: Ryan VanderMeulen <rvandermeulen@mozilla.com> Desc: Merge pull request #21837 from guilherme-pg/bug1034088-offline Bug 1034088 - Display the proper Settings panel for Find My Device when offline. ======== https://hg.mozilla.org/integration/gaia-central/rev/a57845e709a3 Author: Guilherme Goncalves <guilherme.p.gonc@gmail.com> Desc: Bug 1034088 - Display the proper Settings panel for Find My Device when offline. ======== https://hg.mozilla.org/integration/gaia-central/rev/627a576d2058 Author: Ryan VanderMeulen <rvandermeulen@mozilla.com> Desc: Merge pull request #21688 from flodolo/bug892700 Bug 892700 - Display Developer options on 2 lines if necessary ======== https://hg.mozilla.org/integration/gaia-central/rev/d6fe3b318ec0 Author: Francesco Lodolo (:flod) <flod@lodolo.net> Desc: Bug 892700 - Display Developer options on 2 lines if necessary ======== https://hg.mozilla.org/integration/gaia-central/rev/70edf8c17539 Author: Andrew Halberstadt <halbersa@gmail.com> Desc: Merge pull request #21888 from ahal/python_service Create a python runner service to run integration tests on device ======== https://hg.mozilla.org/integration/gaia-central/rev/ff1e44c2f817 Author: Andrew Halberstadt <halbersa@gmail.com> Desc: Bug 994847 - Create a python runner service for integration tests, r=mdas

/* -*- Mode: C++; tab-width: 4; 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/. */

/**
 * A simple test program that reads in RDF/XML into an in-memory data
 * source, then serializes NTriples format back to stdout (or none).
 *
 * The program takes a single parameter: the URL from which to read,
 * plus an optional parameter -q
 */

#include <stdio.h>
#include "nsXPCOM.h"
#include "nsCOMPtr.h"
//#include "nsString.h"
#include "nsIComponentManager.h"
#include "nsComponentManagerUtils.h"
#include "nsServiceManagerUtils.h"
#include "nsThreadUtils.h"
#include "nsIIOService.h"
#include "nsIInputStream.h"
#include "nsIOutputStream.h"
#include "nsIRDFCompositeDataSource.h"
#include "nsIRDFNode.h"
#include "nsIRDFRemoteDataSource.h"
#include "nsIRDFService.h"
#include "nsIRDFXMLSource.h"
#include "nsIServiceManager.h"
#include "nsIStreamListener.h"
#include "nsIURL.h"
#include "nsRDFCID.h"
#include "plstr.h"
#include "prio.h"
#include "prthread.h"

#include "rdf.h"
#include "rdfIDataSource.h"
#include "rdfITripleVisitor.h"
#include "rdfISerializer.h"

////////////////////////////////////////////////////////////////////////
// Blatantly stolen from netwerk/test/
#define RETURN_IF_FAILED(rv, step) \
    PR_BEGIN_MACRO \
    if (NS_FAILED(rv)) { \
        printf(">>> %s failed: rv=%x\n", step, static_cast<uint32_t>(rv)); \
        return 1;\
    } \
    PR_END_MACRO

////////////////////////////////////////////////////////////////////////

class ConsoleOutputStreamImpl : public nsIOutputStream
{
protected:
    virtual ~ConsoleOutputStreamImpl(void) {}

public:
    ConsoleOutputStreamImpl(void) {}

    // nsISupports interface
    NS_DECL_ISUPPORTS

    // nsIOutputStream interface
    NS_IMETHOD Close(void) {
        return NS_OK;
    }

    NS_IMETHOD Write(const char* aBuf, uint32_t aCount, uint32_t *aWriteCount) {
        PR_Write(PR_GetSpecialFD(PR_StandardOutput), aBuf, aCount);
        *aWriteCount = aCount;
        return NS_OK;
    }

    NS_IMETHOD
    WriteFrom(nsIInputStream *inStr, uint32_t count, uint32_t *_retval) {
        NS_NOTREACHED("WriteFrom");
        return NS_ERROR_NOT_IMPLEMENTED;
    }

    NS_IMETHOD
    WriteSegments(nsReadSegmentFun reader, void * closure, uint32_t count, uint32_t *_retval) {
        NS_NOTREACHED("WriteSegments");
        return NS_ERROR_NOT_IMPLEMENTED;
    }

    NS_IMETHOD
    IsNonBlocking(bool *aNonBlocking) {
        NS_NOTREACHED("IsNonBlocking");
        return NS_ERROR_NOT_IMPLEMENTED;
    }

    NS_IMETHOD Flush(void) {
        PR_Sync(PR_GetSpecialFD(PR_StandardOutput));
        return NS_OK;
    }
};

NS_IMPL_ISUPPORTS(ConsoleOutputStreamImpl, nsIOutputStream)

////////////////////////////////////////////////////////////////////////

int
main(int argc, char** argv)
{
    nsresult rv;

    if (argc < 2) {
        fprintf(stderr, "usage: %s <url>\n", argv[0]);
        return 1;
    }

    NS_InitXPCOM2(nullptr, nullptr, nullptr);

    // Create a stream data source and initialize it on argv[1], which
    // is hopefully a "file:" URL.
    nsCOMPtr<nsIRDFDataSource> ds =
        do_CreateInstance(NS_RDF_DATASOURCE_CONTRACTID_PREFIX "xml-datasource",
                          &rv);
    RETURN_IF_FAILED(rv, "RDF/XML datasource creation");

    nsCOMPtr<nsIRDFRemoteDataSource> remote = do_QueryInterface(ds, &rv);
    RETURN_IF_FAILED(rv, "QI to nsIRDFRemoteDataSource");

    rv = remote->Init(argv[1]);
    RETURN_IF_FAILED(rv, "datasource initialization");

    // Okay, this should load the XML file...
    rv = remote->Refresh(false);
    RETURN_IF_FAILED(rv, "datasource refresh");

    // Pump events until the load is finished
    nsCOMPtr<nsIThread> thread = do_GetCurrentThread();
    bool done = false;
    while (!done) {
        NS_ENSURE_TRUE(NS_ProcessNextEvent(thread), 1);
        remote->GetLoaded(&done);
    }

    nsCOMPtr<rdfIDataSource> rdfds = do_QueryInterface(ds, &rv);
    RETURN_IF_FAILED(rv, "QI to rdIDataSource");
    {
        nsCOMPtr<nsIOutputStream> out = new ConsoleOutputStreamImpl();
        nsCOMPtr<rdfISerializer> ser =
            do_CreateInstance(NS_RDF_SERIALIZER "ntriples", &rv);
        RETURN_IF_FAILED(rv, "Creation of NTriples Serializer");
        rv = ser->Serialize(rdfds, out);
        RETURN_IF_FAILED(rv, "Serialization to NTriples");
        out->Close();
    }

    return 0;
}