summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDeb Mukherjee <debargha@google.com>2014-08-12 18:06:21 -0700
committerGerrit Code Review <gerrit@gerrit.golo.chromium.org>2014-08-12 18:06:21 -0700
commit94fbfb9f1b2ff105b8e8bf053c1493bb1f24629f (patch)
tree89e41a403047931c448d2e4b04631e11bf270583
parentf55f68c13a7e40d6aaffec7551796674d58ad31a (diff)
parenta4635138438c9618071dffa3baa71f363dff12bf (diff)
downloadlibvpx-94fbfb9f1b2ff105b8e8bf053c1493bb1f24629f.tar
libvpx-94fbfb9f1b2ff105b8e8bf053c1493bb1f24629f.tar.gz
libvpx-94fbfb9f1b2ff105b8e8bf053c1493bb1f24629f.tar.bz2
libvpx-94fbfb9f1b2ff105b8e8bf053c1493bb1f24629f.zip
Merge "Rework y4mwrite test to pass google3 tests"
-rw-r--r--test/video_source.h59
-rw-r--r--test/y4m_test.cc11
2 files changed, 30 insertions, 40 deletions
diff --git a/test/video_source.h b/test/video_source.h
index 78e7d466b..c924f964f 100644
--- a/test/video_source.h
+++ b/test/video_source.h
@@ -53,55 +53,33 @@ static FILE *OpenTestDataFile(const std::string& file_name) {
return fopen(path_to_source.c_str(), "rb");
}
-static FILE *OpenTestOutFile(const std::string& file_name) {
- const std::string path_to_source = GetDataPath() + "/" + file_name;
- return fopen(path_to_source.c_str(), "wb");
-}
-
-static std::string GetTempOutFilename() {
- std::string basename;
+static FILE *GetTempOutFile(std::string *file_name) {
+ file_name->clear();
#if defined(_WIN32)
char fname[MAX_PATH];
- // Assume for now that the filename generated is unique per process
- const UINT ret = GetTempFileNameA(
- GetDataPath().c_str(), "lvx", 0, fname);
- if (ret != 0) {
- const char *slash = strrchr(fname, '\\');
- if (slash == NULL) slash = strrchr(fname, '/');
- if (slash == NULL)
- basename.assign(fname);
- else
- basename.assign(slash + 1);
- } else {
- basename.clear();
+ char tmppath[MAX_PATH];
+ if (GetTempPathA(MAX_PATH, tmppath)) {
+ // Assume for now that the filename generated is unique per process
+ if (GetTempFileNameA(tmppath, "lvx", 0, fname)) {
+ file_name->assign(fname);
+ return fopen(fname, "wb+");
+ }
}
+ return NULL;
#else
- char fname[256];
- const std::string templ = GetDataPath() + "/libvpx_test_XXXXXX";
- strncpy(fname, templ.c_str(), templ.size());
- fname[templ.size()] = '\0';
- const int fd = mkstemp(fname);
- if (fd != -1) {
- close(fd);
- basename.assign(strrchr(fname, '/') + 1);
- } else {
- basename.clear();
- }
+ return tmpfile();
#endif
- return basename;
}
class TempOutFile {
public:
TempOutFile() {
- file_name_ = GetTempOutFilename();
- file_ = OpenTestOutFile(file_name_);
+ file_ = GetTempOutFile(&file_name_);
}
~TempOutFile() {
CloseFile();
if (!file_name_.empty()) {
- const std::string path_to_source = GetDataPath() + "/" + file_name_;
- EXPECT_EQ(0, remove(path_to_source.c_str()));
+ EXPECT_EQ(0, remove(file_name_.c_str()));
}
}
FILE *file() {
@@ -110,14 +88,19 @@ class TempOutFile {
const std::string& file_name() {
return file_name_;
}
+
+ protected:
void CloseFile() {
if (file_) {
- fclose(file_);
+ // Close if file pointer is associated with an open file
+#if defined(_WIN32)
+ if (file_->_ptr != NULL) fclose(file_);
+#else
+ if (fileno(file_) != -1) fclose(file_);
+#endif
file_ = NULL;
}
}
-
- protected:
FILE *file_;
std::string file_name_;
};
diff --git a/test/y4m_test.cc b/test/y4m_test.cc
index 060f8c40f..d4a2ede20 100644
--- a/test/y4m_test.cc
+++ b/test/y4m_test.cc
@@ -145,6 +145,14 @@ class Y4mVideoWriteTest
delete tmpfile_;
}
+ virtual void ReplaceInputFile(FILE *input_file) {
+ CloseSource();
+ frame_ = 0;
+ input_file_ = input_file;
+ rewind(input_file_);
+ ReadSourceToStart();
+ }
+
// Writes out a y4m file and then reads it back
void WriteY4mAndReadBack() {
ASSERT_TRUE(input_file_ != NULL);
@@ -163,8 +171,7 @@ class Y4mVideoWriteTest
write_image_file(img(), tmpfile_->file());
Next();
}
- tmpfile_->CloseFile();
- Y4mVideoSourceTest::Init(tmpfile_->file_name(), limit_);
+ ReplaceInputFile(tmpfile_->file());
}
virtual void Init(const std::string &file_name, int limit) {