Fixed bug that caused frame_cutter_unittest to fail when built with MVS2008.

This was caused by not supplying a correct pointer to where fread should read. The files are now opened in binary mode (which I have under stood can cause problems between different OS if it is not done). I also check for EOF when I compare data from fread. Previously the checking for correct amount of bytes read failed when the end of the file had been reached.

BUG=

Review URL: https://webrtc-codereview.appspot.com/937032

git-svn-id: http://webrtc.googlecode.com/svn/trunk@3212 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
brykt@google.com 2012-11-30 12:37:14 +00:00
parent 53034fb247
commit c7896df420
2 changed files with 19 additions and 16 deletions

View File

@ -29,7 +29,7 @@ int FrameCutter(const string& in_path, int width, int height,
return -10;
}
FILE* in_fid = fopen(in_path.c_str() , "r");
FILE* in_fid = fopen(in_path.c_str() , "rb");
if (!in_fid) {
fprintf(stderr, "Could not read input file: %s.\n", in_path.c_str());
return -11;
@ -40,7 +40,7 @@ int FrameCutter(const string& in_path, int width, int height,
webrtc::scoped_array<uint8_t> temp_buffer(new uint8_t[frame_length]);
FILE* out_fid = fopen(out_path.c_str(), "w");
FILE* out_fid = fopen(out_path.c_str(), "wb");
if (!out_fid) {
fprintf(stderr, "Could not open output file: %s.\n", out_path.c_str());

View File

@ -44,9 +44,9 @@ TEST(FrameCutterUnittest, ValidInPath) {
last_frame_to_cut, test_video);
EXPECT_EQ(0, result);
FILE* ref_video_fid = fopen(ref_video.c_str(), "r");
FILE* ref_video_fid = fopen(ref_video.c_str(), "rb");
ASSERT_TRUE(ref_video_fid != NULL);
FILE* test_video_fid = fopen(test_video.c_str(), "r");
FILE* test_video_fid = fopen(test_video.c_str(), "rb");
ASSERT_TRUE(test_video_fid != NULL);
const int frame_size =CalcBufferSize(kI420, width, height);
@ -55,30 +55,33 @@ TEST(FrameCutterUnittest, ValidInPath) {
scoped_array<int> test_buffer(new int[frame_size]);
for (int i = 0; i < first_frame_to_cut; ++i) {
num_bytes_read = fread(ref_buffer.get(), frame_size, 1, ref_video_fid);
num_bytes_read = fread(ref_buffer.get(), 1, frame_size, ref_video_fid);
EXPECT_EQ(frame_size, num_bytes_read);
num_bytes_read = fread(test_buffer.get(), frame_size, 1, test_video_fid);
num_bytes_read = fread(test_buffer.get(), 1, frame_size, test_video_fid);
EXPECT_EQ(frame_size, num_bytes_read);
EXPECT_EQ(0, memcmp(ref_buffer.get(), test_buffer.get(), frame_size));
}
// Do not compare the frames that have been cut.
for (int i = first_frame_to_cut; i <= last_frame_to_cut; ++i) {
num_bytes_read = fread(&ref_buffer, frame_size, 1, ref_video_fid);
num_bytes_read = fread(ref_buffer.get(), 1, frame_size, ref_video_fid);
EXPECT_EQ(frame_size, num_bytes_read);
}
while (!feof(test_video_fid)) {
num_bytes_read = fread(&ref_buffer, frame_size, 1, ref_video_fid);
EXPECT_EQ(frame_size, num_bytes_read);
num_bytes_read = fread(&test_buffer, frame_size, 1, test_video_fid);
EXPECT_EQ(frame_size, num_bytes_read);
EXPECT_EQ(0, memcmp(ref_buffer.get(), test_buffer.get(), frame_size));
while (!feof(test_video_fid) && !feof(ref_video_fid)) {
num_bytes_read = fread(ref_buffer.get(), 1, frame_size, ref_video_fid);
if (!feof(ref_video_fid)) {
EXPECT_EQ(frame_size, num_bytes_read);
}
num_bytes_read = fread(test_buffer.get(), 1, frame_size, test_video_fid);
if (!feof(test_video_fid)) {
EXPECT_EQ(frame_size, num_bytes_read);
}
if (!feof(test_video_fid) && !feof(test_video_fid)) {
EXPECT_EQ(0, memcmp(ref_buffer.get(), test_buffer.get(), frame_size));
}
}
bool are_both_files_at_the_end =
(feof(test_video_fid) && feof(test_video_fid));
EXPECT_TRUE(are_both_files_at_the_end);
}
TEST(FrameCutterUnittest, EmptySetToCut) {