Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix C linkage when symbol is not in a header #45

Merged
merged 1 commit into from
Aug 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading