由于mascoj的帮助,我的CMake问题得以解决。现在,我运行了SocketTests文件的测试:“空测试套件”
如果我在班级内订购,则测试有效。这是项目的架构:
componentWillReceiveProps(nextProps) {
this.setState({
value: formatDate(nextProps.value)
});
}
不同的文件: ./ CMakeLists.txt:
+-- CMakeLists.txt
+-- Serveur
| +-- CMakeLists.txt
| +-- Serveur.cpp
| +-- Serveur.h
| +-- Socket.cpp
| +-- Socket.h
|
+-- Tests
| +-- CMakeLists.txt
| +-- main.cpp
| +-- lib
| +-- ServeurTests
| +-- SocketTests.cpp
Serveur / CMakeLists.txt:
cmake_minimum_required(VERSION 3.10)
project(ServeurCheckIn)
set(CMAKE_CXX_STANDARD 14)
add_subdirectory(Serveur)
add_subdirectory(Tests)
Serveur / Socket.h:
cmake_minimum_required(VERSION 3.10)
project(ServeurCheckIn)
set(CMAKE_CXX_STANDARD 14)
add_library(ServeurCheckIn SHARED Serveur.cpp Serveur.h Socket.cpp Socket.h)
Serveur / Socket.cpp:
#include <sys/socket.h>
#include <netinet/in.h>
namespace Serveur
{
class Socket
{
public:
Socket(int domaine, int type, int protocole);
int Domaine();
int Type();
int Protocole();
private:
int _domaine;
int _type;
int _protocole;
};
}
Tests / CMakeLists.txt:
#include "Socket.h"
using namespace Serveur;
Socket::Socket(int domaine, int type, int protocole) :
_domaine(domaine), _type(type), _protocole(protocole)
{
}
int Socket::Domaine()
{
return _domaine;
}
int Socket::Type()
{
return _type;
}
int Socket::Protocole()
{
return _protocole;
}
Tests / SocketTests.cpp:
cmake_minimum_required(VERSION 3.10)
project(Tests)
set(CMAKE_CXX_STANDARD 14)
add_subdirectory(lib/googletest-master)
include_directories(lib/googletest-master/googletest/include)
include_directories(lib/googletest-master/googlemock/include)
add_executable(Tests main.cpp ServeurTests/SocketTests.cpp )
target_link_libraries(Tests gtest gtest_main ServeurCheckIn)
enable_testing()
答案 0 :(得分:0)
您的Tests可执行文件需要与您使用其他CMake创建的库链接。
target_link_libraries(Tests gtest gtest_main ServeurCheckIn)
没有它,这些功能的定义将在链接时不显示。