kjellander@webrtc.org | 7951e81 | 2011-10-13 12:24:41 +0000 | [diff] [blame^] | 1 | /* |
| 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 | |
| 11 | // File utilities for testing purposes. |
| 12 | // The GetProjectRootPath() method is a convenient way of getting an absolute |
| 13 | // path to the project source tree root directory. Using this, it is easy to |
| 14 | // refer to test resource files in a portable way. |
| 15 | // |
| 16 | // Notice that even if Windows platforms use backslash as path delimiter, it is |
| 17 | // also supported to use slash, so there's no need for #ifdef checks in test |
| 18 | // code for setting up the paths to the resource files. |
| 19 | // |
| 20 | // Example use: |
| 21 | // Assume we have the following code being used in a test source file: |
| 22 | // const std::string kInputFile = webrtc::testing::GetProjectRootPath() + |
| 23 | // "test/data/voice_engine/audio_long16.wav"; |
| 24 | // // Use the kInputFile for the tests... |
| 25 | // |
| 26 | // Then here's some example outputs for different platforms: |
| 27 | // Linux: |
| 28 | // * Source tree located in /home/user/webrtc/trunk |
| 29 | // * Test project located in /home/user/webrtc/trunk/src/testproject |
| 30 | // * Test binary compiled as: |
| 31 | // /home/user/webrtc/trunk/out/Debug/testproject_unittests |
| 32 | // Then GetProjectRootPath() will return /home/user/webrtc/trunk/ no matter if |
| 33 | // the test binary is executed from standing in either of: |
| 34 | // /home/user/webrtc/trunk |
| 35 | // or |
| 36 | // /home/user/webrtc/trunk/out/Debug |
| 37 | // (or any other directory below the trunk for that matter). |
| 38 | // |
| 39 | // Windows: |
| 40 | // * Source tree located in C:\Users\user\webrtc\trunk |
| 41 | // * Test project located in C:\Users\user\webrtc\trunk\src\testproject |
| 42 | // * Test binary compiled as: |
| 43 | // C:\Users\user\webrtc\trunk\src\testproject\Debug\testproject_unittests.exe |
| 44 | // Then GetProjectRootPath() will return C:\Users\user\webrtc\trunk\ when the |
| 45 | // test binary is executed from inside Visual Studio. |
| 46 | // It will also return the same path if the test is executed from a command |
| 47 | // prompt standing in C:\Users\user\webrtc\trunk\src\testproject\Debug |
| 48 | // |
| 49 | // Mac: |
| 50 | // * Source tree located in /Users/user/webrtc/trunk |
| 51 | // * Test project located in /Users/user/webrtc/trunk/src/testproject |
| 52 | // * Test binary compiled as: |
| 53 | // /Users/user/webrtc/trunk/xcodebuild/Debug/testproject_unittests |
| 54 | // Then GetProjectRootPath() will return /Users/user/webrtc/trunk/ no matter if |
| 55 | // the test binary is executed from standing in either of: |
| 56 | // /Users/user/webrtc/trunk |
| 57 | // or |
| 58 | // /Users/user/webrtc/trunk/out/Debug |
| 59 | // (or any other directory below the trunk for that matter). |
| 60 | |
| 61 | #ifndef TEST_TESTSUPPORT_FILEUTILS_H_ |
| 62 | #define TEST_TESTSUPPORT_FILEUTILS_H_ |
| 63 | |
| 64 | #include <string> |
| 65 | |
| 66 | namespace webrtc { |
| 67 | namespace test { |
| 68 | |
| 69 | // The file we're looking for to identify the project root dir. |
| 70 | const std::string kProjectRootFileName = "DEPS"; |
| 71 | |
| 72 | // This is the "directory" returned if the GetProjectPath() function fails |
| 73 | // to find the project root. |
| 74 | const std::string kCannotFindProjectRootDir = |
| 75 | "ERROR_CANNOT_FIND_PROJECT_ROOT_DIR"; |
| 76 | |
| 77 | // Finds the root dir of the project, to be able to set correct paths to |
| 78 | // resource files used by tests. |
| 79 | // The implementation is simple: it just looks for the file defined by |
| 80 | // kProjectRootFileName, starting in the current directory (the working |
| 81 | // directory) and then steps upward until it is found (or it is at the root of |
| 82 | // the file system). |
| 83 | // If the current working directory is above the project root dir, it will not |
| 84 | // be found. |
| 85 | // |
| 86 | // If symbolic links occur in the path they will be resolved and the actual |
| 87 | // directory will be returned. |
| 88 | // |
| 89 | // Returns the absolute path to the project root dir (usually the trunk dir) |
| 90 | // WITH a trailing path delimiter. |
| 91 | // If the project root is not found, the string specified by |
| 92 | // kCannotFindProjectRootDir is returned. |
| 93 | const std::string GetProjectRootPath(); |
| 94 | |
| 95 | } // namespace webrtc |
| 96 | } // namespace test |
| 97 | |
| 98 | #endif // TEST_TESTSUPPORT_FILEUTILS_H_ |