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 14 namespace base { 15 class RunLoop; 16 } 17 18 namespace storage { 19 class FileSystemURL; 20 } 21 22 namespace sync_file_system { 23 24 template <typename T> 25 struct TypeTraits { 26 typedef T ParamType; 27 }; 28 29 template <> 30 struct TypeTraits<storage::FileSystemURL> { 31 typedef const storage::FileSystemURL& ParamType; 32 }; 33 34 template <typename T> 35 struct TypeTraits<std::vector<T> > { 36 typedef const std::vector<T>& ParamType; 37 }; 38 39 template <typename Arg1, typename Arg2, typename Param1, typename Param2> 40 void 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 51 template <typename R> 52 void AssignAndQuit(base::RunLoop* run_loop, R* result_out, R result); 53 54 template <typename R> base::Callback<void(R)> 55 AssignAndQuitCallback(base::RunLoop* run_loop, R* result); 56 57 template <typename Arg> 58 base::Callback<void(typename TypeTraits<Arg>::ParamType)> 59 CreateResultReceiver(Arg* arg_out); 60 61 template <typename Arg1, typename Arg2> 62 base::Callback<void(typename TypeTraits<Arg1>::ParamType, 63 typename TypeTraits<Arg2>::ParamType)> 64 CreateResultReceiver(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