History

1. support .c in makefile generator. 2. add test to check C interfaces.

jwwang committed 12 years ago

Commit 4fa810d1 parent b51963c5 files · +183 −3Browse files

Showing the changes to test/cpp_interface_test.cpp (1 of 5 files). Show all

Unified · Split

test/cpp_interface_test.cpp+116−0
@@ -0,0 +1,116 @@
1+#include <gtest/gtest.h>
2+#include "codec_api.h"
3+
4+static void CheckFunctionOrder(int expect, int actual, const char* name) {
5+ EXPECT_EQ(expect, actual) << "Wrong function order: " << name;
6+}
7+
8+typedef void(*CheckFunc)(int, int, const char*);
9+extern "C" void CheckEncoderInterface(ISVCEncoder* p, CheckFunc);
10+extern "C" void CheckDecoderInterface(ISVCDecoder* p, CheckFunc);
11+
12+// Store the 'this' pointer to verify 'this' is received as expected from C code.
13+static void* gThis;
14+
15+/**
16+ * Return a unique number for each virtual function so that we are able to
17+ * check if the order of functions in the virtual table is as expected.
18+ */
19+struct SVCEncoderImpl : public ISVCEncoder {
20+ virtual ~SVCEncoderImpl() {}
21+ virtual int EXTAPI Initialize(SVCEncodingParam* pParam,
22+ const INIT_TYPE kiInitType) {
23+ EXPECT_TRUE(gThis == this);
24+ return 1;
25+ }
26+ virtual int EXTAPI Initialize2(void* pParam, const INIT_TYPE kiInitType) {
27+ EXPECT_TRUE(gThis == this);
28+ return 2;
29+ }
30+ virtual int EXTAPI Uninitialize() {
31+ EXPECT_TRUE(gThis == this);
32+ return 3;
33+ }
34+ virtual int EXTAPI EncodeFrame(const unsigned char* kpSrc,
35+ SFrameBSInfo* pBsInfo) {
36+ EXPECT_TRUE(gThis == this);
37+ return 4;
38+ }
39+ virtual int EXTAPI EncodeFrame2(const SSourcePicture** kppSrcPicList,
40+ int nSrcPicNum, SFrameBSInfo* pBsInfo) {
41+ EXPECT_TRUE(gThis == this);
42+ return 5;
43+ }
44+ virtual int EXTAPI EncodeParameterSets(SFrameBSInfo* pBsInfo) {
45+ EXPECT_TRUE(gThis == this);
46+ return 6;
47+ }
48+ virtual int EXTAPI PauseFrame(const unsigned char* kpSrc,
49+ SFrameBSInfo* pBsInfo) {
50+ EXPECT_TRUE(gThis == this);
51+ return 7;
52+ }
53+ virtual int EXTAPI ForceIntraFrame(bool bIDR) {
54+ EXPECT_TRUE(gThis == this);
55+ return 8;
56+ }
57+ virtual int EXTAPI SetOption(ENCODER_OPTION eOptionId, void* pOption) {
58+ EXPECT_TRUE(gThis == this);
59+ return 9;
60+ }
61+ virtual int EXTAPI GetOption(ENCODER_OPTION eOptionId, void* pOption) {
62+ EXPECT_TRUE(gThis == this);
63+ return 10;
64+ }
65+};
66+
67+struct SVCDecoderImpl : public ISVCDecoder {
68+ virtual ~SVCDecoderImpl() {}
69+ virtual long EXTAPI Initialize(void* pParam, const INIT_TYPE iInitType) {
70+ EXPECT_TRUE(gThis == this);
71+ return 1;
72+ }
73+ virtual long EXTAPI Uninitialize() {
74+ EXPECT_TRUE(gThis == this);
75+ return 2;
76+ }
77+ virtual DECODING_STATE EXTAPI DecodeFrame(const unsigned char* pSrc,
78+ const int iSrcLen, unsigned char** ppDst, int* pStride,
79+ int& iWidth, int& iHeight) {
80+ EXPECT_TRUE(gThis == this);
81+ return static_cast<DECODING_STATE>(3);
82+ }
83+ virtual DECODING_STATE EXTAPI DecodeFrame2(const unsigned char* pSrc,
84+ const int iSrcLen, void** ppDst, SBufferInfo* pDstInfo) {
85+ EXPECT_TRUE(gThis == this);
86+ return static_cast<DECODING_STATE>(4);
87+ }
88+ virtual DECODING_STATE EXTAPI DecodeFrameEx(const unsigned char* pSrc,
89+ const int iSrcLen, unsigned char* pDst, int iDstStride,
90+ int& iDstLen, int& iWidth, int& iHeight, int& iColorFormat) {
91+ EXPECT_TRUE(gThis == this);
92+ return static_cast<DECODING_STATE>(5);
93+ }
94+ virtual long EXTAPI SetOption (DECODER_OPTION eOptionId, void* pOption) {
95+ EXPECT_TRUE(gThis == this);
96+ return 6;
97+ }
98+ virtual long EXTAPI GetOption (DECODER_OPTION eOptionId, void* pOption) {
99+ EXPECT_TRUE(gThis == this);
100+ return 7;
101+ }
102+};
103+
104+TEST(ISVCEncoderTest, CheckFunctionOrder) {
105+ SVCEncoderImpl* p = new SVCEncoderImpl;
106+ gThis = p;
107+ CheckEncoderInterface(p, CheckFunctionOrder);
108+ delete p;
109+}
110+
111+TEST(ISVCDecoderTest, CheckFunctionOrder) {
112+ SVCDecoderImpl* p = new SVCDecoderImpl;
113+ gThis = p;
114+ CheckDecoderInterface(p, CheckFunctionOrder);
115+ delete p;
116+}

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