Skip to content

Commit

Permalink
Problem: tests don't build on Windows
Browse files Browse the repository at this point in the history
There were numerous small issues with test cases:

- some lacked the right source file header
- some were not portable at all
- some were using internal libzmq APIs (headers)

Solution: fixed and cleaned up.
  • Loading branch information
hintjens committed Feb 12, 2016
1 parent 0dbb918 commit 9c0d176
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 21 deletions.
2 changes: 1 addition & 1 deletion tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ Note that testutil.hpp includes platform.h. Do not include it yourself as it cha

All sources must contain the correct header. Please copy from test_system.cpp if you're not certain.


Please use only ANSI C99 in test cases, no C++. This is to make the code more reusable.
13 changes: 4 additions & 9 deletions tests/test_filter_ipc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,6 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include <string.h>
#include <sys/types.h>

#include <string>
#include <sstream>

#include "testutil.hpp"

static void bounce_fail (void *server, void *client)
Expand Down Expand Up @@ -78,9 +72,9 @@ static void run_test (int opt, T optval, int expected_error, int bounce_test)
if (expected_error) {
assert (rc == -1);
assert (zmq_errno () == expected_error);
} else {
assert (rc == 0);
}
else
assert (rc == 0);
}

void *sc = zmq_socket (ctx, ZMQ_DEALER);
Expand Down Expand Up @@ -113,7 +107,6 @@ static void run_test (int opt, T optval, int expected_error, int bounce_test)
else
bounce_fail (sb, sc);
}

close_zero_linger (sc);
close_zero_linger (sb);

Expand All @@ -123,6 +116,7 @@ static void run_test (int opt, T optval, int expected_error, int bounce_test)

int main (void)
{
#if !defined (ZMQ_HAVE_WINDOWS)
setup_test_environment();

// No filters
Expand Down Expand Up @@ -166,6 +160,7 @@ int main (void)
run_test<pid_t> (ZMQ_IPC_FILTER_PID, 0, EINVAL, 0);
#endif // defined ZMQ_HAVE_SO_PEERCRED || defined ZMQ_HAVE_LOCAL_PEERCRED

#endif
return 0 ;
}

2 changes: 2 additions & 0 deletions tests/test_fork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const char *address = "tcp://127.0.0.1:6571";

int main (void)
{
#if !defined (ZMQ_HAVE_WINDOWS)
setup_test_environment ();
void *ctx = zmq_ctx_new ();
assert (ctx);
Expand Down Expand Up @@ -87,5 +88,6 @@ int main (void)
}
exit (0);
}
#endif
return 0;
}
7 changes: 2 additions & 5 deletions tests/test_heartbeats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@
# include <stdexcept>
# define close closesocket
#else
# include <sys/socket.h>
# include <netinet/in.h>
# include <arpa/inet.h>
# include <unistd.h>
#endif

// Read one event off the monitor socket; return value and address
Expand Down Expand Up @@ -184,8 +181,8 @@ test_heartbeat_timeout (void)
int s;

ip4addr.sin_family = AF_INET;
ip4addr.sin_port = htons(5556);
#if (ZMQ_HAVE_WINDOWS and _WIN32_WINNT < 0x0600)
ip4addr.sin_port = htons (5556);
#if defined (ZMQ_HAVE_WINDOWS) && (_WIN32_WINNT < 0x0600)
ip4addr.sin_addr.s_addr = inet_addr ("127.0.0.1");
#else
inet_pton(AF_INET, "127.0.0.1", &ip4addr.sin_addr);
Expand Down
2 changes: 1 addition & 1 deletion tests/test_router_mandatory_hwm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ int main (void)
// This should fail after one message but kernel buffering could
// skew results
assert (i < 10);
sleep(1);
msleep (1000);
// Send second batch of messages
for(; i < 100000; ++i) {
if (TRACE_ENABLED) fprintf(stderr, "Sending message %d (part 2) ...\n", i);
Expand Down
2 changes: 1 addition & 1 deletion tests/test_security_curve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ int main (void)

ip4addr.sin_family = AF_INET;
ip4addr.sin_port = htons (9998);
#if (ZMQ_HAVE_WINDOWS and _WIN32_WINNT < 0x0600)
#if defined (ZMQ_HAVE_WINDOWS) && (_WIN32_WINNT < 0x0600)
ip4addr.sin_addr.s_addr = inet_addr ("127.0.0.1");
#else
inet_pton(AF_INET, "127.0.0.1", &ip4addr.sin_addr);
Expand Down
2 changes: 1 addition & 1 deletion tests/test_security_null.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ int main (void)

ip4addr.sin_family = AF_INET;
ip4addr.sin_port = htons(9003);
#if (ZMQ_HAVE_WINDOWS and _WIN32_WINNT < 0x0600)
#if defined (ZMQ_HAVE_WINDOWS) && (_WIN32_WINNT < 0x0600)
ip4addr.sin_addr.s_addr = inet_addr ("127.0.0.1");
#else
inet_pton(AF_INET, "127.0.0.1", &ip4addr.sin_addr);
Expand Down
4 changes: 2 additions & 2 deletions tests/test_security_plain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,10 @@ int main (void)

ip4addr.sin_family = AF_INET;
ip4addr.sin_port = htons (9998);
#if (ZMQ_HAVE_WINDOWS and _WIN32_WINNT < 0x0600)
#if defined (ZMQ_HAVE_WINDOWS) && (_WIN32_WINNT < 0x0600)
ip4addr.sin_addr.s_addr = inet_addr ("127.0.0.1");
#else
inet_pton(AF_INET, "127.0.0.1", &ip4addr.sin_addr);
inet_pton (AF_INET, "127.0.0.1", &ip4addr.sin_addr);
#endif

s = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP);
Expand Down
2 changes: 1 addition & 1 deletion tests/test_stream_exceeds_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ int main()
int server_sock = socket(AF_INET, SOCK_STREAM, 0);
assert(server_sock!=-1);
int enable = 1;
int rc = setsockopt(server_sock, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(enable));
int rc = setsockopt (server_sock, SOL_SOCKET, SO_REUSEADDR, (char *) &enable, sizeof(enable));
assert(rc!=-1);

struct sockaddr_in saddr;
Expand Down

0 comments on commit 9c0d176

Please sign in to comment.