meekrosoft / fff

A testing micro framework for creating function test doubles
Other
749 stars 163 forks source link

SET_RETURN_SEQ should reset return_val_seq_idx #101

Open jackdigitalinsight opened 2 years ago

jackdigitalinsight commented 2 years ago

Describe the bug Within one test case, I want to modify a fake's return value sequence. SET_RETURN_SEQ updates the sequence and length, but doesn't reset the next index.

To Reproduce example:

void test_protocol()
{
    int rx1[] = { 1, 2, -1 };
    SET_RETURN_SEQ(hal_uart_rx, rx1, 3);
        protocol_update();
        // assert results

        int rx2[] = { 3, 4, 5, 6, -1 };
    SET_RETURN_SEQ(hal_uart_rx, rx2, 5);
        protocol_update();
        // assert results
}

Expected behavior second protocol_update() calls to hal_uart_rx(fake) should see 3, 4, 5, 6, -1. Instead it gets 6, -1.

Compiler, toolset, platform (please complete the following information):

**Suggested change***

 #define SET_RETURN_SEQ(FUNCNAME, ARRAY_POINTER, ARRAY_LEN) \
     FUNCNAME##_fake.return_val_seq = ARRAY_POINTER; \
-    FUNCNAME##_fake.return_val_seq_len = ARRAY_LEN;
+    FUNCNAME##_fake.return_val_seq_len = ARRAY_LEN; \
+    FUNCNAME##_fake.return_val_seq_idx = 0;
+
CiderMan commented 1 year ago

@meekrosoft I think that this makes sense (and the equivalent for custom fake sequences); would you be happy to consider a PR for this change?