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

Side by Side Diff: base/functional_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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "base/functional.h"
6
7 #include <memory>
8 #include <string>
9
10 #include "base/memory/ptr_util.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/weak_ptr.h"
13 #include "base/strings/string_piece.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15
16 namespace base {
17
18 namespace {
19
20 class Smart : public RefCounted<Smart> {
21 Smart() = default;
22 Smart(const Smart&) = default;
23 Smart& operator=(const Smart&) = default;
24
25 WeakPtr<Smart> GetWeakPtr() { return weak_factory_.GetWeakPtr(); }
26
27 private:
28 friend class RefCounted<Smart>;
29 ~Smart() = default;
30
31 WeakPtrFactory<Smart> weak_factory_{this};
32 };
33
34 TEST(Concepts, SmartPointerConcept) {
35 static_assert(SmartPointer<std::unique_ptr<int>>(), "");
36 static_assert(SmartPointer<scoped_refptr<Smart>>, "");
37 static_assert(SmartPointer<WeakPtr<Smart>>, "");
38
39 static_assert(!SmartPointer<int>(), "");
40 static_assert(!SmartPointer<int*>(), "");
41 }
42
43 TEST(Concepts, ComparableConcept) {
44 static_assert(Comparable<int, int>(), "");
45 static_assert(Comparable<int, double>(), "");
46 static_assert(Comparable<std::unique_ptr<int>, std::unique_ptr<int>>(), "");
47 static_assert(Comparable<std::string, base::StringPiece>(), "");
48 static_assert(!Comparable<int*, std::unique_ptr<int>>(), "");
49 }
50
51 TEST(Functional, Less) {
52 auto x = base::MakeUnique<int>();
53 EXPECT_FALSE(base::less{}(x, x));
54 EXPECT_TRUE(base::less{}(x, x.get() + 1));
55 EXPECT_FALSE(base::less{}(x.get() + 1, x.get()));
56 }
57
58 } // namespace
59
60 } // namespace base
OLDNEW
« base/containers/flat_tree.h ('K') | « base/functional.h ('k') | base/type_traits.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698