1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 // vim:cindent:ts=4: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/. */
8 #include "TestHarness.h"
10 #define TEST(aCondition, aMsg) \
11 if (!(aCondition)) { fail("TestAutoRef: "#aMsg); exit(1); }
15 TestObjectA() : mRefCnt(0) {
19 TEST(mRefCnt
== 0, "mRefCnt in destructor");
27 class nsAutoRefTraits
<TestObjectA
> : public nsPointerRefTraits
<TestObjectA
>
30 static int mTotalRefsCnt
;
32 static void Release(TestObjectA
*ptr
) {
34 if (ptr
->mRefCnt
== 0) {
39 static void AddRef(TestObjectA
*ptr
) {
44 int nsAutoRefTraits
<TestObjectA
>::mTotalRefsCnt
= 0;
49 nsCountedRef
<TestObjectA
> a(new TestObjectA());
50 TEST(a
->mRefCnt
== 1, "nsCountedRef instantiation with valid RawRef");
52 nsCountedRef
<TestObjectA
> b
;
53 TEST(b
.get() == nullptr, "nsCountedRef instantiation with invalid RawRef");
56 TEST(b
->mRefCnt
, "nsAutoRef::swap() t1");
57 TEST(a
.get() == nullptr, "nsAutoRef::swap() t2");
60 TEST(true, "All tests pass");