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

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

Issue 814543006: Move //mojo/{public, edk} underneath //third_party (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 11 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/unique_identifier.cc ('k') | mojo/edk/system/waiter.h » ('j') | 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/unique_identifier.h"
6
7 #include <set>
8 #include <sstream>
9
10 #include "base/containers/hash_tables.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12
13 namespace mojo {
14 namespace system {
15 namespace {
16
17 TEST(UniqueIdentifierTest, Basic) {
18 // (This also checks copy constructibility.)
19 UniqueIdentifier id1 = UniqueIdentifier::Generate();
20
21 EXPECT_EQ(id1, id1);
22 EXPECT_FALSE(id1 != id1);
23 EXPECT_FALSE(id1 < id1);
24
25 UniqueIdentifier id2 = UniqueIdentifier::Generate();
26
27 EXPECT_FALSE(id2 == id1);
28 EXPECT_NE(id2, id1);
29 EXPECT_TRUE((id1 < id2) ^ (id2 < id1));
30
31 // Test copyability.
32 id2 = id1;
33 }
34
35 TEST(UniqueIdentifierTest, Logging) {
36 std::ostringstream oss1;
37 UniqueIdentifier id1 = UniqueIdentifier::Generate();
38 oss1 << id1;
39 EXPECT_FALSE(oss1.str().empty());
40
41 std::ostringstream oss2;
42 UniqueIdentifier id2 = UniqueIdentifier::Generate();
43 oss2 << id2;
44 EXPECT_FALSE(oss2.str().empty());
45
46 EXPECT_NE(id1, id2);
47 EXPECT_NE(oss1.str(), oss2.str());
48 }
49
50 TEST(UniqueIdentifierTest, StdSet) {
51 std::set<UniqueIdentifier> s;
52 EXPECT_TRUE(s.empty());
53
54 UniqueIdentifier id1 = UniqueIdentifier::Generate();
55 EXPECT_TRUE(s.find(id1) == s.end());
56 s.insert(id1);
57 EXPECT_TRUE(s.find(id1) != s.end());
58 EXPECT_FALSE(s.empty());
59
60 UniqueIdentifier id2 = UniqueIdentifier::Generate();
61 EXPECT_TRUE(s.find(id2) == s.end());
62 s.insert(id2);
63 EXPECT_TRUE(s.find(id2) != s.end());
64 // Make sure |id1| is still in |s|.
65 EXPECT_TRUE(s.find(id1) != s.end());
66
67 s.erase(id1);
68 EXPECT_TRUE(s.find(id1) == s.end());
69 // Make sure |id2| is still in |s|.
70 EXPECT_TRUE(s.find(id2) != s.end());
71
72 s.erase(id2);
73 EXPECT_TRUE(s.find(id2) == s.end());
74 EXPECT_TRUE(s.empty());
75 }
76
77 TEST(UniqueIdentifierTest, HashSet) {
78 base::hash_set<UniqueIdentifier> s;
79 EXPECT_TRUE(s.empty());
80
81 UniqueIdentifier id1 = UniqueIdentifier::Generate();
82 EXPECT_TRUE(s.find(id1) == s.end());
83 s.insert(id1);
84 EXPECT_TRUE(s.find(id1) != s.end());
85 EXPECT_FALSE(s.empty());
86
87 UniqueIdentifier id2 = UniqueIdentifier::Generate();
88 EXPECT_TRUE(s.find(id2) == s.end());
89 s.insert(id2);
90 EXPECT_TRUE(s.find(id2) != s.end());
91 // Make sure |id1| is still in |s|.
92 EXPECT_TRUE(s.find(id1) != s.end());
93
94 s.erase(id1);
95 EXPECT_TRUE(s.find(id1) == s.end());
96 // Make sure |id2| is still in |s|.
97 EXPECT_TRUE(s.find(id2) != s.end());
98
99 s.erase(id2);
100 EXPECT_TRUE(s.find(id2) == s.end());
101 EXPECT_TRUE(s.empty());
102 }
103
104 } // namespace
105 } // namespace system
106 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/system/unique_identifier.cc ('k') | mojo/edk/system/waiter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698