Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <stdio.h> | 5 #include <stdio.h> |
| 6 | 6 |
| 7 #include "base/at_exit.h" | 7 #include "base/at_exit.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
| 12 #include "base/process_util.h" | 12 #include "base/process_util.h" |
| 13 #include "base/test/test_timeouts.h" | 13 #include "base/test/test_timeouts.h" |
| 14 #include "base/string_number_conversions.h" | |
|
Paweł Hajdan Jr.
2012/05/23 06:53:02
nit: Sort.
Raghu Simha
2012/05/23 19:54:28
Done.
| |
| 14 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
| 15 #include "net/test/python_utils.h" | 16 #include "net/test/python_utils.h" |
| 16 #include "net/test/test_server.h" | 17 #include "net/test/test_server.h" |
| 18 #include "net/test/local_sync_test_server.h" | |
|
Paweł Hajdan Jr.
2012/05/23 06:53:02
nit: Sort.
Raghu Simha
2012/05/23 19:54:28
Done.
| |
| 17 | 19 |
| 18 static void PrintUsage() { | 20 static void PrintUsage() { |
| 19 printf("run_testserver --doc-root=relpath [--http|--https|--ftp|--sync]\n" | 21 printf("run_testserver --doc-root=relpath [--http|--https|--ftp|--sync]\n" |
| 20 " [--https-cert=ok|mismatched-name|expired]\n"); | 22 " [--https-cert=ok|mismatched-name|expired]\n" |
| 21 printf("(NOTE: relpath should be relative to the 'src' directory)\n"); | 23 " [--port=<port>] [--xmpp-port=<xmpp_port>]\n"); |
| 24 printf("(NOTE: relpath should be relative to the 'src' directory.\n"); | |
| 25 printf(" --port and --xmpp-port only work with the --sync flag.)\n"); | |
|
Paweł Hajdan Jr.
2012/05/23 06:53:02
Please add code to error out when those switches a
Raghu Simha
2012/05/23 19:54:28
Done.
| |
| 22 } | 26 } |
| 23 | 27 |
| 24 // Launches the chromiumsync_test script, testing the --sync functionality. | 28 // Launches the chromiumsync_test script, testing the --sync functionality. |
| 25 static bool RunSyncTest() { | 29 static bool RunSyncTest() { |
| 26 if (!net::TestServer::SetPythonPath()) { | 30 if (!net::TestServer::SetPythonPath()) { |
| 27 LOG(ERROR) << "Error trying to set python path. Exiting."; | 31 LOG(ERROR) << "Error trying to set python path. Exiting."; |
| 28 return false; | 32 return false; |
| 29 } | 33 } |
| 30 | 34 |
| 31 FilePath sync_test_path; | 35 FilePath sync_test_path; |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 44 | 48 |
| 45 CommandLine python_command(python_runtime); | 49 CommandLine python_command(python_runtime); |
| 46 python_command.AppendArgPath(sync_test_path); | 50 python_command.AppendArgPath(sync_test_path); |
| 47 if (!base::LaunchProcess(python_command, base::LaunchOptions(), NULL)) { | 51 if (!base::LaunchProcess(python_command, base::LaunchOptions(), NULL)) { |
| 48 LOG(ERROR) << "Failed to launch test script."; | 52 LOG(ERROR) << "Failed to launch test script."; |
| 49 return false; | 53 return false; |
| 50 } | 54 } |
| 51 return true; | 55 return true; |
| 52 } | 56 } |
| 53 | 57 |
| 58 // Gets a port value from the switch with name |switch_name|. | |
| 59 static uint16 GetPortFromSwitch(const std::string& switch_name) { | |
| 60 CommandLine* command_line = CommandLine::ForCurrentProcess(); | |
| 61 int port_int = 0; | |
| 62 if (command_line->HasSwitch(switch_name)) { | |
| 63 std::string port_str = command_line->GetSwitchValueASCII(switch_name); | |
| 64 if (!base::StringToInt(port_str, &port_int)) { | |
| 65 LOG(WARNING) << "Could not extract port from switch " << switch_name; | |
|
Paweł Hajdan Jr.
2012/05/23 06:53:02
How about making the function return bool success,
Raghu Simha
2012/05/23 19:54:28
Done.
| |
| 66 return 0; | |
| 67 } | |
| 68 } | |
| 69 return static_cast<uint16>(port_int); | |
| 70 } | |
| 71 | |
| 54 int main(int argc, const char* argv[]) { | 72 int main(int argc, const char* argv[]) { |
| 55 base::AtExitManager at_exit_manager; | 73 base::AtExitManager at_exit_manager; |
| 56 MessageLoopForIO message_loop; | 74 MessageLoopForIO message_loop; |
| 57 | 75 |
| 58 // Process command line | 76 // Process command line |
| 59 CommandLine::Init(argc, argv); | 77 CommandLine::Init(argc, argv); |
| 60 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 78 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 61 | 79 |
| 62 if (!logging::InitLogging( | 80 if (!logging::InitLogging( |
| 63 FILE_PATH_LITERAL("testserver.log"), | 81 FILE_PATH_LITERAL("testserver.log"), |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 107 } | 125 } |
| 108 | 126 |
| 109 FilePath doc_root = command_line->GetSwitchValuePath("doc-root"); | 127 FilePath doc_root = command_line->GetSwitchValuePath("doc-root"); |
| 110 if ((server_type != net::TestServer::TYPE_SYNC) && doc_root.empty()) { | 128 if ((server_type != net::TestServer::TYPE_SYNC) && doc_root.empty()) { |
| 111 printf("Error: --doc-root must be specified\n"); | 129 printf("Error: --doc-root must be specified\n"); |
| 112 PrintUsage(); | 130 PrintUsage(); |
| 113 return -1; | 131 return -1; |
| 114 } | 132 } |
| 115 | 133 |
| 116 scoped_ptr<net::TestServer> test_server; | 134 scoped_ptr<net::TestServer> test_server; |
| 117 if (server_type == net::TestServer::TYPE_HTTPS) | 135 switch (server_type) { |
| 118 test_server.reset(new net::TestServer(https_options, doc_root)); | 136 case net::TestServer::TYPE_HTTPS: { |
|
akalin
2012/05/23 06:16:49
usual style is to leave the braces out unless nece
Paweł Hajdan Jr.
2012/05/23 06:53:02
+1, please do
Raghu Simha
2012/05/23 19:54:28
Moot.
Raghu Simha
2012/05/23 19:54:28
Moot.
| |
| 119 else | 137 test_server.reset(new net::TestServer(https_options, doc_root)); |
| 120 test_server.reset(new net::TestServer(server_type, | 138 break; |
| 121 net::TestServer::kLocalhost, | 139 } |
| 122 doc_root)); | 140 case net::TestServer::TYPE_SYNC: { |
| 141 test_server.reset(new net::LocalSyncTestServer( | |
| 142 GetPortFromSwitch("port"), GetPortFromSwitch("xmpp-port"))); | |
| 143 break; | |
| 144 } | |
| 145 default: { | |
| 146 test_server.reset(new net::TestServer(server_type, | |
| 147 net::TestServer::kLocalhost, | |
| 148 doc_root)); | |
| 149 break; | |
| 150 } | |
| 151 } | |
| 123 | 152 |
| 124 if (!test_server->Start()) { | 153 if (!test_server->Start()) { |
| 125 printf("Error: failed to start test server. Exiting.\n"); | 154 printf("Error: failed to start test server. Exiting.\n"); |
| 126 return -1; | 155 return -1; |
| 127 } | 156 } |
| 128 | 157 |
| 129 if (!file_util::DirectoryExists(test_server->document_root())) { | 158 if (!file_util::DirectoryExists(test_server->document_root())) { |
| 130 printf("Error: invalid doc root: \"%s\" does not exist!\n", | 159 printf("Error: invalid doc root: \"%s\" does not exist!\n", |
| 131 UTF16ToUTF8(test_server->document_root().LossyDisplayName()).c_str()); | 160 UTF16ToUTF8(test_server->document_root().LossyDisplayName()).c_str()); |
| 132 return -1; | 161 return -1; |
| 133 } | 162 } |
| 134 | 163 |
| 135 printf("testserver running at %s (type ctrl+c to exit)\n", | 164 printf("testserver running at %s (type ctrl+c to exit)\n", |
| 136 test_server->host_port_pair().ToString().c_str()); | 165 test_server->host_port_pair().ToString().c_str()); |
| 137 | 166 |
| 138 message_loop.Run(); | 167 message_loop.Run(); |
| 139 return 0; | 168 return 0; |
| 140 } | 169 } |
| OLD | NEW |