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