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

Question: Usage of __weak__ #43

Closed
susundberg opened this issue Feb 10, 2018 · 1 comment
Closed

Question: Usage of __weak__ #43

susundberg opened this issue Feb 10, 2018 · 1 comment
Assignees
Labels

Comments

@susundberg
Copy link

Hi!

Love this library. I have used it several places, for example in in this arduino testing frame

I am not sure how this is thought, but i usually like to make testing so that all functions are mocked, except few special. I make this by linker; i have fake-objects that contains fake implementation of all functions and before that the real ones. This works fine, but to have it even nicer, one wraps the thing to "libfakes.a" that contains all fakes. To make this work, one should mark all fakes with __attribute__((weak)).

This would make minor pull request, that i am super willing to make, but is there a reason why it has been skipped for now?

Cheers,
Pauli

Here is example of 'fixed' function:

#define DEFINE_FAKE_VOID_FUNC0(FUNCNAME) \
    FFF_EXTERN_C \
        FUNCNAME##_Fake FUNCNAME##_fake; \
        __attribute__((weak))  void FUNCNAME(void)  { \
            if(ROOM_FOR_MORE_HISTORY(FUNCNAME)){ \
            } \
            else{ \
                HISTORY_DROPPED(FUNCNAME); \
            } \
            INCREMENT_CALL_COUNT(FUNCNAME); \
            REGISTER_CALL(FUNCNAME); \
            if (FUNCNAME##_fake.custom_fake_seq_len){ /* a sequence of custom fakes */ \
                if (FUNCNAME##_fake.custom_fake_seq_idx < FUNCNAME##_fake.custom_fake_seq_len){ \
                    FUNCNAME##_fake.custom_fake_seq[FUNCNAME##_fake.custom_fake_seq_idx++](); \
                } \
                else{ \
                    FUNCNAME##_fake.custom_fake_seq[FUNCNAME##_fake.custom_fake_seq_len-1](); \
                } \
            } \
            if (FUNCNAME##_fake.custom_fake) FUNCNAME##_fake.custom_fake(); \
        } \
        DEFINE_RESET_FUNCTION(FUNCNAME) \
    FFF_END_EXTERN_C \
@wulfgarpro
Copy link
Collaborator

Closing this issue ticket in favour of reviewing and closing PR #47.

@wulfgarpro wulfgarpro self-assigned this Dec 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants