History

Add a test that verifies that the bool typedef in C is ABI compatible with C++

Martin Storsjö committed 12 years ago

Commit 76383c71 parent c418a762 files · +33 −0Browse files

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

Unified · Split

test/cpp_interface_test.cpp+15−0
@@ -1,5 +1,6 @@
11 #include <gtest/gtest.h>
22 #include "codec_api.h"
3+#include <stddef.h>
34
45 static void CheckFunctionOrder(int expect, int actual, const char* name) {
56 EXPECT_EQ(expect, actual) << "Wrong function order: " << name;
@@ -8,6 +9,9 @@ static void CheckFunctionOrder(int expect, int actual, const char* name) { · 2 unmodified lines
89 typedef void(*CheckFunc)(int, int, const char*);
910 extern "C" void CheckEncoderInterface(ISVCEncoder* p, CheckFunc);
1011 extern "C" void CheckDecoderInterface(ISVCDecoder* p, CheckFunc);
12+extern "C" size_t GetBoolSize(void);
13+extern "C" size_t GetBoolOffset(void);
14+extern "C" size_t GetBoolStructSize(void);
1115
1216 // Store the 'this' pointer to verify 'this' is received as expected from C code.
1317 static void* gThis;
@@ -114,3 +118,14 @@ TEST(ISVCDecoderTest, CheckFunctionOrder) { · 100 unmodified lines
114118 CheckDecoderInterface(p, CheckFunctionOrder);
115119 delete p;
116120 }
121+
122+struct bool_test_struct {
123+ char c;
124+ bool b;
125+};
126+
127+TEST(ISVCDecoderEncoderTest, CheckCAbi) {
128+ EXPECT_EQ(sizeof(bool), GetBoolSize()) << "Wrong size of bool type";
129+ EXPECT_EQ(offsetof(bool_test_struct, b), GetBoolOffset()) << "Wrong alignment of bool in a struct";
130+ EXPECT_EQ(sizeof(bool_test_struct), GetBoolStructSize()) << "Wrong size of struct with a bool";
131+}

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