1// Copyright (c) 2012 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 CHROME_BROWSER_SYNC_FILE_SYSTEM_SYNC_FILE_SYSTEM_TEST_UTIL_H_
6#define CHROME_BROWSER_SYNC_FILE_SYSTEM_SYNC_FILE_SYSTEM_TEST_UTIL_H_
7
8#include <vector>
9
10#include "base/bind.h"
11#include "base/callback.h"
12#include "testing/gtest/include/gtest/gtest.h"
13
14namespace base {
15class RunLoop;
16}
17
18namespace storage {
19class FileSystemURL;
20}
21
22namespace sync_file_system {
23
24template <typename T>
25struct TypeTraits {
26  typedef T ParamType;
27};
28
29template <>
30struct TypeTraits<storage::FileSystemURL> {
31  typedef const storage::FileSystemURL& ParamType;
32};
33
34template <typename T>
35struct TypeTraits<std::vector<T> > {
36  typedef const std::vector<T>& ParamType;
37};
38
39template <typename Arg1, typename Arg2, typename Param1, typename Param2>
40void ReceiveResult2(bool* done,
41                    Arg1* arg1_out,
42                    Arg2* arg2_out,
43                    Param1 arg1,
44                    Param2 arg2) {
45  EXPECT_FALSE(*done);
46  *done = true;
47  *arg1_out = base::internal::CallbackForward(arg1);
48  *arg2_out = base::internal::CallbackForward(arg2);
49}
50
51template <typename R>
52void AssignAndQuit(base::RunLoop* run_loop, R* result_out, R result);
53
54template <typename R> base::Callback<void(R)>
55AssignAndQuitCallback(base::RunLoop* run_loop, R* result);
56
57template <typename Arg>
58base::Callback<void(typename TypeTraits<Arg>::ParamType)>
59CreateResultReceiver(Arg* arg_out);
60
61template <typename Arg1, typename Arg2>
62base::Callback<void(typename TypeTraits<Arg1>::ParamType,
63                    typename TypeTraits<Arg2>::ParamType)>
64CreateResultReceiver(Arg1* arg1_out,
65                     Arg2* arg2_out) {
66  typedef typename TypeTraits<Arg1>::ParamType Param1;
67  typedef typename TypeTraits<Arg2>::ParamType Param2;
68  return base::Bind(&ReceiveResult2<Arg1, Arg2, Param1, Param2>,
69                    base::Owned(new bool(false)),
70                    arg1_out, arg2_out);
71}
72
73}  // namespace sync_file_system
74
75#endif  // CHROME_BROWSER_SYNC_FILE_SYSTEM_SYNC_FILE_SYSTEM_TEST_UTIL_H_
76