ref: 34b7f38e94b57ff17c5030aee3694a3b56e90e51
parent: 136931c265bbe3a50bea42675adcf3a9ff28e890
parent: 76383c7150817a61df80d370bc8cda653458afbf
author: Ethan Hugg <ethanhugg@gmail.com>
date: Thu Feb 13 02:20:39 EST 2014
Merge pull request #283 from mstorsjo/extend-c-test Test more aspects of the C interface, fix using the C interface on MSVC
--- a/codec/api/svc/codec_api.h
+++ b/codec/api/svc/codec_api.h
@@ -34,7 +34,11 @@
#define WELS_VIDEO_CODEC_SVC_API_H__
#ifndef __cplusplus
+#ifdef _MSC_VER
+typedef unsigned char bool;
+#else
#include <stdbool.h>
+#endif
#endif
#include "codec_app_def.h"
--- 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";
}