FEXLinuxTests/thunks: Add tests for opaque types

This commit is contained in:
Tony Wasserka 2023-10-19 12:49:00 +02:00
parent 6a6886305e
commit 0cf2695772
4 changed files with 40 additions and 0 deletions

View File

@ -10,4 +10,13 @@ extern "C" {
uint32_t GetDoubledValue(uint32_t);
/// Interfaces used to test opaque_type and assume_compatible_data_layout annotations
struct OpaqueType;
OpaqueType* MakeOpaqueType(uint32_t data);
uint32_t ReadOpaqueTypeData(OpaqueType*);
void DestroyOpaqueType(OpaqueType*);
}

View File

@ -6,4 +6,20 @@ uint32_t GetDoubledValue(uint32_t input) {
return 2 * input;
}
struct OpaqueType {
uint32_t data;
};
OpaqueType* MakeOpaqueType(uint32_t data) {
return new OpaqueType { data };
}
uint32_t ReadOpaqueTypeData(OpaqueType* value) {
return value->data;
}
void DestroyOpaqueType(OpaqueType* value) {
delete value;
}
} // extern "C"

View File

@ -12,3 +12,8 @@ template<auto, int, typename>
struct fex_gen_param {};
template<> struct fex_gen_config<GetDoubledValue> {};
template<> struct fex_gen_type<OpaqueType> : fexgen::opaque_type {};
template<> struct fex_gen_config<MakeOpaqueType> {};
template<> struct fex_gen_config<ReadOpaqueTypeData> {};
template<> struct fex_gen_config<DestroyOpaqueType> {};

View File

@ -17,8 +17,18 @@ struct Fixture {
#define GET_SYMBOL(name) decltype(&::name) name = (decltype(name))dlsym(lib, #name)
GET_SYMBOL(GetDoubledValue);
GET_SYMBOL(MakeOpaqueType);
GET_SYMBOL(ReadOpaqueTypeData);
GET_SYMBOL(DestroyOpaqueType);
};
TEST_CASE_METHOD(Fixture, "Trivial") {
CHECK(GetDoubledValue(10) == 20);
}
TEST_CASE_METHOD(Fixture, "Opaque data types") {
auto data = MakeOpaqueType(0x1234);
CHECK(ReadOpaqueTypeData(data) == 0x1234);
DestroyOpaqueType(data);
}