The ReadFile API on Windows invoked by the FileStream::Context class which is used...
[chromium-blink-merge.git] / testing / android / native_test_util.cc
blob885f297c1efb865ef6c72790dfab0af45c9943e7
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
3 // found in the LICENSE file.
5 #include "testing/android/native_test_util.h"
7 #include "base/files/file_path.h"
8 #include "base/files/file_util.h"
9 #include "base/strings/string_tokenizer.h"
10 #include "base/strings/string_util.h"
12 namespace testing {
13 namespace native_test_util {
15 void ParseArgsFromString(const std::string& command_line,
16 std::vector<std::string>* args) {
17 base::StringTokenizer tokenizer(command_line, base::kWhitespaceASCII);
18 tokenizer.set_quote_chars("\"");
19 while (tokenizer.GetNext()) {
20 std::string token;
21 base::RemoveChars(tokenizer.token(), "\"", &token);
22 args->push_back(token);
26 void ParseArgsFromCommandLineFile(
27 const char* path, std::vector<std::string>* args) {
28 base::FilePath command_line(path);
29 std::string command_line_string;
30 if (base::ReadFileToString(command_line, &command_line_string)) {
31 ParseArgsFromString(command_line_string, args);
35 int ArgsToArgv(const std::vector<std::string>& args,
36 std::vector<char*>* argv) {
37 // We need to pass in a non-const char**.
38 int argc = args.size();
40 argv->resize(argc + 1);
41 for (int i = 0; i < argc; ++i) {
42 (*argv)[i] = const_cast<char*>(args[i].c_str());
44 (*argv)[argc] = NULL; // argv must be NULL terminated.
46 return argc;
49 } // namespace native_test_util
50 } // namespace testing