Skip to content

Commit

Permalink
#42: C linkage when symbol is not in a header
Browse files Browse the repository at this point in the history
  • Loading branch information
theHolgi committed Aug 19, 2023
1 parent c432f86 commit 1b4358e
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions hammocking/templates/gmock/mockup.cc.j2
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class_mockup *mockup_global_ptr = 0;
{{ variable.get_definition() }};
{% endfor %}

extern "C" {
{% for function in functions %}

{{function.get_signature()}}{
Expand All @@ -20,3 +21,4 @@ class_mockup *mockup_global_ptr = 0;
{% endif %}
} /* {{function.name}} */
{% endfor %}
}
2 changes: 2 additions & 0 deletions tests/data/gmock_test/test_add_function_get/mockup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
class_mockup *mockup_global_ptr = 0;


extern "C" {

int a_get_y2(){
if(0 != mockup_global_ptr)
return mockup_global_ptr->a_get_y2();
else
return (int)0;
} /* a_get_y2 */
}
2 changes: 2 additions & 0 deletions tests/data/gmock_test/test_add_function_set_one_arg/mockup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
class_mockup *mockup_global_ptr = 0;


extern "C" {

void set_some_int(int some_value){
if(0 != mockup_global_ptr)
mockup_global_ptr->set_some_int(some_value);
} /* set_some_int */
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
class_mockup *mockup_global_ptr = 0;


extern "C" {

float my_func(float unnamed1){
if(0 != mockup_global_ptr)
return mockup_global_ptr->my_func(unnamed1);
else
return (float)0;
} /* my_func */
}
2 changes: 2 additions & 0 deletions tests/data/gmock_test/test_empty_templates/mockup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
class_mockup *mockup_global_ptr = 0;


extern "C" {
}
2 changes: 2 additions & 0 deletions tests/data/gmock_test/test_mini_c_gmock/mockup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ int a_y1;
a_y4_t a_y4;
int c_u1;

extern "C" {

int a_get_y2(){
if(0 != mockup_global_ptr)
Expand Down Expand Up @@ -54,3 +55,4 @@ void c_set_u6(c_u6_t u6){
if(0 != mockup_global_ptr)
mockup_global_ptr->c_set_u6(u6);
} /* c_set_u6 */
}
5 changes: 5 additions & 0 deletions tests/data/mini_c_test/b.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
#include "a.h"
#include "c.h"

// This function is not found in a header, but only here.
extern int local_extern(int x);

void b_init(void){
}

Expand All @@ -29,4 +32,6 @@ void b_step(void){
int b6;
a_get_y6(&b6);
c_set_u6((c_u6_t)b6);

local_extern(2);
}
2 changes: 2 additions & 0 deletions tests/hammocking_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ class class_mockup {
int x;
float y;
extern "C" {
}
"""
)

Expand Down

0 comments on commit 1b4358e

Please sign in to comment.