Skip to content

Commit

Permalink
WebRTC: Replace ProjectRootPath by ResourcePath
Browse files Browse the repository at this point in the history
BUG=webrtc:6727
NOTRY=True

Review-Url: https://codereview.webrtc.org/2513363004
Cr-Commit-Position: refs/heads/master@{#15201}
  • Loading branch information
ehlemur-zz authored and Commit bot committed Nov 22, 2016
1 parent 10165ab commit d661e9c
Show file tree
Hide file tree
Showing 13 changed files with 14 additions and 166 deletions.
Binary file removed data/voice_engine/audio_long16.pcm
Binary file not shown.
Binary file removed data/voice_engine/audio_tiny48.wav
Binary file not shown.
2 changes: 1 addition & 1 deletion webrtc/modules/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ if (rtc_include_tests) {
}

modules_unittests_resources = [
"//data/voice_engine/audio_tiny48.wav",
"//resources/att-downlink.rx",
"//resources/att-uplink.rx",
"//resources/audio_coding/neteq_opus.rtp",
Expand Down Expand Up @@ -238,6 +237,7 @@ if (rtc_include_tests) {
"//resources/verizon3g-uplink.rx",
"//resources/verizon4g-downlink.rx",
"//resources/verizon4g-uplink.rx",
"//resources/voice_engine/audio_tiny48.wav",
]

if (is_ios) {
Expand Down
4 changes: 2 additions & 2 deletions webrtc/modules/media_file/media_file_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ class MediaFileTest : public testing::Test {
TEST_F(MediaFileTest, MAYBE_StartPlayingAudioFileWithoutError) {
// TODO(leozwang): Use hard coded filename here, we want to
// loop through all audio files in future
const std::string audio_file = webrtc::test::ProjectRootPath() +
"data/voice_engine/audio_tiny48.wav";
const std::string audio_file =
webrtc::test::ResourcePath("voice_engine/audio_tiny48", "wav");
ASSERT_EQ(0, media_file_->StartPlayingAudioFile(
audio_file.c_str(),
0,
Expand Down
73 changes: 2 additions & 71 deletions webrtc/test/testsupport/fileutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,57 +10,6 @@

#include <stdio.h>

// File utilities for testing purposes.
//
// 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.
//
// Notice that even if Windows platforms use backslash as path delimiter, it is
// also supported to use slash, so there's no need for #ifdef checks in test
// code for setting up the paths to the resource files.
//
// Example use:
// Assume we have the following code being used in a test source file:
// const std::string kInputFile = webrtc::test::ProjectRootPath() +
// "test/data/voice_engine/audio_long16.wav";
// // Use the kInputFile for the tests...
//
// Then here's some example outputs for different platforms:
// Linux:
// * Source tree located in /home/user/webrtc/trunk
// * Test project located in /home/user/webrtc/trunk/src/testproject
// * Test binary compiled as:
// /home/user/webrtc/trunk/out/Debug/testproject_unittests
// 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
// /home/user/webrtc/trunk/out/Debug
// (or any other directory below the trunk for that matter).
//
// Windows:
// * Source tree located in C:\Users\user\webrtc\trunk
// * 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 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
//
// Mac:
// * Source tree located in /Users/user/webrtc/trunk
// * Test project located in /Users/user/webrtc/trunk/src/testproject
// * Test binary compiled as:
// /Users/user/webrtc/trunk/xcodebuild/Debug/testproject_unittests
// 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
// /Users/user/webrtc/trunk/out/Debug
// (or any other directory below the trunk for that matter).

#ifndef WEBRTC_TEST_TESTSUPPORT_FILEUTILS_H_
#define WEBRTC_TEST_TESTSUPPORT_FILEUTILS_H_

Expand All @@ -73,32 +22,14 @@ namespace test {
// to find the project root.
extern const char* kCannotFindProjectRootDir;

// Finds the root dir of the project, to be able to set correct paths to
// resource files used by tests.
// For desktop, we assume that the project root is two levels above (i.e. the
// current working directory + /../../)
// For Android, it is assumed to be /sdcard/chromium_tests_root/
// For iOS, the resource files are assumed to be included in the test's .app
// bundle.
// If the current working directory is above the project root dir, it will not
// be found.
//
// If symbolic links occur in the path they will be resolved and the actual
// directory will be returned.
//
// Returns the absolute path to the project root dir (usually the trunk dir)
// WITH a trailing path delimiter.
// If the project root is not found, the string specified by
// kCannotFindProjectRootDir is returned.
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 generally a
// directory named "out" at the top-level of the project, i.e. a subfolder to
// the path returned by ProjectRootPath(). The exception is Android where we use
// /sdcard/ instead.
//
// Details described for ProjectRootPath() apply here too.
// If symbolic links occur in the path they will be resolved and the actual
// directory will be returned.
//
// Returns the path WITH a trailing path delimiter. If the project root is not
// found, the current working directory ("./") is returned as a fallback.
Expand Down
9 changes: 1 addition & 8 deletions webrtc/test/testsupport/fileutils_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,10 @@ class FileUtilsTest : public testing::Test {

std::string FileUtilsTest::original_working_dir_ = "";

// Tests that the project root path is returned for the default working
// Tests that the project output dir path is returned for the default working
// directory that is automatically set when the test executable is launched.
// The test is not fully testing the implementation, since we cannot be sure
// of where the executable was launched from.
TEST_F(FileUtilsTest, ProjectRootPath) {
std::string project_root = webrtc::test::ProjectRootPath();
// Not very smart, but at least tests something.
ASSERT_GT(project_root.length(), 0u);
}

// Similar to the above test, but for the output dir
#if defined(WEBRTC_ANDROID)
#define MAYBE_OutputPathFromUnchangedWorkingDir \
DISABLED_OutputPathFromUnchangedWorkingDir
Expand Down
1 change: 0 additions & 1 deletion webrtc/voice_engine/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,6 @@ if (rtc_include_tests) {
"test/auto_test/fixtures/before_initialization_fixture.h",
"test/auto_test/fixtures/before_streaming_fixture.cc",
"test/auto_test/fixtures/before_streaming_fixture.h",
"test/auto_test/resource_manager.cc",
"test/auto_test/standard/audio_processing_test.cc",
"test/auto_test/standard/codec_before_streaming_test.cc",
"test/auto_test/standard/codec_test.cc",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@
* be found in the AUTHORS file in the root of the source tree.
*/

#include "webrtc/test/testsupport/fileutils.h"
#include "webrtc/voice_engine/test/auto_test/fixtures/before_streaming_fixture.h"

BeforeStreamingFixture::BeforeStreamingFixture()
: channel_(voe_base_->CreateChannel()),
transport_(NULL) {
EXPECT_GE(channel_, 0);

fake_microphone_input_file_ = resource_manager_.long_audio_file_path();
EXPECT_FALSE(fake_microphone_input_file_.empty());
fake_microphone_input_file_ =
webrtc::test::ResourcePath("voice_engine/audio_long16", "pcm");

SetUpLocalPlayback();
RestartFakeMicrophone();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

#include <string>
#include "webrtc/voice_engine/test/auto_test/fixtures/after_initialization_fixture.h"
#include "webrtc/voice_engine/test/auto_test/resource_manager.h"

// This fixture will, in addition to the work done by its superclasses,
// create a channel and prepare playing a file through the fake microphone
Expand All @@ -26,7 +25,6 @@ class BeforeStreamingFixture : public AfterInitializationFixture {

protected:
int channel_;
ResourceManager resource_manager_;
std::string fake_microphone_input_file_;

// Shuts off the fake microphone for this test.
Expand Down
28 changes: 0 additions & 28 deletions webrtc/voice_engine/test/auto_test/resource_manager.cc

This file was deleted.

30 changes: 0 additions & 30 deletions webrtc/voice_engine/test/auto_test/resource_manager.h

This file was deleted.

10 changes: 3 additions & 7 deletions webrtc/voice_engine/test/auto_test/voe_standard_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
#include <string>

#include "gflags/gflags.h"
#include "webrtc/test/testsupport/fileutils.h"
#include "webrtc/voice_engine/include/voe_audio_processing.h"
#include "webrtc/voice_engine/include/voe_base.h"
#include "webrtc/voice_engine/include/voe_errors.h"
#include "webrtc/voice_engine/include/voe_file.h"
#include "webrtc/voice_engine/include/voe_rtp_rtcp.h"
#include "webrtc/voice_engine/test/auto_test/resource_manager.h"
#include "webrtc/voice_engine/test/auto_test/voe_test_common.h"
#include "webrtc/voice_engine/test/auto_test/voe_test_interface.h"
#ifdef WEBRTC_VOICE_ENGINE_CODEC_API
Expand Down Expand Up @@ -118,10 +118,8 @@ class VoETestManager {
int ReleaseInterfaces();

const char* AudioFilename() const {
const std::string& result = resource_manager_.long_audio_file_path();
if (result.length() == 0) {
TEST_LOG("ERROR: Failed to open input file!");
}
const std::string& result =
webrtc::test::ResourcePath("voice_engine/audio_long16", "pcm");
return result.c_str();
}

Expand Down Expand Up @@ -187,8 +185,6 @@ class VoETestManager {
VoEVideoSync* voe_vsync_;
VoEVolumeControl* voe_volume_control_;
VoEAudioProcessing* voe_apm_;

ResourceManager resource_manager_;
};

} // namespace voetest
Expand Down
16 changes: 2 additions & 14 deletions webrtc/voice_engine/test/cmd_test/voe_cmd_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -229,20 +229,8 @@ void RunTest(std::string out_path) {
bool experimental_ns_enabled = false;
bool debug_recording_started = false;

#if defined(WEBRTC_ANDROID)
std::string resource_path = "/sdcard/";
#else
std::string resource_path = webrtc::test::ProjectRootPath();
if (resource_path == webrtc::test::kCannotFindProjectRootDir) {
printf("*** Unable to get project root directory. "
"File playing may fail. ***\n");
// Fall back to the current directory.
resource_path = "./";
} else {
resource_path += "data/voice_engine/";
}
#endif
const std::string audio_filename = resource_path + "audio_long16.pcm";
const std::string audio_filename =
webrtc::test::ResourcePath("voice_engine/audio_long16", "pcm");

const std::string play_filename = out_path + "recorded_playout.pcm";
const std::string mic_filename = out_path + "recorded_mic.pcm";
Expand Down

0 comments on commit d661e9c

Please sign in to comment.