2
INT32 shellInit(shell_t *shell)
{
    INT32 ret = ZKOS_SUCCESS;

    /* initialize shell device */
    if (shell->dev->ops->init)
    {
        if ((ret = shell->dev->ops->init(shell->dev)) != ZKOS_SUCCESS)
        {
            ZKOS_LOG("fail to initialize shell device.\n");
            return ret;
        }
    }
    
    ...
    
    return ret;
}

As the above code shows, shellInit calls a function by a function pointer shell->dev->ops->init, which has been assigned to a function defined in another file. How to mock this called function?

Wanghz
  • 305
  • 2
  • 12
  • 1
    Did you try to assign a mocked function? -- Did you try to mock the called function? – the busybee Nov 12 '21 at 10:29
  • @thebusybee You mean: 1. mock the called function 2. make `shell->dev->ops->init` point to the mocked function in the test function? – Wanghz Nov 12 '21 at 10:39
  • 1
    Correct. It depends how the pointer is set, how much effort you like to spend, how much you understood mocking, and probably more aspects. – the busybee Nov 12 '21 at 13:28

0 Answers0