HelenOS sources
This source file includes following definitions.
- PCUT_TEST
- PCUT_TEST
- PCUT_TEST
- PCUT_TEST
- PCUT_TEST
- PCUT_TEST
- PCUT_TEST
- PCUT_TEST
- PCUT_TEST
- PCUT_TEST
- PCUT_TEST
- PCUT_TEST
- test_recv_msg
- test_get_srcaddr
- test_transmit_msg
#include <errno.h>
#include <inet/endpoint.h>
#include <io/log.h>
#include <pcut/pcut.h>
#include <str.h>
#include "../assoc.h"
#include "../msg.h"
PCUT_INIT;
PCUT_TEST_SUITE(assoc);
static void test_recv_msg(void *, inet_ep2_t *, udp_msg_t *);
static udp_assoc_cb_t test_assoc_cb = {
.recv_msg = test_recv_msg
};
static errno_t test_get_srcaddr(inet_addr_t *, uint8_t, inet_addr_t *);
static errno_t test_transmit_msg(inet_ep2_t *, udp_msg_t *);
static udp_assocs_dep_t test_assocs_dep = {
.get_srcaddr = test_get_srcaddr,
.transmit_msg = test_transmit_msg
};
static inet_ep2_t *sent_epp;
static udp_msg_t *sent_msg;
PCUT_TEST_BEFORE
{
errno_t rc;
rc = log_init("test-udp");
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
rc = udp_assocs_init(&test_assocs_dep);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
}
PCUT_TEST_AFTER
{
udp_assocs_fini();
}
PCUT_TEST(new_delete)
{
udp_assoc_t *assoc;
inet_ep2_t epp;
inet_ep2_init(&epp);
assoc = udp_assoc_new(&epp, &test_assoc_cb, NULL);
PCUT_ASSERT_NOT_NULL(assoc);
udp_assoc_delete(assoc);
}
PCUT_TEST(add_remove)
{
udp_assoc_t *assoc;
inet_ep2_t epp;
errno_t rc;
inet_ep2_init(&epp);
assoc = udp_assoc_new(&epp, &test_assoc_cb, NULL);
PCUT_ASSERT_NOT_NULL(assoc);
rc = udp_assoc_add(assoc);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
udp_assoc_remove(assoc);
udp_assoc_delete(assoc);
}
PCUT_TEST(addref_delref)
{
udp_assoc_t *assoc;
inet_ep2_t epp;
inet_ep2_init(&epp);
assoc = udp_assoc_new(&epp, &test_assoc_cb, NULL);
PCUT_ASSERT_NOT_NULL(assoc);
udp_assoc_addref(assoc);
udp_assoc_delref(assoc);
udp_assoc_delete(assoc);
}
PCUT_TEST(set_iplink)
{
udp_assoc_t *assoc;
inet_ep2_t epp;
inet_ep2_init(&epp);
assoc = udp_assoc_new(&epp, &test_assoc_cb, NULL);
PCUT_ASSERT_NOT_NULL(assoc);
udp_assoc_set_iplink(assoc, 42);
PCUT_ASSERT_INT_EQUALS(42, assoc->ident.local_link);
udp_assoc_delete(assoc);
}
PCUT_TEST(send_null_dest)
{
udp_assoc_t *assoc;
inet_ep2_t epp;
inet_ep_t dest;
errno_t rc;
udp_msg_t *msg;
const char *msgstr = "Hello";
msg = udp_msg_new();
PCUT_ASSERT_NOT_NULL(msg);
msg->data_size = str_size(msgstr) + 1;
msg->data = str_dup(msgstr);
inet_ep2_init(&epp);
inet_ep_init(&dest);
assoc = udp_assoc_new(&epp, &test_assoc_cb, NULL);
PCUT_ASSERT_NOT_NULL(assoc);
rc = udp_assoc_add(assoc);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
rc = udp_assoc_send(assoc, &dest, msg);
PCUT_ASSERT_ERRNO_VAL(EINVAL, rc);
udp_msg_delete(msg);
udp_assoc_remove(assoc);
udp_assoc_delete(assoc);
}
PCUT_TEST(send_unset_dest)
{
udp_assoc_t *assoc;
inet_ep2_t epp;
inet_ep_t dest;
errno_t rc;
udp_msg_t *msg;
const char *msgstr = "Hello";
msg = udp_msg_new();
PCUT_ASSERT_NOT_NULL(msg);
msg->data_size = str_size(msgstr) + 1;
msg->data = str_dup(msgstr);
inet_ep2_init(&epp);
inet_ep_init(&dest);
assoc = udp_assoc_new(&epp, &test_assoc_cb, NULL);
PCUT_ASSERT_NOT_NULL(assoc);
rc = udp_assoc_add(assoc);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
rc = udp_assoc_send(assoc, &dest, msg);
PCUT_ASSERT_ERRNO_VAL(EINVAL, rc);
udp_msg_delete(msg);
udp_assoc_remove(assoc);
udp_assoc_delete(assoc);
}
PCUT_TEST(send_explicit_dest)
{
udp_assoc_t *assoc;
inet_ep2_t epp;
inet_ep_t dest;
errno_t rc;
udp_msg_t *msg;
const char *msgstr = "Hello";
msg = udp_msg_new();
PCUT_ASSERT_NOT_NULL(msg);
msg->data_size = str_size(msgstr) + 1;
msg->data = str_dup(msgstr);
inet_ep2_init(&epp);
inet_addr(&dest.addr, 127, 0, 0, 1);
dest.port = 42;
assoc = udp_assoc_new(&epp, &test_assoc_cb, NULL);
PCUT_ASSERT_NOT_NULL(assoc);
rc = udp_assoc_add(assoc);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
sent_epp = NULL;
sent_msg = NULL;
rc = udp_assoc_send(assoc, &dest, msg);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_EQUALS(msg, sent_msg);
PCUT_ASSERT_TRUE(inet_addr_compare(&dest.addr, &sent_epp->remote.addr));
PCUT_ASSERT_EQUALS(dest.port, sent_epp->remote.port);
udp_msg_delete(msg);
udp_assoc_remove(assoc);
udp_assoc_delete(assoc);
}
PCUT_TEST(send_assoc_any_dest)
{
udp_assoc_t *assoc;
inet_ep2_t epp;
inet_ep_t ep;
errno_t rc;
udp_msg_t *msg;
const char *msgstr = "Hello";
msg = udp_msg_new();
PCUT_ASSERT_NOT_NULL(msg);
msg->data_size = str_size(msgstr) + 1;
msg->data = str_dup(msgstr);
inet_ep2_init(&epp);
inet_addr(&epp.remote.addr, 127, 0, 0, 1);
epp.remote.port = 42;
inet_addr(&epp.local.addr, 127, 0, 0, 1);
epp.local.port = 1;
inet_ep_init(&ep);
assoc = udp_assoc_new(&epp, &test_assoc_cb, NULL);
PCUT_ASSERT_NOT_NULL(assoc);
rc = udp_assoc_add(assoc);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
sent_epp = NULL;
sent_msg = NULL;
rc = udp_assoc_send(assoc, &ep, msg);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_EQUALS(msg, sent_msg);
PCUT_ASSERT_TRUE(inet_addr_compare(&epp.remote.addr, &sent_epp->remote.addr));
PCUT_ASSERT_EQUALS(epp.remote.port, sent_epp->remote.port);
udp_msg_delete(msg);
udp_assoc_remove(assoc);
udp_assoc_delete(assoc);
}
PCUT_TEST(send_assoc_unset_dest)
{
udp_assoc_t *assoc;
inet_ep2_t epp;
inet_ep_t dest;
errno_t rc;
udp_msg_t *msg;
const char *msgstr = "Hello";
msg = udp_msg_new();
PCUT_ASSERT_NOT_NULL(msg);
msg->data_size = str_size(msgstr) + 1;
msg->data = str_dup(msgstr);
inet_ep2_init(&epp);
inet_addr(&epp.local.addr, 127, 0, 0, 1);
epp.local.port = 1;
inet_ep_init(&dest);
assoc = udp_assoc_new(&epp, &test_assoc_cb, NULL);
PCUT_ASSERT_NOT_NULL(assoc);
rc = udp_assoc_add(assoc);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
rc = udp_assoc_send(assoc, &dest, msg);
PCUT_ASSERT_ERRNO_VAL(EINVAL, rc);
udp_msg_delete(msg);
udp_assoc_remove(assoc);
udp_assoc_delete(assoc);
}
PCUT_TEST(recv)
{
}
PCUT_TEST(received)
{
udp_assoc_t *assoc;
inet_ep2_t epp;
errno_t rc;
udp_msg_t *msg;
const char *msgstr = "Hello";
bool received;
msg = udp_msg_new();
PCUT_ASSERT_NOT_NULL(msg);
msg->data_size = str_size(msgstr) + 1;
msg->data = str_dup(msgstr);
inet_ep2_init(&epp);
inet_addr(&epp.remote.addr, 127, 0, 0, 1);
epp.remote.port = 1;
inet_addr(&epp.local.addr, 127, 0, 0, 1);
epp.local.port = 2;
assoc = udp_assoc_new(&epp, &test_assoc_cb, (void *) &received);
PCUT_ASSERT_NOT_NULL(assoc);
rc = udp_assoc_add(assoc);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
received = false;
udp_assoc_received(&epp, msg);
PCUT_ASSERT_TRUE(received);
udp_assoc_remove(assoc);
udp_assoc_delete(assoc);
}
PCUT_TEST(reset)
{
udp_assoc_t *assoc;
inet_ep2_t epp;
inet_ep2_init(&epp);
assoc = udp_assoc_new(&epp, &test_assoc_cb, NULL);
PCUT_ASSERT_NOT_NULL(assoc);
udp_assoc_reset(assoc);
udp_assoc_delete(assoc);
}
static void test_recv_msg(void *arg, inet_ep2_t *epp, udp_msg_t *msg)
{
bool *received = (bool *) arg;
*received = true;
}
static errno_t test_get_srcaddr(inet_addr_t *remote, uint8_t tos,
inet_addr_t *local)
{
inet_addr(local, 127, 0, 0, 1);
return EOK;
}
static errno_t test_transmit_msg(inet_ep2_t *epp, udp_msg_t *msg)
{
sent_epp = epp;
sent_msg = msg;
return EOK;
}
PCUT_EXPORT(assoc);
HelenOS homepage, sources at GitHub