blob: f3772c4fe33349bfa60f8cdfc428d12567689409 [file] [log] [blame]
kjellander@webrtc.org7951e812011-10-13 12:24:41 +00001/*
2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10#include "fileutils.h"
11#include "gtest/gtest.h"
12
13#ifdef WIN32
14#define PATH_DELIMITER "\\"
15#else
16#define PATH_DELIMITER "/"
17#endif
18
19namespace webrtc {
20namespace test {
21
22// Tests that the project root path is returnd for the default working directory
23// that is automatically set when the test executable is launched.
24// The test is not fully testing the implementation, since we cannot be sure
25// of where the executable was launched from.
26// The test will fail if the top level directory is not named "trunk".
27TEST(FileUtilsTest, GetProjectRootPathFromUnchangedWorkingDir) {
28 std::string path = GetProjectRootPath();
29 std::string expected_end = "trunk";
30 expected_end = PATH_DELIMITER + expected_end + PATH_DELIMITER;
31 ASSERT_EQ(path.length() - expected_end.length(), path.find(expected_end));
32}
33
34// Tests setting the current working directory to a directory three levels
35// deeper from the current one. Then testing that the project path returned
36// is still the same, when the function under test is called again.
37TEST(FileUtilsTest, GetProjectRootPathFromDeeperWorkingDir) {
38 std::string path = GetProjectRootPath();
39 std::string original_working_dir = path; // This is the correct project root
40
41 // Change to a subdirectory path (the full path doesn't have to exist).
42 path += "foo/bar/baz";
43 chdir(path.c_str());
44
45 ASSERT_EQ(original_working_dir, GetProjectRootPath());
46}
47
48// Tests with current working directory set to a directory higher up in the
49// directory tree than the project root dir. This case shall return a specified
50// error string as a directory (which will be an invalid path).
51TEST(FileUtilsTest, GetProjectRootPathFromRootWorkingDir) {
52 // Change current working dir to the root of the current file system
53 // (this will always be "above" our project root dir).
54 chdir(PATH_DELIMITER);
55 ASSERT_EQ(kCannotFindProjectRootDir, GetProjectRootPath());
56}
57
58} // namespace test
59} // namespace webrtc