Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(168)

Unified Diff: webrtc/base/criticalsection_unittest.cc

Issue 1537923003: Fix pointer compare-and-swap on Windows. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: fix argument order Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webrtc/base/atomicops.h ('k') | webrtc/base/event_tracer.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/base/criticalsection_unittest.cc
diff --git a/webrtc/base/criticalsection_unittest.cc b/webrtc/base/criticalsection_unittest.cc
index ff4fdef9486f2a19ca83450c9175d205039e55de..85ef20dc409ae0e1bdaca5d476502e6ec5fac5f2 100644
--- a/webrtc/base/criticalsection_unittest.cc
+++ b/webrtc/base/criticalsection_unittest.cc
@@ -14,6 +14,7 @@
#include "webrtc/base/criticalsection.h"
#include "webrtc/base/event.h"
#include "webrtc/base/gunit.h"
+#include "webrtc/base/scoped_ptr.h"
#include "webrtc/base/scopedptrcollection.h"
#include "webrtc/base/thread.h"
#include "webrtc/test/testsupport/gtest_disable.h"
@@ -220,6 +221,28 @@ TEST(AtomicOpsTest, Simple) {
EXPECT_EQ(0, value);
}
+TEST(AtomicOpsTest, SimplePtr) {
+ class Foo {};
+ Foo* volatile foo = nullptr;
+ scoped_ptr<Foo> a(new Foo());
+ scoped_ptr<Foo> b(new Foo());
+ // Reading the initial value should work as expected.
+ EXPECT_TRUE(rtc::AtomicOps::AcquireLoadPtr(&foo) == nullptr);
+ // Setting using compare and swap should work.
+ EXPECT_TRUE(rtc::AtomicOps::CompareAndSwapPtr(
+ &foo, static_cast<Foo*>(nullptr), a.get()) == nullptr);
+ EXPECT_TRUE(rtc::AtomicOps::AcquireLoadPtr(&foo) == a.get());
+ // Setting another value but with the wrong previous pointer should fail
+ // (remain a).
+ EXPECT_TRUE(rtc::AtomicOps::CompareAndSwapPtr(
+ &foo, static_cast<Foo*>(nullptr), b.get()) == a.get());
+ EXPECT_TRUE(rtc::AtomicOps::AcquireLoadPtr(&foo) == a.get());
+ // Replacing a with b should work.
+ EXPECT_TRUE(rtc::AtomicOps::CompareAndSwapPtr(&foo, a.get(), b.get()) ==
+ a.get());
+ EXPECT_TRUE(rtc::AtomicOps::AcquireLoadPtr(&foo) == b.get());
+}
+
TEST(AtomicOpsTest, Increment) {
// Create and start lots of threads.
AtomicOpRunner<IncrementOp, UniqueValueVerifier> runner(0);
« no previous file with comments | « webrtc/base/atomicops.h ('k') | webrtc/base/event_tracer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698