mirror of
https://github.com/strongswan/strongswan.git
synced 2025-10-04 00:00:14 -04:00
- Tests are now separated in test files in the tests-directory
This commit is contained in:
parent
6e4c8294fb
commit
5ea7551195
@ -27,9 +27,11 @@
|
||||
|
||||
#include "types.h"
|
||||
#include "tester.h"
|
||||
#include "tests/tests.h"
|
||||
#include "job_queue.h"
|
||||
|
||||
|
||||
|
||||
/* output for test messages */
|
||||
extern FILE * stderr;
|
||||
|
||||
@ -44,10 +46,12 @@ int main()
|
||||
|
||||
tester_t *tester = tester_create(test_output);
|
||||
|
||||
tester->test_all(tester);
|
||||
tester->test_all(tester,tests);
|
||||
|
||||
tester->destroy(tester);
|
||||
|
||||
job_queue->destroy(job_queue);
|
||||
|
||||
#ifdef LEAK_DETECTIVE
|
||||
/* Leaks are reported in log file */
|
||||
report_leaks();
|
||||
|
@ -40,7 +40,7 @@
|
||||
typedef struct private_tester_s private_tester_t;
|
||||
|
||||
struct private_tester_s {
|
||||
tester_t tester;
|
||||
tester_t public;
|
||||
|
||||
/* Private values */
|
||||
FILE* output;
|
||||
@ -48,179 +48,26 @@ struct private_tester_s {
|
||||
int failed_tests_count;
|
||||
int failed_asserts_count;
|
||||
pthread_mutex_t mutex;
|
||||
|
||||
/* Private functions */
|
||||
/**
|
||||
* @brief is called in a testcase to check a specific situation
|
||||
*
|
||||
* @param this tester object
|
||||
* @param to_be_true assert which has to be true
|
||||
* @param Name of the assertion
|
||||
*/
|
||||
void (*assert_true) (private_tester_t *this, bool to_be_true, char *assert_name);
|
||||
|
||||
/**
|
||||
* @brief run a specific test case
|
||||
*
|
||||
* @param this tester object
|
||||
* @param test_function implements the test case
|
||||
* @param Name of the Test
|
||||
*/
|
||||
void (*run_test) (private_tester_t *this, void (*test_function) (private_tester_t * tester), char * test_name);
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Test function to test the linked list class
|
||||
*/
|
||||
static void test_linked_list(private_tester_t *this)
|
||||
{
|
||||
void *test_value = NULL;
|
||||
|
||||
linked_list_t *linked_list = linked_list_create();
|
||||
this->assert_true(this,(linked_list->count == 0), "count check");
|
||||
|
||||
linked_list->insert_first(linked_list,"one");
|
||||
this->assert_true(this,(linked_list->count == 1), "count check");
|
||||
|
||||
linked_list->insert_first(linked_list,"two");
|
||||
this->assert_true(this,(linked_list->count == 2), "count check");
|
||||
|
||||
linked_list->insert_first(linked_list,"three");
|
||||
this->assert_true(this,(linked_list->count == 3), "count check");
|
||||
|
||||
linked_list->insert_first(linked_list,"four");
|
||||
this->assert_true(this,(linked_list->count == 4), "count check");
|
||||
|
||||
linked_list->insert_first(linked_list,"five");
|
||||
this->assert_true(this,(linked_list->count == 5), "count check");
|
||||
|
||||
this->assert_true(this,(linked_list->get_first(linked_list,&test_value) == SUCCESS), "get_first call check");
|
||||
this->assert_true(this,(strcmp((char *) test_value,"five") == 0), "get_first value check");
|
||||
this->assert_true(this,(linked_list->count == 5), "count check");
|
||||
|
||||
this->assert_true(this,(linked_list->get_last(linked_list,&test_value) == SUCCESS), "get_last call check");
|
||||
this->assert_true(this,(strcmp((char *) test_value,"one") == 0), "get_last value check");
|
||||
this->assert_true(this,(linked_list->count == 5), "count check");
|
||||
this->assert_true(this,(linked_list->remove_first(linked_list,&test_value) == SUCCESS), "remove_first call check");
|
||||
this->assert_true(this,(strcmp((char *) test_value,"five") == 0), "remove_first value check");
|
||||
this->assert_true(this,(linked_list->count == 4), "count check");
|
||||
|
||||
this->assert_true(this,(linked_list->get_first(linked_list,&test_value) == SUCCESS), "get_first call check");
|
||||
this->assert_true(this,(strcmp((char *) test_value,"four") == 0), "get_first value check");
|
||||
this->assert_true(this,(linked_list->count == 4), "count check");
|
||||
|
||||
this->assert_true(this,(linked_list->get_last(linked_list,&test_value) == SUCCESS), "get_last call check");
|
||||
this->assert_true(this,(strcmp((char *) test_value,"one") == 0), "get_last value check");
|
||||
this->assert_true(this,(linked_list->count == 4), "count check");
|
||||
|
||||
this->assert_true(this,(linked_list->remove_last(linked_list,&test_value) == SUCCESS), "remove_last call check");
|
||||
this->assert_true(this,(strcmp((char *) test_value,"one") == 0), "remove_last value check");
|
||||
this->assert_true(this,(linked_list->count == 3), "count check");
|
||||
|
||||
this->assert_true(this,(linked_list->get_last(linked_list,&test_value) == SUCCESS), "get_last call check");
|
||||
this->assert_true(this,(strcmp((char *) test_value,"two") == 0), "get_last value check");
|
||||
this->assert_true(this,(linked_list->count == 3), "count check");
|
||||
|
||||
this->assert_true(this,(linked_list->get_first(linked_list,&test_value) == SUCCESS), "get_first call check");
|
||||
this->assert_true(this,(strcmp((char *) test_value,"four") == 0), "get_first value check");
|
||||
this->assert_true(this,(linked_list->count == 3), "count check");
|
||||
|
||||
this->assert_true(this,(linked_list->destroy(linked_list) == SUCCESS), "destroy call check");
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Test function to test the thread pool class
|
||||
*/
|
||||
static void test_thread_pool(private_tester_t *this)
|
||||
{
|
||||
size_t desired_pool_size = 10;
|
||||
size_t pool_size;
|
||||
|
||||
thread_pool_t *pool = thread_pool_create(desired_pool_size);
|
||||
pool->get_pool_size(pool, &pool_size);
|
||||
this->assert_true(this, (desired_pool_size == pool_size), "thread creation");
|
||||
pool->destroy(pool);
|
||||
}
|
||||
|
||||
typedef struct job_queue_test_s job_queue_test_t;
|
||||
|
||||
struct job_queue_test_s{
|
||||
private_tester_t *tester;
|
||||
job_queue_t *job_queue;
|
||||
int max_queue_item_count;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief sender thread used in the the job_queue test function
|
||||
*/
|
||||
static void test_job_queue_sender(job_queue_test_t * testinfo)
|
||||
{
|
||||
|
||||
int i;
|
||||
|
||||
for (i = 0; i < testinfo->max_queue_item_count; i++)
|
||||
{
|
||||
int *value = alloc_thing(int,"int");
|
||||
*value = i;
|
||||
job_t *job = job_create(INCOMING_PACKET,value);
|
||||
testinfo->job_queue->add(testinfo->job_queue,job);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief receiver thread used in the the job_queue test function
|
||||
*/
|
||||
static void test_job_queue_receiver(job_queue_test_t * testinfo)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < testinfo->max_queue_item_count; i++)
|
||||
{
|
||||
job_t *job;
|
||||
testinfo->tester->assert_true(testinfo->tester,(testinfo->job_queue->get(testinfo->job_queue,&job) == SUCCESS), "get job call check");
|
||||
testinfo->tester->assert_true(testinfo->tester,(job->type == INCOMING_PACKET), "job type check");
|
||||
testinfo->tester->assert_true(testinfo->tester,((*((int *) (job->assigned_data))) == i), "job value check");
|
||||
|
||||
pfree(job->assigned_data);
|
||||
testinfo->tester->assert_true(testinfo->tester,(job->destroy(job) == SUCCESS), "job destroy call check");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Test function test the job_queue functionality
|
||||
*/
|
||||
static void test_job_queue(private_tester_t *this)
|
||||
{
|
||||
pthread_t sender_thread, receiver_thread;
|
||||
job_queue_t *job_queue = job_queue_create();
|
||||
job_queue_test_t test_infos;
|
||||
test_infos.tester = this;
|
||||
test_infos.job_queue = job_queue;
|
||||
test_infos.max_queue_item_count = 100;
|
||||
|
||||
pthread_create( &receiver_thread, NULL,(void*(*)(void*)) &test_job_queue_receiver, (void*) &test_infos);
|
||||
pthread_create( &sender_thread, NULL,(void*(*)(void*)) &test_job_queue_sender, (void*) &test_infos);
|
||||
|
||||
pthread_join(sender_thread, NULL);
|
||||
pthread_join(receiver_thread, NULL);
|
||||
|
||||
this->assert_true(this,(job_queue->destroy(job_queue) == SUCCESS), "destroy call check");
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Testing of all registered tests
|
||||
*
|
||||
* New tests have to be added in this function
|
||||
*/
|
||||
static status_t test_all(tester_t *tester)
|
||||
static status_t test_all(tester_t *tester,test_t **tests)
|
||||
{
|
||||
private_tester_t *this =(private_tester_t*) tester;
|
||||
int current_test = 0;
|
||||
fprintf(this->output,"Start testing\n");
|
||||
|
||||
/* Add new Tests here! */
|
||||
this->run_test(this,test_linked_list,"Linked List");
|
||||
this->run_test(this,test_thread_pool,"Thread Pool");
|
||||
this->run_test(this,test_job_queue,"Job-Queue");
|
||||
while (tests[current_test] != NULL)
|
||||
{
|
||||
tester->run_test(tester,tests[current_test]->test_function,tests[current_test]->test_name);
|
||||
current_test++;
|
||||
}
|
||||
|
||||
fprintf(this->output,"End testing. %d of %d tests succeeded\n",this->tests_count - this->failed_tests_count,this->tests_count);
|
||||
|
||||
@ -232,13 +79,13 @@ static status_t test_all(tester_t *tester)
|
||||
* @brief implements the private run_test-Function
|
||||
*
|
||||
*/
|
||||
static void run_test(private_tester_t *tester, void (*test_function) (private_tester_t * tester), char * test_name)
|
||||
static void run_test(tester_t *tester, void (*test_function) (tester_t * tester), char * test_name)
|
||||
{
|
||||
private_tester_t *this = tester;
|
||||
private_tester_t *this = (private_tester_t *) tester;
|
||||
this->tests_count++;
|
||||
this->failed_asserts_count = 0;
|
||||
fprintf(this->output,"Start Test '%s'\n", test_name);
|
||||
test_function(this);
|
||||
test_function(tester);
|
||||
fprintf(this->output,"End Test '%s'\n", test_name);
|
||||
if (this->failed_asserts_count > 0)
|
||||
{
|
||||
@ -250,9 +97,9 @@ static void run_test(private_tester_t *tester, void (*test_function) (private_te
|
||||
* @brief implements the private assert_true-Function
|
||||
*
|
||||
*/
|
||||
static void assert_true(private_tester_t *tester, bool to_be_true,char * assert_name)
|
||||
static void assert_true(tester_t *tester, bool to_be_true,char * assert_name)
|
||||
{
|
||||
private_tester_t *this = tester;
|
||||
private_tester_t *this = (private_tester_t *) tester;
|
||||
|
||||
if (assert_name == NULL)
|
||||
{
|
||||
@ -287,15 +134,15 @@ tester_t *tester_create(FILE *output)
|
||||
{
|
||||
private_tester_t *this = alloc_thing(private_tester_t, "private_tester_t");
|
||||
|
||||
this->tester.destroy = destroy;
|
||||
this->tester.test_all = test_all;
|
||||
this->run_test = run_test;
|
||||
this->assert_true = assert_true;
|
||||
this->public.destroy = destroy;
|
||||
this->public.test_all = test_all;
|
||||
this->public.run_test = run_test;
|
||||
this->public.assert_true = assert_true;
|
||||
|
||||
this->failed_tests_count = 0;
|
||||
this->tests_count = 0;
|
||||
this->output = output;
|
||||
pthread_mutex_init(&(this->mutex),NULL);
|
||||
|
||||
return &(this->tester);
|
||||
return &(this->public);
|
||||
}
|
||||
|
@ -24,15 +24,66 @@
|
||||
#define TESTER_H_
|
||||
|
||||
#include <stdio.h>
|
||||
#include <freeswan.h>
|
||||
#include <pluto/constants.h>
|
||||
#include <pluto/defs.h>
|
||||
|
||||
#include "types.h"
|
||||
|
||||
/**
|
||||
* @brief Specifies a test
|
||||
*/
|
||||
typedef struct test_s test_t;
|
||||
|
||||
|
||||
/**
|
||||
* @brief A tester object to perform tests
|
||||
*/
|
||||
typedef struct tester_s tester_t;
|
||||
|
||||
struct test_s{
|
||||
void (*test_function) (tester_t * tester);
|
||||
char * test_name;
|
||||
};
|
||||
|
||||
struct tester_s {
|
||||
status_t (*test_all) (tester_t *tester);
|
||||
|
||||
/**
|
||||
* @brief Tests all testcases of specific tester object
|
||||
*
|
||||
* @param tester tester object
|
||||
* @param pointer to a list of tests to perform.
|
||||
* the last list item has to be NULL.
|
||||
* @return SUCCESSFUL if succeeded, FAILED otherwise
|
||||
*/
|
||||
status_t (*test_all) (tester_t *tester,test_t **tests);
|
||||
|
||||
/**
|
||||
* @brief is called in a testcase to check a specific situation
|
||||
*
|
||||
* Log-Values to the tester output are protected from multiple access
|
||||
*
|
||||
* @param this tester object
|
||||
* @param to_be_true assert which has to be true
|
||||
* @param Name of the assertion
|
||||
*/
|
||||
void (*assert_true) (tester_t *tester, bool to_be_true, char *assert_name);
|
||||
|
||||
/**
|
||||
* @brief run a specific test case
|
||||
*
|
||||
* @param this tester object
|
||||
* @param test_function implements the test case
|
||||
* @param Name of the Test
|
||||
*/
|
||||
void (*run_test) (tester_t *this, void (*test_function) (tester_t * tester), char * test_name);
|
||||
|
||||
/**
|
||||
* @brief Destroys a tester object
|
||||
*
|
||||
* @param tester tester object
|
||||
* @param Name of the Test
|
||||
* @return SUCCESSFUL if succeeded, FAILED otherwise
|
||||
*/
|
||||
status_t (*destroy) (tester_t *tester);
|
||||
};
|
||||
|
||||
|
101
Source/charon/tests/job_queue_test.c
Normal file
101
Source/charon/tests/job_queue_test.c
Normal file
@ -0,0 +1,101 @@
|
||||
/**
|
||||
* @file job_queue_test.c
|
||||
*
|
||||
* @brief Tests to test the Job-Queue type job_queue_t
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2005 Jan Hutter, Martin Willi
|
||||
* Hochschule fuer Technik Rapperswil
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at your
|
||||
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*/
|
||||
|
||||
|
||||
//#include <stdlib.h>
|
||||
#include <freeswan.h>
|
||||
#include <pluto/constants.h>
|
||||
#include <pluto/defs.h>
|
||||
#include <pthread.h>
|
||||
|
||||
#include "../tester.h"
|
||||
#include "../job_queue.h"
|
||||
|
||||
|
||||
typedef struct job_queue_test_s job_queue_test_t;
|
||||
|
||||
struct job_queue_test_s{
|
||||
tester_t *tester;
|
||||
job_queue_t *job_queue;
|
||||
int max_queue_item_count;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief sender thread used in the the job_queue test function
|
||||
*/
|
||||
static void test_job_queue_sender(job_queue_test_t * testinfo)
|
||||
{
|
||||
|
||||
int i;
|
||||
|
||||
for (i = 0; i < testinfo->max_queue_item_count; i++)
|
||||
{
|
||||
int *value = alloc_thing(int,"int");
|
||||
*value = i;
|
||||
job_t *job = job_create(INCOMING_PACKET,value);
|
||||
testinfo->job_queue->add(testinfo->job_queue,job);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief receiver thread used in the the job_queue test function
|
||||
*/
|
||||
static void test_job_queue_receiver(job_queue_test_t * testinfo)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < testinfo->max_queue_item_count; i++)
|
||||
{
|
||||
job_t *job;
|
||||
testinfo->tester->assert_true(testinfo->tester,(testinfo->job_queue->get(testinfo->job_queue,&job) == SUCCESS), "get job call check");
|
||||
testinfo->tester->assert_true(testinfo->tester,(job->type == INCOMING_PACKET), "job type check");
|
||||
testinfo->tester->assert_true(testinfo->tester,((*((int *) (job->assigned_data))) == i), "job value check");
|
||||
|
||||
pfree(job->assigned_data);
|
||||
testinfo->tester->assert_true(testinfo->tester,(job->destroy(job) == SUCCESS), "job destroy call check");
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
* description is in header file
|
||||
*/
|
||||
void test_job_queue(tester_t *tester)
|
||||
{
|
||||
int value = 1000;
|
||||
pthread_t sender_thread, receiver_thread;
|
||||
job_queue_t *job_queue = job_queue_create();
|
||||
job_queue_test_t test_infos;
|
||||
test_infos.tester = tester;
|
||||
test_infos.job_queue = job_queue;
|
||||
test_infos.max_queue_item_count = 100000;
|
||||
|
||||
pthread_create( &receiver_thread, NULL,(void*(*)(void*)) &test_job_queue_receiver, (void*) &test_infos);
|
||||
pthread_create( &sender_thread, NULL,(void*(*)(void*)) &test_job_queue_sender, (void*) &test_infos);
|
||||
|
||||
pthread_join(sender_thread, NULL);
|
||||
pthread_join(receiver_thread, NULL);
|
||||
|
||||
tester->assert_true(tester,(job_queue->get_count(job_queue,&value) == SUCCESS), "get count call check");
|
||||
tester->assert_true(tester,(value == 0), "get count value check");
|
||||
tester->assert_true(tester,(job_queue->destroy(job_queue) == SUCCESS), "destroy call check");
|
||||
}
|
35
Source/charon/tests/job_queue_test.h
Normal file
35
Source/charon/tests/job_queue_test.h
Normal file
@ -0,0 +1,35 @@
|
||||
/**
|
||||
* @file job_queue_test.h
|
||||
*
|
||||
* @brief Tests to test the Job-Queue type job_queue_t
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2005 Jan Hutter, Martin Willi
|
||||
* Hochschule fuer Technik Rapperswil
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at your
|
||||
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*/
|
||||
|
||||
#ifndef JOB_QUEUE_TEST_H_
|
||||
#define JOB_QUEUE_TEST_H_
|
||||
|
||||
/**
|
||||
* @brief Test function used to test the job_queue functionality
|
||||
*
|
||||
* @param tester associated tester object
|
||||
*/
|
||||
void test_job_queue(tester_t *tester);
|
||||
|
||||
test_t job_queue_test1 = {test_job_queue,"Job-Queue Test1"};
|
||||
|
||||
#endif /*JOB_QUEUE_TEST_H_*/
|
85
Source/charon/tests/linked_list_test.c
Normal file
85
Source/charon/tests/linked_list_test.c
Normal file
@ -0,0 +1,85 @@
|
||||
/**
|
||||
* @file linked_list_test.c
|
||||
*
|
||||
* @brief Tests to test the Linked List type linked_list_t
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2005 Jan Hutter, Martin Willi
|
||||
* Hochschule fuer Technik Rapperswil
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at your
|
||||
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "../tester.h"
|
||||
#include "../linked_list.h"
|
||||
|
||||
/*
|
||||
* Description in header-file
|
||||
*/
|
||||
void test_linked_list(tester_t *tester)
|
||||
{
|
||||
void *test_value = NULL;
|
||||
|
||||
linked_list_t *linked_list = linked_list_create();
|
||||
tester->assert_true(tester,(linked_list->count == 0), "count check");
|
||||
|
||||
linked_list->insert_first(linked_list,"one");
|
||||
tester->assert_true(tester,(linked_list->count == 1), "count check");
|
||||
|
||||
linked_list->insert_first(linked_list,"two");
|
||||
tester->assert_true(tester,(linked_list->count == 2), "count check");
|
||||
|
||||
linked_list->insert_first(linked_list,"three");
|
||||
tester->assert_true(tester,(linked_list->count == 3), "count check");
|
||||
|
||||
linked_list->insert_first(linked_list,"four");
|
||||
tester->assert_true(tester,(linked_list->count == 4), "count check");
|
||||
|
||||
linked_list->insert_first(linked_list,"five");
|
||||
tester->assert_true(tester,(linked_list->count == 5), "count check");
|
||||
|
||||
tester->assert_true(tester,(linked_list->get_first(linked_list,&test_value) == SUCCESS), "get_first call check");
|
||||
tester->assert_true(tester,(strcmp((char *) test_value,"five") == 0), "get_first value check");
|
||||
tester->assert_true(tester,(linked_list->count == 5), "count check");
|
||||
|
||||
tester->assert_true(tester,(linked_list->get_last(linked_list,&test_value) == SUCCESS), "get_last call check");
|
||||
tester->assert_true(tester,(strcmp((char *) test_value,"one") == 0), "get_last value check");
|
||||
tester->assert_true(tester,(linked_list->count == 5), "count check");
|
||||
tester->assert_true(tester,(linked_list->remove_first(linked_list,&test_value) == SUCCESS), "remove_first call check");
|
||||
tester->assert_true(tester,(strcmp((char *) test_value,"five") == 0), "remove_first value check");
|
||||
tester->assert_true(tester,(linked_list->count == 4), "count check");
|
||||
|
||||
tester->assert_true(tester,(linked_list->get_first(linked_list,&test_value) == SUCCESS), "get_first call check");
|
||||
tester->assert_true(tester,(strcmp((char *) test_value,"four") == 0), "get_first value check");
|
||||
tester->assert_true(tester,(linked_list->count == 4), "count check");
|
||||
|
||||
tester->assert_true(tester,(linked_list->get_last(linked_list,&test_value) == SUCCESS), "get_last call check");
|
||||
tester->assert_true(tester,(strcmp((char *) test_value,"one") == 0), "get_last value check");
|
||||
tester->assert_true(tester,(linked_list->count == 4), "count check");
|
||||
|
||||
tester->assert_true(tester,(linked_list->remove_last(linked_list,&test_value) == SUCCESS), "remove_last call check");
|
||||
tester->assert_true(tester,(strcmp((char *) test_value,"one") == 0), "remove_last value check");
|
||||
tester->assert_true(tester,(linked_list->count == 3), "count check");
|
||||
|
||||
tester->assert_true(tester,(linked_list->get_last(linked_list,&test_value) == SUCCESS), "get_last call check");
|
||||
tester->assert_true(tester,(strcmp((char *) test_value,"two") == 0), "get_last value check");
|
||||
tester->assert_true(tester,(linked_list->count == 3), "count check");
|
||||
|
||||
tester->assert_true(tester,(linked_list->get_first(linked_list,&test_value) == SUCCESS), "get_first call check");
|
||||
tester->assert_true(tester,(strcmp((char *) test_value,"four") == 0), "get_first value check");
|
||||
tester->assert_true(tester,(linked_list->count == 3), "count check");
|
||||
|
||||
tester->assert_true(tester,(linked_list->destroy(linked_list) == SUCCESS), "destroy call check");
|
||||
}
|
36
Source/charon/tests/linked_list_test.h
Normal file
36
Source/charon/tests/linked_list_test.h
Normal file
@ -0,0 +1,36 @@
|
||||
/**
|
||||
* @file linked_list_test.h
|
||||
*
|
||||
* @brief Tests to test the Linked List type linked_list_t
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2005 Jan Hutter, Martin Willi
|
||||
* Hochschule fuer Technik Rapperswil
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at your
|
||||
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*/
|
||||
|
||||
#ifndef LINKED_LIST_TEST_H_
|
||||
#define LINKED_LIST_TEST_H_
|
||||
|
||||
/**
|
||||
* @brief Tes function for the type linked_list_t
|
||||
*
|
||||
* @param tester tester object
|
||||
*/
|
||||
void test_linked_list(tester_t *tester);
|
||||
|
||||
|
||||
test_t linked_list_test = {test_linked_list,"Linked List"};
|
||||
|
||||
#endif /*LINKED_LIST_TEST_H_*/
|
41
Source/charon/tests/tests.h
Normal file
41
Source/charon/tests/tests.h
Normal file
@ -0,0 +1,41 @@
|
||||
/**
|
||||
* @file tests.h
|
||||
*
|
||||
* @brief Lists all the tests to get performed by the tester
|
||||
*
|
||||
* New tests have to be added here
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2005 Jan Hutter, Martin Willi
|
||||
* Hochschule fuer Technik Rapperswil
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at your
|
||||
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*/
|
||||
|
||||
#ifndef TESTS_H_
|
||||
#define TESTS_H_
|
||||
|
||||
#include "../tester.h"
|
||||
#include "linked_list_test.h"
|
||||
#include "thread_pool_test.h"
|
||||
#include "job_queue_test.h"
|
||||
|
||||
|
||||
test_t *tests[] ={
|
||||
&linked_list_test,
|
||||
&thread_pool_test,
|
||||
&job_queue_test1,
|
||||
NULL
|
||||
};
|
||||
|
||||
#endif /*TESTS_H_*/
|
40
Source/charon/tests/thread_pool_test.c
Normal file
40
Source/charon/tests/thread_pool_test.c
Normal file
@ -0,0 +1,40 @@
|
||||
/**
|
||||
* @file thread_pool_test.c
|
||||
*
|
||||
* @brief Tests to test the Thread-Pool type thread_pool_t
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2005 Jan Hutter, Martin Willi
|
||||
* Hochschule fuer Technik Rapperswil
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at your
|
||||
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "../tester.h"
|
||||
#include "../thread_pool.h"
|
||||
|
||||
/**
|
||||
* @brief Test function to test the thread pool class
|
||||
*/
|
||||
void test_thread_pool(tester_t *tester)
|
||||
{
|
||||
size_t desired_pool_size = 10;
|
||||
size_t pool_size;
|
||||
|
||||
thread_pool_t *pool = thread_pool_create(desired_pool_size);
|
||||
pool->get_pool_size(pool, &pool_size);
|
||||
tester->assert_true(tester, (desired_pool_size == pool_size), "thread creation");
|
||||
pool->destroy(pool);
|
||||
}
|
||||
|
30
Source/charon/tests/thread_pool_test.h
Normal file
30
Source/charon/tests/thread_pool_test.h
Normal file
@ -0,0 +1,30 @@
|
||||
/**
|
||||
* @file thread_pool_test.h
|
||||
*
|
||||
* @brief Tests to test the Thread-Pool type thread_pool_t
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2005 Jan Hutter, Martin Willi
|
||||
* Hochschule fuer Technik Rapperswil
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at your
|
||||
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*/
|
||||
|
||||
#ifndef THREAD_POOL_TEST_H_
|
||||
#define THREAD_POOL_TEST_H_
|
||||
|
||||
void test_thread_pool(tester_t *tester);
|
||||
|
||||
test_t thread_pool_test = {test_thread_pool,"Thread Pool"};
|
||||
|
||||
#endif /*THREAD_POOL_TEST_H_*/
|
Loading…
x
Reference in New Issue
Block a user