OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "base/test/gtest_util.h" | 5 #include "base/test/gtest_util.h" |
6 | 6 |
7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
8 #include "base/json/json_file_value_serializer.h" | 8 #include "base/json/json_file_value_serializer.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
11 | 11 |
12 namespace base { | 12 namespace base { |
13 | 13 |
| 14 TestIdentifier::TestIdentifier() { |
| 15 } |
| 16 |
14 std::string FormatFullTestName(const std::string& test_case_name, | 17 std::string FormatFullTestName(const std::string& test_case_name, |
15 const std::string& test_name) { | 18 const std::string& test_name) { |
16 return test_case_name + "." + test_name; | 19 return test_case_name + "." + test_name; |
17 } | 20 } |
18 | 21 |
19 std::vector<SplitTestName> GetCompiledInTests() { | 22 std::vector<TestIdentifier> GetCompiledInTests() { |
20 testing::UnitTest* const unit_test = testing::UnitTest::GetInstance(); | 23 testing::UnitTest* const unit_test = testing::UnitTest::GetInstance(); |
21 | 24 |
22 std::vector<SplitTestName> tests; | 25 std::vector<TestIdentifier> tests; |
23 for (int i = 0; i < unit_test->total_test_case_count(); ++i) { | 26 for (int i = 0; i < unit_test->total_test_case_count(); ++i) { |
24 const testing::TestCase* test_case = unit_test->GetTestCase(i); | 27 const testing::TestCase* test_case = unit_test->GetTestCase(i); |
25 for (int j = 0; j < test_case->total_test_count(); ++j) { | 28 for (int j = 0; j < test_case->total_test_count(); ++j) { |
26 const testing::TestInfo* test_info = test_case->GetTestInfo(j); | 29 const testing::TestInfo* test_info = test_case->GetTestInfo(j); |
27 tests.push_back(std::make_pair(test_case->name(), test_info->name())); | 30 TestIdentifier test_data; |
| 31 test_data.test_case_name = test_case->name(); |
| 32 test_data.test_name = test_info->name(); |
| 33 test_data.file = test_info->file(); |
| 34 test_data.line = test_info->line(); |
| 35 tests.push_back(test_data); |
28 } | 36 } |
29 } | 37 } |
30 return tests; | 38 return tests; |
31 } | 39 } |
32 | 40 |
33 bool WriteCompiledInTestsToFile(const FilePath& path) { | 41 bool WriteCompiledInTestsToFile(const FilePath& path) { |
34 std::vector<SplitTestName> tests(GetCompiledInTests()); | 42 std::vector<TestIdentifier> tests(GetCompiledInTests()); |
35 | 43 |
36 ListValue root; | 44 ListValue root; |
37 for (size_t i = 0; i < tests.size(); ++i) { | 45 for (size_t i = 0; i < tests.size(); ++i) { |
38 DictionaryValue* test_info = new DictionaryValue; | 46 DictionaryValue* test_info = new DictionaryValue; |
39 test_info->SetString("test_case_name", tests[i].first); | 47 test_info->SetString("test_case_name", tests[i].test_case_name); |
40 test_info->SetString("test_name", tests[i].second); | 48 test_info->SetString("test_name", tests[i].test_name); |
| 49 test_info->SetString("file", tests[i].file); |
| 50 test_info->SetInteger("line", tests[i].line); |
41 root.Append(test_info); | 51 root.Append(test_info); |
42 } | 52 } |
43 | 53 |
44 JSONFileValueSerializer serializer(path); | 54 JSONFileValueSerializer serializer(path); |
45 return serializer.Serialize(root); | 55 return serializer.Serialize(root); |
46 } | 56 } |
47 | 57 |
48 bool ReadTestNamesFromFile(const FilePath& path, | 58 bool ReadTestNamesFromFile(const FilePath& path, |
49 std::vector<SplitTestName>* output) { | 59 std::vector<TestIdentifier>* output) { |
50 JSONFileValueDeserializer deserializer(path); | 60 JSONFileValueDeserializer deserializer(path); |
51 int error_code = 0; | 61 int error_code = 0; |
52 std::string error_message; | 62 std::string error_message; |
53 scoped_ptr<base::Value> value( | 63 scoped_ptr<base::Value> value( |
54 deserializer.Deserialize(&error_code, &error_message)); | 64 deserializer.Deserialize(&error_code, &error_message)); |
55 if (!value.get()) | 65 if (!value.get()) |
56 return false; | 66 return false; |
57 | 67 |
58 base::ListValue* tests = nullptr; | 68 base::ListValue* tests = nullptr; |
59 if (!value->GetAsList(&tests)) | 69 if (!value->GetAsList(&tests)) |
60 return false; | 70 return false; |
61 | 71 |
62 std::vector<base::SplitTestName> result; | 72 std::vector<base::TestIdentifier> result; |
63 for (base::ListValue::iterator i = tests->begin(); i != tests->end(); ++i) { | 73 for (base::ListValue::iterator i = tests->begin(); i != tests->end(); ++i) { |
64 base::DictionaryValue* test = nullptr; | 74 base::DictionaryValue* test = nullptr; |
65 if (!(*i)->GetAsDictionary(&test)) | 75 if (!(*i)->GetAsDictionary(&test)) |
66 return false; | 76 return false; |
67 | 77 |
68 std::string test_case_name; | 78 TestIdentifier test_data; |
69 if (!test->GetStringASCII("test_case_name", &test_case_name)) | 79 |
| 80 if (!test->GetStringASCII("test_case_name", &test_data.test_case_name)) |
70 return false; | 81 return false; |
71 | 82 |
72 std::string test_name; | 83 if (!test->GetStringASCII("test_name", &test_data.test_name)) |
73 if (!test->GetStringASCII("test_name", &test_name)) | |
74 return false; | 84 return false; |
75 | 85 |
76 result.push_back(std::make_pair(test_case_name, test_name)); | 86 if (!test->GetStringASCII("file", &test_data.file)) |
| 87 return false; |
| 88 |
| 89 if (!test->GetInteger("line", &test_data.line)) |
| 90 return false; |
| 91 |
| 92 result.push_back(test_data); |
77 } | 93 } |
78 | 94 |
79 output->swap(result); | 95 output->swap(result); |
80 return true; | 96 return true; |
81 } | 97 } |
82 | 98 |
83 } // namespace base | 99 } // namespace base |
OLD | NEW |