2

我正在尝试编译我的测试组项目,但由于下一个我在输出中无法理解的编译错误,我没有成功:

控制台输出:

"test_TestHW.c: In member function ‘virtual void TEST_TestHW_TestHW_main_Test::testBody()’:
 test_TestHW.c:617:6: error: request for member ‘enable’ in ‘mock’, which is
 of non-class type ‘MockSupport&(const SimpleString&, MockFailureReporter*)’
 mock.enable();
 ^
  test_TestHW.c:651:6: error: request for member ‘disable’ in ‘mock’, which is of non-class     
  type ‘MockSupport&(const SimpleString&, MockFailureReporter*)’ 
  mock.disable();"

部分项目代码:

测试组代码 .c 文件。

  /*******************************************************************************
*   INCLUDES
*******************************************************************************/

#include <CppUTest/CommandLineTestRunner.h>

#include <CppUTest/TestHarness.h> 

#include <CppUTestExt/MockSupport.h>

extern "C"
{
    #include "RFID_Drv.h"
    #include "HAL_AS393x_mock.h"
}

TEST_GROUP (TestHW)
{ 
  protected:    

  public:       
    /* Define data accessible to test group members here */
    void setup()
    {       
         mock().disable();
    }

    void teardown()
    {
        /* Clean up steps are executed after each TEST */           
        mock().checkExpectations();
        mock().clear();
    }   
 };

 TEST(TestHW,TestHW_main_FC_cuenta)
 {

    unsigned char error_val;

    FLAG_Ocupado =0;
    ControlEmi = 150;   /* Valor de frecuencia para probar */
    mock.enable();
    mock().expectOneCall("CapturaTimer").andReturnValue(1000);
    error_val=TestHW();
    CHECK_EQUAL(error_val,FCENTRAL_CUENTA)  /* Entra en el esatdo 2 */
    CHECK_EQUAL(ControlEmi, 150);
    mock.disable();
 }

    .......

    //more test cases here

    .......

int main(int ac, char** av)
{   
     /* Executes all the tests */
     CommandLineTestRunner::RunAllTests(ac,av); 

      /* Returns value */
     return(0);
 }

包含在 mock.c 文件中:

 /*******************************************************************************
 *  INCLUDES                                                                
 *******************************************************************************/

 #include <CppUTest/TestHarness.h>

 #include <CppUTestExt/MockSupport.h>


 extern "C"
 {  
     #include "timer_mock.h"        
 }

 unsigned long CapturaTimer(void)
 {
   mock().actualCall("CapturaTimer");
   return mock().unsignedIntReturnValue();
 }

cpputest 似乎没有考虑启用/禁用,也不知道启用/禁用。我认为这可能是我错过的一件愚蠢的事情。但现在我看不出是什么。

我知道我正在 Cpp 测试文件中测试 C 源代码函数。因此,我使用的是 extern c 实例。我很惊讶,因为 dis/en 未被识别,但 Mock().expectonecall 被识别(没有编译错误)。

  • 因此,在当前情况下是否有另一种方法来启用/禁用模拟?
  • 是否可以在包含 cputest 相关依赖项等的方式中看到一些错误?如果可能的话如何修复它们?
4

1 回答 1

1

我找到了这个错误的原因:我忘记了“()”:

 mock.enable();

它必须替换为:

 mock().enable(); 

所以它编译。

于 2017-03-06T11:35:52.713 回答