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

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 validation_interfaces.mojom for now Created 6 years, 8 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
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
viettrungluu 2014/04/25 21:55:59 #include "base/files/file_path.h"
viettrungluu 2014/04/25 21:55:59 #include <stdlib.h> #include <string.h> (for call
darin (slow to review) 2014/04/29 06:31:45 Hmm, I generally follow an approach of only includ
viettrungluu 2014/04/29 20:55:01 In this case, file_util.h really should only forwa
7 #include "base/file_util.h"
8 #include "base/files/file_enumerator.h"
9 #include "base/path_service.h"
10 #include "base/strings/string_split.h"
7 #include "base/test/perf_log.h" 11 #include "base/test/perf_log.h"
8 12
9 namespace mojo { 13 namespace mojo {
10 namespace test { 14 namespace test {
15 namespace {
16
17 base::FilePath ResolveSourceRootRelativePath(const char* relative_path) {
18 base::FilePath path;
19 if (!PathService::Get(base::DIR_SOURCE_ROOT, &path))
20 return base::FilePath();
21
22 std::vector<std::string> components;
23 base::SplitString(relative_path, '/', &components);
24
25 for (size_t i = 0; i < components.size(); ++i) {
26 if (!components[i].empty())
27 path = path.AppendASCII(components[i]);
28 }
29
30 return path;
31 }
32
33 } // namespace
11 34
12 TestSupportImpl::TestSupportImpl() { 35 TestSupportImpl::TestSupportImpl() {
13 } 36 }
14 37
15 TestSupportImpl::~TestSupportImpl() { 38 TestSupportImpl::~TestSupportImpl() {
16 } 39 }
17 40
18 void TestSupportImpl::LogPerfResult(const char* test_name, 41 void TestSupportImpl::LogPerfResult(const char* test_name,
19 double value, 42 double value,
20 const char* units) { 43 const char* units) {
21 base::LogPerfResult(test_name, value, units); 44 base::LogPerfResult(test_name, value, units);
22 } 45 }
23 46
47 FILE* TestSupportImpl::OpenSourceRootRelativeFile(const char* relative_path) {
48 return base::OpenFile(ResolveSourceRootRelativePath(relative_path), "rt");
viettrungluu 2014/04/25 21:55:59 Do we really want "rt"?
darin (slow to review) 2014/04/29 06:31:45 Oh, hmm... we can leave off the "t". That is just
viettrungluu 2014/04/29 20:55:01 (Makes me think that we should do "rb", actually!)
49 }
50
51 char** TestSupportImpl::EnumerateSourceRootRelativeDirectory(
52 const char* relative_path) {
53 std::vector<std::string> names;
54 base::FileEnumerator e(ResolveSourceRootRelativePath(relative_path), false,
55 base::FileEnumerator::FILES);
56 for (base::FilePath name = e.Next(); !name.empty(); name = e.Next())
57 names.push_back(name.BaseName().AsUTF8Unsafe());
58
59 char** rv = static_cast<char**>(calloc(names.size() + 1, sizeof(char*)));
60 for (size_t i = 0; i < names.size(); ++i)
61 rv[i] = strdup(names[i].c_str());
62 rv[names.size()] = NULL;
viettrungluu 2014/04/25 21:55:59 calloc actually zeros memory.
darin (slow to review) 2014/04/29 06:31:45 Yeah. Perhaps I'll draw attention to the extra NUL
63 return rv;
64 }
65
24 } // namespace test 66 } // namespace test
25 } // namespace mojo 67 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698