OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_TEST_TEST_LAUNCHER_H_ | 5 #ifndef BASE_TEST_TEST_LAUNCHER_H_ |
6 #define BASE_TEST_TEST_LAUNCHER_H_ | 6 #define BASE_TEST_TEST_LAUNCHER_H_ |
7 | 7 |
| 8 #include <string> |
| 9 |
8 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/callback_forward.h" |
9 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "base/time.h" |
10 | 14 |
11 namespace testing { | 15 namespace testing { |
12 class TestCase; | 16 class TestCase; |
13 class TestInfo; | 17 class TestInfo; |
14 } | 18 } |
15 | 19 |
16 namespace base { | 20 namespace base { |
17 | 21 |
18 // Constants for GTest command-line flags. | 22 // Constants for GTest command-line flags. |
19 extern const char kGTestFilterFlag[]; | 23 extern const char kGTestFilterFlag[]; |
20 extern const char kGTestListTestsFlag[]; | 24 extern const char kGTestListTestsFlag[]; |
21 extern const char kGTestRepeatFlag[]; | 25 extern const char kGTestRepeatFlag[]; |
22 extern const char kGTestRunDisabledTestsFlag[]; | 26 extern const char kGTestRunDisabledTestsFlag[]; |
23 extern const char kGTestOutputFlag[]; | 27 extern const char kGTestOutputFlag[]; |
24 | 28 |
| 29 // Structure containing result of a single test. |
| 30 struct TestResult { |
| 31 TestResult(); |
| 32 |
| 33 // Name of the test case (before the dot, e.g. "A" for test "A.B"). |
| 34 std::string test_case_name; |
| 35 |
| 36 // Name of the test (after the dot, e.g. "B" for test "A.B"). |
| 37 std::string test_name; |
| 38 |
| 39 // True if the test passed. |
| 40 bool success; |
| 41 |
| 42 // Time it took to run the test. |
| 43 base::TimeDelta elapsed_time; |
| 44 }; |
| 45 |
25 // Interface for use with LaunchTests that abstracts away exact details | 46 // Interface for use with LaunchTests that abstracts away exact details |
26 // which tests and how are run. | 47 // which tests and how are run. |
27 class TestLauncherDelegate { | 48 class TestLauncherDelegate { |
28 public: | 49 public: |
29 // Called before a test is considered for running. If it returns false, | 50 // Called before a test is considered for running. If it returns false, |
30 // the test is not run. If it returns true, the test will be run provided | 51 // the test is not run. If it returns true, the test will be run provided |
31 // it is part of the current shard. | 52 // it is part of the current shard. |
32 virtual bool ShouldRunTest(const testing::TestCase* test_case, | 53 virtual bool ShouldRunTest(const testing::TestCase* test_case, |
33 const testing::TestInfo* test_info) = 0; | 54 const testing::TestInfo* test_info) = 0; |
34 | 55 |
35 // Called to make the delegate run specified test. Should return true | 56 // Called to make the delegate run specified test. After the delegate |
36 // on success. | 57 // finishes running the test (can do so asynchronously and out-of-order) |
37 virtual bool RunTest(const testing::TestCase* test_case, | 58 // it must call |callback| regardless of test success. |
38 const testing::TestInfo* test_info) = 0; | 59 typedef base::Callback<void(const TestResult& result)> TestResultCallback; |
| 60 virtual void RunTest(const testing::TestCase* test_case, |
| 61 const testing::TestInfo* test_info, |
| 62 const TestResultCallback& callback) = 0; |
| 63 |
| 64 // If the delegate is running tests asynchronously, it must finish |
| 65 // running all pending tests and call their callbacks before returning |
| 66 // from this method. |
| 67 virtual void RunRemainingTests() = 0; |
39 | 68 |
40 protected: | 69 protected: |
41 virtual ~TestLauncherDelegate(); | 70 virtual ~TestLauncherDelegate(); |
42 }; | 71 }; |
43 | 72 |
44 // Launches GTest-based tests from the current executable | 73 // Launches GTest-based tests from the current executable |
45 // using |launcher_delegate|. | 74 // using |launcher_delegate|. |
46 int LaunchTests(TestLauncherDelegate* launcher_delegate, | 75 int LaunchTests(TestLauncherDelegate* launcher_delegate, |
47 int argc, | 76 int argc, |
48 char** argv) WARN_UNUSED_RESULT; | 77 char** argv) WARN_UNUSED_RESULT; |
49 | 78 |
50 } // namespace base | 79 } // namespace base |
51 | 80 |
52 #endif // BASE_TEST_TEST_LAUNCHER_H_ | 81 #endif // BASE_TEST_TEST_LAUNCHER_H_ |
OLD | NEW |