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 #include "chrome/browser/sync_file_system/sync_file_system_test_util.h"
6
7 #include <memory>
8 #include <utility>
9
10 #include "base/run_loop.h"
11 #include "chrome/browser/sync_file_system/remote_file_sync_service.h"
12 #include "chrome/browser/sync_file_system/sync_status_code.h"
13 #include "content/public/test/test_utils.h"
14 #include "google_apis/drive/drive_api_error_codes.h"
15
16 using content::BrowserThread;
17
18 namespace sync_file_system {
19
20 namespace drive_backend {
21 class MetadataDatabase;
22 } // drive_backend
23
24 template <typename R>
AssignAndQuit(base::RunLoop * run_loop,R * result_out,R result)25 void AssignAndQuit(base::RunLoop* run_loop, R* result_out, R result) {
26 DCHECK(result_out);
27 DCHECK(run_loop);
28 *result_out = result;
29 run_loop->Quit();
30 }
31
32 template <typename R> base::Callback<void(R)>
AssignAndQuitCallback(base::RunLoop * run_loop,R * result)33 AssignAndQuitCallback(base::RunLoop* run_loop, R* result) {
34 return base::Bind(&AssignAndQuit<R>, run_loop, base::Unretained(result));
35 }
36
37 template <typename Arg, typename Param>
ReceiveResult1(bool * done,Arg * arg_out,Param arg)38 void ReceiveResult1(bool* done, Arg* arg_out, Param arg) {
39 EXPECT_FALSE(*done);
40 *done = true;
41 *arg_out = std::forward<Param>(arg);
42 }
43
44 template <typename Arg>
45 base::Callback<void(typename TypeTraits<Arg>::ParamType)>
CreateResultReceiver(Arg * arg_out)46 CreateResultReceiver(Arg* arg_out) {
47 typedef typename TypeTraits<Arg>::ParamType Param;
48 return base::Bind(&ReceiveResult1<Arg, Param>,
49 base::Owned(new bool(false)), arg_out);
50 }
51
52 // Instantiate versions we know callers will need.
53 template base::Callback<void(SyncStatusCode)>
54 AssignAndQuitCallback(base::RunLoop*, SyncStatusCode*);
55
56 #define INSTANTIATE_RECEIVER(type) \
57 template base::Callback<void(type)> CreateResultReceiver(type*)
58 INSTANTIATE_RECEIVER(SyncStatusCode);
59 INSTANTIATE_RECEIVER(google_apis::DriveApiErrorCode);
60 INSTANTIATE_RECEIVER(std::unique_ptr<RemoteFileSyncService::OriginStatusMap>);
61 #undef INSTANTIATE_RECEIVER
62
63 } // namespace sync_file_system
64