ref: 94b79c42b1b453d2bee44c4d271896f826f9d5a6
parent: 6f58a0c1f756e625169f67ff2d228cc2e39149be
author: jwwang <jwwang@mozilla.com>
date: Wed Jan 8 06:42:58 EST 2014
minor fixes to the tests
--- a/test/decoder_test.cpp
+++ b/test/decoder_test.cpp
@@ -15,7 +15,6 @@
static void UpdateHashFromPlane(SHA_CTX* ctx, const uint8_t* plane,
int width, int height, int stride) {
-
for (int i = 0; i < height; i++) {
SHA1_Update(ctx, plane, width);
plane += stride;
@@ -30,7 +29,11 @@
int zeroCount = 0;
char b;
- while (file->read(&b, 1), file->gcount() == 1) {
+ for (;;) {
+ file->read(&b, 1);
+ if (file->gcount() != 1) {
+ break;
+ }
if (!buf->Push(b)) {
return -1;
}
@@ -43,8 +46,12 @@
zeroCount = b != 0 ? 0 : zeroCount + 1;
} else {
if (b == 1) {
- file->seekg(-4, file->cur);
- return buf->Length() - 4;
+ if (file->seekg(-4, file->cur).good()) {
+ return buf->Length() - 4;
+ } else {
+ // seeking fails
+ return -1;
+ }
} else if (b == 0) {
zeroCount = 3;
} else {
@@ -60,7 +67,6 @@
*/
static bool DecodeAndProcess(ISVCDecoder* decoder, const uint8_t* src,
int sliceSize, SHA_CTX* ctx) {
-
void* data[3];
SBufferInfo bufInfo;
memset(data, 0, sizeof(data));
@@ -67,33 +73,32 @@
memset(&bufInfo, 0, sizeof(SBufferInfo));
DECODING_STATE rv = decoder->DecodeFrame(src, sliceSize, data, &bufInfo);
- if (rv == dsErrorFree) {
- if (bufInfo.iBufferStatus == 1) {
- // y plane
- UpdateHashFromPlane(ctx, static_cast<uint8_t*>(data[0]),
- bufInfo.UsrData.sSystemBuffer.iWidth,
- bufInfo.UsrData.sSystemBuffer.iHeight,
- bufInfo.UsrData.sSystemBuffer.iStride[0]);
- // u plane
- UpdateHashFromPlane(ctx, static_cast<uint8_t*>(data[1]),
- bufInfo.UsrData.sSystemBuffer.iWidth / 2,
- bufInfo.UsrData.sSystemBuffer.iHeight / 2,
- bufInfo.UsrData.sSystemBuffer.iStride[1]);
- // v plane
- UpdateHashFromPlane(ctx, static_cast<uint8_t*>(data[2]),
- bufInfo.UsrData.sSystemBuffer.iWidth / 2,
- bufInfo.UsrData.sSystemBuffer.iHeight / 2,
- bufInfo.UsrData.sSystemBuffer.iStride[1]);
- }
- return true;
- } else {
+ if (rv != dsErrorFree) {
return false;
}
+
+ if (bufInfo.iBufferStatus == 1) {
+ // y plane
+ UpdateHashFromPlane(ctx, static_cast<uint8_t*>(data[0]),
+ bufInfo.UsrData.sSystemBuffer.iWidth,
+ bufInfo.UsrData.sSystemBuffer.iHeight,
+ bufInfo.UsrData.sSystemBuffer.iStride[0]);
+ // u plane
+ UpdateHashFromPlane(ctx, static_cast<uint8_t*>(data[1]),
+ bufInfo.UsrData.sSystemBuffer.iWidth / 2,
+ bufInfo.UsrData.sSystemBuffer.iHeight / 2,
+ bufInfo.UsrData.sSystemBuffer.iStride[1]);
+ // v plane
+ UpdateHashFromPlane(ctx, static_cast<uint8_t*>(data[2]),
+ bufInfo.UsrData.sSystemBuffer.iWidth / 2,
+ bufInfo.UsrData.sSystemBuffer.iHeight / 2,
+ bufInfo.UsrData.sSystemBuffer.iStride[1]);
+ }
+ return true;
}
static void CompareFileToHash(ISVCDecoder* decoder,
const char* fileName, const char* hashStr) {
-
std::ifstream file(fileName, std::ios::in | std::ios::binary);
ASSERT_TRUE(file.is_open());
@@ -118,7 +123,7 @@
FAIL() << "unable to allocate memory";
}
- int32_t iEndOfStreamFlag = true;
+ int32_t iEndOfStreamFlag = 1;
decoder->SetOption(DECODER_OPTION_END_OF_STREAM, &iEndOfStreamFlag);
// Get pending last frame
@@ -132,7 +137,7 @@
}
class DecoderInitTest : public ::testing::Test {
-public:
+ public:
DecoderInitTest() : decoder_(NULL) {}
virtual void SetUp() {
@@ -158,7 +163,7 @@
}
}
-protected:
+ protected:
ISVCDecoder* decoder_;
};
--- a/test/encoder_test.cpp
+++ b/test/encoder_test.cpp
@@ -57,7 +57,6 @@
static void CompareFileToHash(ISVCEncoder* encoder,
const char* fileName, const char* hashStr,
int width, int height, float frameRate) {
-
std::ifstream file(fileName, std::ios::in | std::ios::binary);
ASSERT_TRUE(file.is_open());
@@ -94,9 +93,9 @@
ASSERT_TRUE(CompareHash(digest, hashStr));
}
-class EncoderInitTest : public ::testing::Test {
-public:
- EncoderInitTest() : encoder_(NULL) {}
+class EncoderBaseTest : public ::testing::Test {
+ public:
+ EncoderBaseTest() : encoder_(NULL) {}
virtual void SetUp() {
int rv = CreateSVCEncoder(&encoder_);
@@ -105,17 +104,17 @@
}
virtual void TearDown() {
- if (encoder_ != NULL) {
+ if (encoder_) {
encoder_->Uninitialize();
DestroySVCEncoder(encoder_);
}
}
-protected:
+ protected:
ISVCEncoder* encoder_;
};
-TEST_F(EncoderInitTest, JustInit) {
+TEST_F(EncoderBaseTest, JustInit) {
}
struct EncodeFileParam {
@@ -126,7 +125,7 @@
float frameRate;
};
-class EncoderOutputTest : public EncoderInitTest ,
+class EncoderOutputTest : public EncoderBaseTest ,
public ::testing::WithParamInterface<EncodeFileParam> {
};
--- a/test/utils/BufferedData.h
+++ b/test/utils/BufferedData.h
@@ -4,11 +4,9 @@
#include <stddef.h>
#include <stdlib.h>
-class BufferedData
-{
-public:
- BufferedData() : data_(NULL), capacity_(0), length_(0) {
- }
+class BufferedData {
+ public:
+ BufferedData() : data_(NULL), capacity_(0), length_(0) {}
~BufferedData() {
free(data_);
@@ -40,7 +38,7 @@
return data_;
}
-private:
+ private:
bool EnsureCapacity(size_t capacity) {
if (capacity > capacity_) {
size_t newsize = capacity * 2;