- code cleanup in network and config
- moved packet_t members to private, added getter and setters
This commit is contained in:
@@ -37,22 +37,19 @@ void test_packet(tester_t *tester)
|
||||
{
|
||||
packet_t *packet = packet_create();
|
||||
packet_t *packet2;
|
||||
char * string_to_copy = "aha, soso";
|
||||
chunk_t data;
|
||||
char *string_to_copy = "aha, soso";
|
||||
|
||||
packet->data.ptr = allocator_alloc(strlen(string_to_copy) + 1);
|
||||
tester->assert_true(tester,(packet->data.ptr != NULL),"NULL pointer check");
|
||||
data.len = strlen(string_to_copy) + 1;
|
||||
data.ptr = allocator_alloc(data.len);
|
||||
memcpy(data.ptr, string_to_copy, data.len);
|
||||
|
||||
packet->data.len = strlen(string_to_copy) + 1;
|
||||
strcpy(packet->data.ptr,string_to_copy);
|
||||
|
||||
tester->assert_true(tester,(packet != NULL),"NULL pointer check");
|
||||
packet->set_data(packet, data);
|
||||
packet2 = packet->clone(packet);
|
||||
|
||||
tester->assert_false(tester,(packet->data.ptr == packet2->data.ptr),"value pointer check");
|
||||
data = packet2->get_data(packet2);
|
||||
|
||||
tester->assert_true(tester,(packet->data.len == (strlen(string_to_copy) + 1)),"value length check");
|
||||
|
||||
tester->assert_true(tester,(memcmp(packet->data.ptr,packet2->data.ptr,packet->data.len) == 0),"cloned value check");
|
||||
tester->assert_true(tester,(data.len == (strlen(string_to_copy) + 1)),"value length check");
|
||||
tester->assert_true(tester,(memcmp(data.ptr,string_to_copy,data.len) == 0),"cloned value check");
|
||||
|
||||
packet2->destroy(packet2);
|
||||
packet->destroy(packet);
|
||||
|
||||
@@ -58,15 +58,17 @@ void test_receiver(tester_t *tester)
|
||||
job_t *job;
|
||||
packet_t *received_packet;
|
||||
receiver = receiver_create();
|
||||
chunk_t test_data;
|
||||
|
||||
for (i = 0; i < NUMBER_OF_PACKETS_TO_SEND; i++)
|
||||
{
|
||||
packet = packet_create();
|
||||
packet->destination = host_create(AF_INET,DESTINATION_IP,PORT_TO_SEND);
|
||||
packet->data.ptr = allocator_alloc_thing(int);
|
||||
packet->data.len = ( sizeof(int));
|
||||
*((int *) (packet->data.ptr)) = i;
|
||||
charon->socket->send(charon->socket,packet);
|
||||
packet->set_destination(packet, host_create(AF_INET,DESTINATION_IP,PORT_TO_SEND));
|
||||
test_data.ptr = allocator_alloc_thing(int);
|
||||
test_data.len = ( sizeof(int));
|
||||
*((int *) (test_data.ptr)) = i;
|
||||
packet->set_data(packet, test_data);
|
||||
charon->socket->send(charon->socket, packet);
|
||||
packet->destroy(packet);
|
||||
}
|
||||
|
||||
@@ -76,8 +78,9 @@ void test_receiver(tester_t *tester)
|
||||
tester->assert_true(tester, (job->get_type(job) == INCOMING_PACKET), "job type check");
|
||||
|
||||
received_packet = ((incoming_packet_job_t *)(job))->get_packet((incoming_packet_job_t *)(job));
|
||||
tester->assert_true(tester, (received_packet->data.len == (sizeof(int))), "received data length check");
|
||||
tester->assert_true(tester, (i == *((int *)(received_packet->data.ptr))), "received data value check");
|
||||
test_data = received_packet->get_data(received_packet);
|
||||
tester->assert_true(tester, (test_data.len == (sizeof(int))), "received data length check");
|
||||
tester->assert_true(tester, (i == *((int *)(test_data.ptr))), "received data value check");
|
||||
received_packet->destroy(received_packet);
|
||||
|
||||
job->destroy(job);
|
||||
|
||||
@@ -54,7 +54,7 @@ void test_rsa(tester_t *tester)
|
||||
data.len = sizeof(test_data);
|
||||
|
||||
logger = charon->logger_manager->create_logger(charon->logger_manager, TESTER, NULL);
|
||||
logger->enable_level(logger, FULL);
|
||||
logger->disable_level(logger, FULL);
|
||||
|
||||
private_key = rsa_private_key_create();
|
||||
|
||||
|
||||
@@ -53,23 +53,26 @@ void test_sender(tester_t *tester)
|
||||
sender_t *sender;
|
||||
packet_t *packet;
|
||||
packet_t *received_packet;
|
||||
chunk_t packet_data;
|
||||
sender = sender_create();
|
||||
|
||||
for (i = 0; i < NUMBER_OF_PACKETS_TO_SEND; i++)
|
||||
{
|
||||
packet = packet_create(AF_INET);
|
||||
packet->destination = host_create(AF_INET,DESTINATION_IP,PORT_TO_SEND);
|
||||
packet->data.ptr = allocator_alloc_thing(int);
|
||||
packet->data.len = ( sizeof(int));
|
||||
*((int *) (packet->data.ptr)) = i;
|
||||
packet->set_destination(packet, host_create(AF_INET,DESTINATION_IP,PORT_TO_SEND));
|
||||
packet_data.ptr = allocator_alloc_thing(int);
|
||||
packet_data.len = ( sizeof(int));
|
||||
*((int *) (packet_data.ptr)) = i;
|
||||
packet->set_data(packet, packet_data);
|
||||
charon->send_queue->add(charon->send_queue,packet);
|
||||
}
|
||||
|
||||
for (i = 0; i < NUMBER_OF_PACKETS_TO_SEND; i++)
|
||||
{
|
||||
charon->socket->receive(charon->socket,&received_packet);
|
||||
tester->assert_true(tester, (received_packet->data.len == (sizeof(int))), "received data length check");
|
||||
tester->assert_true(tester, (i == *((int *)(received_packet->data.ptr))), "received data value check");
|
||||
packet_data = received_packet->get_data(received_packet);
|
||||
tester->assert_true(tester, (packet_data.len == (sizeof(int))), "received data length check");
|
||||
tester->assert_true(tester, (i == *((int *)(packet_data.ptr))), "received data value check");
|
||||
received_packet->destroy(received_packet);
|
||||
}
|
||||
|
||||
|
||||
@@ -38,14 +38,16 @@ void test_socket(tester_t *tester)
|
||||
socket_t *skt = socket_create(4500);
|
||||
packet_t *pkt = packet_create(AF_INET);
|
||||
char *test_string = "Testing functionality of socket_t";
|
||||
chunk_t data;
|
||||
|
||||
|
||||
pkt->data.ptr = allocator_alloc(strlen(test_string) + 1);
|
||||
memcpy(pkt->data.ptr,test_string,strlen(test_string) + 1);
|
||||
pkt->data.len = strlen(test_string) + 1;
|
||||
data.ptr = allocator_alloc(strlen(test_string) + 1);
|
||||
memcpy(data.ptr,test_string,strlen(test_string) + 1);
|
||||
data.len = strlen(test_string) + 1;
|
||||
|
||||
/* send to previously bound socket */
|
||||
pkt->destination = host_create(AF_INET, "127.0.0.1", 4500);
|
||||
pkt->set_destination(pkt, host_create(AF_INET, "127.0.0.1", 4500));
|
||||
pkt->set_data(pkt, data);
|
||||
|
||||
/* send packet_count packets */
|
||||
for (current = 0; current < packet_count; current++)
|
||||
@@ -61,7 +63,8 @@ void test_socket(tester_t *tester)
|
||||
for (current = 0; current < packet_count; current++)
|
||||
{
|
||||
skt->receive(skt, &pkt);
|
||||
tester->assert_false(tester, strcmp(test_string, pkt->data.ptr), "packet exchange");
|
||||
data = pkt->get_data(pkt);
|
||||
tester->assert_false(tester, strcmp(test_string, data.ptr), "packet exchange");
|
||||
pkt->destroy(pkt);
|
||||
}
|
||||
|
||||
|
||||
@@ -252,7 +252,7 @@ int main()
|
||||
|
||||
|
||||
tester->perform_tests(tester,all_tests);
|
||||
// tester->perform_test(tester,&parser_test14);
|
||||
// tester->perform_test(tester,&packet_test);
|
||||
|
||||
|
||||
tester->destroy(tester);
|
||||
|
||||
Reference in New Issue
Block a user