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

Side by Side Diff: test/unittests/atomic-utils-unittest.cc

Issue 1322693004: Fix a -Wsign-compare error under GCC 4.9.2. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 3 months 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 {
11 namespace internal { 11 namespace internal {
12 12
13 TEST(AtomicNumber, Constructor) { 13 TEST(AtomicNumber, Constructor) {
14 // Test some common types. 14 // Test some common types.
15 AtomicNumber<int> zero_int; 15 AtomicNumber<int> zero_int;
16 AtomicNumber<size_t> zero_size_t; 16 AtomicNumber<size_t> zero_size_t;
17 AtomicNumber<intptr_t> zero_intptr_t; 17 AtomicNumber<intptr_t> zero_intptr_t;
18 EXPECT_EQ(0, zero_int.Value()); 18 EXPECT_EQ(0, zero_int.Value());
19 EXPECT_EQ(0, zero_size_t.Value()); 19 EXPECT_EQ(0U, zero_size_t.Value());
20 EXPECT_EQ(0, zero_intptr_t.Value()); 20 EXPECT_EQ(0, zero_intptr_t.Value());
21 } 21 }
22 22
23 23
24 TEST(AtomicNumber, Value) { 24 TEST(AtomicNumber, Value) {
25 AtomicNumber<int> a(1); 25 AtomicNumber<int> a(1);
26 EXPECT_EQ(1, a.Value()); 26 EXPECT_EQ(1, a.Value());
27 AtomicNumber<int> b(-1); 27 AtomicNumber<int> b(-1);
28 EXPECT_EQ(-1, b.Value()); 28 EXPECT_EQ(-1, b.Value());
29 AtomicNumber<size_t> c(1); 29 AtomicNumber<size_t> c(1);
30 EXPECT_EQ(1, c.Value()); 30 EXPECT_EQ(1U, c.Value());
31 AtomicNumber<size_t> d(static_cast<size_t>(-1)); 31 AtomicNumber<size_t> d(static_cast<size_t>(-1));
32 EXPECT_EQ(std::numeric_limits<size_t>::max(), d.Value()); 32 EXPECT_EQ(std::numeric_limits<size_t>::max(), d.Value());
33 } 33 }
34 34
35 35
36 TEST(AtomicNumber, SetValue) { 36 TEST(AtomicNumber, SetValue) {
37 AtomicNumber<int> a(1); 37 AtomicNumber<int> a(1);
38 a.SetValue(-1); 38 a.SetValue(-1);
39 EXPECT_EQ(-1, a.Value()); 39 EXPECT_EQ(-1, a.Value());
40 } 40 }
41 41
42 42
43 TEST(AtomicNumber, Increment) { 43 TEST(AtomicNumber, Increment) {
44 AtomicNumber<int> a(std::numeric_limits<int>::max()); 44 AtomicNumber<int> a(std::numeric_limits<int>::max());
45 a.Increment(1); 45 a.Increment(1);
46 EXPECT_EQ(std::numeric_limits<int>::min(), a.Value()); 46 EXPECT_EQ(std::numeric_limits<int>::min(), a.Value());
47 // Check that potential signed-ness of the underlying storage has no impact 47 // Check that potential signed-ness of the underlying storage has no impact
48 // on unsigned types. 48 // on unsigned types.
49 AtomicNumber<size_t> b(std::numeric_limits<intptr_t>::max()); 49 AtomicNumber<size_t> b(std::numeric_limits<intptr_t>::max());
50 b.Increment(1); 50 b.Increment(1);
51 EXPECT_EQ(static_cast<size_t>(std::numeric_limits<intptr_t>::max()) + 1, 51 EXPECT_EQ(static_cast<size_t>(std::numeric_limits<intptr_t>::max()) + 1,
52 b.Value()); 52 b.Value());
53 // Should work as decrement as well. 53 // Should work as decrement as well.
54 AtomicNumber<size_t> c(1); 54 AtomicNumber<size_t> c(1);
55 c.Increment(-1); 55 c.Increment(-1);
56 EXPECT_EQ(0, c.Value()); 56 EXPECT_EQ(0U, c.Value());
57 c.Increment(-1); 57 c.Increment(-1);
58 EXPECT_EQ(std::numeric_limits<size_t>::max(), c.Value()); 58 EXPECT_EQ(std::numeric_limits<size_t>::max(), c.Value());
59 } 59 }
60 60
61 61
62 namespace { 62 namespace {
63 63
64 enum TestFlag { 64 enum TestFlag {
65 kA, 65 kA,
66 kB, 66 kB,
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698