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

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

Issue 638343003: Mojo: Add some tests for ChannelEndpointId, etc. (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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "mojo/edk/system/channel_endpoint_id.h"
6
7 #include <sstream>
8
9 #include "testing/gtest/include/gtest/gtest.h"
10
11 namespace mojo {
12 namespace system {
13 namespace {
14
15 TEST(ChannelEndpointIdTest, Basic) {
16 ChannelEndpointId invalid;
17 ChannelEndpointId bootstrap(ChannelEndpointId::GetBootstrap());
18
19 EXPECT_EQ(invalid, invalid);
20 EXPECT_EQ(bootstrap, bootstrap);
21 EXPECT_FALSE(invalid == bootstrap);
22
23 EXPECT_FALSE(invalid != invalid);
24 EXPECT_FALSE(bootstrap != bootstrap);
25 EXPECT_NE(invalid, bootstrap);
26
27 EXPECT_FALSE(invalid < invalid);
28 EXPECT_LT(invalid, bootstrap);
29
30 EXPECT_FALSE(invalid.is_valid());
31 EXPECT_TRUE(bootstrap.is_valid());
32
33 // Test assignment.
34 ChannelEndpointId copy;
35 copy = bootstrap;
36 EXPECT_EQ(copy, bootstrap);
37 copy = invalid;
38 EXPECT_EQ(copy, invalid);
39 }
40
41 // Tests values of invalid and bootstrap IDs. (This tests implementation
42 // details.)
43 TEST(ChannelEndpointIdTest, Value) {
44 EXPECT_EQ(0u, ChannelEndpointId().value());
45 EXPECT_EQ(1u, ChannelEndpointId::GetBootstrap().value());
46 }
47
48 // Tests ostream output. (This tests implementation details.)
49 TEST(ChannelEndpointIdTest, Ostream) {
50 {
51 std::ostringstream stream;
52 stream << ChannelEndpointId();
53 EXPECT_EQ("0", stream.str());
54 }
55 {
56 std::ostringstream stream;
57 stream << ChannelEndpointId::GetBootstrap();
58 EXPECT_EQ("1", stream.str());
59 }
60 }
61
62 TEST(LocalChannelEndpointIdGeneratorTest, Basic) {
63 LocalChannelEndpointIdGenerator gen;
64
65 ChannelEndpointId id1;
66 EXPECT_FALSE(id1.is_valid()); // Check sanity.
67
68 id1 = gen.GetNext();
69 EXPECT_TRUE(id1.is_valid());
70
71 EXPECT_EQ(id1, ChannelEndpointId::GetBootstrap());
72
73 ChannelEndpointId id2 = gen.GetNext();
74 EXPECT_TRUE(id2.is_valid());
75 // Technically, nonequality here is an implementation detail, since, e.g.,
76 // random generation of IDs would be a valid implementation.
77 EXPECT_NE(id2, id1);
78 // ... but right now we just increment to generate IDs.
79 EXPECT_EQ(2u, id2.value());
80 }
81
82 } // namespace
83
84 // Tests that the generator handles wrap-around correctly. (This tests
85 // implementation details.) This test isn't in an anonymous namespace, since
86 // it needs to be friended.
87 TEST(LocalChannelEndpointIdGeneratorTest, WrapAround) {
88 LocalChannelEndpointIdGenerator gen;
89 gen.next_channel_endpoint_id_.value_ = static_cast<uint32_t>(-1);
90
91 ChannelEndpointId id = gen.GetNext();
92 EXPECT_TRUE(id.is_valid());
93 EXPECT_EQ(static_cast<uint32_t>(-1), id.value());
94
95 id = gen.GetNext();
96 EXPECT_TRUE(id.is_valid());
97 EXPECT_EQ(1u, id.value());
98 }
99
100 } // namespace system
101 } // 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