summaryrefslogtreecommitdiffstats
path: root/net/tools
diff options
context:
space:
mode:
authordarin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-09 19:16:42 +0000
committerdarin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-09 19:16:42 +0000
commitf87591e53e63812e918442f1013ab86bbbc4f84e (patch)
tree7be6313446bac823ad2e64b4b8471c918a29d940 /net/tools
parent6fd53820b6597855957560170c74a2f879ffd9ba (diff)
downloadchromium_src-f87591e53e63812e918442f1013ab86bbbc4f84e.zip
chromium_src-f87591e53e63812e918442f1013ab86bbbc4f84e.tar.gz
chromium_src-f87591e53e63812e918442f1013ab86bbbc4f84e.tar.bz2
Add a run_testserver executable to make it easy to run the testserver
standalone. Example: $ testserver --doc-root=net/data/url_request_unittest --http Also supports --https and --ftp. R=eroman BUG=none TEST=none Review URL: http://codereview.chromium.org/2901006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@51993 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/tools')
-rw-r--r--net/tools/testserver/run_testserver.cc70
1 files changed, 70 insertions, 0 deletions
diff --git a/net/tools/testserver/run_testserver.cc b/net/tools/testserver/run_testserver.cc
new file mode 100644
index 0000000..716e320
--- /dev/null
+++ b/net/tools/testserver/run_testserver.cc
@@ -0,0 +1,70 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <stdio.h>
+
+#include "base/at_exit.h"
+#include "base/command_line.h"
+#include "base/logging.h"
+#include "base/message_loop.h"
+#include "net/url_request/url_request_unittest.h"
+
+static void PrintUsage() {
+ printf("run_testserver --doc-root=relpath [--http|--https|--ftp]\n");
+ printf("(NOTE: relpath should be relative to the 'src' directory)\n");
+}
+
+int main(int argc, const char* argv[]) {
+ base::AtExitManager at_exit_manager;
+ MessageLoopForIO message_loop;
+
+ // Process command line
+ CommandLine::Init(argc, argv);
+ CommandLine* command_line = CommandLine::ForCurrentProcess();
+
+ if (command_line->GetSwitchCount() == 0 ||
+ command_line->HasSwitch("help")) {
+ PrintUsage();
+ return -1;
+ }
+
+ std::string protocol;
+ int port;
+ if (command_line->HasSwitch("https")) {
+ protocol = "https";
+ port = net::TestServerLauncher::kOKHTTPSPort;
+ } else if (command_line->HasSwitch("ftp")) {
+ protocol = "ftp";
+ port = kFTPDefaultPort;
+ } else {
+ protocol = "http";
+ port = kHTTPDefaultPort;
+ }
+ std::wstring doc_root = command_line->GetSwitchValue("doc-root");
+ if (doc_root.empty()) {
+ printf("Error: --doc-root must be specified\n");
+ PrintUsage();
+ return -1;
+ }
+
+ // Launch testserver
+ scoped_refptr<BaseTestServer> test_server;
+ if (protocol == "https") {
+ test_server = HTTPSTestServer::CreateGoodServer(doc_root);
+ } else if (protocol == "ftp") {
+ test_server = FTPTestServer::CreateServer(doc_root);
+ } else if (protocol == "http") {
+ test_server = HTTPTestServer::CreateServer(doc_root, NULL);
+ } else {
+ NOTREACHED();
+ }
+
+ printf("testserver running at %s://%s:%d (type ctrl+c to exit)\n",
+ protocol.c_str(),
+ net::TestServerLauncher::kHostName,
+ port);
+
+ message_loop.Run();
+ return 0;
+}