为什么我不能为zmq编译基本的发送和接收模拟

问题描述 投票:1回答:1

我正在zmq.hpp中为socket_t :: send和socket_t :: recv写一个gmock(仅zmq c ++标头绑定器)

zmq_mock_class.h

#pragma once

namespace zmq {
class ZmqMockSocketClass {
public:
  virtual size_t send(const void *buf_, size_t len_, int flags_ = 0) = 0;
  virtual size_t recv (void *buf_, size_t len_, int flags_ = 0) = 0;
};

}

zmq_mock.h

#include "zmq_mock_class.h"
#include <gmock/gmock.h>
#include <zmq.hpp>

class ZmqMockSocket : public zmq::ZmqMockSocketClass {
public:
  MOCK_METHOD3(send, size_t(const void *buf_, size_t len_, int flags_));
  MOCK_METHOD3(recv, size_t(void *buf_, size_t len_, int flags_ ));
};

zmq_test.cc

using  ::testing::_;
using  ::testing::AtLeast;
TEST(ZmqSendTest, TestSendErrorAgain)
{    
   ZmqMockSocket zmq_local;
}

int main(int argc, char **argv) {
  testing::InitGoogleTest(&argc, argv);
  return RUN_ALL_TESTS();
}

CMakeLists.txt:

cmake_minimum_required(VERSION 2.6)

# Locate GTest
find_package(GTest REQUIRED)
#find_package(GMock REQUIRED)
find_package(PkgConfig)
pkg_check_modules(GMOCK "gmock" REQUIRED)

include_directories(${GTEST_INCLUDE_DIRS})

# Link runTests with what we want to test and the GTest and pthread library
add_executable(runTests test/zmq_test.cc)
target_link_libraries(runTests ${GTEST_LIBRARIES} ${GMOCK_LIBRARIES} pthread zmq)
target_include_directories(runTests SYSTEM PRIVATE inc)

编译错误:

CMakeFiles/runTests.dir/test/zmq_test.cc.o: In function `testing::internal::FunctionMockerBase<void ()>::InvokeWith(std::tuple<> const&)':
zmq_test.cc:(.text._ZN7testing8internal18FunctionMockerBaseIFvvEE10InvokeWithERKSt5tupleIJEE[_ZN7testing8internal18FunctionMockerBaseIFvvEE10InvokeWithERKSt5tupleIJEE]+0x2e): undefined reference to `testing::internal::UntypedFunctionMockerBase::UntypedInvokeWith(void const*)'
CMakeFiles/runTests.dir/test/zmq_test.cc.o: In function `testing::internal::FunctionMockerBase<void (int)>::InvokeWith(std::tuple<int> const&)':
zmq_test.cc:(.text._ZN7testing8internal18FunctionMockerBaseIFviEE10InvokeWithERKSt5tupleIJiEE[_ZN7testing8internal18FunctionMockerBaseIFviEE10InvokeWithERKSt5tupleIJiEE]+0x2e): undefined reference to `testing::internal::UntypedFunctionMockerBase::UntypedInvokeWith(void const*)'
CMakeFiles/runTests.dir/test/zmq_test.cc.o: In function `testing::internal::FunctionMockerBase<void (int, int)>::InvokeWith(std::tuple<int, int> const&)':
zmq_test.cc:(.text._ZN7testing8internal18FunctionMockerBaseIFviiEE10InvokeWithERKSt5tupleIJiiEE[_ZN7testing8internal18FunctionMockerBaseIFviiEE10InvokeWithERKSt5tupleIJiiEE]+0x2e): undefined reference to `testing::internal::UntypedFunctionMockerBase::UntypedInvokeWith(void const*)'
CMakeFiles/runTests.dir/test/zmq_test.cc.o: In function `testing::internal::FunctionMockerBase<int ()>::InvokeWith(std::tuple<> const&)':
zmq_test.cc:(.text._ZN7testing8internal18FunctionMockerBaseIFivEE10InvokeWithERKSt5tupleIJEE[_ZN7testing8internal18FunctionMockerBaseIFivEE10InvokeWithERKSt5tupleIJEE]+0x2f): undefined reference to `testing::internal::UntypedFunctionMockerBase::UntypedInvokeWith(void const*)'
collect2: error: ld returned 1 exit status
CMakeFiles/runTests.dir/build.make:95: recipe for target 'runTests' failed
make[2]: *** [runTests] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/runTests.dir/all' failed
make[1]: *** [CMakeFiles/runTests.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
zeromq gmock googlemock
1个回答
0
投票

Google测试框架的构建和安装存在问题。从apt包中卸载Google测试

sudo apt remove google-mock
sudo apt-get remove googletest
© www.soinside.com 2019 - 2024. All rights reserved.