Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(19)

Side by Side Diff: base/test/gtest_util.cc

Issue 1647803004: Move base to DEPS (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/test/gtest_util.h ('k') | base/test/gtest_xml_unittest_result_printer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "base/test/gtest_util.h"
6
7 #include "base/files/file_path.h"
8 #include "base/json/json_file_value_serializer.h"
9 #include "base/values.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11
12 namespace base {
13
14 std::string FormatFullTestName(const std::string& test_case_name,
15 const std::string& test_name) {
16 return test_case_name + "." + test_name;
17 }
18
19 std::vector<SplitTestName> GetCompiledInTests() {
20 testing::UnitTest* const unit_test = testing::UnitTest::GetInstance();
21
22 std::vector<SplitTestName> tests;
23 for (int i = 0; i < unit_test->total_test_case_count(); ++i) {
24 const testing::TestCase* test_case = unit_test->GetTestCase(i);
25 for (int j = 0; j < test_case->total_test_count(); ++j) {
26 const testing::TestInfo* test_info = test_case->GetTestInfo(j);
27 tests.push_back(std::make_pair(test_case->name(), test_info->name()));
28 }
29 }
30 return tests;
31 }
32
33 bool WriteCompiledInTestsToFile(const FilePath& path) {
34 std::vector<SplitTestName> tests(GetCompiledInTests());
35
36 ListValue root;
37 for (size_t i = 0; i < tests.size(); ++i) {
38 DictionaryValue* test_info = new DictionaryValue;
39 test_info->SetString("test_case_name", tests[i].first);
40 test_info->SetString("test_name", tests[i].second);
41 root.Append(test_info);
42 }
43
44 JSONFileValueSerializer serializer(path);
45 return serializer.Serialize(root);
46 }
47
48 bool ReadTestNamesFromFile(const FilePath& path,
49 std::vector<SplitTestName>* output) {
50 JSONFileValueDeserializer deserializer(path);
51 int error_code = 0;
52 std::string error_message;
53 scoped_ptr<base::Value> value(
54 deserializer.Deserialize(&error_code, &error_message));
55 if (!value.get())
56 return false;
57
58 base::ListValue* tests = nullptr;
59 if (!value->GetAsList(&tests))
60 return false;
61
62 std::vector<base::SplitTestName> result;
63 for (base::ListValue::iterator i = tests->begin(); i != tests->end(); ++i) {
64 base::DictionaryValue* test = nullptr;
65 if (!(*i)->GetAsDictionary(&test))
66 return false;
67
68 std::string test_case_name;
69 if (!test->GetStringASCII("test_case_name", &test_case_name))
70 return false;
71
72 std::string test_name;
73 if (!test->GetStringASCII("test_name", &test_name))
74 return false;
75
76 result.push_back(std::make_pair(test_case_name, test_name));
77 }
78
79 output->swap(result);
80 return true;
81 }
82
83 } // namespace base
OLDNEW
« no previous file with comments | « base/test/gtest_util.h ('k') | base/test/gtest_xml_unittest_result_printer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698