xpcom/tests/TestStaticAtoms.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/xpcom/tests/TestStaticAtoms.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,75 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +#include "TestHarness.h"
     1.9 +#include "TestingAtoms.cpp"
    1.10 +#include "MoreTestingAtoms.cpp"
    1.11 +
    1.12 +int main(int argc, char** argv)
    1.13 +{
    1.14 +  ScopedXPCOM xpcom("TestStaticAtoms");
    1.15 +  if (xpcom.failed()) {
    1.16 +    return 1;
    1.17 +  }
    1.18 +
    1.19 +  TestingAtoms::AddRefAtoms();
    1.20 +
    1.21 +  NS_SealStaticAtomTable();
    1.22 +
    1.23 +  nsCOMPtr<nsIAtom> atom = do_GetAtom("foo");
    1.24 +  if (!atom) {
    1.25 +    fail("Didn't get an atom for foo.");
    1.26 +    return 1;
    1.27 +  }
    1.28 +  if (atom->IsStaticAtom()) {
    1.29 +    passed("foo is a static atom");
    1.30 +  } else {
    1.31 +    fail("foo is not a static atom.");
    1.32 +    return 1;
    1.33 +  }
    1.34 +  if (atom == TestingAtoms::foo) {
    1.35 +    passed("foo is the right pointer");
    1.36 +  } else {
    1.37 +    fail("foo was not the right pointer");
    1.38 +    return 1;
    1.39 +  }
    1.40 +  nsIAtom* staticAtom = NS_GetStaticAtom(NS_LITERAL_STRING("foo"));
    1.41 +  if (!staticAtom) {
    1.42 +    fail("Did not get a static atom for foo");
    1.43 +    return 1;
    1.44 +  }
    1.45 +
    1.46 +  if (atom == staticAtom) {
    1.47 +    passed("do_GetAtom and NS_GetStaticAtom returned the same atom.");
    1.48 +  } else {
    1.49 +    fail("do_GetAtom and NS_GetStaticAtom returned different atoms.");
    1.50 +    return 1;
    1.51 +  }
    1.52 +
    1.53 +  MoreTestingAtoms::AddRefAtoms();
    1.54 +  
    1.55 +  atom = do_GetAtom("qux");
    1.56 +  if (!atom) {
    1.57 +    fail("Didn't get an atom for qux.");
    1.58 +    return 1;
    1.59 +  }
    1.60 +  if (atom->IsStaticAtom()) {
    1.61 +    passed("qux is a static atom");
    1.62 +  } else {
    1.63 +    fail("qux is not a static atom.");
    1.64 +    return 1;
    1.65 +  }
    1.66 +  if (atom == MoreTestingAtoms::qux) {
    1.67 +    passed("qux is the right pointer");
    1.68 +  } else {
    1.69 +    fail("qux was not the right pointer");
    1.70 +    return 1;
    1.71 +  }
    1.72 +  staticAtom = NS_GetStaticAtom(NS_LITERAL_STRING("qux"));
    1.73 +  if (staticAtom) {
    1.74 +    fail("Got an atom for qux. The static atom table was not sealed properly.");
    1.75 +    return 1;
    1.76 +  }
    1.77 +  return 0;
    1.78 +}

mercurial