OLD | NEW |
1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2008 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 #include "multiprocess_func_list.h" | 5 #include "multiprocess_func_list.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 | 8 |
9 // Helper functions to maintain mapping of "test name"->test func. | 9 // Helper functions to maintain mapping of "test name"->test func. |
10 // The information is accessed via a global map. | 10 // The information is accessed via a global map. |
11 namespace multi_process_function_list { | 11 namespace multi_process_function_list { |
12 | 12 |
13 namespace { | 13 namespace { |
14 | 14 |
15 typedef std::map<std::string, ChildFunctionPtr> MultiProcessTestMap; | 15 struct ProcessFunctions { |
| 16 ProcessFunctions() : main(NULL), setup(NULL) {} |
| 17 ProcessFunctions(TestMainFunctionPtr main, SetupFunctionPtr setup) |
| 18 : main(main), |
| 19 setup(setup) { |
| 20 } |
| 21 TestMainFunctionPtr main; |
| 22 SetupFunctionPtr setup; |
| 23 }; |
| 24 |
| 25 typedef std::map<std::string, ProcessFunctions> MultiProcessTestMap; |
16 | 26 |
17 // Retrieve a reference to the global 'func name' -> func ptr map. | 27 // Retrieve a reference to the global 'func name' -> func ptr map. |
18 MultiProcessTestMap &GetMultiprocessFuncMap() { | 28 MultiProcessTestMap& GetMultiprocessFuncMap() { |
19 static MultiProcessTestMap test_name_to_func_ptr_map; | 29 static MultiProcessTestMap test_name_to_func_ptr_map; |
20 return test_name_to_func_ptr_map; | 30 return test_name_to_func_ptr_map; |
21 } | 31 } |
22 | 32 |
23 } // namespace | 33 } // namespace |
24 | 34 |
25 AppendMultiProcessTest::AppendMultiProcessTest(std::string test_name, | 35 AppendMultiProcessTest::AppendMultiProcessTest( |
26 ChildFunctionPtr func_ptr) { | 36 std::string test_name, |
27 GetMultiprocessFuncMap()[test_name] = func_ptr; | 37 TestMainFunctionPtr main_func_ptr, |
| 38 SetupFunctionPtr setup_func_ptr) { |
| 39 GetMultiprocessFuncMap()[test_name] = |
| 40 ProcessFunctions(main_func_ptr, setup_func_ptr); |
28 } | 41 } |
29 | 42 |
30 int InvokeChildProcessTest(std::string test_name) { | 43 int InvokeChildProcessTest(std::string test_name) { |
31 MultiProcessTestMap &func_lookup_table = GetMultiprocessFuncMap(); | 44 MultiProcessTestMap& func_lookup_table = GetMultiprocessFuncMap(); |
32 MultiProcessTestMap::iterator it = func_lookup_table.find(test_name); | 45 MultiProcessTestMap::iterator it = func_lookup_table.find(test_name); |
33 if (it != func_lookup_table.end()) { | 46 if (it != func_lookup_table.end()) { |
34 ChildFunctionPtr func = it->second; | 47 const ProcessFunctions& process_functions = it->second; |
35 if (func) { | 48 if (process_functions.setup) |
36 return (*func)(); | 49 (*process_functions.setup)(); |
37 } | 50 if (process_functions.main) |
| 51 return (*process_functions.main)(); |
38 } | 52 } |
39 | 53 |
40 return -1; | 54 return -1; |
41 } | 55 } |
42 | 56 |
43 } // namespace multi_process_function_list | 57 } // namespace multi_process_function_list |
OLD | NEW |