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