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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: base/functional_unittest.cc
diff --git a/base/functional_unittest.cc b/base/functional_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..a188281035c2cdf7031048d261975d233f466dc9
--- /dev/null
+++ b/base/functional_unittest.cc
@@ -0,0 +1,60 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/functional.h"
+
+#include <memory>
+#include <string>
+
+#include "base/memory/ptr_util.h"
+#include "base/memory/ref_counted.h"
+#include "base/memory/weak_ptr.h"
+#include "base/strings/string_piece.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace base {
+
+namespace {
+
+class Smart : public RefCounted<Smart> {
+ Smart() = default;
+ Smart(const Smart&) = default;
+ Smart& operator=(const Smart&) = default;
+
+ WeakPtr<Smart> GetWeakPtr() { return weak_factory_.GetWeakPtr(); }
+
+ private:
+ friend class RefCounted<Smart>;
+ ~Smart() = default;
+
+ WeakPtrFactory<Smart> weak_factory_{this};
+};
+
+TEST(Concepts, SmartPointerConcept) {
+ static_assert(SmartPointer<std::unique_ptr<int>>(), "");
+ static_assert(SmartPointer<scoped_refptr<Smart>>, "");
+ static_assert(SmartPointer<WeakPtr<Smart>>, "");
+
+ static_assert(!SmartPointer<int>(), "");
+ static_assert(!SmartPointer<int*>(), "");
+}
+
+TEST(Concepts, ComparableConcept) {
+ static_assert(Comparable<int, int>(), "");
+ static_assert(Comparable<int, double>(), "");
+ static_assert(Comparable<std::unique_ptr<int>, std::unique_ptr<int>>(), "");
+ static_assert(Comparable<std::string, base::StringPiece>(), "");
+ static_assert(!Comparable<int*, std::unique_ptr<int>>(), "");
+}
+
+TEST(Functional, Less) {
+ auto x = base::MakeUnique<int>();
+ EXPECT_FALSE(base::less{}(x, x));
+ EXPECT_TRUE(base::less{}(x, x.get() + 1));
+ EXPECT_FALSE(base::less{}(x.get() + 1, x.get()));
+}
+
+} // namespace
+
+} // namespace base
« 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