4

Ubuntu 16.04 および Eclipse 4.7.2 で Ceedling を使用しています。これまでのところ、_ExpectWithArray モック関数を動作させることができないという例外を除いて、すべて正常に動作しています。

たとえば、モックする必要がある次の関数がありますvoid TestFunc(uint8_t * data);。私のテストファイルには、次の呼び出しがあります uint8_t TEST_DATA[5] = { 0xFF, 0x00, 0xA0, 0x00, 0x09 }; TestFunc_ExpectWithArray(TEST_DATA, 5)

また、さまざまな値を指定しようとしましparam_depthたが、うまくいきませんでした。

テストを実行しようとすると、常に失敗します

implicit declaration of function ‘TestFunc_ExpectWithArray’ [-Wimplicit-function-declaration]

私の経験では、モックする関数が適切なパラメーターで呼び出されず、CMock がモックされたバージョンの生成に失敗した場合に常に発生します。私は何を間違っていますか?誰かが _ExpectWithArray を適切に使用する方法の例を挙げてもらえますか?

4

2 に答える 2

3

この行を追加します- :array for plugins in .yml -file

    :cmock:
    :mock_prefix: mock_
    :when_no_prototypes: :warn
    :enforce_strict_ordering: TRUE
    :plugins:
       - :array
       - :ignore
       - :callback

使用例 _ExpectWithArray

/test/test_example.c

    #include "unity.h"
    #include "temp.h"
    #include "mock_example.h"

    void setUp(void)
    {
    }

    void tearDown(void)
    {
    }

    void test_sendMesFirst(void)
    {
        uint8_t message[] = {"Hello"}, answerMessage[] = {"Hello"}, answerNum = 4;
        sendBytes_ExpectWithArray(answerMessage, sizeof(message), answerNum);
        sendMes(message, sizeof(message), answerNum);
    }  

/src/example.h

   #ifndef example_H
   #define example_H

   #include "stdint.h"

   void sendBytes(uint8_t *bytes, int size);

   #endif //

/src/temp.c

    #include "temp.h"
    #include "example.h"


    void sendMes(uint8_t *mes, int size, int num)
    {
        if(num < size)
            sendBytes(mes, num);
        else
            sendBytes(mes, size);
    }

/src/temp.h

    #ifndef temp_H
    #define temp_H

    #include "stdint.h"

    void sendMes(uint8_t *mes, int size, int num);        
    #endif
于 2018-10-30T12:06:15.990 に答える