phajdan.jr@chromium.org | efd7440 | 2010-09-03 23:54:36 +0000 | [diff] [blame] | 1 | // Copyright (c) 2010 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. |
| 4 | |
| 5 | #include <stdio.h> |
| 6 | |
| 7 | #include "base/at_exit.h" |
| 8 | #include "base/command_line.h" |
akalin@chromium.org | 3dfcd45 | 2010-11-18 22:29:38 +0000 | [diff] [blame] | 9 | #include "base/file_path.h" |
phajdan.jr@chromium.org | efd7440 | 2010-09-03 23:54:36 +0000 | [diff] [blame] | 10 | #include "base/logging.h" |
| 11 | #include "base/message_loop.h" |
| 12 | #include "net/test/test_server.h" |
| 13 | |
| 14 | static void PrintUsage() { |
akalin@chromium.org | 154bb13 | 2010-11-12 02:20:27 +0000 | [diff] [blame] | 15 | printf("run_testserver --doc-root=relpath [--http|--https|--ftp|--sync]\n"); |
phajdan.jr@chromium.org | efd7440 | 2010-09-03 23:54:36 +0000 | [diff] [blame] | 16 | printf("(NOTE: relpath should be relative to the 'src' directory)\n"); |
| 17 | } |
| 18 | |
| 19 | int main(int argc, const char* argv[]) { |
| 20 | base::AtExitManager at_exit_manager; |
| 21 | MessageLoopForIO message_loop; |
| 22 | |
| 23 | // Process command line |
| 24 | CommandLine::Init(argc, argv); |
| 25 | CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 26 | |
akalin@chromium.org | c3062de | 2011-01-11 01:03:36 +0000 | [diff] [blame] | 27 | if (!logging::InitLogging( |
| 28 | FILE_PATH_LITERAL("testserver.log"), |
| 29 | logging::LOG_TO_BOTH_FILE_AND_SYSTEM_DEBUG_LOG, |
| 30 | logging::LOCK_LOG_FILE, |
| 31 | logging::APPEND_TO_OLD_LOG_FILE, |
| 32 | logging::DISABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS)) { |
akalin@chromium.org | 3dfcd45 | 2010-11-18 22:29:38 +0000 | [diff] [blame] | 33 | printf("Error: could not initialize logging. Exiting.\n"); |
| 34 | return -1; |
| 35 | } |
| 36 | |
phajdan.jr@chromium.org | efd7440 | 2010-09-03 23:54:36 +0000 | [diff] [blame] | 37 | if (command_line->GetSwitchCount() == 0 || |
| 38 | command_line->HasSwitch("help")) { |
| 39 | PrintUsage(); |
| 40 | return -1; |
| 41 | } |
| 42 | |
phajdan.jr@chromium.org | efd7440 | 2010-09-03 23:54:36 +0000 | [diff] [blame] | 43 | net::TestServer::Type server_type(net::TestServer::TYPE_HTTP); |
| 44 | if (command_line->HasSwitch("https")) { |
| 45 | server_type = net::TestServer::TYPE_HTTPS; |
| 46 | } else if (command_line->HasSwitch("ftp")) { |
| 47 | server_type = net::TestServer::TYPE_FTP; |
akalin@chromium.org | 154bb13 | 2010-11-12 02:20:27 +0000 | [diff] [blame] | 48 | } else if (command_line->HasSwitch("sync")) { |
| 49 | server_type = net::TestServer::TYPE_SYNC; |
| 50 | } |
| 51 | |
| 52 | FilePath doc_root = command_line->GetSwitchValuePath("doc-root"); |
| 53 | if ((server_type != net::TestServer::TYPE_SYNC) && doc_root.empty()) { |
| 54 | printf("Error: --doc-root must be specified\n"); |
| 55 | PrintUsage(); |
| 56 | return -1; |
phajdan.jr@chromium.org | efd7440 | 2010-09-03 23:54:36 +0000 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | net::TestServer test_server(server_type, doc_root); |
| 60 | if (!test_server.Start()) { |
| 61 | printf("Error: failed to start test server. Exiting.\n"); |
| 62 | return -1; |
| 63 | } |
| 64 | |
| 65 | printf("testserver running at %s (type ctrl+c to exit)\n", |
| 66 | test_server.host_port_pair().ToString().c_str()); |
| 67 | |
| 68 | message_loop.Run(); |
| 69 | return 0; |
| 70 | } |