ref: 76383c7150817a61df80d370bc8cda653458afbf
parent: c418a76d8e02fb8a2914aa849c3b88f2a70908e3
author: Martin Storsjö <martin@martin.st>
date: Wed Feb 12 17:28:35 EST 2014
Add a test that verifies that the bool typedef in C is ABI compatible with C++
--- a/test/c_interface_test.c
+++ b/test/c_interface_test.c
@@ -1,4 +1,5 @@
#include "codec_api.h"
+#include <stddef.h>
// Cast to this function type to ignore other parameters.
typedef int (*Func)(void*);
@@ -29,4 +30,21 @@
CHECK(5, p, DecodeFrameEx);
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);
}
--- a/test/cpp_interface_test.cpp
+++ b/test/cpp_interface_test.cpp
@@ -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 @@
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;
@@ -113,4 +117,15 @@
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";
}