(1) Chrome data compression proxy should use QUIC only if
[chromium-blink-merge.git] / testing / multiprocess_func_list.cc
blob49ae07dd3e8d99d57ba806851b9e53474c95128c
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.
5 #include "multiprocess_func_list.h"
7 #include <map>
9 // Helper functions to maintain mapping of "test name"->test func.
10 // The information is accessed via a global map.
11 namespace multi_process_function_list {
13 namespace {
15 struct ProcessFunctions {
16 ProcessFunctions() : main(NULL), setup(NULL) {}
17 ProcessFunctions(TestMainFunctionPtr main, SetupFunctionPtr setup)
18 : main(main),
19 setup(setup) {
21 TestMainFunctionPtr main;
22 SetupFunctionPtr setup;
25 typedef std::map<std::string, ProcessFunctions> MultiProcessTestMap;
27 // Retrieve a reference to the global 'func name' -> func ptr map.
28 MultiProcessTestMap& GetMultiprocessFuncMap() {
29 static MultiProcessTestMap test_name_to_func_ptr_map;
30 return test_name_to_func_ptr_map;
33 } // namespace
35 AppendMultiProcessTest::AppendMultiProcessTest(
36 std::string test_name,
37 TestMainFunctionPtr main_func_ptr,
38 SetupFunctionPtr setup_func_ptr) {
39 GetMultiprocessFuncMap()[test_name] =
40 ProcessFunctions(main_func_ptr, setup_func_ptr);
43 int InvokeChildProcessTest(std::string test_name) {
44 MultiProcessTestMap& func_lookup_table = GetMultiprocessFuncMap();
45 MultiProcessTestMap::iterator it = func_lookup_table.find(test_name);
46 if (it != func_lookup_table.end()) {
47 const ProcessFunctions& process_functions = it->second;
48 if (process_functions.setup)
49 (*process_functions.setup)();
50 if (process_functions.main)
51 return (*process_functions.main)();
54 return -1;
57 } // namespace multi_process_function_list