I had a problem in the CMake that was fixed thanks to mascoj's help. Now I have this I run the test of the SocketTests file: "Empty tests suite"
If I order inside the class, the test works. Here is the architecture of the project:
+-- CMakeLists.txt
+-- Serveur
| +-- CMakeLists.txt
| +-- Serveur.cpp
| +-- Serveur.h
| +-- Socket.cpp
| +-- Socket.h
|
+-- Tests
| +-- CMakeLists.txt
| +-- main.cpp
| +-- lib
| +-- ServeurTests
| +-- SocketTests.cpp
The different files : ./ CMakeLists.txt :
cmake_minimum_required(VERSION 3.10)
project(ServeurCheckIn)
set(CMAKE_CXX_STANDARD 14)
add_subdirectory(Serveur)
add_subdirectory(Tests)
Serveur/CMakeLists.txt:
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.h :
#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;
};
}
Serveur/Socket.cpp:
#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/CMakeLists.txt:
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()
Tests/SocketTests.cpp:
#include <gtest/gtest.h>
#include "../../Serveur/Serveur.h"
using namespace Serveur;
class SocketTests : public testing::Test
{
public:
SocketTests() : _socket(AF_INET, SOCK_RAW, IPPROTO_IP)
{
}
protected:
Socket _socket;
};
TEST_F(SocketTests, CreateSocket_SocketIsCreated)
{
ASSERT_EQ(1, 1);
}