LCOV - code coverage report
Current view: top level - dom/xslt/xpath - txNameTest.cpp (source / functions) Hit Total Coverage
Test: output.info Lines: 0 50 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 6 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /* This Source Code Form is subject to the terms of the Mozilla Public
       3             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       4             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
       5             : 
       6             : #include "txExpr.h"
       7             : #include "nsIAtom.h"
       8             : #include "nsGkAtoms.h"
       9             : #include "txXPathTreeWalker.h"
      10             : #include "txIXPathContext.h"
      11             : 
      12           0 : txNameTest::txNameTest(nsIAtom* aPrefix, nsIAtom* aLocalName, int32_t aNSID,
      13           0 :                        uint16_t aNodeType)
      14             :     :mPrefix(aPrefix), mLocalName(aLocalName), mNamespace(aNSID),
      15           0 :      mNodeType(aNodeType)
      16             : {
      17           0 :     if (aPrefix == nsGkAtoms::_empty)
      18           0 :         mPrefix = nullptr;
      19           0 :     NS_ASSERTION(aLocalName, "txNameTest without a local name?");
      20           0 :     NS_ASSERTION(aNodeType == txXPathNodeType::DOCUMENT_NODE ||
      21             :                  aNodeType == txXPathNodeType::ELEMENT_NODE ||
      22             :                  aNodeType == txXPathNodeType::ATTRIBUTE_NODE,
      23             :                  "Go fix txNameTest::matches");
      24           0 : }
      25             : 
      26             : nsresult
      27           0 : txNameTest::matches(const txXPathNode& aNode, txIMatchContext* aContext,
      28             :                     bool& aMatched)
      29             : {
      30           0 :     if ((mNodeType == txXPathNodeType::ELEMENT_NODE &&
      31           0 :          !txXPathNodeUtils::isElement(aNode)) ||
      32           0 :         (mNodeType == txXPathNodeType::ATTRIBUTE_NODE &&
      33           0 :          !txXPathNodeUtils::isAttribute(aNode)) ||
      34           0 :         (mNodeType == txXPathNodeType::DOCUMENT_NODE &&
      35           0 :          !txXPathNodeUtils::isRoot(aNode))) {
      36           0 :         aMatched = false;
      37           0 :         return NS_OK;
      38             :     }
      39             : 
      40             :     // Totally wild?
      41           0 :     if (mLocalName == nsGkAtoms::_asterisk && !mPrefix) {
      42           0 :         aMatched = true;
      43           0 :         return NS_OK;
      44             :     }
      45             : 
      46             :     // Compare namespaces
      47           0 :     if (mNamespace != txXPathNodeUtils::getNamespaceID(aNode)
      48           0 :         && !(mNamespace == kNameSpaceID_None &&
      49           0 :              txXPathNodeUtils::isHTMLElementInHTMLDocument(aNode))
      50             :        ) {
      51           0 :         aMatched = false;
      52           0 :         return NS_OK;
      53             :     }
      54             : 
      55             :     // Name wild?
      56           0 :     if (mLocalName == nsGkAtoms::_asterisk) {
      57           0 :         aMatched = true;
      58           0 :         return NS_OK;
      59             :     }
      60             : 
      61             :     // Compare local-names
      62           0 :     aMatched = txXPathNodeUtils::localNameEquals(aNode, mLocalName);
      63           0 :     return NS_OK;
      64             : }
      65             : 
      66             : /*
      67             :  * Returns the default priority of this txNodeTest
      68             :  */
      69           0 : double txNameTest::getDefaultPriority()
      70             : {
      71           0 :     if (mLocalName == nsGkAtoms::_asterisk) {
      72           0 :         if (!mPrefix)
      73           0 :             return -0.5;
      74           0 :         return -0.25;
      75             :     }
      76           0 :     return 0;
      77             : }
      78             : 
      79             : txNodeTest::NodeTestType
      80           0 : txNameTest::getType()
      81             : {
      82           0 :     return NAME_TEST;
      83             : }
      84             : 
      85             : bool
      86           0 : txNameTest::isSensitiveTo(Expr::ContextSensitivity aContext)
      87             : {
      88           0 :     return !!(aContext & Expr::NODE_CONTEXT);
      89             : }
      90             : 
      91             : #ifdef TX_TO_STRING
      92             : void
      93           0 : txNameTest::toString(nsAString& aDest)
      94             : {
      95           0 :     if (mPrefix) {
      96           0 :         nsAutoString prefix;
      97           0 :         mPrefix->ToString(prefix);
      98           0 :         aDest.Append(prefix);
      99           0 :         aDest.Append(char16_t(':'));
     100             :     }
     101           0 :     nsAutoString localName;
     102           0 :     mLocalName->ToString(localName);
     103           0 :     aDest.Append(localName);
     104           0 : }
     105             : #endif

Generated by: LCOV version 1.13