OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <limits.h> | 5 #include <limits.h> |
6 | 6 |
7 #include "src/atomic-utils.h" | 7 #include "src/atomic-utils.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 | 9 |
10 namespace v8 { | 10 namespace v8 { |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 TEST(AtomicValue, TrySetValue) { | 79 TEST(AtomicValue, TrySetValue) { |
80 AtomicValue<TestFlag> a(kA); | 80 AtomicValue<TestFlag> a(kA); |
81 EXPECT_FALSE(a.TrySetValue(kB, kC)); | 81 EXPECT_FALSE(a.TrySetValue(kB, kC)); |
82 EXPECT_TRUE(a.TrySetValue(kA, kC)); | 82 EXPECT_TRUE(a.TrySetValue(kA, kC)); |
83 EXPECT_EQ(TestFlag::kC, a.Value()); | 83 EXPECT_EQ(TestFlag::kC, a.Value()); |
84 } | 84 } |
85 | 85 |
86 | 86 |
87 TEST(AtomicValue, SetValue) { | 87 TEST(AtomicValue, SetValue) { |
88 AtomicValue<TestFlag> a(kB); | 88 AtomicValue<TestFlag> a(kB); |
89 EXPECT_EQ(kB, a.SetValue(kC)); | 89 a.SetValue(kC); |
90 EXPECT_EQ(TestFlag::kC, a.Value()); | 90 EXPECT_EQ(TestFlag::kC, a.Value()); |
91 } | 91 } |
92 | 92 |
93 | 93 |
94 TEST(AtomicValue, WithVoidStar) { | 94 TEST(AtomicValue, WithVoidStar) { |
95 AtomicValue<void*> a(nullptr); | 95 AtomicValue<void*> a(nullptr); |
96 AtomicValue<void*> dummy(nullptr); | 96 AtomicValue<void*> dummy(nullptr); |
97 EXPECT_EQ(nullptr, a.Value()); | 97 EXPECT_EQ(nullptr, a.Value()); |
98 EXPECT_EQ(nullptr, a.SetValue(&a)); | 98 a.SetValue(&a); |
99 EXPECT_EQ(&a, a.Value()); | 99 EXPECT_EQ(&a, a.Value()); |
100 EXPECT_FALSE(a.TrySetValue(nullptr, &dummy)); | 100 EXPECT_FALSE(a.TrySetValue(nullptr, &dummy)); |
101 EXPECT_TRUE(a.TrySetValue(&a, &dummy)); | 101 EXPECT_TRUE(a.TrySetValue(&a, &dummy)); |
102 EXPECT_EQ(&dummy, a.Value()); | 102 EXPECT_EQ(&dummy, a.Value()); |
103 } | 103 } |
104 | 104 |
105 | 105 |
106 namespace { | 106 namespace { |
107 | 107 |
108 enum TestSetValue { kAA, kBB, kCC, kLastValue = kCC }; | 108 enum TestSetValue { kAA, kBB, kCC, kLastValue = kCC }; |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 a.Add(kAA); | 208 a.Add(kAA); |
209 EXPECT_FALSE(a == b); | 209 EXPECT_FALSE(a == b); |
210 EXPECT_TRUE(a != b); | 210 EXPECT_TRUE(a != b); |
211 b.Add(kAA); | 211 b.Add(kAA); |
212 EXPECT_TRUE(a == b); | 212 EXPECT_TRUE(a == b); |
213 EXPECT_FALSE(a != b); | 213 EXPECT_FALSE(a != b); |
214 } | 214 } |
215 | 215 |
216 } // namespace internal | 216 } // namespace internal |
217 } // namespace v8 | 217 } // namespace v8 |
OLD | NEW |