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 "mojo/common/test/test_support_impl.h"
10 #include "base/files/file_enumerator.h"
11 #include "base/files/file_path.h"
12 #include "base/files/file_util.h"
13 #include "base/path_service.h"
14 #include "base/strings/string_split.h"
15 #include "base/strings/string_util.h"
16 #include "base/test/perf_log.h"
22 base::FilePath ResolveSourceRootRelativePath(const char* relative_path) {
24 if (!PathService::Get(base::DIR_SOURCE_ROOT, &path))
25 return base::FilePath();
27 std::vector<std::string> components;
28 base::SplitString(relative_path, '/', &components);
30 for (size_t i = 0; i < components.size(); ++i) {
31 if (!components[i].empty())
32 path = path.AppendASCII(components[i]);
40 TestSupportImpl::TestSupportImpl() {
43 TestSupportImpl::~TestSupportImpl() {
46 void TestSupportImpl::LogPerfResult(const char* test_name,
49 base::LogPerfResult(test_name, value, units);
52 FILE* TestSupportImpl::OpenSourceRootRelativeFile(const char* relative_path) {
53 return base::OpenFile(ResolveSourceRootRelativePath(relative_path), "rb");
56 char** TestSupportImpl::EnumerateSourceRootRelativeDirectory(
57 const char* relative_path) {
58 std::vector<std::string> names;
59 base::FileEnumerator e(ResolveSourceRootRelativePath(relative_path), false,
60 base::FileEnumerator::FILES);
61 for (base::FilePath name = e.Next(); !name.empty(); name = e.Next())
62 names.push_back(name.BaseName().AsUTF8Unsafe());
64 // |names.size() + 1| for null terminator.
65 char** rv = static_cast<char**>(calloc(names.size() + 1, sizeof(char*)));
66 for (size_t i = 0; i < names.size(); ++i)
67 rv[i] = base::strdup(names[i].c_str());