summaryrefslogtreecommitdiffstats
path: root/net/test
diff options
context:
space:
mode:
authorlzheng@chromium.org <lzheng@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-16 18:36:46 +0000
committerlzheng@chromium.org <lzheng@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-16 18:36:46 +0000
commit9c7361237bc798c936278c6e01ca93e57fd53177 (patch)
tree4dd8e376a5609ff622ae17ce9886764bff3a912d /net/test
parentbb91929b4f9407b3bccd40e81eee3334fa0b3a47 (diff)
downloadchromium_src-9c7361237bc798c936278c6e01ca93e57fd53177.zip
chromium_src-9c7361237bc798c936278c6e01ca93e57fd53177.tar.gz
chromium_src-9c7361237bc798c936278c6e01ca93e57fd53177.tar.bz2
Revert 59671 - Refactor test_server so some python related functions could be shared by other test servers.
BUG=none TEST=python_utils_unittest.cc Review URL: http://codereview.chromium.org/3366026 TBR=thakis@chromium.org Review URL: http://codereview.chromium.org/3415011 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@59680 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/test')
-rw-r--r--net/test/python_utils.cc51
-rw-r--r--net/test/python_utils.h23
-rw-r--r--net/test/python_utils_unittest.cc51
-rw-r--r--net/test/test_server.cc1
-rw-r--r--net/test/test_server.h3
-rw-r--r--net/test/test_server_posix.cc16
-rw-r--r--net/test/test_server_win.cc16
7 files changed, 35 insertions, 126 deletions
diff --git a/net/test/python_utils.cc b/net/test/python_utils.cc
deleted file mode 100644
index 5f574fe..0000000
--- a/net/test/python_utils.cc
+++ /dev/null
@@ -1,51 +0,0 @@
-// 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 "net/test/python_utils.h"
-
-#include "base/base_paths.h"
-#include "base/environment.h"
-#include "base/file_path.h"
-#include "base/path_service.h"
-#include "base/scoped_ptr.h"
-#include "base/utf_string_conversions.h"
-
-const char kPythonPathEnv[] = "PYTHONPATH";
-
-void AppendToPythonPath(const FilePath& dir) {
- scoped_ptr<base::Environment> env(base::Environment::Create());
- std::string old_path;
- std::string dir_path;
-#if defined(OS_WIN)
- dir_path = WideToUTF8(dir.value());
-#elif defined(OS_POSIX)
- dir_path = dir.value();
-#endif
- if (!env->GetVar(kPythonPathEnv, &old_path)) {
- env->SetVar(kPythonPathEnv, dir_path.c_str());
- } else if (old_path.find(dir_path) == std::string::npos) {
- std::string new_path(old_path);
-#if defined(OS_WIN)
- new_path.append(";");
-#elif defined(OS_POSIX)
- new_path.append(":");
-#endif
- new_path.append(dir_path.c_str());
- env->SetVar(kPythonPathEnv, new_path);
- }
-}
-
-bool GetPythonRunTime(FilePath* dir) {
-#if defined(OS_WIN)
- if (!PathService::Get(base::DIR_SOURCE_ROOT, dir))
- return false;
- *dir = FilePath(FILE_PATH_LITERAL("third_party"))
- .Append(FILE_PATH_LITERAL("python_24"))
- .Append(FILE_PATH_LITERAL("python.exe"));
-#elif defined(OS_POSIX)
- *dir = FilePath("python");
-#endif
- return true;
-}
-
diff --git a/net/test/python_utils.h b/net/test/python_utils.h
deleted file mode 100644
index 215569c..0000000
--- a/net/test/python_utils.h
+++ /dev/null
@@ -1,23 +0,0 @@
-// 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.
-
-#ifndef NET_TEST_PYTHON_UTILS_H_
-#define NET_TEST_PYTHON_UTILS_H_
-#pragma once
-
-#include "base/compiler_specific.h"
-
-class FilePath;
-
-// This is the python path variable name.
-extern const char kPythonPathEnv[];
-
-// Appends the dir to python path environment variable.
-void AppendToPythonPath(const FilePath& dir);
-
-// Returns the path that should be used to launch Python.
-bool GetPythonRunTime(FilePath* path) WARN_UNUSED_RESULT;
-
-#endif // NET_TEST_PYTHON_UTILS_H_
-
diff --git a/net/test/python_utils_unittest.cc b/net/test/python_utils_unittest.cc
deleted file mode 100644
index 4026840..0000000
--- a/net/test/python_utils_unittest.cc
+++ /dev/null
@@ -1,51 +0,0 @@
-// 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 "base/environment.h"
-#include "base/file_path.h"
-#include "base/scoped_ptr.h"
-#include "net/test/python_utils.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-TEST(PythonUtils, Append) {
- const FilePath::CharType kAppendDir1[] =
- FILE_PATH_LITERAL("test/path_append1");
- const FilePath::CharType kAppendDir2[] =
- FILE_PATH_LITERAL("test/path_append2");
-
- scoped_ptr<base::Environment> env(base::Environment::Create());
-
- std::string python_path;
- FilePath append_path1(kAppendDir1);
- FilePath append_path2(kAppendDir2);
-
- // Get a clean start
- env->UnSetVar(kPythonPathEnv);
-
- // Append the path
- AppendToPythonPath(append_path1);
- env->GetVar(kPythonPathEnv, &python_path);
- ASSERT_EQ(python_path, "test/path_append1");
-
- // Append the safe path again, nothing changes
- AppendToPythonPath(append_path2);
- env->GetVar(kPythonPathEnv, &python_path);
-#if defined(OS_WIN)
- ASSERT_EQ(std::string("test/path_append1;test/path_append2"), python_path);
-#elif defined(OS_POSIX)
- ASSERT_EQ(std::string("test/path_append1:test/path_append2"), python_path);
-#endif
-}
-
-TEST(PythonUtils, PythonRunTime) {
- FilePath dir;
- EXPECT_TRUE(GetPythonRunTime(&dir));
-#if defined(OS_WIN)
- EXPECT_NE(std::wstring::npos,
- dir.value().find(L"third_party\\python_24\\python.exe"));
-#elif defined(OS_POSIX)
- EXPECT_NE(std::string::npos, dir.value().find("python"));
-#endif
-}
-
diff --git a/net/test/test_server.cc b/net/test/test_server.cc
index 4c698b0..e727791 100644
--- a/net/test/test_server.cc
+++ b/net/test/test_server.cc
@@ -28,7 +28,6 @@
#include "net/base/test_completion_callback.h"
#include "net/socket/tcp_client_socket.h"
#include "net/socket/tcp_pinger.h"
-#include "net/test/python_utils.h"
#include "testing/platform_test.h"
namespace {
diff --git a/net/test/test_server.h b/net/test/test_server.h
index 8b6dc63..5f51571 100644
--- a/net/test/test_server.h
+++ b/net/test/test_server.h
@@ -72,6 +72,9 @@ class TestServer {
const std::string& password);
private:
+ // Appends |dir| to PYTHONPATH.
+ static void AppendToPythonPath(const FilePath& dir);
+
// Modify PYTHONPATH to contain libraries we need.
bool SetPythonPath() WARN_UNUSED_RESULT;
diff --git a/net/test/test_server_posix.cc b/net/test/test_server_posix.cc
index 7741d89..783bdc3 100644
--- a/net/test/test_server_posix.cc
+++ b/net/test/test_server_posix.cc
@@ -9,6 +9,22 @@
#include "base/string_number_conversions.h"
namespace net {
+
+// static
+void TestServer::AppendToPythonPath(const FilePath& dir) {
+ const char kPythonPath[] = "PYTHONPATH";
+ const char* oldpath = getenv(kPythonPath);
+ // setenv() leaks memory intentionally on Mac
+ if (!oldpath) {
+ setenv(kPythonPath, dir.value().c_str(), 1);
+ } else if (!strstr(oldpath, dir.value().c_str())) {
+ std::string newpath(oldpath);
+ newpath.append(":");
+ newpath.append(dir.value());
+ setenv(kPythonPath, newpath.c_str(), 1);
+ }
+}
+
bool TestServer::LaunchPython(const FilePath& testserver_path) {
std::vector<std::string> command_line;
command_line.push_back("python");
diff --git a/net/test/test_server_win.cc b/net/test/test_server_win.cc
index 7e8443f..b806cba 100644
--- a/net/test/test_server_win.cc
+++ b/net/test/test_server_win.cc
@@ -74,6 +74,22 @@ bool LaunchTestServerAsJob(const std::wstring& cmdline,
} // namespace
namespace net {
+
+// static
+void TestServer::AppendToPythonPath(const FilePath& dir) {
+ const wchar_t kPythonPath[] = L"PYTHONPATH";
+ // TODO(dkegel): handle longer PYTHONPATH variables
+ wchar_t oldpath[4096];
+ if (GetEnvironmentVariable(kPythonPath, oldpath, arraysize(oldpath)) == 0) {
+ SetEnvironmentVariableW(kPythonPath, dir.value().c_str());
+ } else if (!wcsstr(oldpath, dir.value().c_str())) {
+ std::wstring newpath(oldpath);
+ newpath.append(L";");
+ newpath.append(dir.value());
+ SetEnvironmentVariableW(kPythonPath, newpath.c_str());
+ }
+}
+
bool TestServer::LaunchPython(const FilePath& testserver_path) {
FilePath python_exe;
if (!PathService::Get(base::DIR_SOURCE_ROOT, &python_exe))