| 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
|
|
|