mirror of
https://github.com/fpagliughi/sockpp.git
synced 2026-01-12 00:04:45 +08:00
Got unit tests compiling on Windows, though not passing yet.
This commit is contained in:
@@ -85,6 +85,11 @@
|
||||
#endif // _WIN64
|
||||
#endif // _SSIZE_T_DEFINED
|
||||
|
||||
#ifndef _SUSECONDS_T
|
||||
#define _SUSECONDS_T
|
||||
typedef long suseconds_t; // signed # of microseconds in timeval
|
||||
#endif // _SUSECONDS_T
|
||||
|
||||
#define SHUT_RD SD_RECEIVE
|
||||
#define SHUT_WR SD_SEND
|
||||
#define SHUT_RDWR SD_BOTH
|
||||
|
||||
@@ -62,14 +62,13 @@ namespace sockpp {
|
||||
#define SOCKPP_SOCKET_T_DEFINED
|
||||
#endif
|
||||
|
||||
#if !defined(_WIN32)
|
||||
timeval to_timeval(const std::chrono::microseconds& dur);
|
||||
|
||||
template<class Rep, class Period>
|
||||
timeval to_timeval(const std::chrono::duration<Rep,Period>& dur) {
|
||||
return to_timeval(std::chrono::duration_cast<std::chrono::microseconds>(dur));
|
||||
}
|
||||
#endif
|
||||
timeval to_timeval(const std::chrono::microseconds& dur);
|
||||
|
||||
template<class Rep, class Period>
|
||||
timeval to_timeval(const std::chrono::duration<Rep,Period>& dur) {
|
||||
return to_timeval(std::chrono::duration_cast<std::chrono::microseconds>(dur));
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
@@ -48,19 +48,21 @@ using namespace std::chrono;
|
||||
namespace sockpp {
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Some platform-specific functions
|
||||
// Some aux functions
|
||||
|
||||
#if !defined(_WIN32)
|
||||
timeval to_timeval(const microseconds& dur)
|
||||
{
|
||||
const seconds sec = duration_cast<seconds>(dur);
|
||||
|
||||
timeval tv;
|
||||
tv.tv_sec = time_t(sec.count());
|
||||
#if defined(_WIN32)
|
||||
tv.tv_sec = long(sec.count());
|
||||
#else
|
||||
tv.tv_sec = time_t(sec.count());
|
||||
#endif
|
||||
tv.tv_usec = suseconds_t(duration_cast<microseconds>(dur - sec).count());
|
||||
return tv;
|
||||
}
|
||||
#endif
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// socket
|
||||
|
||||
@@ -50,7 +50,7 @@ add_executable(unit_tests
|
||||
test_inet_address.cpp
|
||||
test_socket.cpp
|
||||
test_stream_socket.cpp
|
||||
test_datagram_socket.cpp
|
||||
test_datagram_socket.cpp
|
||||
test_acceptor.cpp
|
||||
test_connector.cpp
|
||||
)
|
||||
|
||||
@@ -38,9 +38,9 @@
|
||||
// --------------------------------------------------------------------------
|
||||
//
|
||||
|
||||
#include "catch2/catch.hpp"
|
||||
#include "sockpp/acceptor.h"
|
||||
#include "sockpp/inet_address.h"
|
||||
#include "catch2/catch.hpp"
|
||||
#include <string>
|
||||
|
||||
using namespace sockpp;
|
||||
|
||||
@@ -38,9 +38,9 @@
|
||||
// --------------------------------------------------------------------------
|
||||
//
|
||||
|
||||
#include "catch2/catch.hpp"
|
||||
#include "sockpp/connector.h"
|
||||
#include "sockpp/sock_address.h"
|
||||
#include "catch2/catch.hpp"
|
||||
#include <string>
|
||||
|
||||
using namespace sockpp;
|
||||
|
||||
@@ -38,9 +38,9 @@
|
||||
// --------------------------------------------------------------------------
|
||||
//
|
||||
|
||||
#include "catch2/catch.hpp"
|
||||
#include "sockpp/datagram_socket.h"
|
||||
#include "sockpp/inet_address.h"
|
||||
#include "catch2/catch.hpp"
|
||||
#include <string>
|
||||
|
||||
using namespace sockpp;
|
||||
|
||||
@@ -38,8 +38,8 @@
|
||||
// --------------------------------------------------------------------------
|
||||
//
|
||||
|
||||
#include "catch2/catch.hpp"
|
||||
#include "sockpp/inet_address.h"
|
||||
#include "catch2/catch.hpp"
|
||||
#include <string>
|
||||
|
||||
using namespace sockpp;
|
||||
|
||||
@@ -38,9 +38,9 @@
|
||||
// --------------------------------------------------------------------------
|
||||
//
|
||||
|
||||
#include "catch2/catch.hpp"
|
||||
#include "sockpp/socket.h"
|
||||
#include "sockpp/inet_address.h"
|
||||
#include "catch2/catch.hpp"
|
||||
#include <string>
|
||||
|
||||
using namespace sockpp;
|
||||
|
||||
@@ -38,9 +38,9 @@
|
||||
// --------------------------------------------------------------------------
|
||||
//
|
||||
|
||||
#include "catch2/catch.hpp"
|
||||
#include "sockpp/stream_socket.h"
|
||||
#include "sockpp/inet_address.h"
|
||||
#include "catch2/catch.hpp"
|
||||
#include <string>
|
||||
|
||||
using namespace sockpp;
|
||||
|
||||
@@ -38,8 +38,8 @@
|
||||
// --------------------------------------------------------------------------
|
||||
//
|
||||
|
||||
#include "catch2/catch.hpp"
|
||||
#include "sockpp/unix_address.h"
|
||||
#include "catch2/catch.hpp"
|
||||
#include <string>
|
||||
|
||||
using namespace sockpp;
|
||||
|
||||
@@ -38,8 +38,8 @@
|
||||
// --------------------------------------------------------------------------
|
||||
//
|
||||
|
||||
#include "catch2/catch.hpp"
|
||||
#include "sockpp/unix_dgram_socket.h"
|
||||
#include "catch2/catch.hpp"
|
||||
#include <string>
|
||||
|
||||
using namespace sockpp;
|
||||
|
||||
@@ -38,8 +38,8 @@
|
||||
// --------------------------------------------------------------------------
|
||||
//
|
||||
|
||||
#include "catch2/catch.hpp"
|
||||
#include "sockpp/unix_stream_socket.h"
|
||||
#include "catch2/catch.hpp"
|
||||
#include <string>
|
||||
|
||||
using namespace sockpp;
|
||||
|
||||
@@ -38,7 +38,34 @@
|
||||
// --------------------------------------------------------------------------
|
||||
//
|
||||
|
||||
// Normally, we would just tell Catch2 to define main() like this...
|
||||
// This tells Catch to provide a main() - only do this in one cpp file
|
||||
#define CATCH_CONFIG_MAIN
|
||||
//#define CATCH_CONFIG_MAIN
|
||||
|
||||
// ...but we need to run the sockpp global initialization before running
|
||||
// any of the tests. Defining a main() is described here:
|
||||
// https://github.com/catchorg/Catch2/blob/master/docs/own-main.md
|
||||
//
|
||||
|
||||
#include "sockpp/socket.h"
|
||||
|
||||
// This seems to be required, at least for MSVS 2015 on Win7,
|
||||
// using Catch2 v2.9.2
|
||||
#if defined(_WIN32)
|
||||
#define CATCH_CONFIG_DISABLE_EXCEPTIONS
|
||||
#endif
|
||||
|
||||
#define CATCH_CONFIG_RUNNER
|
||||
#include "catch2/catch.hpp"
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
// global setup...
|
||||
sockpp::socket_initializer sockInit;
|
||||
|
||||
int result = Catch::Session().run(argc, argv);
|
||||
|
||||
// global clean-up...
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user