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