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