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

Side by Side Diff: mojo/common/test/test_support_impl.cc

Issue 229683005: Validate MessageHeader before using (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove debug printfs Created 6 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « mojo/common/test/test_support_impl.h ('k') | mojo/mojo_public.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/common/test/test_support_impl.h" 5 #include "mojo/common/test/test_support_impl.h"
6 6
7 #include <stdlib.h>
8 #include <string.h>
9
10 #include "base/file_util.h"
11 #include "base/files/file_enumerator.h"
12 #include "base/files/file_path.h"
13 #include "base/path_service.h"
14 #include "base/strings/string_split.h"
15 #include "base/strings/string_util.h"
7 #include "base/test/perf_log.h" 16 #include "base/test/perf_log.h"
8 17
9 namespace mojo { 18 namespace mojo {
10 namespace test { 19 namespace test {
20 namespace {
21
22 base::FilePath ResolveSourceRootRelativePath(const char* relative_path) {
23 base::FilePath path;
24 if (!PathService::Get(base::DIR_SOURCE_ROOT, &path))
25 return base::FilePath();
26
27 std::vector<std::string> components;
28 base::SplitString(relative_path, '/', &components);
29
30 for (size_t i = 0; i < components.size(); ++i) {
31 if (!components[i].empty())
32 path = path.AppendASCII(components[i]);
33 }
34
35 return path;
36 }
37
38 } // namespace
11 39
12 TestSupportImpl::TestSupportImpl() { 40 TestSupportImpl::TestSupportImpl() {
13 } 41 }
14 42
15 TestSupportImpl::~TestSupportImpl() { 43 TestSupportImpl::~TestSupportImpl() {
16 } 44 }
17 45
18 void TestSupportImpl::LogPerfResult(const char* test_name, 46 void TestSupportImpl::LogPerfResult(const char* test_name,
19 double value, 47 double value,
20 const char* units) { 48 const char* units) {
21 base::LogPerfResult(test_name, value, units); 49 base::LogPerfResult(test_name, value, units);
22 } 50 }
23 51
52 FILE* TestSupportImpl::OpenSourceRootRelativeFile(const char* relative_path) {
53 return base::OpenFile(ResolveSourceRootRelativePath(relative_path), "rb");
54 }
55
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());
63
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());
68 return rv;
69 }
70
24 } // namespace test 71 } // namespace test
25 } // namespace mojo 72 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/common/test/test_support_impl.h ('k') | mojo/mojo_public.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698