layout/style/test/ParseCSS.cpp

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)

     1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
     2 // vim:cindent:ts=8:et:sw=4:
     3 /* This Source Code Form is subject to the terms of the Mozilla Public
     4  * License, v. 2.0. If a copy of the MPL was not distributed with this
     5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     7 /*
     8  * This file is meant to be used with |#define CSS_REPORT_PARSE_ERRORS|
     9  * in mozilla/content/html/style/src/nsCSSScanner.h uncommented, and the
    10  * |#ifdef DEBUG| block in nsCSSScanner::OutputError (in
    11  * nsCSSScanner.cpp in the same directory) used (even if not a debug
    12  * build).
    13  */
    15 #include "nsXPCOM.h"
    16 #include "nsCOMPtr.h"
    18 #include "nsIFile.h"
    19 #include "nsNetUtil.h"
    21 #include "nsContentCID.h"
    22 #include "mozilla/css/Loader.h"
    23 #include "nsCSSStyleSheet.h"
    25 static already_AddRefed<nsIURI>
    26 FileToURI(const char *aFilename, nsresult *aRv = 0)
    27 {
    28     nsCOMPtr<nsIFile> lf(do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, aRv));
    29     NS_ENSURE_TRUE(lf, nullptr);
    30     // XXX Handle relative paths somehow.
    31     lf->InitWithNativePath(nsDependentCString(aFilename));
    33     nsIURI *uri = nullptr;
    34     nsresult rv = NS_NewFileURI(&uri, lf);
    35     if (aRv)
    36         *aRv = rv;
    37     return uri;
    38 }
    40 static int
    41 ParseCSSFile(nsIURI *aSheetURI)
    42 {
    43     nsRefPtr<mozilla::css::Loader> = new mozilla::css::Loader();
    44     nsRefPtr<nsCSSStyleSheet> sheet;
    45     loader->LoadSheetSync(aSheetURI, getter_AddRefs(sheet));
    46     NS_ASSERTION(sheet, "sheet load failed");
    47     /* This can happen if the file can't be found (e.g. you
    48      * ask for a relative path and xpcom/io rejects it)
    49      */
    50     if (!sheet)
    51         return -1;
    52     bool complete;
    53     sheet->GetComplete(complete);
    54     NS_ASSERTION(complete, "synchronous load did not complete");
    55     if (!complete)
    56         return -2;
    57     return 0;
    58 }
    60 int main(int argc, char** argv)
    61 {
    62     if (argc < 2) {
    63         fprintf(stderr, "%s [FILE]...\n", argv[0]);
    64     }
    65     nsresult rv = NS_InitXPCOM2(nullptr, nullptr, nullptr);
    66     if (NS_FAILED(rv))
    67         return (int)rv;
    69     int res = 0;
    70     for (int i = 1; i < argc; ++i) {
    71         const char *filename = argv[i];
    73         printf("\nParsing %s.\n", filename);
    75         nsCOMPtr<nsIURI> uri = FileToURI(filename, &rv);
    76         if (rv == NS_ERROR_OUT_OF_MEMORY) {
    77             fprintf(stderr, "Out of memory.\n");
    78             return 1;
    79         }
    80         if (uri)
    81             res = ParseCSSFile(uri);
    82     }
    84     NS_ShutdownXPCOM(nullptr);
    86     return res;
    87 }

mercurial