diff --git a/webrtc/test/testsupport/fileutils_unittest.cc b/webrtc/test/testsupport/fileutils_unittest.cc index 4cd4513729..114f108359 100644 --- a/webrtc/test/testsupport/fileutils_unittest.cc +++ b/webrtc/test/testsupport/fileutils_unittest.cc @@ -29,8 +29,6 @@ static const std::string kResourcesDir = "resources"; static const std::string kTestName = "fileutils_unittest"; static const std::string kExtension = "tmp"; -typedef std::list FileList; - namespace webrtc { // Test fixture to restore the working directory between each test, since some @@ -44,38 +42,6 @@ class FileUtilsTest : public testing::Test { // Runs before the first test static void SetUpTestCase() { original_working_dir_ = webrtc::test::WorkingDir(); - std::string resources_path = original_working_dir_ + kPathDelimiter + - kResourcesDir + kPathDelimiter; - webrtc::test::CreateDir(resources_path); - - files_.push_back(resources_path + kTestName + "." + kExtension); - files_.push_back(resources_path + kTestName + "_32." + kExtension); - files_.push_back(resources_path + kTestName + "_64." + kExtension); - files_.push_back(resources_path + kTestName + "_linux." + kExtension); - files_.push_back(resources_path + kTestName + "_mac." + kExtension); - files_.push_back(resources_path + kTestName + "_win." + kExtension); - files_.push_back(resources_path + kTestName + "_linux_32." + kExtension); - files_.push_back(resources_path + kTestName + "_mac_32." + kExtension); - files_.push_back(resources_path + kTestName + "_win_32." + kExtension); - files_.push_back(resources_path + kTestName + "_linux_64." + kExtension); - files_.push_back(resources_path + kTestName + "_mac_64." + kExtension); - files_.push_back(resources_path + kTestName + "_win_64." + kExtension); - - // Now that the resources dir exists, write some empty test files into it. - for (FileList::iterator file_it = files_.begin(); - file_it != files_.end(); ++file_it) { - FILE* file = fopen(file_it->c_str(), "wb"); - ASSERT_TRUE(file != NULL) << "Failed to write file: " << file_it->c_str(); - ASSERT_GT(fprintf(file, "%s", "Dummy data"), 0); - fclose(file); - } - } - static void TearDownTestCase() { - // Clean up all resource files written - for (FileList::iterator file_it = files_.begin(); - file_it != files_.end(); ++file_it) { - remove(file_it->c_str()); - } } void SetUp() { ASSERT_EQ(chdir(original_working_dir_.c_str()), 0); @@ -83,13 +49,10 @@ class FileUtilsTest : public testing::Test { void TearDown() { ASSERT_EQ(chdir(original_working_dir_.c_str()), 0); } - protected: - static FileList files_; private: static std::string original_working_dir_; }; -FileList FileUtilsTest::files_; std::string FileUtilsTest::original_working_dir_ = ""; // Tests that the project root path is returned for the default working @@ -159,7 +122,16 @@ TEST_F(FileUtilsTest, ResourcePathFromRootWorkingDir) { } TEST_F(FileUtilsTest, GetFileSizeExistingFile) { - ASSERT_GT(webrtc::test::GetFileSize(files_.front()), 0u); + // Create a file with some dummy data in. + std::string temp_filename = webrtc::test::TempFilename( + webrtc::test::OutputPath(), "fileutils_unittest"); + FILE* file = fopen(temp_filename.c_str(), "wb"); + ASSERT_TRUE(file != NULL) << "Failed to open file: " << temp_filename; + ASSERT_GT(fprintf(file, "%s", "Dummy data"), 0) << + "Failed to write to file: " << temp_filename; + fclose(file); + ASSERT_GT(webrtc::test::GetFileSize(std::string(temp_filename.c_str())), 0u); + remove(temp_filename.c_str()); } TEST_F(FileUtilsTest, GetFileSizeNonExistingFile) { diff --git a/webrtc/test/testsupport/frame_reader_unittest.cc b/webrtc/test/testsupport/frame_reader_unittest.cc index c70db5b6ce..25ea9132f2 100644 --- a/webrtc/test/testsupport/frame_reader_unittest.cc +++ b/webrtc/test/testsupport/frame_reader_unittest.cc @@ -16,7 +16,6 @@ namespace webrtc { namespace test { -const std::string kInputFilename = "temp_inputfile.tmp"; const std::string kInputFileContents = "baz"; // Setting the kFrameLength value to a value much larger than the // file to test causes the ReadFrame test to fail on Windows. @@ -27,27 +26,27 @@ class FrameReaderTest: public testing::Test { FrameReaderTest() {} virtual ~FrameReaderTest() {} void SetUp() { - // Cleanup any previous dummy input file. - remove(kInputFilename.c_str()); - // Create a dummy input file. - FILE* dummy = fopen(kInputFilename.c_str(), "wb"); + temp_filename_ = webrtc::test::TempFilename(webrtc::test::OutputPath(), + "frame_reader_unittest"); + FILE* dummy = fopen(temp_filename_.c_str(), "wb"); fprintf(dummy, "%s", kInputFileContents.c_str()); fclose(dummy); - frame_reader_ = new FrameReaderImpl(kInputFilename, kFrameLength); + frame_reader_ = new FrameReaderImpl(temp_filename_, kFrameLength); ASSERT_TRUE(frame_reader_->Init()); } void TearDown() { delete frame_reader_; // Cleanup the dummy input file. - remove(kInputFilename.c_str()); + remove(temp_filename_.c_str()); } FrameReader* frame_reader_; + std::string temp_filename_; }; TEST_F(FrameReaderTest, InitSuccess) { - FrameReaderImpl frame_reader(kInputFilename, kFrameLength); + FrameReaderImpl frame_reader(temp_filename_, kFrameLength); ASSERT_TRUE(frame_reader.Init()); ASSERT_EQ(kFrameLength, frame_reader.FrameLength()); ASSERT_EQ(0, frame_reader.NumberOfFrames()); @@ -64,7 +63,7 @@ TEST_F(FrameReaderTest, ReadFrame) { TEST_F(FrameReaderTest, ReadFrameUninitialized) { uint8_t buffer[3]; - FrameReaderImpl file_reader(kInputFilename, kFrameLength); + FrameReaderImpl file_reader(temp_filename_, kFrameLength); ASSERT_FALSE(file_reader.ReadFrame(buffer)); } diff --git a/webrtc/test/testsupport/frame_writer_unittest.cc b/webrtc/test/testsupport/frame_writer_unittest.cc index 3e32feff98..da1e268662 100644 --- a/webrtc/test/testsupport/frame_writer_unittest.cc +++ b/webrtc/test/testsupport/frame_writer_unittest.cc @@ -16,7 +16,6 @@ namespace webrtc { namespace test { -const std::string kOutputFilename = "temp_outputfile.tmp"; const size_t kFrameLength = 1000; class FrameWriterTest: public testing::Test { @@ -24,21 +23,22 @@ class FrameWriterTest: public testing::Test { FrameWriterTest() {} virtual ~FrameWriterTest() {} void SetUp() { - // Cleanup any previous output file. - remove(kOutputFilename.c_str()); - frame_writer_ = new FrameWriterImpl(kOutputFilename, kFrameLength); + temp_filename_ = webrtc::test::TempFilename(webrtc::test::OutputPath(), + "frame_writer_unittest"); + frame_writer_ = new FrameWriterImpl(temp_filename_, kFrameLength); ASSERT_TRUE(frame_writer_->Init()); } void TearDown() { delete frame_writer_; // Cleanup the temporary file. - remove(kOutputFilename.c_str()); + remove(temp_filename_.c_str()); } FrameWriter* frame_writer_; + std::string temp_filename_; }; TEST_F(FrameWriterTest, InitSuccess) { - FrameWriterImpl frame_writer(kOutputFilename, kFrameLength); + FrameWriterImpl frame_writer(temp_filename_, kFrameLength); ASSERT_TRUE(frame_writer.Init()); ASSERT_EQ(kFrameLength, frame_writer.FrameLength()); } @@ -50,12 +50,12 @@ TEST_F(FrameWriterTest, WriteFrame) { ASSERT_TRUE(result); // success // Close the file and verify the size. frame_writer_->Close(); - ASSERT_EQ(kFrameLength, GetFileSize(kOutputFilename)); + ASSERT_EQ(kFrameLength, GetFileSize(temp_filename_)); } TEST_F(FrameWriterTest, WriteFrameUninitialized) { uint8_t buffer[3]; - FrameWriterImpl frame_writer(kOutputFilename, kFrameLength); + FrameWriterImpl frame_writer(temp_filename_, kFrameLength); ASSERT_FALSE(frame_writer.WriteFrame(buffer)); } diff --git a/webrtc/test/testsupport/metrics/video_metrics_unittest.cc b/webrtc/test/testsupport/metrics/video_metrics_unittest.cc index ba59b2f6fa..0958dcfbad 100644 --- a/webrtc/test/testsupport/metrics/video_metrics_unittest.cc +++ b/webrtc/test/testsupport/metrics/video_metrics_unittest.cc @@ -15,7 +15,6 @@ namespace webrtc { -static const char* kNonExistingFileName = "video_metrics_unittest_non_existing"; static const int kWidth = 352; static const int kHeight = 288; @@ -28,13 +27,17 @@ static const double kSsimPerfectResult = 1.0; class VideoMetricsTest: public testing::Test { protected: VideoMetricsTest() { - empty_file_ = webrtc::test::OutputPath() + - "video_metrics_unittest_empty_file.tmp"; video_file_ = webrtc::test::ResourcePath("foreman_cif_short", "yuv"); } virtual ~VideoMetricsTest() {} void SetUp() { + non_existing_file_ = webrtc::test::OutputPath() + + "video_metrics_unittest_non_existing"; + remove(non_existing_file_.c_str()); // To be sure it doesn't exist. + // Create an empty file: + empty_file_ = webrtc::test::TempFilename( + webrtc::test::OutputPath(), "video_metrics_unittest_empty_file"); FILE* dummy = fopen(empty_file_.c_str(), "wb"); fclose(dummy); } @@ -43,6 +46,7 @@ class VideoMetricsTest: public testing::Test { } webrtc::test::QualityMetricsResult psnr_result_; webrtc::test::QualityMetricsResult ssim_result_; + std::string non_existing_file_; std::string empty_file_; std::string video_file_; }; @@ -71,40 +75,42 @@ TEST_F(VideoMetricsTest, ReturnsPerfectResultForIdenticalFilesBothMetrics) { // Tests that the right return code is given when the reference file is missing. TEST_F(VideoMetricsTest, MissingReferenceFilePSNR) { EXPECT_EQ(kMissingReferenceFileReturnCode, - I420PSNRFromFiles(kNonExistingFileName, video_file_.c_str(), - kWidth, kHeight, &ssim_result_)); + I420PSNRFromFiles(non_existing_file_.c_str(), + video_file_.c_str(), kWidth, kHeight, + &ssim_result_)); } TEST_F(VideoMetricsTest, MissingReferenceFileSSIM) { EXPECT_EQ(kMissingReferenceFileReturnCode, - I420SSIMFromFiles(kNonExistingFileName, video_file_.c_str(), - kWidth, kHeight, &ssim_result_)); + I420SSIMFromFiles(non_existing_file_.c_str(), + video_file_.c_str(), kWidth, kHeight, + &ssim_result_)); } TEST_F(VideoMetricsTest, MissingReferenceFileBothMetrics) { EXPECT_EQ(kMissingReferenceFileReturnCode, - I420MetricsFromFiles(kNonExistingFileName, video_file_.c_str(), - kWidth, kHeight, + I420MetricsFromFiles(non_existing_file_.c_str(), + video_file_.c_str(), kWidth, kHeight, &psnr_result_, &ssim_result_)); } // Tests that the right return code is given when the test file is missing. TEST_F(VideoMetricsTest, MissingTestFilePSNR) { EXPECT_EQ(kMissingTestFileReturnCode, - I420PSNRFromFiles(video_file_.c_str(), kNonExistingFileName, + I420PSNRFromFiles(video_file_.c_str(), non_existing_file_.c_str(), kWidth, kHeight, &ssim_result_)); } TEST_F(VideoMetricsTest, MissingTestFileSSIM) { EXPECT_EQ(kMissingTestFileReturnCode, - I420SSIMFromFiles(video_file_.c_str(), kNonExistingFileName, + I420SSIMFromFiles(video_file_.c_str(), non_existing_file_.c_str(), kWidth, kHeight, &ssim_result_)); } TEST_F(VideoMetricsTest, MissingTestFileBothMetrics) { EXPECT_EQ(kMissingTestFileReturnCode, - I420MetricsFromFiles(video_file_.c_str(), kNonExistingFileName, - kWidth, kHeight, + I420MetricsFromFiles(video_file_.c_str(), + non_existing_file_.c_str(), kWidth, kHeight, &psnr_result_, &ssim_result_)); } diff --git a/webrtc/tools/frame_editing/frame_editing_unittest.cc b/webrtc/tools/frame_editing/frame_editing_unittest.cc index bdcc2f21f5..69468e18ce 100644 --- a/webrtc/tools/frame_editing/frame_editing_unittest.cc +++ b/webrtc/tools/frame_editing/frame_editing_unittest.cc @@ -30,7 +30,8 @@ class FrameEditingTest : public ::testing::Test { protected: virtual void SetUp() { reference_video_ = ResourcePath("foreman_cif", "yuv"); - test_video_ = OutputPath() + "testvideo.yuv"; + test_video_ = webrtc::test::TempFilename(webrtc::test::OutputPath(), + "frame_editing_unittest.yuv"); original_fid_ = fopen(reference_video_.c_str(), "rb"); ASSERT_TRUE(original_fid_ != NULL); @@ -50,6 +51,7 @@ class FrameEditingTest : public ::testing::Test { virtual void TearDown() { fclose(original_fid_); fclose(edited_fid_); + remove(test_video_.c_str()); } // Compares the frames in both streams to the end of one of the streams. void CompareToTheEnd(FILE* test_video_fid, FILE* ref_video_fid,