Fix emulator build error
[platform/framework/web/chromium-efl.git] / base / functional / invoke_unittest.cc
1 // Copyright 2020 The Chromium Authors
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/invoke.h"
6
7 #include <functional>
8
9 #include "testing/gtest/include/gtest/gtest.h"
10
11 namespace base {
12
13 TEST(FunctionalTest, Invoke) {
14   struct S {
15     int i;
16     constexpr int add(int x) const { return i + x; }
17   };
18
19   constexpr S s = {1};
20
21   // Note: The tests involving a std::reference_wrapper are not static_asserts,
22   // since std::reference_wrapper is not constexpr prior to C++20.
23   static_assert(base::invoke(&S::add, s, 2) == 3, "");
24   EXPECT_EQ(base::invoke(&S::add, std::ref(s), 2), 3);
25   static_assert(base::invoke(&S::add, &s, 3) == 4, "");
26
27   static_assert(base::invoke(&S::i, s) == 1, "");
28   EXPECT_EQ(base::invoke(&S::i, std::ref(s)), 1);
29   static_assert(base::invoke(&S::i, &s) == 1, "");
30
31   static_assert(base::invoke(std::plus<>(), 1, 2) == 3, "");
32 }
33
34 }  // namespace base