run_testserver.cc revision 3345a6884c488ff3a535c2c9acdd33d74b37e311
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" 9#include "base/logging.h" 10#include "base/message_loop.h" 11#include "net/test/test_server.h" 12 13static void PrintUsage() { 14 printf("run_testserver --doc-root=relpath [--http|--https|--ftp]\n"); 15 printf("(NOTE: relpath should be relative to the 'src' directory)\n"); 16} 17 18int main(int argc, const char* argv[]) { 19 base::AtExitManager at_exit_manager; 20 MessageLoopForIO message_loop; 21 22 // Process command line 23 CommandLine::Init(argc, argv); 24 CommandLine* command_line = CommandLine::ForCurrentProcess(); 25 26 if (command_line->GetSwitchCount() == 0 || 27 command_line->HasSwitch("help")) { 28 PrintUsage(); 29 return -1; 30 } 31 32 FilePath doc_root = command_line->GetSwitchValuePath("doc-root"); 33 if (doc_root.empty()) { 34 printf("Error: --doc-root must be specified\n"); 35 PrintUsage(); 36 return -1; 37 } 38 39 net::TestServer::Type server_type(net::TestServer::TYPE_HTTP); 40 if (command_line->HasSwitch("https")) { 41 server_type = net::TestServer::TYPE_HTTPS; 42 } else if (command_line->HasSwitch("ftp")) { 43 server_type = net::TestServer::TYPE_FTP; 44 } 45 46 net::TestServer test_server(server_type, doc_root); 47 if (!test_server.Start()) { 48 printf("Error: failed to start test server. Exiting.\n"); 49 return -1; 50 } 51 52 printf("testserver running at %s (type ctrl+c to exit)\n", 53 test_server.host_port_pair().ToString().c_str()); 54 55 message_loop.Run(); 56 return 0; 57} 58