Add file-playing channels to voe_cmd_test.
Fix file reading and writing. TEST=voe_cmd_test Review URL: http://webrtc-codereview.appspot.com/279001 git-svn-id: http://webrtc.googlecode.com/svn/trunk@938 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
@@ -36,9 +36,10 @@ static const char* kPathDelimiter = "/";
|
||||
// The file we're looking for to identify the project root dir.
|
||||
static const char* kProjectRootFileName = "DEPS";
|
||||
static const char* kOutputDirName = "out";
|
||||
static const char* kOutputFallbackPath = "./";
|
||||
const char* kCannotFindProjectRootDir = "ERROR_CANNOT_FIND_PROJECT_ROOT_DIR";
|
||||
|
||||
std::string GetProjectRootPath() {
|
||||
std::string ProjectRootPath() {
|
||||
char path_buffer[FILENAME_MAX];
|
||||
if (!GET_CURRENT_DIR(path_buffer, sizeof(path_buffer))) {
|
||||
fprintf(stderr, "Cannot get current directory!\n");
|
||||
@@ -67,10 +68,10 @@ std::string GetProjectRootPath() {
|
||||
return kCannotFindProjectRootDir;
|
||||
}
|
||||
|
||||
std::string GetOutputDir() {
|
||||
std::string path = GetProjectRootPath();
|
||||
std::string OutputPath() {
|
||||
std::string path = ProjectRootPath();
|
||||
if (path == kCannotFindProjectRootDir) {
|
||||
return kCannotFindProjectRootDir;
|
||||
return kOutputFallbackPath;
|
||||
}
|
||||
path += kOutputDirName;
|
||||
struct stat path_info = {0};
|
||||
@@ -79,7 +80,7 @@ std::string GetOutputDir() {
|
||||
if (!S_ISDIR(path_info.st_mode)) {
|
||||
fprintf(stderr, "Path %s exists but is not a directory! Remove this file "
|
||||
"and re-run to create the output folder.\n", path.c_str());
|
||||
return kCannotFindProjectRootDir;
|
||||
return kOutputFallbackPath;
|
||||
}
|
||||
} else {
|
||||
#ifdef WIN32
|
||||
|
@@ -9,7 +9,7 @@
|
||||
*/
|
||||
|
||||
// File utilities for testing purposes.
|
||||
// The GetProjectRootPath() method is a convenient way of getting an absolute
|
||||
// The ProjectRootPath() method is a convenient way of getting an absolute
|
||||
// path to the project source tree root directory. Using this, it is easy to
|
||||
// refer to test resource files in a portable way.
|
||||
//
|
||||
@@ -19,7 +19,7 @@
|
||||
//
|
||||
// Example use:
|
||||
// Assume we have the following code being used in a test source file:
|
||||
// const std::string kInputFile = webrtc::test::GetProjectRootPath() +
|
||||
// const std::string kInputFile = webrtc::test::ProjectRootPath() +
|
||||
// "test/data/voice_engine/audio_long16.wav";
|
||||
// // Use the kInputFile for the tests...
|
||||
//
|
||||
@@ -29,7 +29,7 @@
|
||||
// * Test project located in /home/user/webrtc/trunk/src/testproject
|
||||
// * Test binary compiled as:
|
||||
// /home/user/webrtc/trunk/out/Debug/testproject_unittests
|
||||
// Then GetProjectRootPath() will return /home/user/webrtc/trunk/ no matter if
|
||||
// Then ProjectRootPath() will return /home/user/webrtc/trunk/ no matter if
|
||||
// the test binary is executed from standing in either of:
|
||||
// /home/user/webrtc/trunk
|
||||
// or
|
||||
@@ -41,7 +41,7 @@
|
||||
// * Test project located in C:\Users\user\webrtc\trunk\src\testproject
|
||||
// * Test binary compiled as:
|
||||
// C:\Users\user\webrtc\trunk\src\testproject\Debug\testproject_unittests.exe
|
||||
// Then GetProjectRootPath() will return C:\Users\user\webrtc\trunk\ when the
|
||||
// Then ProjectRootPath() will return C:\Users\user\webrtc\trunk\ when the
|
||||
// test binary is executed from inside Visual Studio.
|
||||
// It will also return the same path if the test is executed from a command
|
||||
// prompt standing in C:\Users\user\webrtc\trunk\src\testproject\Debug
|
||||
@@ -51,7 +51,7 @@
|
||||
// * Test project located in /Users/user/webrtc/trunk/src/testproject
|
||||
// * Test binary compiled as:
|
||||
// /Users/user/webrtc/trunk/xcodebuild/Debug/testproject_unittests
|
||||
// Then GetProjectRootPath() will return /Users/user/webrtc/trunk/ no matter if
|
||||
// Then ProjectRootPath() will return /Users/user/webrtc/trunk/ no matter if
|
||||
// the test binary is executed from standing in either of:
|
||||
// /Users/user/webrtc/trunk
|
||||
// or
|
||||
@@ -66,7 +66,7 @@
|
||||
namespace webrtc {
|
||||
namespace test {
|
||||
|
||||
// This is the "directory" returned if the GetProjectPath() function fails
|
||||
// This is the "directory" returned if the ProjectPath() function fails
|
||||
// to find the project root.
|
||||
extern const char* kCannotFindProjectRootDir;
|
||||
|
||||
@@ -86,20 +86,18 @@ extern const char* kCannotFindProjectRootDir;
|
||||
// WITH a trailing path delimiter.
|
||||
// If the project root is not found, the string specified by
|
||||
// kCannotFindProjectRootDir is returned.
|
||||
std::string GetProjectRootPath();
|
||||
std::string ProjectRootPath();
|
||||
|
||||
// Creates and returns the absolute path to the output directory where log files
|
||||
// and other test artifacts should be put. The output directory is always a
|
||||
// directory named "out" at the top-level of the project, i.e. a subfolder to
|
||||
// the path returned by GetProjectRootPath().
|
||||
// the path returned by ProjectRootPath().
|
||||
//
|
||||
// Details described for GetProjectRootPath() apply here too.
|
||||
// Details described for ProjectRootPath() apply here too.
|
||||
//
|
||||
// Returns the absolute path to the output directory (named "out") below the
|
||||
// project root dir WITH a trailing path delimiter.
|
||||
// If the project root is not found, the string specified by
|
||||
// kCannotFindProjectRootDir is returned.
|
||||
std::string GetOutputDir();
|
||||
// Returns the path WITH a trailing path delimiter. If the project root is not
|
||||
// found, the current working directory ("./") is returned as a fallback.
|
||||
std::string OutputPath();
|
||||
|
||||
} // namespace test
|
||||
} // namespace webrtc
|
||||
|
@@ -53,16 +53,16 @@ class FileUtilsTest: public testing::Test {
|
||||
// The test is not fully testing the implementation, since we cannot be sure
|
||||
// of where the executable was launched from.
|
||||
// The test will fail if the top level directory is not named "trunk".
|
||||
TEST_F(FileUtilsTest, GetProjectRootPathFromUnchangedWorkingDir) {
|
||||
std::string path = GetProjectRootPath();
|
||||
TEST_F(FileUtilsTest, ProjectRootPathFromUnchangedWorkingDir) {
|
||||
std::string path = ProjectRootPath();
|
||||
std::string expected_end = "trunk";
|
||||
expected_end = kPathDelimiter + expected_end + kPathDelimiter;
|
||||
ASSERT_EQ(path.length() - expected_end.length(), path.find(expected_end));
|
||||
}
|
||||
|
||||
// Similar to the above test, but for the output dir
|
||||
TEST_F(FileUtilsTest, GetOutputDirFromUnchangedWorkingDir) {
|
||||
std::string path = GetOutputDir();
|
||||
TEST_F(FileUtilsTest, OutputPathFromUnchangedWorkingDir) {
|
||||
std::string path = OutputPath();
|
||||
std::string expected_end = "out";
|
||||
expected_end = kPathDelimiter + expected_end + kPathDelimiter;
|
||||
ASSERT_EQ(path.length() - expected_end.length(), path.find(expected_end));
|
||||
@@ -71,38 +71,38 @@ TEST_F(FileUtilsTest, GetOutputDirFromUnchangedWorkingDir) {
|
||||
// Tests setting the current working directory to a directory three levels
|
||||
// deeper from the current one. Then testing that the project path returned
|
||||
// is still the same, when the function under test is called again.
|
||||
TEST_F(FileUtilsTest, GetProjectRootPathFromDeeperWorkingDir) {
|
||||
std::string path = GetProjectRootPath();
|
||||
TEST_F(FileUtilsTest, ProjectRootPathFromDeeperWorkingDir) {
|
||||
std::string path = ProjectRootPath();
|
||||
std::string original_working_dir = path; // This is the correct project root
|
||||
// Change to a subdirectory path (the full path doesn't have to exist).
|
||||
path += "foo/bar/baz";
|
||||
chdir(path.c_str());
|
||||
ASSERT_EQ(original_working_dir, GetProjectRootPath());
|
||||
ASSERT_EQ(original_working_dir, ProjectRootPath());
|
||||
}
|
||||
|
||||
// Similar to the above test, but for the output dir
|
||||
TEST_F(FileUtilsTest, GetOutputDirFromDeeperWorkingDir) {
|
||||
std::string path = GetOutputDir();
|
||||
TEST_F(FileUtilsTest, OutputPathFromDeeperWorkingDir) {
|
||||
std::string path = OutputPath();
|
||||
std::string original_working_dir = path;
|
||||
path += "foo/bar/baz";
|
||||
chdir(path.c_str());
|
||||
ASSERT_EQ(original_working_dir, GetOutputDir());
|
||||
ASSERT_EQ(original_working_dir, OutputPath());
|
||||
}
|
||||
|
||||
// Tests with current working directory set to a directory higher up in the
|
||||
// directory tree than the project root dir. This case shall return a specified
|
||||
// error string as a directory (which will be an invalid path).
|
||||
TEST_F(FileUtilsTest, GetProjectRootPathFromRootWorkingDir) {
|
||||
TEST_F(FileUtilsTest, ProjectRootPathFromRootWorkingDir) {
|
||||
// Change current working dir to the root of the current file system
|
||||
// (this will always be "above" our project root dir).
|
||||
chdir(kPathDelimiter);
|
||||
ASSERT_EQ(kCannotFindProjectRootDir, GetProjectRootPath());
|
||||
ASSERT_EQ(kCannotFindProjectRootDir, ProjectRootPath());
|
||||
}
|
||||
|
||||
// Similar to the above test, but for the output dir
|
||||
TEST_F(FileUtilsTest, GetOutputDirFromRootWorkingDir) {
|
||||
TEST_F(FileUtilsTest, OutputPathFromRootWorkingDir) {
|
||||
chdir(kPathDelimiter);
|
||||
ASSERT_EQ(kCannotFindProjectRootDir, GetOutputDir());
|
||||
ASSERT_EQ("./", OutputPath());
|
||||
}
|
||||
|
||||
} // namespace test
|
||||
|
Reference in New Issue
Block a user