Bug 846687 - Set the transport as non-seekable if the server sends Accept-Ranges...
[gecko.git] / xpcom / tests / TestAutoRef.cpp
blob744a80065fd9f2354c3202aa51ddc52eb7fc0d9a
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/. */
7 #include "nsAutoRef.h"
8 #include "TestHarness.h"
10 #define TEST(aCondition, aMsg) \
11 if (!(aCondition)) { fail("TestAutoRef: "#aMsg); exit(1); }
13 struct TestObjectA {
14 public:
15 TestObjectA() : mRefCnt(0) {
18 ~TestObjectA() {
19 TEST(mRefCnt == 0, "mRefCnt in destructor");
22 public:
23 int mRefCnt;
26 template <>
27 class nsAutoRefTraits<TestObjectA> : public nsPointerRefTraits<TestObjectA>
29 public:
30 static int mTotalRefsCnt;
32 static void Release(TestObjectA *ptr) {
33 ptr->mRefCnt--;
34 if (ptr->mRefCnt == 0) {
35 delete ptr;
39 static void AddRef(TestObjectA *ptr) {
40 ptr->mRefCnt++;
44 int nsAutoRefTraits<TestObjectA>::mTotalRefsCnt = 0;
46 int main()
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");
55 a.swap(b);
56 TEST(b->mRefCnt, "nsAutoRef::swap() t1");
57 TEST(a.get() == nullptr, "nsAutoRef::swap() t2");
60 TEST(true, "All tests pass");
61 return 0;