small medium large xlarge

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

Hi,

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

TEST(LedDriver, LedsOffAfterCreate)
{
    **uint16_t virtualLeds = 0xffff;**
    LedDriver_Create(&virtualLeds);
    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

James2009_pragsmall
15 Mar 2017, 12:39
James Grenning (168 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?

Image_pragsmall
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