xpcom/tests/TestStaticAtoms.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this
     3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     5 #include "TestHarness.h"
     6 #include "TestingAtoms.cpp"
     7 #include "MoreTestingAtoms.cpp"
     9 int main(int argc, char** argv)
    10 {
    11   ScopedXPCOM xpcom("TestStaticAtoms");
    12   if (xpcom.failed()) {
    13     return 1;
    14   }
    16   TestingAtoms::AddRefAtoms();
    18   NS_SealStaticAtomTable();
    20   nsCOMPtr<nsIAtom> atom = do_GetAtom("foo");
    21   if (!atom) {
    22     fail("Didn't get an atom for foo.");
    23     return 1;
    24   }
    25   if (atom->IsStaticAtom()) {
    26     passed("foo is a static atom");
    27   } else {
    28     fail("foo is not a static atom.");
    29     return 1;
    30   }
    31   if (atom == TestingAtoms::foo) {
    32     passed("foo is the right pointer");
    33   } else {
    34     fail("foo was not the right pointer");
    35     return 1;
    36   }
    37   nsIAtom* staticAtom = NS_GetStaticAtom(NS_LITERAL_STRING("foo"));
    38   if (!staticAtom) {
    39     fail("Did not get a static atom for foo");
    40     return 1;
    41   }
    43   if (atom == staticAtom) {
    44     passed("do_GetAtom and NS_GetStaticAtom returned the same atom.");
    45   } else {
    46     fail("do_GetAtom and NS_GetStaticAtom returned different atoms.");
    47     return 1;
    48   }
    50   MoreTestingAtoms::AddRefAtoms();
    52   atom = do_GetAtom("qux");
    53   if (!atom) {
    54     fail("Didn't get an atom for qux.");
    55     return 1;
    56   }
    57   if (atom->IsStaticAtom()) {
    58     passed("qux is a static atom");
    59   } else {
    60     fail("qux is not a static atom.");
    61     return 1;
    62   }
    63   if (atom == MoreTestingAtoms::qux) {
    64     passed("qux is the right pointer");
    65   } else {
    66     fail("qux was not the right pointer");
    67     return 1;
    68   }
    69   staticAtom = NS_GetStaticAtom(NS_LITERAL_STRING("qux"));
    70   if (staticAtom) {
    71     fail("Got an atom for qux. The static atom table was not sealed properly.");
    72     return 1;
    73   }
    74   return 0;
    75 }

mercurial