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.
5 #ifndef COMPONENTS_FILESYSTEM_FILES_TEST_BASE_H_
6 #define COMPONENTS_FILESYSTEM_FILES_TEST_BASE_H_
8 #include "base/macros.h"
9 #include "components/filesystem/public/interfaces/file_system.mojom.h"
10 #include "mojo/application/public/cpp/application_test_base.h"
12 namespace filesystem
{
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
;
20 template <class T
, T v
>
21 const T IntegralConstant
<T
, v
>::value
;
23 typedef IntegralConstant
<bool, true> TrueType
;
24 typedef IntegralConstant
<bool, false> FalseType
;
27 struct IsConst
: FalseType
{};
29 struct IsConst
<const T
> : TrueType
{};
31 template <bool B
, typename T
= void>
35 struct EnableIf
<true, T
> {
46 struct IsMoveOnlyType
{
48 static YesType
Test(const typename
U::MoveOnlyTypeForCPP03
*);
51 static NoType
Test(...);
53 static const bool value
=
54 sizeof(Test
<T
>(0)) == sizeof(YesType
) && !IsConst
<T
>::value
;
58 typename EnableIf
<!IsMoveOnlyType
<T
>::value
, T
>::type
& Forward(T
& t
) {
63 typename EnableIf
<IsMoveOnlyType
<T
>::value
, T
>::type
Forward(T
& t
) {
66 // TODO(vtl): (End of stuff copied from template_util.h.)
68 template <typename T1
>
69 mojo::Callback
<void(T1
)> Capture(T1
* t1
) {
70 return [t1
](T1 got_t1
) { *t1
= Forward(got_t1
); };
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
);
81 class FilesTestBase
: public mojo::test::ApplicationTestBase
{
84 ~FilesTestBase() override
;
86 void SetUp() override
;
89 // Note: This has an out parameter rather than returning the |DirectoryPtr|,
90 // since |ASSERT_...()| doesn't work with return values.
91 void GetTemporaryRoot(DirectoryPtr
* directory
);
93 FileSystemPtr
& files() { return files_
; }
98 DISALLOW_COPY_AND_ASSIGN(FilesTestBase
);
101 } // namespace filesystem
103 #endif // COMPONENTS_FILESYSTEM_FILES_TEST_BASE_H_