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

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

Issue 2496913002: Fix more -Wsign-compare warnings in heap, mips, base, etc. (Closed)
Patch Set: Created 4 years, 1 month 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 | « test/cctest/test-global-handles.cc ('k') | test/unittests/heap/gc-tracer-unittest.cc » ('j') | 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/base/atomic-utils.h" 7 #include "src/base/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 base { 11 namespace base {
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(0U, 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(1U, 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(0U, 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 TEST(AtomicNumber, Decrement) { 61 TEST(AtomicNumber, Decrement) {
62 AtomicNumber<size_t> a(std::numeric_limits<size_t>::max()); 62 AtomicNumber<size_t> a(std::numeric_limits<size_t>::max());
63 a.Increment(1); 63 a.Increment(1);
64 EXPECT_EQ(0, a.Value()); 64 EXPECT_EQ(0u, a.Value());
65 a.Decrement(1); 65 a.Decrement(1);
66 EXPECT_EQ(std::numeric_limits<size_t>::max(), a.Value()); 66 EXPECT_EQ(std::numeric_limits<size_t>::max(), a.Value());
67 } 67 }
68 68
69 TEST(AtomicNumber, OperatorAdditionAssignment) { 69 TEST(AtomicNumber, OperatorAdditionAssignment) {
70 AtomicNumber<size_t> a(0u); 70 AtomicNumber<size_t> a(0u);
71 AtomicNumber<size_t> b(std::numeric_limits<size_t>::max()); 71 AtomicNumber<size_t> b(std::numeric_limits<size_t>::max());
72 a += b.Value(); 72 a += b.Value();
73 EXPECT_EQ(a.Value(), b.Value()); 73 EXPECT_EQ(a.Value(), b.Value());
74 EXPECT_EQ(b.Value(), std::numeric_limits<size_t>::max()); 74 EXPECT_EQ(b.Value(), std::numeric_limits<size_t>::max());
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 a.Add(kAA); 265 a.Add(kAA);
266 EXPECT_FALSE(a == b); 266 EXPECT_FALSE(a == b);
267 EXPECT_TRUE(a != b); 267 EXPECT_TRUE(a != b);
268 b.Add(kAA); 268 b.Add(kAA);
269 EXPECT_TRUE(a == b); 269 EXPECT_TRUE(a == b);
270 EXPECT_FALSE(a != b); 270 EXPECT_FALSE(a != b);
271 } 271 }
272 272
273 } // namespace base 273 } // namespace base
274 } // namespace v8 274 } // namespace v8
OLDNEW
« no previous file with comments | « test/cctest/test-global-handles.cc ('k') | test/unittests/heap/gc-tracer-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698