small medium large xlarge

15 Mar 2017, 11:05
Lin Chun Han (2 posts)


I’m going through this book step by step and found this code snippet suspicious to me:

TEST(LedDriver, LedsOffAfterCreate)
    **uint16_t virtualLeds = 0xffff;**
    TEST_ASSERT_EQUAL_HEX16(0, virtualLeds);

After this case is tested, ledsAddress will point to a address in the stack previously used by call to LedsOffAfterCreate but not valid anymore. Any good reason for using it this way ?

Thanks in advance, Edison

15 Mar 2017, 12:39
James Grenning (190 posts)

Hi Edison,

Each test is stand alone. By the end of this test, we are able to confirm that calling Create() sets the LEDs memory mapped I/O value to zero. The lifetime of virtualLeds is, as you suggest, is the duration of this test function. But that’s OK as it will not be used again.

The reason it is done this way is that each test usually focuses on one small behavior.

Does that help?

16 Mar 2017, 00:51
Lin Chun Han (2 posts)

Hi James,

I overlooked a setup phase for re-assigning the right pointer. Thanks for your time.

cheers, Edison

You must be logged in to comment