1
0
mirror of https://github.com/meekrosoft/fff synced 2026-01-23 00:15:59 +01:00

Remove extern "C" from fake declarations.

Assuming your C interfaces are appropriately wrapped for C++, it is
unnecessary to force the fakes to be declared extern "C", and doing so
causes any functions declared with C++ linkage to be impossible to fake
due to the conflicting linkage declarations.
This commit is contained in:
Michael Hansen
2018-05-09 13:25:42 -07:00
parent ef24c19e64
commit b8f9e65387
4 changed files with 4808 additions and 5105 deletions

View File

@@ -1,6 +1,7 @@
extern "C"{
#include "driver.h"
#include "registers.h"
#include "hardware_abstraction.h"
}
#include "../../fff.h"
#include <gtest/gtest.h>

View File

@@ -271,23 +271,19 @@ def output_macro(arg_count, has_varargs, is_value_function)
puts
output_macro_header(declare_macro_name, saved_arg_count, has_varargs, return_type)
indent {
extern_c { # define argument capture variables
output_variables(saved_arg_count, has_varargs, is_value_function)
}
output_variables(saved_arg_count, has_varargs, is_value_function)
}
puts
output_macro_header(define_macro_name, saved_arg_count, has_varargs, return_type)
indent {
extern_c {
putd_backslash "FUNCNAME##_Fake FUNCNAME##_fake;"
putd_backslash function_signature(saved_arg_count, has_varargs, is_value_function) + "{"
indent {
output_function_body(saved_arg_count, has_varargs, is_value_function)
}
putd_backslash "}"
putd_backslash "DEFINE_RESET_FUNCTION(FUNCNAME)"
putd_backslash "FUNCNAME##_Fake FUNCNAME##_fake;"
putd_backslash function_signature(saved_arg_count, has_varargs, is_value_function) + "{"
indent {
output_function_body(saved_arg_count, has_varargs, is_value_function)
}
putd_backslash "}"
putd_backslash "DEFINE_RESET_FUNCTION(FUNCNAME)"
}
puts
@@ -453,9 +449,9 @@ def define_fff_globals
}
putd "} fff_globals_t;"
puts
putd_backslash "FFF_EXTERN_C"
putd "FFF_EXTERN_C"
putd "extern fff_globals_t fff;"
putd_backslash "FFF_END_EXTERN_C"
putd "FFF_END_EXTERN_C"
puts
putd_backslash "#define DEFINE_FFF_GLOBALS"
indent {
@@ -477,14 +473,6 @@ def define_fff_globals
}
end
def extern_c
putd_backslash "FFF_EXTERN_C"
indent {
yield
}
putd_backslash "FFF_END_EXTERN_C"
end
def in_struct
putd_backslash "typedef struct FUNCNAME##_Fake {"
indent {

9848
fff.h

File diff suppressed because it is too large Load Diff

View File

@@ -46,3 +46,37 @@ TEST_F(FFFTestSuite, default_constants_can_be_overridden)
ASSERT_EQ(OVERRIDE_ARG_HIST_LEN, voidfunc2_fake.arg_history_len);
}
// Fake declared in C++ context (not extern "C", using namespace)
// before the fake is declared
namespace cxx
{
typedef int int_t;
void voidfunc1(cxx::int_t);
}
// Now declare the fake. Must be in the same namespace as the
// original declaration.
namespace cxx
{
FAKE_VOID_FUNC(voidfunc1, cxx::int_t);
}
TEST_F(FFFTestSuite, cxx_fake_is_called)
{
cxx::voidfunc1(66);
ASSERT_EQ(cxx::voidfunc1_fake.call_count, 1u);
ASSERT_EQ(cxx::voidfunc1_fake.arg0_val, 66);
}
static int cxx_my_custom_fake_called = 0;
void cxx_my_custom_fake(cxx::int_t i)
{
cxx_my_custom_fake_called++;
}
TEST_F(FFFTestSuite, cxx_can_register_custom_fake)
{
cxx::voidfunc1_fake.custom_fake = cxx_my_custom_fake;
cxx::voidfunc1(66);
ASSERT_EQ(1, cxx_my_custom_fake_called);
}