OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef SERVICES_FILES_FILES_TEST_BASE_H_ |
| 6 #define SERVICES_FILES_FILES_TEST_BASE_H_ |
| 7 |
| 8 #include "base/macros.h" |
| 9 #include "components/filesystem/public/interfaces/files.mojom.h" |
| 10 #include "mojo/application/public/cpp/application_test_base.h" |
| 11 |
| 12 namespace mojo { |
| 13 namespace files { |
| 14 |
| 15 // TODO(vtl): Stuff copied from mojo/public/cpp/bindings/lib/template_util.h. |
| 16 template <class T, T v> |
| 17 struct IntegralConstant { |
| 18 static const T value = v; |
| 19 }; |
| 20 |
| 21 template <class T, T v> |
| 22 const T IntegralConstant<T, v>::value; |
| 23 |
| 24 typedef IntegralConstant<bool, true> TrueType; |
| 25 typedef IntegralConstant<bool, false> FalseType; |
| 26 |
| 27 template <class T> |
| 28 struct IsConst : FalseType {}; |
| 29 template <class T> |
| 30 struct IsConst<const T> : TrueType {}; |
| 31 |
| 32 template <bool B, typename T = void> |
| 33 struct EnableIf {}; |
| 34 |
| 35 template <typename T> |
| 36 struct EnableIf<true, T> { |
| 37 typedef T type; |
| 38 }; |
| 39 |
| 40 typedef char YesType; |
| 41 |
| 42 struct NoType { |
| 43 YesType dummy[2]; |
| 44 }; |
| 45 |
| 46 template <typename T> |
| 47 struct IsMoveOnlyType { |
| 48 template <typename U> |
| 49 static YesType Test(const typename U::MoveOnlyTypeForCPP03*); |
| 50 |
| 51 template <typename U> |
| 52 static NoType Test(...); |
| 53 |
| 54 static const bool value = |
| 55 sizeof(Test<T>(0)) == sizeof(YesType) && !IsConst<T>::value; |
| 56 }; |
| 57 |
| 58 template <typename T> |
| 59 typename EnableIf<!IsMoveOnlyType<T>::value, T>::type& Forward(T& t) { |
| 60 return t; |
| 61 } |
| 62 |
| 63 template <typename T> |
| 64 typename EnableIf<IsMoveOnlyType<T>::value, T>::type Forward(T& t) { |
| 65 return t.Pass(); |
| 66 } |
| 67 // TODO(vtl): (End of stuff copied from template_util.h.) |
| 68 |
| 69 template <typename T1> |
| 70 Callback<void(T1)> Capture(T1* t1) { |
| 71 return [t1](T1 got_t1) { *t1 = Forward(got_t1); }; |
| 72 } |
| 73 |
| 74 template <typename T1, typename T2> |
| 75 Callback<void(T1, T2)> Capture(T1* t1, T2* t2) { |
| 76 return [t1, t2](T1 got_t1, T2 got_t2) { |
| 77 *t1 = Forward(got_t1); |
| 78 *t2 = Forward(got_t2); |
| 79 }; |
| 80 } |
| 81 |
| 82 class FilesTestBase : public test::ApplicationTestBase { |
| 83 public: |
| 84 FilesTestBase(); |
| 85 ~FilesTestBase() override; |
| 86 |
| 87 void SetUp() override; |
| 88 |
| 89 protected: |
| 90 // Note: This has an out parameter rather than returning the |DirectoryPtr|, |
| 91 // since |ASSERT_...()| doesn't work with return values. |
| 92 void GetTemporaryRoot(DirectoryPtr* directory); |
| 93 |
| 94 FilesPtr& files() { return files_; } |
| 95 |
| 96 private: |
| 97 FilesPtr files_; |
| 98 |
| 99 DISALLOW_COPY_AND_ASSIGN(FilesTestBase); |
| 100 }; |
| 101 |
| 102 } // namespace files |
| 103 } // namespace mojo |
| 104 |
| 105 #endif // SERVICES_FILES_FILES_TEST_BASE_H_ |
OLD | NEW |