Added initial implementation of dgram_socket_test.

This commit is contained in:
chris 2004-01-09 03:27:13 +00:00
parent a55f2ea4b7
commit 53600fdbea
5 changed files with 53 additions and 1 deletions

View File

@ -7,6 +7,7 @@ noinst_PROGRAMS = \
tests/performance/client \
tests/performance/server \
tests/unit/demuxer_test \
tests/unit/dgram_socket_test \
tests/unit/error_handler_test \
tests/unit/fixed_buffer_test \
tests/unit/timer_test \
@ -28,8 +29,10 @@ noinst_PROGRAMS = \
TESTS = \
tests/unit/demuxer_test \
tests/unit/dgram_socket_test \
tests/unit/error_handler_test \
tests/unit/fixed_buffer_test
tests/unit/fixed_buffer_test \
tests/unit/timer_test
noinst_HEADERS = \
tests/unit/unit_test.hpp \
@ -41,6 +44,7 @@ tests_socket_accept_test_SOURCES = tests/socket_accept_test.cpp
tests_performance_client_SOURCES = tests/performance/client.cpp
tests_performance_server_SOURCES = tests/performance/server.cpp
tests_unit_demuxer_test_SOURCES = tests/unit/demuxer_test.cpp
tests_unit_dgram_socket_test_SOURCES = tests/unit/dgram_socket_test.cpp
tests_unit_error_handler_test_SOURCES = tests/unit/error_handler_test.cpp
tests_unit_fixed_buffer_test_SOURCES = tests/unit/fixed_buffer_test.cpp
tests_unit_timer_test_SOURCES = tests/unit/timer_test.cpp

View File

@ -11,6 +11,7 @@ all: \
tests\performance\client.exe \
tests\performance\server.exe \
tests\unit\demuxer_test.exe \
tests\unit\dgram_socket_test.exe \
tests\unit\error_handler_test.exe \
tests\unit\fixed_buffer_test.exe \
tests\unit\timer_test.exe \

View File

@ -11,6 +11,7 @@ TEST_EXES = \
tests/performance/client.exe \
tests/performance/server.exe \
tests/unit/demuxer_test.exe \
tests/unit/dgram_socket_test.exe \
tests/unit/error_handler_test.exe \
tests/unit/fixed_buffer_test.exe \
tests/unit/timer_test.exe

View File

@ -11,6 +11,7 @@ all: \
tests\performance\client.exe \
tests\performance\server.exe \
tests\unit\demuxer_test.exe \
tests\unit\dgram_socket_test.exe \
tests\unit\error_handler_test.exe \
tests\unit\fixed_buffer_test.exe \
tests\unit\timer_test.exe \
@ -34,6 +35,7 @@ tests\socket_accept_test.exe: tests\socket_accept_test.obj
tests\performance\client.exe: tests\performance\client.obj
tests\performance\server.exe: tests\performance\server.obj
tests\unit\demuxer_test.exe: tests\unit\demuxer_test.obj
tests\unit\dgram_socket_test.exe: tests\unit\dgram_socket_test.obj
tests\unit\error_handler_test.exe: tests\unit\error_handler_test.obj
tests\unit\fixed_buffer_test.exe: tests\unit\fixed_buffer_test.obj
tests\unit\timer_test.exe: tests\unit\timer_test.obj

View File

@ -0,0 +1,44 @@
//
// dgram_socket_test.hpp
// ~~~~~~~~~~~~~~
//
// Copyright (c) 2003, 2004 Christopher M. Kohlhoff (chris@kohlhoff.com)
//
// Permission to use, copy, modify, distribute and sell this software and its
// documentation for any purpose is hereby granted without fee, provided that
// the above copyright notice appears in all copies and that both the copyright
// notice and this permission notice appear in supporting documentation. This
// software is provided "as is" without express or implied warranty, and with
// no claim as to its suitability for any purpose.
//
#include <boost/bind.hpp>
#include <cstring>
#include "asio.hpp"
#include "unit_test.hpp"
using namespace asio;
void dgram_socket_test()
{
using namespace std; // For memcmp.
demuxer d;
dgram_socket s1(d, inet_address_v4(0));
inet_address_v4 target_addr;
s1.get_local_address(target_addr);
dgram_socket s2(d, inet_address_v4(0));
char send_msg[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
s2.sendto(send_msg, sizeof(send_msg), target_addr);
char recv_msg[sizeof(send_msg)];
inet_address_v4 sender_addr;
size_t bytes_recvd = s1.recvfrom(recv_msg, sizeof(recv_msg), sender_addr);
UNIT_TEST_CHECK(bytes_recvd == sizeof(send_msg));
UNIT_TEST_CHECK(memcmp(send_msg, recv_msg, sizeof(send_msg)) == 0);
}
UNIT_TEST(dgram_socket_test)