Add test for lam_pointer_array.c
This commit was SVN r706.
Этот коммит содержится в:
родитель
4dfecb34f7
Коммит
190b9b13b5
@ -6,7 +6,8 @@
|
|||||||
include $(top_srcdir)/config/Makefile.options
|
include $(top_srcdir)/config/Makefile.options
|
||||||
AM_CPPFLAGS = -I$(top_srcdir)/test/support -DLAM_ENABLE_DEBUG=1
|
AM_CPPFLAGS = -I$(top_srcdir)/test/support -DLAM_ENABLE_DEBUG=1
|
||||||
|
|
||||||
noinst_PROGRAMS = list_test htable_test
|
noinst_PROGRAMS = list_test \
|
||||||
|
test_lam_pointer_array
|
||||||
|
|
||||||
list_test_SOURCES = list_test.c
|
list_test_SOURCES = list_test.c
|
||||||
list_test_LDADD = \
|
list_test_LDADD = \
|
||||||
@ -18,13 +19,12 @@ list_test_LDADD = \
|
|||||||
$(top_builddir)/test/support/libsupport.la
|
$(top_builddir)/test/support/libsupport.la
|
||||||
list_test_DEPENDENCIES = $(list_test_LDADD)
|
list_test_DEPENDENCIES = $(list_test_LDADD)
|
||||||
|
|
||||||
htable_test_SOURCES = htable_test.c
|
test_lam_pointer_array_SOURCES = test_lam_pointer_array.c
|
||||||
htable_test_LDADD = \
|
test_lam_pointer_array_LDADD = \
|
||||||
$(top_builddir)/src/lam/lfc/list.lo \
|
$(top_builddir)/src/lam/lfc/lam_pointer_array.lo \
|
||||||
$(top_builddir)/src/lam/lfc/object.lo \
|
|
||||||
$(top_builddir)/src/lam/mem/malloc.lo \
|
$(top_builddir)/src/lam/mem/malloc.lo \
|
||||||
$(top_builddir)/src/lam/util/output.lo \
|
$(top_builddir)/src/lam/util/output.lo \
|
||||||
$(top_builddir)/src/lam/threads/mutex.lo \
|
$(top_builddir)/src/lam/threads/mutex.lo \
|
||||||
|
$(top_builddir)/src/lam/util/libutil.la \
|
||||||
$(top_builddir)/test/support/libsupport.la
|
$(top_builddir)/test/support/libsupport.la
|
||||||
htable_test_DEPENDENCIES = $(list_test_LDADD)
|
test_lam_pointer_array_DEPENDENCIES = $(test_lam_pointer_array_LDADD)
|
||||||
|
|
||||||
|
143
test/lam/lfc/test_lam_pointer_array.c
Обычный файл
143
test/lam/lfc/test_lam_pointer_array.c
Обычный файл
@ -0,0 +1,143 @@
|
|||||||
|
/*
|
||||||
|
* $HEADER$
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This test is intended to test the lam_pointer_array
|
||||||
|
* class
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <assert.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "support.h"
|
||||||
|
#include "lam/lfc/lam_pointer_array.h"
|
||||||
|
|
||||||
|
void test(bool thread_usage){
|
||||||
|
|
||||||
|
/* local variables */
|
||||||
|
lam_pointer_array_t *array;
|
||||||
|
char *test_value;
|
||||||
|
char **test_data;
|
||||||
|
size_t len_test_data,i,test_len_in_array,error_cnt;
|
||||||
|
size_t ele_index;
|
||||||
|
int use_threads,error_code;
|
||||||
|
|
||||||
|
/* initialize thread levels */
|
||||||
|
use_threads=(int)lam_set_using_threads(thread_usage);
|
||||||
|
|
||||||
|
array=malloc(sizeof(lam_pointer_array_t));
|
||||||
|
assert(array);
|
||||||
|
bzero(array,sizeof(lam_pointer_array_t));
|
||||||
|
/* init the mutex */
|
||||||
|
lam_mutex_init(&(array->lock));
|
||||||
|
|
||||||
|
len_test_data=5;
|
||||||
|
test_data=malloc(sizeof(char *)*len_test_data);
|
||||||
|
assert(test_data);
|
||||||
|
|
||||||
|
for(i=0 ; i < len_test_data ; i++ ) {
|
||||||
|
test_data[i]=(char *)(i+1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* add data to table */
|
||||||
|
test_len_in_array=3;
|
||||||
|
assert(len_test_data>=test_len_in_array);
|
||||||
|
for(i=0 ; i < test_len_in_array ; i++ ) {
|
||||||
|
lam_pointer_array_add(array,test_data[i]);
|
||||||
|
}
|
||||||
|
/* check to see that test_len_in_array are in array */
|
||||||
|
if( (array->size - array->number_free) ==
|
||||||
|
test_len_in_array) {
|
||||||
|
test_success();
|
||||||
|
} else {
|
||||||
|
test_failure("check on number of elments in array");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* check order of data */
|
||||||
|
error_cnt=0;
|
||||||
|
for(i=0 ; i < test_len_in_array ; i++ ) {
|
||||||
|
if( ((char *)(i+1)) != array->addr[i] )
|
||||||
|
error_cnt++;
|
||||||
|
}
|
||||||
|
if( 0 == error_cnt ) {
|
||||||
|
test_success();
|
||||||
|
} else {
|
||||||
|
test_failure(" data check ");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* free 2nd element and make sure that value is reset correctly,
|
||||||
|
* and that the lowest_index is also reset correctly */
|
||||||
|
ele_index=1;
|
||||||
|
error_code=lam_pointer_array_set_item(array,ele_index,NULL);
|
||||||
|
if( 0 == error_code ) {
|
||||||
|
test_success();
|
||||||
|
} else {
|
||||||
|
test_failure(" lam_pointer_array_set_item ");
|
||||||
|
}
|
||||||
|
if( NULL == array->addr[ele_index]){
|
||||||
|
test_success();
|
||||||
|
} else {
|
||||||
|
test_failure(" set pointer value");
|
||||||
|
}
|
||||||
|
if( ele_index == array->lowest_free ) {
|
||||||
|
test_success();
|
||||||
|
} else {
|
||||||
|
test_failure(" lowest free ");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* test lam_pointer_array_get_item */
|
||||||
|
array->number_free=array->size;
|
||||||
|
array->lowest_free=0;
|
||||||
|
for(i=0 ; i < array->size ; i++ ) {
|
||||||
|
array->addr[i] = NULL;
|
||||||
|
}
|
||||||
|
error_cnt=0;
|
||||||
|
for(i=0 ; i < array->size ; i++ ) {
|
||||||
|
ele_index=lam_pointer_array_add(array,((char *)(i+2)) );
|
||||||
|
if( i != ele_index ) {
|
||||||
|
error_cnt++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if( 0 == error_cnt ) {
|
||||||
|
test_success();
|
||||||
|
} else {
|
||||||
|
test_failure(" lam_pointer_array_add 2nd ");
|
||||||
|
}
|
||||||
|
|
||||||
|
error_cnt=0;
|
||||||
|
for(i=0 ; i < array->size ; i++ ) {
|
||||||
|
test_value=lam_pointer_array_get_item(array,i);
|
||||||
|
if( ((char *)(i+2)) != test_value ) {
|
||||||
|
error_cnt++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if( 0 == error_cnt ) {
|
||||||
|
test_success();
|
||||||
|
} else {
|
||||||
|
test_failure(" data check - 2nd ");
|
||||||
|
}
|
||||||
|
|
||||||
|
free (array);
|
||||||
|
free(test_data);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
test_init("lam_pointer_array");
|
||||||
|
|
||||||
|
/* run through tests with thread usage set to false */
|
||||||
|
test(false);
|
||||||
|
|
||||||
|
/* run through tests with thread usage set to true */
|
||||||
|
test(true);
|
||||||
|
|
||||||
|
test_finalize();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
Загрузка…
x
Ссылка в новой задаче
Block a user