1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
|
#include <gtest/gtest.h>
#include "codec_api.h"
#include <stddef.h>
static void CheckFunctionOrder (int expect, int actual, const char* name) {
EXPECT_EQ (expect, actual) << "Wrong function order: " << name;
}
typedef void (*CheckFunc) (int, int, const char*);
extern "C" void CheckEncoderInterface (ISVCEncoder* p, CheckFunc);
extern "C" void CheckDecoderInterface (ISVCDecoder* p, CheckFunc);
extern "C" size_t GetBoolSize (void);
extern "C" size_t GetBoolOffset (void);
extern "C" size_t GetBoolStructSize (void);
// Store the 'this' pointer to verify 'this' is received as expected from C code.
static void* gThis;
/**
* Return a unique number for each virtual function so that we are able to
* check if the order of functions in the virtual table is as expected.
*/
struct SVCEncoderImpl : public ISVCEncoder {
virtual ~SVCEncoderImpl() {}
virtual int EXTAPI Initialize (const SEncParamBase* pParam) {
EXPECT_TRUE (gThis == this);
return 1;
}
virtual int EXTAPI InitializeExt (const SEncParamExt* pParam) {
EXPECT_TRUE (gThis == this);
return 2;
}
virtual int EXTAPI GetDefaultParams (SEncParamExt* pParam) {
EXPECT_TRUE (gThis == this);
return 3;
}
virtual int EXTAPI Uninitialize() {
EXPECT_TRUE (gThis == this);
return 4;
}
virtual int EXTAPI EncodeFrame (const SSourcePicture* kpSrcPic,
SFrameBSInfo* pBsInfo) {
EXPECT_TRUE (gThis == this);
return 5;
}
virtual int EXTAPI EncodeParameterSets (SFrameBSInfo* pBsInfo) {
EXPECT_TRUE (gThis == this);
return 6;
}
virtual int EXTAPI ForceIntraFrame (bool bIDR, int iLayerId = -1) {
EXPECT_TRUE (gThis == this);
return 7;
}
virtual int EXTAPI SetOption (ENCODER_OPTION eOptionId, void* pOption) {
EXPECT_TRUE (gThis == this);
return 8;
}
virtual int EXTAPI GetOption (ENCODER_OPTION eOptionId, void* pOption) {
EXPECT_TRUE (gThis == this);
return 9;
}
};
struct SVCDecoderImpl : public ISVCDecoder {
virtual ~SVCDecoderImpl() {}
virtual long EXTAPI Initialize (const SDecodingParam* pParam) {
EXPECT_TRUE (gThis == this);
return 1;
}
virtual long EXTAPI Uninitialize() {
EXPECT_TRUE (gThis == this);
return 2;
}
virtual DECODING_STATE EXTAPI DecodeFrame (const unsigned char* pSrc,
const int iSrcLen, unsigned char** ppDst, int* pStride,
int& iWidth, int& iHeight) {
EXPECT_TRUE (gThis == this);
return static_cast<DECODING_STATE> (3);
}
virtual DECODING_STATE EXTAPI DecodeFrameNoDelay (const unsigned char* pSrc,
const int iSrcLen, unsigned char** ppDst, SBufferInfo* pDstInfo) {
EXPECT_TRUE (gThis == this);
return static_cast<DECODING_STATE> (4);
}
virtual DECODING_STATE EXTAPI DecodeFrame2 (const unsigned char* pSrc,
const int iSrcLen, unsigned char** ppDst, SBufferInfo* pDstInfo) {
EXPECT_TRUE (gThis == this);
return static_cast<DECODING_STATE> (5);
}
virtual DECODING_STATE EXTAPI FlushFrame (unsigned char** ppDst, SBufferInfo* pDstInfo) {
EXPECT_TRUE (gThis == this);
return static_cast<DECODING_STATE> (10);
}
virtual DECODING_STATE EXTAPI DecodeFrameEx (const unsigned char* pSrc,
const int iSrcLen, unsigned char* pDst, int iDstStride,
int& iDstLen, int& iWidth, int& iHeight, int& iColorFormat) {
EXPECT_TRUE (gThis == this);
return static_cast<DECODING_STATE> (6);
}
virtual DECODING_STATE EXTAPI DecodeParser (const unsigned char* pSrc,
const int iSrcLen, SParserBsInfo* pDstInfo) {
EXPECT_TRUE (gThis == this);
return static_cast<DECODING_STATE> (7);
}
virtual long EXTAPI SetOption (DECODER_OPTION eOptionId, void* pOption) {
EXPECT_TRUE (gThis == this);
return static_cast<DECODING_STATE> (8);
}
virtual long EXTAPI GetOption (DECODER_OPTION eOptionId, void* pOption) {
EXPECT_TRUE (gThis == this);
return static_cast<DECODING_STATE> (9);
}
};
TEST (ISVCEncoderTest, CheckFunctionOrder) {
SVCEncoderImpl* p = new SVCEncoderImpl;
gThis = p;
CheckEncoderInterface (p, CheckFunctionOrder);
delete p;
}
TEST (ISVCDecoderTest, CheckFunctionOrder) {
SVCDecoderImpl* p = new SVCDecoderImpl;
gThis = p;
CheckDecoderInterface (p, CheckFunctionOrder);
delete p;
}
struct bool_test_struct {
char c;
bool b;
};
TEST (ISVCDecoderEncoderTest, CheckCAbi) {
EXPECT_EQ (sizeof (bool), GetBoolSize()) << "Wrong size of bool type";
EXPECT_EQ (offsetof (bool_test_struct, b), GetBoolOffset()) << "Wrong alignment of bool in a struct";
EXPECT_EQ (sizeof (bool_test_struct), GetBoolStructSize()) << "Wrong size of struct with a bool";
}
|