blob: 4026840b5d7073d90b551abdcac185577fb5d390 [file] [log] [blame]
[email protected]9af13ce2010-09-16 21:45:481// 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 "base/environment.h"
6#include "base/file_path.h"
7#include "base/scoped_ptr.h"
8#include "net/test/python_utils.h"
9#include "testing/gtest/include/gtest/gtest.h"
10
11TEST(PythonUtils, Append) {
12 const FilePath::CharType kAppendDir1[] =
13 FILE_PATH_LITERAL("test/path_append1");
14 const FilePath::CharType kAppendDir2[] =
15 FILE_PATH_LITERAL("test/path_append2");
16
17 scoped_ptr<base::Environment> env(base::Environment::Create());
18
19 std::string python_path;
20 FilePath append_path1(kAppendDir1);
21 FilePath append_path2(kAppendDir2);
22
23 // Get a clean start
24 env->UnSetVar(kPythonPathEnv);
25
26 // Append the path
27 AppendToPythonPath(append_path1);
28 env->GetVar(kPythonPathEnv, &python_path);
29 ASSERT_EQ(python_path, "test/path_append1");
30
31 // Append the safe path again, nothing changes
32 AppendToPythonPath(append_path2);
33 env->GetVar(kPythonPathEnv, &python_path);
34#if defined(OS_WIN)
35 ASSERT_EQ(std::string("test/path_append1;test/path_append2"), python_path);
36#elif defined(OS_POSIX)
37 ASSERT_EQ(std::string("test/path_append1:test/path_append2"), python_path);
38#endif
39}
40
41TEST(PythonUtils, PythonRunTime) {
42 FilePath dir;
43 EXPECT_TRUE(GetPythonRunTime(&dir));
44#if defined(OS_WIN)
45 EXPECT_NE(std::wstring::npos,
46 dir.value().find(L"third_party\\python_24\\python.exe"));
47#elif defined(OS_POSIX)
48 EXPECT_NE(std::string::npos, dir.value().find("python"));
49#endif
50}
51