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

Side by Side Diff: mojo/edk/system/channel_endpoint_id_unittest.cc

Issue 649303002: Mojo: Add a "remote" channel endpoint ID generator. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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 | « mojo/edk/system/channel_endpoint_id.cc ('k') | 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 Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium 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 "mojo/edk/system/channel_endpoint_id.h" 5 #include "mojo/edk/system/channel_endpoint_id.h"
6 6
7 #include <sstream> 7 #include <sstream>
8 8
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
(...skipping 12 matching lines...) Expand all
23 EXPECT_FALSE(invalid != invalid); 23 EXPECT_FALSE(invalid != invalid);
24 EXPECT_FALSE(bootstrap != bootstrap); 24 EXPECT_FALSE(bootstrap != bootstrap);
25 EXPECT_NE(invalid, bootstrap); 25 EXPECT_NE(invalid, bootstrap);
26 26
27 EXPECT_FALSE(invalid < invalid); 27 EXPECT_FALSE(invalid < invalid);
28 EXPECT_LT(invalid, bootstrap); 28 EXPECT_LT(invalid, bootstrap);
29 29
30 EXPECT_FALSE(invalid.is_valid()); 30 EXPECT_FALSE(invalid.is_valid());
31 EXPECT_TRUE(bootstrap.is_valid()); 31 EXPECT_TRUE(bootstrap.is_valid());
32 32
33 EXPECT_FALSE(invalid.is_remotely_allocated()); 33 EXPECT_FALSE(invalid.is_remote());
34 EXPECT_FALSE(bootstrap.is_remotely_allocated()); 34 EXPECT_FALSE(bootstrap.is_remote());
35 35
36 // Test assignment. 36 // Test assignment.
37 ChannelEndpointId copy; 37 ChannelEndpointId copy;
38 copy = bootstrap; 38 copy = bootstrap;
39 EXPECT_EQ(copy, bootstrap); 39 EXPECT_EQ(copy, bootstrap);
40 copy = invalid; 40 copy = invalid;
41 EXPECT_EQ(copy, invalid); 41 EXPECT_EQ(copy, invalid);
42 } 42 }
43 43
44 // Tests values of invalid and bootstrap IDs. (This tests implementation 44 // Tests values of invalid and bootstrap IDs. (This tests implementation
(...skipping 18 matching lines...) Expand all
63 } 63 }
64 64
65 TEST(LocalChannelEndpointIdGeneratorTest, Basic) { 65 TEST(LocalChannelEndpointIdGeneratorTest, Basic) {
66 LocalChannelEndpointIdGenerator gen; 66 LocalChannelEndpointIdGenerator gen;
67 67
68 ChannelEndpointId id1; 68 ChannelEndpointId id1;
69 EXPECT_FALSE(id1.is_valid()); // Check sanity. 69 EXPECT_FALSE(id1.is_valid()); // Check sanity.
70 70
71 id1 = gen.GetNext(); 71 id1 = gen.GetNext();
72 EXPECT_TRUE(id1.is_valid()); 72 EXPECT_TRUE(id1.is_valid());
73 EXPECT_FALSE(id1.is_remote());
73 74
74 EXPECT_EQ(id1, ChannelEndpointId::GetBootstrap()); 75 EXPECT_EQ(ChannelEndpointId::GetBootstrap().value(), id1.value());
75 76
76 ChannelEndpointId id2 = gen.GetNext(); 77 ChannelEndpointId id2 = gen.GetNext();
77 EXPECT_TRUE(id2.is_valid()); 78 EXPECT_TRUE(id2.is_valid());
79 EXPECT_FALSE(id2.is_remote());
78 // Technically, nonequality here is an implementation detail, since, e.g., 80 // Technically, nonequality here is an implementation detail, since, e.g.,
79 // random generation of IDs would be a valid implementation. 81 // random generation of IDs would be a valid implementation.
80 EXPECT_NE(id2, id1); 82 EXPECT_NE(id2, id1);
81 // ... but right now we just increment to generate IDs. 83 // ... but right now we just increment to generate IDs.
82 EXPECT_EQ(2u, id2.value()); 84 EXPECT_EQ(2u, id2.value());
83 } 85 }
84 86
87 // Note: LocalChannelEndpointIdGeneratorTest.WrapAround is defined further
88 // below, outside the anonymous namespace.
89
90 TEST(RemoteChannelEndpointIdGeneratorTest, Basic) {
91 RemoteChannelEndpointIdGenerator gen;
92
93 ChannelEndpointId id1;
94 EXPECT_FALSE(id1.is_valid()); // Check sanity.
95
96 id1 = gen.GetNext();
97 EXPECT_TRUE(id1.is_valid());
98 EXPECT_TRUE(id1.is_remote());
99
100 // This tests an implementation detail.
101 EXPECT_EQ(ChannelEndpointId::kRemoteFlag, id1.value());
102
103 ChannelEndpointId id2 = gen.GetNext();
104 EXPECT_TRUE(id2.is_valid());
105 EXPECT_TRUE(id2.is_remote());
106 // Technically, nonequality here is an implementation detail, since, e.g.,
107 // random generation of IDs would be a valid implementation.
108 EXPECT_NE(id2, id1);
109 // ... but right now we just increment to generate IDs.
110 EXPECT_EQ(ChannelEndpointId::kRemoteFlag + 1, id2.value());
111 }
112
113 // Note: RemoteChannelEndpointIdGeneratorTest.WrapAround is defined further
114 // below, outside the anonymous namespace.
115
85 } // namespace 116 } // namespace
86 117
87 // Tests that the generator handles wrap-around correctly. (This tests 118 // Tests that |LocalChannelEndpointIdGenerator| handles wrap-around correctly.
88 // implementation details.) This test isn't in an anonymous namespace, since 119 // (This tests implementation details.) This test isn't in an anonymous
89 // it needs to be friended. 120 // namespace, since it needs to be friended.
90 TEST(LocalChannelEndpointIdGeneratorTest, WrapAround) { 121 TEST(LocalChannelEndpointIdGeneratorTest, WrapAround) {
91 LocalChannelEndpointIdGenerator gen; 122 LocalChannelEndpointIdGenerator gen;
92 gen.next_channel_endpoint_id_.value_ = 123 gen.next_ = ChannelEndpointId(ChannelEndpointId::kRemoteFlag - 1);
93 ChannelEndpointId::kRemotelyAllocatedFlag - 1;
94 124
95 ChannelEndpointId id = gen.GetNext(); 125 ChannelEndpointId id = gen.GetNext();
96 EXPECT_TRUE(id.is_valid()); 126 EXPECT_TRUE(id.is_valid());
97 EXPECT_FALSE(id.is_remotely_allocated()); 127 EXPECT_FALSE(id.is_remote());
98 EXPECT_EQ(ChannelEndpointId::kRemotelyAllocatedFlag - 1, id.value()); 128 EXPECT_EQ(ChannelEndpointId::kRemoteFlag - 1, id.value());
99 129
100 id = gen.GetNext(); 130 id = gen.GetNext();
101 EXPECT_TRUE(id.is_valid()); 131 EXPECT_TRUE(id.is_valid());
102 EXPECT_FALSE(id.is_remotely_allocated()); 132 EXPECT_FALSE(id.is_remote());
103 EXPECT_EQ(1u, id.value()); 133 EXPECT_EQ(1u, id.value());
104 } 134 }
105 135
136 // Tests that |RemoteChannelEndpointIdGenerator| handles wrap-around correctly.
137 // (This tests implementation details.) This test isn't in an anonymous
138 // namespace, since it needs to be friended.
139 TEST(RemoteChannelEndpointIdGeneratorTest, WrapAround) {
140 RemoteChannelEndpointIdGenerator gen;
141 gen.next_ = ChannelEndpointId(~0u);
142
143 ChannelEndpointId id = gen.GetNext();
144 EXPECT_TRUE(id.is_valid());
145 EXPECT_TRUE(id.is_remote());
146 EXPECT_EQ(~0u, id.value());
147
148 id = gen.GetNext();
149 EXPECT_TRUE(id.is_valid());
150 EXPECT_TRUE(id.is_remote());
151 EXPECT_EQ(ChannelEndpointId::kRemoteFlag, id.value());
152 }
153
106 } // namespace system 154 } // namespace system
107 } // namespace mojo 155 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/system/channel_endpoint_id.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698