Index: webrtc/base/refcount_unittest.cc |
diff --git a/webrtc/base/refcount_unittest.cc b/webrtc/base/refcount_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..d21cb388ace5b23ee2062719ad031e400ce7457d |
--- /dev/null |
+++ b/webrtc/base/refcount_unittest.cc |
@@ -0,0 +1,62 @@ |
+/* |
+ * Copyright 2016 The WebRTC Project Authors. All rights reserved. |
+ * |
+ * Use of this source code is governed by a BSD-style license |
+ * that can be found in the LICENSE file in the root of the source |
+ * tree. An additional intellectual property rights grant can be found |
+ * in the file PATENTS. All contributing project authors may |
+ * be found in the AUTHORS file in the root of the source tree. |
+ */ |
+ |
+#include <string> |
+ |
+#include "webrtc/base/gunit.h" |
+#include "webrtc/base/refcount.h" |
+ |
+namespace rtc { |
+ |
+namespace { |
+ |
+class A { |
+ public: |
+ A() {} |
+ |
+ RTC_DISALLOW_COPY_AND_ASSIGN(A); |
tommi
2016/10/18 15:57:58
private
perkj_webrtc
2016/10/19 00:43:14
Done.
|
+}; |
+ |
+class Aref : public RefCountInterface { |
+ public: |
+ Aref() {} |
+ |
+ protected: |
+ virtual ~Aref() {} |
+}; |
+ |
+class Bref : public RefCountInterface { |
+ public: |
+ Bref(std::unique_ptr<A> a) : a_(std::move(a)) {} |
+ |
+ protected: |
+ virtual ~Bref() {} |
+ |
+ public: |
+ std::unique_ptr<A> a_; |
+}; |
+ |
+} // namespace |
+ |
+TEST(RefCountedObject, Basic) { |
+ scoped_refptr<RefCountedObject<Aref>> aref(new RefCountedObject<Aref>()); |
hbos
2016/10/18 17:50:04
Can you add more tests to make sure a constructor
perkj_webrtc
2016/10/19 00:43:14
done. Since we use pump we don't need to test all
|
+ EXPECT_TRUE(aref->HasOneRef()); |
+ EXPECT_EQ(2, aref->AddRef()); |
+ EXPECT_EQ(1, aref->Release()); |
+} |
+ |
+TEST(RefCountedObject, SupportRValuesInCtor) { |
+ std::unique_ptr<A> a(new A()); |
+ scoped_refptr<Bref> bref(new RefCountedObject<Bref>(std::move(a))); |
+ EXPECT_TRUE(bref->a_.get() != nullptr); |
+ EXPECT_TRUE(a.get() == nullptr); |
+} |
+ |
+} // namespace rtc |