Add a test that verifies that the bool typedef in C is ABI compatible with C++
This commit is contained in:
parent
c418a76d8e
commit
76383c7150
@ -1,4 +1,5 @@
|
||||
#include "codec_api.h"
|
||||
#include <stddef.h>
|
||||
|
||||
// Cast to this function type to ignore other parameters.
|
||||
typedef int (*Func)(void*);
|
||||
@ -30,3 +31,20 @@ void CheckDecoderInterface(ISVCDecoder* p, CheckFunc check) {
|
||||
CHECK(6, p, SetOption);
|
||||
CHECK(7, p, GetOption);
|
||||
}
|
||||
|
||||
struct bool_test_struct {
|
||||
char c;
|
||||
bool b;
|
||||
};
|
||||
|
||||
size_t GetBoolSize(void) {
|
||||
return sizeof(bool);
|
||||
}
|
||||
|
||||
size_t GetBoolOffset(void) {
|
||||
return offsetof(struct bool_test_struct, b);
|
||||
}
|
||||
|
||||
size_t GetBoolStructSize(void) {
|
||||
return sizeof(struct bool_test_struct);
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
#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;
|
||||
@ -8,6 +9,9 @@ static void CheckFunctionOrder(int expect, int actual, const char* 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;
|
||||
@ -114,3 +118,14 @@ TEST(ISVCDecoderTest, CheckFunctionOrder) {
|
||||
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";
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user