OLD | NEW |
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 "media/cast/test/utility/input_builder.h" | 5 #include "media/cast/test/utility/input_builder.h" |
6 | 6 |
7 #include <stdlib.h> | 7 #include <stdlib.h> |
8 #include <cstdio> | 8 #include <cstdio> |
9 | 9 |
| 10 #include "base/command_line.h" |
10 #include "base/logging.h" | 11 #include "base/logging.h" |
11 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
12 | 13 |
13 namespace media { | 14 namespace media { |
14 namespace cast { | 15 namespace cast { |
15 namespace test { | 16 namespace test { |
16 | 17 |
| 18 static const char kEnablePromptsSwitch[] = "enable-prompts"; |
| 19 |
17 InputBuilder::InputBuilder(const std::string& title, | 20 InputBuilder::InputBuilder(const std::string& title, |
18 const std::string& default_value, | 21 const std::string& default_value, |
19 int low_range, | 22 int low_range, |
20 int high_range) | 23 int high_range) |
21 : title_(title), | 24 : title_(title), |
22 default_value_(default_value), | 25 default_value_(default_value), |
23 low_range_(low_range), | 26 low_range_(low_range), |
24 high_range_(high_range) {} | 27 high_range_(high_range) {} |
25 | 28 |
26 InputBuilder::~InputBuilder() {} | 29 InputBuilder::~InputBuilder() {} |
27 | 30 |
28 std::string InputBuilder::GetStringInput() const { | 31 std::string InputBuilder::GetStringInput() const { |
| 32 if (!CommandLine::ForCurrentProcess()->HasSwitch(kEnablePromptsSwitch)) |
| 33 return default_value_; |
| 34 |
29 printf("\n%s\n", title_.c_str()); | 35 printf("\n%s\n", title_.c_str()); |
30 if (!default_value_.empty()) | 36 if (!default_value_.empty()) |
31 printf("Hit enter for default (%s):\n", default_value_.c_str()); | 37 printf("Hit enter for default (%s):\n", default_value_.c_str()); |
32 | 38 |
33 printf("# "); | 39 printf("# "); |
34 fflush(stdout); | 40 fflush(stdout); |
35 char raw_input[128]; | 41 char raw_input[128]; |
36 if (!fgets(raw_input, 128, stdin)) { | 42 if (!fgets(raw_input, 128, stdin)) { |
37 NOTREACHED(); | 43 NOTREACHED(); |
38 return std::string(); | 44 return std::string(); |
(...skipping 24 matching lines...) Expand all Loading... |
63 return true; | 69 return true; |
64 int value; | 70 int value; |
65 if (!base::StringToInt(input, &value)) | 71 if (!base::StringToInt(input, &value)) |
66 return false; | 72 return false; |
67 return value >= low_range_ && value <= high_range_; | 73 return value >= low_range_ && value <= high_range_; |
68 } | 74 } |
69 | 75 |
70 } // namespace test | 76 } // namespace test |
71 } // namespace cast | 77 } // namespace cast |
72 } // namespace media | 78 } // namespace media |
OLD | NEW |