GoogleMock发出用Eclipse构建C 的简单代码

GoogleMock issue building C++ simple code with Eclipse

本文关键字:简单 代码 构建 Eclipse GoogleMock      更新时间:2023-10-16

in mobiletest.h我有:

#include <gtest/gtest.h>
#include <gmock/gmock.h>
using ::testing::Return;
#include "Mobile.h"
class MockedCamera : public Camera {
public:
    MOCK_METHOD0(ON, bool());
    MOCK_METHOD0(OFF,bool());
};

Mobile.h代码:

#ifndef __MOBILE_H__
#define __MOBILE_H__
#include <iostream>
using namespace std;
#include "Camera.h"
class Mobile {
private:
    Camera *pCamera;
public:
    Mobile();
    Mobile(Camera *pCamera);
    bool powerOn();
    bool powerOff();
    virtual ~Mobile(){};
};
#endif /* __MOBILE_H__ */

camera.h头文件

#ifndef __CAMERA_H__
#define __CAMERA_H__
#include <iostream>
using namespace std;
class Camera {
public:
    Camera();
    virtual bool ON();
    virtual bool OFF();
    virtual ~Camera(){};
};
#endif /* __CAMERA_H__ */

这是Udemy C 课程的简单代码,但是使用Eclipse构建时会给我错误,没有移动测试。

Symbol 'ArgumentCount' could not be resolved
The type 'testing::internal::FunctionMocker' must implement the inherited pure virtual method 'testing::internal::UntypedFunctionMockerBase::UntypedPerformAction' 

这是项目的制作费,当我尝试使用make命令时,它给了我很多错误的GTEST:

SRC = $(wildcard src/*.cpp test/*.cpp)
OBJS = $(SRC:.cpp=.o)
CXXFLAGS = -std=c++14
LIBS = -pthread libgtest.a
INC = -I googletest/googletest 
      -I googletest/googletest/include 
      -I googlemock/googlemock 
      -I googlemock/googlemock/include 
      -I src 
      -I test
EXE = mobileTest.exe
all: $(OBJS)
    cp -f $(OBJS) .
    g++-7 -o $(EXE) $(CXXFLAGS) $(OBJS) $(LIBS) $(INC)
    rm -f $(OBJS)
%.o: %.cpp
    g++-7 -c $(CXXFLAGS) $(INC) $< -o $@
.PHONY: clean
clean:
    rm -f *.o *.exe

建议?

我将gtest和gmock用作库。

GTEST库的项目文件包含以下源文件

SOURCES += ../googletest/src/gtest.cc 
../googletest/src/gtest-death-test.cc 
../googletest/src/gtest-filepath.cc 
../googletest/src/gtest-port.cc 
../googletest/src/gtest-printers.cc 
../googletest/src/gtest-test-part.cc 
../googletest/src/gtest-typed-test.cc

gmock库的项目文件包含以下源文件

SOURCES += ../googlemock/src/gmock-cardinalities.cc 
       ../googlemock/src/gmock-internal-utils.cc 
       ../googlemock/src/gmock-matchers.cc 
       ../googlemock/src/gmock-spec-builders.cc 
       ../googlemock/src/gmock.cc