History

minor fixes to the tests

jwwang committed 12 years ago

Commit 94b79c41 parent 6f58a0c3 files · +45 −43Browse files

Showing the changes to test/decoder_test.cpp (1 of 3 files). Show all

Unified · Split

test/decoder_test.cpp+34−29
@@ -15,7 +15,6 @@ · 14 unmodified lines
1515
1616 static void UpdateHashFromPlane(SHA_CTX* ctx, const uint8_t* plane,
1717 int width, int height, int stride) {
18−
1918 for (int i = 0; i < height; i++) {
2019 SHA1_Update(ctx, plane, width);
2120 plane += stride;
@@ -30,7 +29,11 @@ static int ReadFrame(std::ifstream* file, BufferedData* buf) { · 8 unmodified lines
3029 int zeroCount = 0;
3130 char b;
3231
33− while (file->read(&b, 1), file->gcount() == 1) {
32+ for (;;) {
33+ file->read(&b, 1);
34+ if (file->gcount() != 1) {
35+ break;
36+ }
3437 if (!buf->Push(b)) {
3538 return -1;
3639 }
@@ -43,8 +46,12 @@ static int ReadFrame(std::ifstream* file, BufferedData* buf) { · 6 unmodified lines
4346 zeroCount = b != 0 ? 0 : zeroCount + 1;
4447 } else {
4548 if (b == 1) {
46− file->seekg(-4, file->cur);
47− return buf->Length() - 4;
49+ if (file->seekg(-4, file->cur).good()) {
50+ return buf->Length() - 4;
51+ } else {
52+ // seeking fails
53+ return -1;
54+ }
4855 } else if (b == 0) {
4956 zeroCount = 3;
5057 } else {
@@ -60,40 +67,38 @@ static int ReadFrame(std::ifstream* file, BufferedData* buf) { · 9 unmodified lines
6067 */
6168 static bool DecodeAndProcess(ISVCDecoder* decoder, const uint8_t* src,
6269 int sliceSize, SHA_CTX* ctx) {
63−
6470 void* data[3];
6571 SBufferInfo bufInfo;
6672 memset(data, 0, sizeof(data));
6773 memset(&bufInfo, 0, sizeof(SBufferInfo));
6874
6975 DECODING_STATE rv = decoder->DecodeFrame(src, sliceSize, data, &bufInfo);
70− if (rv == dsErrorFree) {
71− if (bufInfo.iBufferStatus == 1) {
72− // y plane
73− UpdateHashFromPlane(ctx, static_cast<uint8_t*>(data[0]),
74− bufInfo.UsrData.sSystemBuffer.iWidth,
75− bufInfo.UsrData.sSystemBuffer.iHeight,
76− bufInfo.UsrData.sSystemBuffer.iStride[0]);
77− // u plane
78− UpdateHashFromPlane(ctx, static_cast<uint8_t*>(data[1]),
79− bufInfo.UsrData.sSystemBuffer.iWidth / 2,
80− bufInfo.UsrData.sSystemBuffer.iHeight / 2,
81− bufInfo.UsrData.sSystemBuffer.iStride[1]);
82− // v plane
83− UpdateHashFromPlane(ctx, static_cast<uint8_t*>(data[2]),
84− bufInfo.UsrData.sSystemBuffer.iWidth / 2,
85− bufInfo.UsrData.sSystemBuffer.iHeight / 2,
86− bufInfo.UsrData.sSystemBuffer.iStride[1]);
87− }
88− return true;
89− } else {
76+ if (rv != dsErrorFree) {
9077 return false;
9178 }
79+
80+ if (bufInfo.iBufferStatus == 1) {
81+ // y plane
82+ UpdateHashFromPlane(ctx, static_cast<uint8_t*>(data[0]),
83+ bufInfo.UsrData.sSystemBuffer.iWidth,
84+ bufInfo.UsrData.sSystemBuffer.iHeight,
85+ bufInfo.UsrData.sSystemBuffer.iStride[0]);
86+ // u plane
87+ UpdateHashFromPlane(ctx, static_cast<uint8_t*>(data[1]),
88+ bufInfo.UsrData.sSystemBuffer.iWidth / 2,
89+ bufInfo.UsrData.sSystemBuffer.iHeight / 2,
90+ bufInfo.UsrData.sSystemBuffer.iStride[1]);
91+ // v plane
92+ UpdateHashFromPlane(ctx, static_cast<uint8_t*>(data[2]),
93+ bufInfo.UsrData.sSystemBuffer.iWidth / 2,
94+ bufInfo.UsrData.sSystemBuffer.iHeight / 2,
95+ bufInfo.UsrData.sSystemBuffer.iStride[1]);
96+ }
97+ return true;
9298 }
9399
94100 static void CompareFileToHash(ISVCDecoder* decoder,
95101 const char* fileName, const char* hashStr) {
96−
97102 std::ifstream file(fileName, std::ios::in | std::ios::binary);
98103 ASSERT_TRUE(file.is_open());
99104
@@ -118,7 +123,7 @@ static void CompareFileToHash(ISVCDecoder* decoder, · 18 unmodified lines
118123 FAIL() << "unable to allocate memory";
119124 }
120125
121− int32_t iEndOfStreamFlag = true;
126+ int32_t iEndOfStreamFlag = 1;
122127 decoder->SetOption(DECODER_OPTION_END_OF_STREAM, &iEndOfStreamFlag);
123128
124129 // Get pending last frame
@@ -132,7 +137,7 @@ static void CompareFileToHash(ISVCDecoder* decoder, · 7 unmodified lines
132137 }
133138
134139 class DecoderInitTest : public ::testing::Test {
135−public:
140+ public:
136141 DecoderInitTest() : decoder_(NULL) {}
137142
138143 virtual void SetUp() {
@@ -158,7 +163,7 @@ public: · 19 unmodified lines
158163 }
159164 }
160165
161−protected:
166+ protected:
162167 ISVCDecoder* decoder_;
163168 };
164169

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t