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

Merge branch 'zrax-no_extern_c'

This commit is contained in:
James Fraser
2018-12-14 19:58:13 +11:00
4 changed files with 5193 additions and 5490 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, has_calling_conventions, is_value_funct
puts
output_macro_header(declare_macro_name, saved_arg_count, has_varargs, has_calling_conventions, return_type)
indent {
extern_c { # define argument capture variables
output_variables(saved_arg_count, has_varargs, has_calling_conventions, is_value_function)
}
output_variables(saved_arg_count, has_varargs, has_calling_conventions, is_value_function)
}
puts
output_macro_header(define_macro_name, saved_arg_count, has_varargs, has_calling_conventions, return_type)
indent {
extern_c {
putd_backslash "FUNCNAME##_Fake FUNCNAME##_fake;"
putd_backslash function_signature(saved_arg_count, has_varargs, has_calling_conventions, 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, has_calling_conventions, is_value_function) + "{"
indent {
output_function_body(saved_arg_count, has_varargs, is_value_function)
}
putd_backslash "}"
putd_backslash "DEFINE_RESET_FUNCTION(FUNCNAME)"
}
puts
@@ -492,9 +488,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 {
@@ -520,14 +516,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 {

10617
fff.h

File diff suppressed because it is too large Load Diff

View File

@@ -59,4 +59,39 @@ 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);
}
#include "test_cases.include"