Showing the changes to test/api/BaseDecoderTest.cpp (1 of 9 files). Show all
Unified · Split
| @@ -5,7 +5,7 @@ · 4 unmodified lines | |||
| 5 | #include "utils/BufferedData.h" | 5 | #include "utils/BufferedData.h" |
| 6 | #include "BaseDecoderTest.h" | 6 | #include "BaseDecoderTest.h" |
| 7 | 7 | ||
| 8 | static void ReadFrame (std::ifstream* file, BufferedData* buf) { | 8 | static bool ReadFrame (std::ifstream* file, BufferedData* buf) { |
| 9 | // start code of a frame is {0, 0, 0, 1} | 9 | // start code of a frame is {0, 0, 0, 1} |
| 10 | int zeroCount = 0; | 10 | int zeroCount = 0; |
| 11 | char b; | 11 | char b; |
| @@ -14,10 +14,11 @@ static void ReadFrame (std::ifstream* file, BufferedData* buf) { · 2 unmodified lines | |||
| 14 | for (;;) { | 14 | for (;;) { |
| 15 | file->read (&b, 1); | 15 | file->read (&b, 1); |
| 16 | if (file->gcount() != 1) { // end of file | 16 | if (file->gcount() != 1) { // end of file |
| 17 | return; | 17 | return true; |
| 18 | } | 18 | } |
| 19 | if (!buf->PushBack (b)) { | 19 | if (!buf->PushBack (b)) { |
| 20 | FAIL() << "unable to allocate memory"; | 20 | std::cout << "unable to allocate memory" << std::endl; |
| 21 | return false; | ||
| 21 | } | 22 | } |
| 22 | 23 | ||
| 23 | if (buf->Length() <= 4) { | 24 | if (buf->Length() <= 4) { |
| @@ -29,10 +30,12 @@ static void ReadFrame (std::ifstream* file, BufferedData* buf) { · 5 unmodified lines | |||
| 29 | } else { | 30 | } else { |
| 30 | if (b == 1) { | 31 | if (b == 1) { |
| 31 | if (file->seekg (-4, file->cur).good()) { | 32 | if (file->seekg (-4, file->cur).good()) { |
| 32 | buf->SetLength (buf->Length() - 4); | 33 | if (-1 == buf->SetLength(buf->Length() - 4)) |
| 33 | return; | 34 | return false; |
| 35 | return true; | ||
| 34 | } else { | 36 | } else { |
| 35 | FAIL() << "unable to seek file"; | 37 | std::cout << "unable to seek file" << std::endl; |
| 38 | return false; | ||
| 36 | } | 39 | } |
| 37 | } else if (b == 0) { | 40 | } else if (b == 0) { |
| 38 | zeroCount = 3; | 41 | zeroCount = 3; |
| @@ -145,22 +148,24 @@ void BaseDecoderTest::FlushFrame (Callback* cbk) { · 106 unmodified lines | |||
| 145 | cbk->onDecodeFrame (frame); | 148 | cbk->onDecodeFrame (frame); |
| 146 | } | 149 | } |
| 147 | } | 150 | } |
| 148 | void BaseDecoderTest::DecodeFile (const char* fileName, Callback* cbk) { | 151 | bool BaseDecoderTest::DecodeFile (const char* fileName, Callback* cbk) { |
| 149 | std::ifstream file (fileName, std::ios::in | std::ios::binary); | 152 | std::ifstream file (fileName, std::ios::in | std::ios::binary); |
| 150 | ASSERT_TRUE (file.is_open()); | 153 | if (!file.is_open()) |
| 154 | return false; | ||
| 151 | 155 | ||
| 152 | BufferedData buf; | 156 | BufferedData buf; |
| 153 | while (true) { | 157 | while (true) { |
| 154 | ReadFrame (&file, &buf); | 158 | if (false == ReadFrame(&file, &buf)) |
| 159 | return false; | ||
| 155 | if (::testing::Test::HasFatalFailure()) { | 160 | if (::testing::Test::HasFatalFailure()) { |
| 156 | return; | 161 | return false; |
| 157 | } | 162 | } |
| 158 | if (buf.Length() == 0) { | 163 | if (buf.Length() == 0) { |
| 159 | break; | 164 | break; |
| 160 | } | 165 | } |
| 161 | DecodeFrame (buf.data(), buf.Length(), cbk); | 166 | DecodeFrame (buf.data(), buf.Length(), cbk); |
| 162 | if (::testing::Test::HasFatalFailure()) { | 167 | if (::testing::Test::HasFatalFailure()) { |
| 163 | return; | 168 | return false; |
| 164 | } | 169 | } |
| 165 | } | 170 | } |
| 166 | 171 | ||
| @@ -175,6 +180,7 @@ void BaseDecoderTest::DecodeFile (const char* fileName, Callback* cbk) { · 8 unmodified lines | |||
| 175 | for (int32_t i = 0; i < num_of_frames_in_buffer; ++i) { | 180 | for (int32_t i = 0; i < num_of_frames_in_buffer; ++i) { |
| 176 | FlushFrame (cbk); | 181 | FlushFrame (cbk); |
| 177 | } | 182 | } |
| 183 | return true; | ||
| 178 | } | 184 | } |
| 179 | 185 | ||
| 180 | bool BaseDecoderTest::Open (const char* fileName) { | 186 | bool BaseDecoderTest::Open (const char* fileName) { |
| @@ -191,7 +197,8 @@ bool BaseDecoderTest::Open (const char* fileName) { · 10 unmodified lines | |||
| 191 | bool BaseDecoderTest::DecodeNextFrame (Callback* cbk) { | 197 | bool BaseDecoderTest::DecodeNextFrame (Callback* cbk) { |
| 192 | switch (decodeStatus_) { | 198 | switch (decodeStatus_) { |
| 193 | case Decoding: | 199 | case Decoding: |
| 194 | ReadFrame (&file_, &buf_); | 200 | if (false == ReadFrame(&file_, &buf_)) |
| 201 | return false; | ||
| 195 | if (::testing::Test::HasFatalFailure()) { | 202 | if (::testing::Test::HasFatalFailure()) { |
| 196 | return false; | 203 | return false; |
| 197 | } | 204 | } |