| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #ifndef SERVICES_NATIVE_SUPPORT_PROCESS_TEST_BASE_H_ | 5 #ifndef SERVICES_NATIVE_SUPPORT_PROCESS_TEST_BASE_H_ |
| 6 #define SERVICES_NATIVE_SUPPORT_PROCESS_TEST_BASE_H_ | 6 #define SERVICES_NATIVE_SUPPORT_PROCESS_TEST_BASE_H_ |
| 7 | 7 |
| 8 #include <type_traits> | 8 #include <type_traits> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "mojo/public/cpp/application/application_test_base.h" | 11 #include "mojo/public/cpp/application/application_test_base.h" |
| 12 #include "mojo/services/native_support/interfaces/process.mojom.h" | 12 #include "mojo/public/cpp/bindings/synchronous_interface_ptr.h" |
| 13 #include "mojo/services/native_support/interfaces/process.mojom-sync.h" |
| 13 | 14 |
| 14 namespace native_support { | 15 namespace native_support { |
| 15 | 16 |
| 16 // TODO(vtl): Stuff copied from mojo/public/cpp/bindings/lib/template_util.h. | |
| 17 typedef char YesType; | |
| 18 | |
| 19 struct NoType { | |
| 20 YesType dummy[2]; | |
| 21 }; | |
| 22 | |
| 23 template <typename T> | |
| 24 struct IsMoveOnlyType { | |
| 25 template <typename U> | |
| 26 static YesType Test(const typename U::MoveOnlyTypeForCPP03*); | |
| 27 | |
| 28 template <typename U> | |
| 29 static NoType Test(...); | |
| 30 | |
| 31 static const bool value = | |
| 32 sizeof(Test<T>(0)) == sizeof(YesType) && !std::is_const<T>::value; | |
| 33 }; | |
| 34 | |
| 35 template <typename T> | |
| 36 typename std::enable_if<!IsMoveOnlyType<T>::value, T>::type& Forward(T& t) { | |
| 37 return t; | |
| 38 } | |
| 39 | |
| 40 template <typename T> | |
| 41 typename std::enable_if<IsMoveOnlyType<T>::value, T>::type Forward(T& t) { | |
| 42 return t.Pass(); | |
| 43 } | |
| 44 // TODO(vtl): (End of stuff copied from template_util.h.) | |
| 45 | |
| 46 template <typename T1> | |
| 47 mojo::Callback<void(T1)> Capture(T1* t1) { | |
| 48 return [t1](T1 got_t1) { *t1 = Forward(got_t1); }; | |
| 49 } | |
| 50 | |
| 51 template <typename T1, typename T2> | |
| 52 mojo::Callback<void(T1, T2)> Capture(T1* t1, T2* t2) { | |
| 53 return [t1, t2](T1 got_t1, T2 got_t2) { | |
| 54 *t1 = Forward(got_t1); | |
| 55 *t2 = Forward(got_t2); | |
| 56 }; | |
| 57 } | |
| 58 | |
| 59 class ProcessTestBase : public mojo::test::ApplicationTestBase { | 17 class ProcessTestBase : public mojo::test::ApplicationTestBase { |
| 60 public: | 18 public: |
| 61 ProcessTestBase(); | 19 ProcessTestBase(); |
| 62 ~ProcessTestBase() override; | 20 ~ProcessTestBase() override; |
| 63 | 21 |
| 64 void SetUp() override; | 22 void SetUp() override; |
| 65 | 23 |
| 66 protected: | 24 protected: |
| 67 ProcessPtr& process() { return process_; } | 25 mojo::SynchronousInterfacePtr<Process>& process() { return process_; } |
| 68 | 26 |
| 69 private: | 27 private: |
| 70 ProcessPtr process_; | 28 mojo::SynchronousInterfacePtr<Process> process_; |
| 71 | 29 |
| 72 DISALLOW_COPY_AND_ASSIGN(ProcessTestBase); | 30 DISALLOW_COPY_AND_ASSIGN(ProcessTestBase); |
| 73 }; | 31 }; |
| 74 | 32 |
| 75 } // namespace native_support | 33 } // namespace native_support |
| 76 | 34 |
| 77 #endif // SERVICES_NATIVE_SUPPORT_PROCESS_TEST_BASE_H_ | 35 #endif // SERVICES_NATIVE_SUPPORT_PROCESS_TEST_BASE_H_ |
| OLD | NEW |