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

Side by Side Diff: base/containers/flat_map_unittest.cc

Issue 2944523002: Improving flat containers interface. (Closed)
Patch Set: Removing redundant tests. Created 3 years, 6 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
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 "base/containers/flat_map.h" 5 #include "base/containers/flat_map.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/containers/container_test_utils.h" 10 #include "base/containers/container_test_utils.h"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/memory/ptr_util.h"
12 #include "testing/gmock/include/gmock/gmock.h" 13 #include "testing/gmock/include/gmock/gmock.h"
13 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
14 15
15 // A flat_map is basically a interface to flat_tree. So several basic 16 // A flat_map is basically a interface to flat_tree. So several basic
16 // operations are tested to make sure things are set up properly, but the bulk 17 // operations are tested to make sure things are set up properly, but the bulk
17 // of the tests are in flat_tree_unittests.cc. 18 // of the tests are in flat_tree_unittests.cc.
18 19
19 using ::testing::ElementsAre; 20 using ::testing::ElementsAre;
20 21
21 namespace base { 22 namespace base {
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 164
164 // The returned mapped reference should refer into the map. 165 // The returned mapped reference should refer into the map.
165 s = 22; 166 s = 22;
166 EXPECT_EQ(22, m[MoveOnlyInt(1)]); 167 EXPECT_EQ(22, m[MoveOnlyInt(1)]);
167 168
168 // Overwrite existing elements. 169 // Overwrite existing elements.
169 m[MoveOnlyInt(1)] = 44; 170 m[MoveOnlyInt(1)] = 44;
170 EXPECT_EQ(44, m[MoveOnlyInt(1)]); 171 EXPECT_EQ(44, m[MoveOnlyInt(1)]);
171 } 172 }
172 173
174 TEST(FlatMap, UniquePtrKeys) {
175 base::flat_map<std::unique_ptr<int>, int> m;
176 const auto& m1 = m;
177 int x = 0;
178 m.count(&x);
179 m1.count(&x);
180 m.find(&x);
181 m1.find(&x);
182 m.equal_range(&x);
183 m1.equal_range(&x);
184 m.lower_bound(&x);
185 m1.lower_bound(&x);
186 m.upper_bound(&x);
187 m1.upper_bound(&x);
188 m.erase(&x);
189
190 // Check if we broke overload resolution.
191 m.emplace(base::MakeUnique<int>(0), 0);
192 m.emplace(base::MakeUnique<int>(1), 0);
193 m.erase(m.begin());
194 m.erase(m.cbegin());
195 }
196
173 } // namespace base 197 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698