Delete chrome.mediaGalleriesPrivate because the functionality unique to it has since...
[chromium-blink-merge.git] / base / test / gtest_util.cc
blobf98320c52746e063f92d16ba178167b9faefeeaa
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.
5 #include "base/test/gtest_util.h"
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"
12 namespace base {
14 std::vector<SplitTestName> GetCompiledInTests() {
15 testing::UnitTest* const unit_test = testing::UnitTest::GetInstance();
17 std::vector<SplitTestName> tests;
18 for (int i = 0; i < unit_test->total_test_case_count(); ++i) {
19 const testing::TestCase* test_case = unit_test->GetTestCase(i);
20 for (int j = 0; j < test_case->total_test_count(); ++j) {
21 const testing::TestInfo* test_info = test_case->GetTestInfo(j);
22 tests.push_back(std::make_pair(test_case->name(), test_info->name()));
25 return tests;
28 bool WriteCompiledInTestsToFile(const FilePath& path) {
29 std::vector<SplitTestName> tests(GetCompiledInTests());
31 ListValue root;
32 for (size_t i = 0; i < tests.size(); ++i) {
33 DictionaryValue* test_info = new DictionaryValue;
34 test_info->SetString("test_case_name", tests[i].first);
35 test_info->SetString("test_name", tests[i].second);
36 root.Append(test_info);
39 JSONFileValueSerializer serializer(path);
40 return serializer.Serialize(root);
43 bool ReadTestNamesFromFile(const FilePath& path,
44 std::vector<SplitTestName>* output) {
45 JSONFileValueSerializer deserializer(path);
46 int error_code = 0;
47 std::string error_message;
48 scoped_ptr<base::Value> value(
49 deserializer.Deserialize(&error_code, &error_message));
50 if (!value.get())
51 return false;
53 base::ListValue* tests = nullptr;
54 if (!value->GetAsList(&tests))
55 return false;
57 std::vector<base::SplitTestName> result;
58 for (base::ListValue::iterator i = tests->begin(); i != tests->end(); ++i) {
59 base::DictionaryValue* test = nullptr;
60 if (!(*i)->GetAsDictionary(&test))
61 return false;
63 std::string test_case_name;
64 if (!test->GetStringASCII("test_case_name", &test_case_name))
65 return false;
67 std::string test_name;
68 if (!test->GetStringASCII("test_name", &test_name))
69 return false;
71 result.push_back(std::make_pair(test_case_name, test_name));
74 output->swap(result);
75 return true;
78 } // namespace