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 @@
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 4
4static void CheckFunctionOrder(int expect, int actual, const char* name) {5static void CheckFunctionOrder(int expect, int actual, const char* name) {
5 EXPECT_EQ(expect, actual) << "Wrong function order: " << name;6 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
8typedef void(*CheckFunc)(int, int, const char*);9typedef void(*CheckFunc)(int, int, const char*);
9extern "C" void CheckEncoderInterface(ISVCEncoder* p, CheckFunc);10extern "C" void CheckEncoderInterface(ISVCEncoder* p, CheckFunc);
10extern "C" void CheckDecoderInterface(ISVCDecoder* p, CheckFunc);11extern "C" void CheckDecoderInterface(ISVCDecoder* p, CheckFunc);
12extern "C" size_t GetBoolSize(void);
13extern "C" size_t GetBoolOffset(void);
14extern "C" size_t GetBoolStructSize(void);
11 15
12// 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.
13static void* gThis;17static void* gThis;
@@ -114,3 +118,14 @@ TEST(ISVCDecoderTest, CheckFunctionOrder) { · 100 unmodified lines
114 CheckDecoderInterface(p, CheckFunctionOrder);118 CheckDecoderInterface(p, CheckFunctionOrder);
115 delete p;119 delete p;
116}120}
121
122struct bool_test_struct {
123 char c;
124 bool b;
125};
126
127TEST(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