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:
@@ -1,6 +1,7 @@
|
|||||||
extern "C"{
|
extern "C"{
|
||||||
#include "driver.h"
|
#include "driver.h"
|
||||||
#include "registers.h"
|
#include "registers.h"
|
||||||
|
#include "hardware_abstraction.h"
|
||||||
}
|
}
|
||||||
#include "../../fff.h"
|
#include "../../fff.h"
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
|||||||
30
fakegen.rb
30
fakegen.rb
@@ -271,23 +271,19 @@ def output_macro(arg_count, has_varargs, has_calling_conventions, is_value_funct
|
|||||||
puts
|
puts
|
||||||
output_macro_header(declare_macro_name, saved_arg_count, has_varargs, has_calling_conventions, return_type)
|
output_macro_header(declare_macro_name, saved_arg_count, has_varargs, has_calling_conventions, return_type)
|
||||||
indent {
|
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
|
puts
|
||||||
output_macro_header(define_macro_name, saved_arg_count, has_varargs, has_calling_conventions, return_type)
|
output_macro_header(define_macro_name, saved_arg_count, has_varargs, has_calling_conventions, return_type)
|
||||||
indent {
|
indent {
|
||||||
extern_c {
|
putd_backslash "FUNCNAME##_Fake FUNCNAME##_fake;"
|
||||||
putd_backslash "FUNCNAME##_Fake FUNCNAME##_fake;"
|
putd_backslash function_signature(saved_arg_count, has_varargs, has_calling_conventions, is_value_function) + "{"
|
||||||
putd_backslash function_signature(saved_arg_count, has_varargs, has_calling_conventions, is_value_function) + "{"
|
indent {
|
||||||
indent {
|
output_function_body(saved_arg_count, has_varargs, is_value_function)
|
||||||
output_function_body(saved_arg_count, has_varargs, is_value_function)
|
|
||||||
}
|
|
||||||
putd_backslash "}"
|
|
||||||
putd_backslash "DEFINE_RESET_FUNCTION(FUNCNAME)"
|
|
||||||
}
|
}
|
||||||
|
putd_backslash "}"
|
||||||
|
putd_backslash "DEFINE_RESET_FUNCTION(FUNCNAME)"
|
||||||
}
|
}
|
||||||
|
|
||||||
puts
|
puts
|
||||||
@@ -492,9 +488,9 @@ def define_fff_globals
|
|||||||
}
|
}
|
||||||
putd "} fff_globals_t;"
|
putd "} fff_globals_t;"
|
||||||
puts
|
puts
|
||||||
putd_backslash "FFF_EXTERN_C"
|
putd "FFF_EXTERN_C"
|
||||||
putd "extern fff_globals_t fff;"
|
putd "extern fff_globals_t fff;"
|
||||||
putd_backslash "FFF_END_EXTERN_C"
|
putd "FFF_END_EXTERN_C"
|
||||||
puts
|
puts
|
||||||
putd_backslash "#define DEFINE_FFF_GLOBALS"
|
putd_backslash "#define DEFINE_FFF_GLOBALS"
|
||||||
indent {
|
indent {
|
||||||
@@ -520,14 +516,6 @@ def define_fff_globals
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def extern_c
|
|
||||||
putd_backslash "FFF_EXTERN_C"
|
|
||||||
indent {
|
|
||||||
yield
|
|
||||||
}
|
|
||||||
putd_backslash "FFF_END_EXTERN_C"
|
|
||||||
end
|
|
||||||
|
|
||||||
def in_struct
|
def in_struct
|
||||||
putd_backslash "typedef struct FUNCNAME##_Fake {"
|
putd_backslash "typedef struct FUNCNAME##_Fake {"
|
||||||
indent {
|
indent {
|
||||||
|
|||||||
@@ -59,4 +59,39 @@ TEST_F(FFFTestSuite, default_constants_can_be_overridden)
|
|||||||
ASSERT_EQ(OVERRIDE_ARG_HIST_LEN, voidfunc2_fake.arg_history_len);
|
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"
|
#include "test_cases.include"
|
||||||
|
|||||||
Reference in New Issue
Block a user