openh264/test/decoder_test.cpp

72 lines
1.9 KiB
C++
Raw Normal View History

2013-12-24 09:25:30 +01:00
#include <gtest/gtest.h>
2014-01-07 03:23:44 +01:00
#include "utils/HashFunctions.h"
#include "BaseDecoderTest.h"
2013-12-24 09:25:30 +01:00
static void UpdateHashFromPlane(SHA1Context* ctx, const uint8_t* plane,
2013-12-24 09:25:30 +01:00
int width, int height, int stride) {
for (int i = 0; i < height; i++) {
SHA1Input(ctx, plane, width);
2013-12-24 09:25:30 +01:00
plane += stride;
}
}
class DecoderInitTest : public ::testing::Test, public BaseDecoderTest {
2014-01-08 04:42:58 +01:00
public:
2013-12-24 09:25:30 +01:00
virtual void SetUp() {
BaseDecoderTest::SetUp();
2013-12-24 09:25:30 +01:00
}
virtual void TearDown() {
BaseDecoderTest::TearDown();
2013-12-24 09:25:30 +01:00
}
};
TEST_F(DecoderInitTest, JustInit) {}
2013-12-24 09:25:30 +01:00
struct FileParam {
const char* fileName;
const char* hashStr;
};
class DecoderOutputTest : public ::testing::WithParamInterface<FileParam>,
public DecoderInitTest, public BaseDecoderTest::Callback {
public:
virtual void SetUp() {
DecoderInitTest::SetUp();
if (HasFatalFailure()) {
return;
}
SHA1Reset(&ctx_);
}
virtual void onDecodeFrame(const Frame& frame) {
const Plane& y = frame.y;
const Plane& u = frame.u;
const Plane& v = frame.v;
UpdateHashFromPlane(&ctx_, y.data, y.width, y.height, y.stride);
UpdateHashFromPlane(&ctx_, u.data, u.width, u.height, u.stride);
UpdateHashFromPlane(&ctx_, v.data, v.width, v.height, v.stride);
}
protected:
SHA1Context ctx_;
2013-12-24 09:25:30 +01:00
};
TEST_P(DecoderOutputTest, CompareOutput) {
FileParam p = GetParam();
DecodeFile(p.fileName, this);
unsigned char digest[SHA_DIGEST_LENGTH];
SHA1Result(&ctx_, digest);
if (!HasFatalFailure()) {
ASSERT_TRUE(CompareHash(digest, p.hashStr));
}
2013-12-24 09:25:30 +01:00
}
static const FileParam kFileParamArray[] = {
{"res/test_vd_1d.264", "5827d2338b79ff82cd091c707823e466197281d3"},
{"res/test_vd_rc.264", "eea02e97bfec89d0418593a8abaaf55d02eaa1ca"},
{"res/Static.264", "91dd4a7a796805b2cd015cae8fd630d96c663f42"}
2013-12-24 09:25:30 +01:00
};
INSTANTIATE_TEST_CASE_P(DecodeFile, DecoderOutputTest,
::testing::ValuesIn(kFileParamArray));