History

reorganize tests

Licai Guo committed 12 years ago

Commit f26bb571 parent 667bfe223 files · +68 −43Browse files

Showing the changes to test/api/decode_encode_test.cpp (1 of 23 files). Show all

Unified · Split

test/api/decode_encode_test.cpp+112−0
@@ -0,0 +1,112 @@
1+#include <gtest/gtest.h>
2+#include "codec_def.h"
3+#include "utils/HashFunctions.h"
4+#include "utils/BufferedData.h"
5+#include "utils/InputStream.h"
6+#include "BaseDecoderTest.h"
7+#include "BaseEncoderTest.h"
8+
9+static void UpdateHashFromFrame(const SFrameBSInfo& info, SHA1Context* ctx) {
10+ for (int i = 0; i < info.iLayerNum; ++i) {
11+ const SLayerBSInfo& layerInfo = info.sLayerInfo[i];
12+ int layerSize = 0;
13+ for (int j = 0; j < layerInfo.iNalCount; ++j) {
14+ layerSize += layerInfo.iNalLengthInByte[j];
15+ }
16+ SHA1Input(ctx, layerInfo.pBsBuf, layerSize);
17+ }
18+}
19+
20+static void WritePlaneBuffer(BufferedData* buf, const uint8_t* plane,
21+ int width, int height, int stride) {
22+ for (int i = 0; i < height; i++) {
23+ if (!buf->PushBack(plane, width)) {
24+ FAIL() << "unable to allocate memory";
25+ }
26+ plane += stride;
27+ }
28+}
29+
30+struct DecodeEncodeFileParam {
31+ const char* fileName;
32+ const char* hashStr;
33+ int width;
34+ int height;
35+ float frameRate;
36+};
37+
38+class DecodeEncodeTest : public ::testing::TestWithParam<DecodeEncodeFileParam>,
39+ public BaseDecoderTest, public BaseDecoderTest::Callback,
40+ public BaseEncoderTest , public BaseEncoderTest::Callback,
41+ public InputStream {
42+ public:
43+ virtual void SetUp() {
44+ BaseDecoderTest::SetUp();
45+ if (HasFatalFailure()) {
46+ return;
47+ }
48+ BaseEncoderTest::SetUp();
49+ if (HasFatalFailure()) {
50+ return;
51+ }
52+ SHA1Reset(&ctx_);
53+ }
54+
55+ virtual void TearDown() {
56+ BaseDecoderTest::TearDown();
57+ BaseEncoderTest::TearDown();
58+ }
59+
60+ virtual void onDecodeFrame(const Frame& frame) {
61+ const Plane& y = frame.y;
62+ const Plane& u = frame.u;
63+ const Plane& v = frame.v;
64+ WritePlaneBuffer(&buf_, y.data, y.width, y.height, y.stride);
65+ WritePlaneBuffer(&buf_, u.data, u.width, u.height, u.stride);
66+ WritePlaneBuffer(&buf_, v.data, v.width, v.height, v.stride);
67+ }
68+
69+ virtual void onEncodeFrame(const SFrameBSInfo& frameInfo) {
70+ UpdateHashFromFrame(frameInfo, &ctx_);
71+ }
72+
73+ virtual int read(void* ptr, size_t len) {
74+ while (buf_.Length() < len) {
75+ bool hasNext = DecodeNextFrame(this);
76+ if (HasFatalFailure()) {
77+ return -1;
78+ }
79+ if (!hasNext) {
80+ if (buf_.Length() == 0) {
81+ return -1;
82+ }
83+ break;
84+ }
85+ }
86+ return buf_.PopFront(static_cast<uint8_t*>(ptr), len);
87+ }
88+
89+ protected:
90+ SHA1Context ctx_;
91+ BufferedData buf_;
92+};
93+
94+TEST_P(DecodeEncodeTest, CompareOutput) {
95+ DecodeEncodeFileParam p = GetParam();
96+
97+ ASSERT_TRUE(Open(p.fileName));
98+ EncodeStream(this, p.width, p.height, p.frameRate, SM_SINGLE_SLICE, false, 1, 1, this);
99+ unsigned char digest[SHA_DIGEST_LENGTH];
100+ SHA1Result(&ctx_, digest);
101+ if (!HasFatalFailure()) {
102+ CompareHash(digest, p.hashStr);
103+ }
104+}
105+
106+static const DecodeEncodeFileParam kFileParamArray[] = {
107+ {"res/test_vd_1d.264", "c04a5978eb715837c29463e79b6598a05136829f", 320, 192, 12.0f},
108+ {"res/test_vd_rc.264", "40d8eb5a54d358c663f836c689a158c326de4b1c", 320, 192, 12.0f},
109+};
110+
111+INSTANTIATE_TEST_CASE_P(DecodeEncodeFile, DecodeEncodeTest,
112+ ::testing::ValuesIn(kFileParamArray));

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