OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "testing/android/native_test_util.h" | 5 #include "testing/android/native_test_util.h" |
6 | 6 |
7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
9 #include "base/strings/string_tokenizer.h" | 9 #include "base/strings/string_tokenizer.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
11 | 11 |
12 namespace { | 12 namespace testing { |
| 13 namespace native_test_util { |
13 | 14 |
14 void ParseArgsFromString(const std::string& command_line, | 15 void ParseArgsFromString(const std::string& command_line, |
15 std::vector<std::string>* args) { | 16 std::vector<std::string>* args) { |
16 base::StringTokenizer tokenizer(command_line, base::kWhitespaceASCII); | 17 base::StringTokenizer tokenizer(command_line, base::kWhitespaceASCII); |
17 tokenizer.set_quote_chars("\""); | 18 tokenizer.set_quote_chars("\""); |
18 while (tokenizer.GetNext()) { | 19 while (tokenizer.GetNext()) { |
19 std::string token; | 20 std::string token; |
20 base::RemoveChars(tokenizer.token(), "\"", &token); | 21 base::RemoveChars(tokenizer.token(), "\"", &token); |
21 args->push_back(token); | 22 args->push_back(token); |
22 } | 23 } |
23 } | 24 } |
24 | 25 |
25 } // namespace | |
26 | |
27 namespace testing { | |
28 namespace native_test_util { | |
29 | |
30 void ParseArgsFromCommandLineFile( | 26 void ParseArgsFromCommandLineFile( |
31 const char* path, std::vector<std::string>* args) { | 27 const char* path, std::vector<std::string>* args) { |
32 base::FilePath command_line(path); | 28 base::FilePath command_line(path); |
33 std::string command_line_string; | 29 std::string command_line_string; |
34 if (base::ReadFileToString(command_line, &command_line_string)) { | 30 if (base::ReadFileToString(command_line, &command_line_string)) { |
35 ParseArgsFromString(command_line_string, args); | 31 ParseArgsFromString(command_line_string, args); |
36 } | 32 } |
37 } | 33 } |
38 | 34 |
39 int ArgsToArgv(const std::vector<std::string>& args, | 35 int ArgsToArgv(const std::vector<std::string>& args, |
40 std::vector<char*>* argv) { | 36 std::vector<char*>* argv) { |
41 // We need to pass in a non-const char**. | 37 // We need to pass in a non-const char**. |
42 int argc = args.size(); | 38 int argc = args.size(); |
43 | 39 |
44 argv->resize(argc + 1); | 40 argv->resize(argc + 1); |
45 for (int i = 0; i < argc; ++i) { | 41 for (int i = 0; i < argc; ++i) { |
46 (*argv)[i] = const_cast<char*>(args[i].c_str()); | 42 (*argv)[i] = const_cast<char*>(args[i].c_str()); |
47 } | 43 } |
48 (*argv)[argc] = NULL; // argv must be NULL terminated. | 44 (*argv)[argc] = NULL; // argv must be NULL terminated. |
49 | 45 |
50 return argc; | 46 return argc; |
51 } | 47 } |
52 | 48 |
53 } // namespace native_test_util | 49 } // namespace native_test_util |
54 } // namespace testing | 50 } // namespace testing |
OLD | NEW |