| 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 "mojo/edk/test/test_support_impl.h" | 5 #include "mojo/edk/test/test_support_impl.h" |
| 6 | 6 |
| 7 #include <stdlib.h> | 7 #include <stdlib.h> |
| 8 #include <string.h> | 8 #include <string.h> |
| 9 | 9 |
| 10 #include <string> |
| 11 |
| 10 #include "base/files/file_enumerator.h" | 12 #include "base/files/file_enumerator.h" |
| 11 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
| 12 #include "base/files/file_util.h" | 14 #include "base/files/file_util.h" |
| 15 #include "base/logging.h" |
| 13 #include "base/path_service.h" | 16 #include "base/path_service.h" |
| 14 #include "base/strings/string_split.h" | 17 #include "base/strings/string_split.h" |
| 15 #include "base/strings/string_util.h" | 18 #include "base/strings/string_util.h" |
| 19 #include "base/strings/stringprintf.h" |
| 16 #include "base/test/perf_log.h" | 20 #include "base/test/perf_log.h" |
| 17 | 21 |
| 18 namespace mojo { | 22 namespace mojo { |
| 19 namespace test { | 23 namespace test { |
| 20 namespace { | 24 namespace { |
| 21 | 25 |
| 22 base::FilePath ResolveSourceRootRelativePath(const char* relative_path) { | 26 base::FilePath ResolveSourceRootRelativePath(const char* relative_path) { |
| 23 base::FilePath path; | 27 base::FilePath path; |
| 24 if (!PathService::Get(base::DIR_SOURCE_ROOT, &path)) | 28 if (!PathService::Get(base::DIR_SOURCE_ROOT, &path)) |
| 25 return base::FilePath(); | 29 return base::FilePath(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 37 | 41 |
| 38 } // namespace | 42 } // namespace |
| 39 | 43 |
| 40 TestSupportImpl::TestSupportImpl() { | 44 TestSupportImpl::TestSupportImpl() { |
| 41 } | 45 } |
| 42 | 46 |
| 43 TestSupportImpl::~TestSupportImpl() { | 47 TestSupportImpl::~TestSupportImpl() { |
| 44 } | 48 } |
| 45 | 49 |
| 46 void TestSupportImpl::LogPerfResult(const char* test_name, | 50 void TestSupportImpl::LogPerfResult(const char* test_name, |
| 51 const char* sub_test_name, |
| 47 double value, | 52 double value, |
| 48 const char* units) { | 53 const char* units) { |
| 49 base::LogPerfResult(test_name, value, units); | 54 DCHECK(test_name); |
| 55 if (sub_test_name) { |
| 56 std::string name = base::StringPrintf("%s/%s", test_name, sub_test_name); |
| 57 base::LogPerfResult(name.c_str(), value, units); |
| 58 } else { |
| 59 base::LogPerfResult(test_name, value, units); |
| 60 } |
| 50 } | 61 } |
| 51 | 62 |
| 52 FILE* TestSupportImpl::OpenSourceRootRelativeFile(const char* relative_path) { | 63 FILE* TestSupportImpl::OpenSourceRootRelativeFile(const char* relative_path) { |
| 53 return base::OpenFile(ResolveSourceRootRelativePath(relative_path), "rb"); | 64 return base::OpenFile(ResolveSourceRootRelativePath(relative_path), "rb"); |
| 54 } | 65 } |
| 55 | 66 |
| 56 char** TestSupportImpl::EnumerateSourceRootRelativeDirectory( | 67 char** TestSupportImpl::EnumerateSourceRootRelativeDirectory( |
| 57 const char* relative_path) { | 68 const char* relative_path) { |
| 58 std::vector<std::string> names; | 69 std::vector<std::string> names; |
| 59 base::FileEnumerator e(ResolveSourceRootRelativePath(relative_path), false, | 70 base::FileEnumerator e(ResolveSourceRootRelativePath(relative_path), false, |
| 60 base::FileEnumerator::FILES); | 71 base::FileEnumerator::FILES); |
| 61 for (base::FilePath name = e.Next(); !name.empty(); name = e.Next()) | 72 for (base::FilePath name = e.Next(); !name.empty(); name = e.Next()) |
| 62 names.push_back(name.BaseName().AsUTF8Unsafe()); | 73 names.push_back(name.BaseName().AsUTF8Unsafe()); |
| 63 | 74 |
| 64 // |names.size() + 1| for null terminator. | 75 // |names.size() + 1| for null terminator. |
| 65 char** rv = static_cast<char**>(calloc(names.size() + 1, sizeof(char*))); | 76 char** rv = static_cast<char**>(calloc(names.size() + 1, sizeof(char*))); |
| 66 for (size_t i = 0; i < names.size(); ++i) | 77 for (size_t i = 0; i < names.size(); ++i) |
| 67 rv[i] = base::strdup(names[i].c_str()); | 78 rv[i] = base::strdup(names[i].c_str()); |
| 68 return rv; | 79 return rv; |
| 69 } | 80 } |
| 70 | 81 |
| 71 } // namespace test | 82 } // namespace test |
| 72 } // namespace mojo | 83 } // namespace mojo |
| OLD | NEW |