| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-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 #ifndef BASE_MULTIPROCESS_TEST_H__ | 5 #ifndef BASE_MULTIPROCESS_TEST_H__ |
| 6 #define BASE_MULTIPROCESS_TEST_H__ | 6 #define BASE_MULTIPROCESS_TEST_H__ |
| 7 | 7 |
| 8 #include "base/base_switches.h" | 8 #include "base/base_switches.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/process_util.h" | 10 #include "base/process_util.h" |
| 11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 #include "testing/multiprocess_func_list.h" | 13 #include "testing/multiprocess_func_list.h" |
| 14 #include "testing/platform_test.h" | 14 #include "testing/platform_test.h" |
| 15 | 15 |
| 16 #if defined(OS_POSIX) | 16 #if defined(OS_POSIX) |
| 17 #include <sys/types.h> | 17 #include <sys/types.h> |
| 18 #include <unistd.h> | 18 #include <unistd.h> |
| 19 #endif | 19 #endif |
| 20 | 20 |
| 21 // Command line switch to invoke a child process rather than | 21 // Command line switch to invoke a child process rather than |
| 22 // to run the normal test suite. | 22 // to run the normal test suite. |
| 23 static const wchar_t kRunClientProcess[] = L"client"; | 23 static const wchar_t kRunClientProcess[] = L"client"; |
| 24 | 24 |
| 25 // A MultiProcessTest is a test class which makes it easier to | 25 // A MultiProcessTest is a test class which makes it easier to |
| 26 // write a test which requires code running out of process. | 26 // write a test which requires code running out of process. |
| 27 // | 27 // |
| 28 // To create a multiprocess test simply follow these steps: | 28 // To create a multiprocess test simply follow these steps: |
| 29 // | 29 // |
| 30 // 1) Derive your test from MultiProcessTest. | 30 // 1) Derive your test from MultiProcessTest. Example: |
| 31 // |
| 32 // class MyTest : public MultiProcessTest { |
| 33 // }; |
| 34 // |
| 35 // TEST_F(MyTest, TestCaseName) { |
| 36 // ... |
| 37 // } |
| 38 // |
| 31 // 2) Create a mainline function for the child processes and include | 39 // 2) Create a mainline function for the child processes and include |
| 32 // testing/multiprocess_func_list.h. | 40 // testing/multiprocess_func_list.h. |
| 33 // See the declaration of the MULTIPROCESS_TEST_MAIN macro | 41 // See the declaration of the MULTIPROCESS_TEST_MAIN macro |
| 34 // in that file for an example. | 42 // in that file for an example. |
| 35 // 3) Call SpawnChild("foo"), where "foo" is the name of | 43 // 3) Call SpawnChild(L"foo"), where "foo" is the name of |
| 36 // the function you wish to run in the child processes. | 44 // the function you wish to run in the child processes. |
| 37 // That's it! | 45 // That's it! |
| 38 // | 46 // |
| 39 class MultiProcessTest : public PlatformTest { | 47 class MultiProcessTest : public PlatformTest { |
| 40 protected: | 48 protected: |
| 41 // Run a child process. | 49 // Run a child process. |
| 42 // 'procname' is the name of a function which the child will | 50 // 'procname' is the name of a function which the child will |
| 43 // execute. It must be exported from this library in order to | 51 // execute. It must be exported from this library in order to |
| 44 // run. | 52 // run. |
| 45 // | 53 // |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 std::string switchstr = WideToUTF8(wswitchstr); | 90 std::string switchstr = WideToUTF8(wswitchstr); |
| 83 clvec.push_back(switchstr.c_str()); | 91 clvec.push_back(switchstr.c_str()); |
| 84 base::LaunchApp(clvec, false, &handle); | 92 base::LaunchApp(clvec, false, &handle); |
| 85 #endif | 93 #endif |
| 86 | 94 |
| 87 return handle; | 95 return handle; |
| 88 } | 96 } |
| 89 }; | 97 }; |
| 90 | 98 |
| 91 #endif // BASE_MULTIPROCESS_TEST_H__ | 99 #endif // BASE_MULTIPROCESS_TEST_H__ |
| OLD | NEW |