2004-02-11 17:45:35 +03:00
|
|
|
/*
|
|
|
|
* $HEADER$
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2004-06-07 19:33:53 +04:00
|
|
|
* This test is intended to test the ompi_value_array class
|
2004-02-11 17:45:35 +03:00
|
|
|
*/
|
|
|
|
|
2004-10-20 05:03:09 +04:00
|
|
|
#include "ompi_config.h"
|
2004-02-11 17:45:35 +03:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "support.h"
|
2004-06-07 19:33:53 +04:00
|
|
|
#include "class/ompi_value_array.h"
|
2004-02-11 17:45:35 +03:00
|
|
|
|
|
|
|
|
|
|
|
#define NUM_ITEMS 10
|
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
uint64_t count;
|
|
|
|
|
2004-06-07 19:33:53 +04:00
|
|
|
ompi_value_array_t array;
|
|
|
|
OBJ_CONSTRUCT(&array, ompi_value_array_t);
|
2004-02-11 17:45:35 +03:00
|
|
|
|
2004-06-09 08:31:38 +04:00
|
|
|
test_init("ompi_value_array_t");
|
2004-06-07 19:33:53 +04:00
|
|
|
ompi_value_array_init(&array, sizeof(int));
|
|
|
|
test_verify_int(0, ompi_value_array_get_size(&array));
|
2004-02-11 17:45:35 +03:00
|
|
|
|
|
|
|
/* add several items to the array */
|
|
|
|
for(i=0; i < NUM_ITEMS; i++)
|
2004-06-07 19:33:53 +04:00
|
|
|
ompi_value_array_append_item(&array, &i);
|
|
|
|
test_verify_int(NUM_ITEMS, ompi_value_array_get_size(&array));
|
2004-02-11 17:45:35 +03:00
|
|
|
|
|
|
|
/* verify contents */
|
|
|
|
for(i=0; i < NUM_ITEMS; i++)
|
2004-06-07 19:33:53 +04:00
|
|
|
test_verify_int(i, OMPI_VALUE_ARRAY_GET_ITEM(&array, int, i));
|
2004-02-11 17:45:35 +03:00
|
|
|
|
|
|
|
/* re-init array with new type */
|
2004-06-07 19:33:53 +04:00
|
|
|
ompi_value_array_init(&array, sizeof(uint64_t));
|
|
|
|
test_verify_int(0, ompi_value_array_get_size(&array));
|
2004-02-11 17:45:35 +03:00
|
|
|
|
|
|
|
/* set fixed size */
|
2004-06-07 19:33:53 +04:00
|
|
|
ompi_value_array_set_size(&array, NUM_ITEMS);
|
2004-02-11 17:45:35 +03:00
|
|
|
|
|
|
|
/* initialize array */
|
|
|
|
count = 0;
|
|
|
|
for(i=0; i < NUM_ITEMS; i++)
|
2004-06-07 19:33:53 +04:00
|
|
|
OMPI_VALUE_ARRAY_SET_ITEM(&array, uint64_t, i, count++);
|
2004-02-11 17:45:35 +03:00
|
|
|
|
|
|
|
/* grow it */
|
|
|
|
for(i=0; i < NUM_ITEMS; i++) {
|
2004-06-07 19:33:53 +04:00
|
|
|
ompi_value_array_append_item(&array, &count);
|
2004-02-11 17:45:35 +03:00
|
|
|
count++;
|
|
|
|
}
|
|
|
|
/* check size */
|
2004-06-07 19:33:53 +04:00
|
|
|
test_verify_int(count, ompi_value_array_get_size(&array));
|
2004-02-11 17:45:35 +03:00
|
|
|
|
|
|
|
/* validate contents */
|
|
|
|
for(i=0; i < count; i++)
|
2004-06-07 19:33:53 +04:00
|
|
|
test_verify_int(i, OMPI_VALUE_ARRAY_GET_ITEM(&array, uint64_t, i));
|
2004-02-11 17:45:35 +03:00
|
|
|
|
|
|
|
/* remove an item */
|
2004-06-07 19:33:53 +04:00
|
|
|
ompi_value_array_remove_item(&array, NUM_ITEMS);
|
2004-02-11 17:45:35 +03:00
|
|
|
|
|
|
|
/* check size */
|
2004-06-07 19:33:53 +04:00
|
|
|
test_verify_int(count-1, ompi_value_array_get_size(&array));
|
2004-02-11 17:45:35 +03:00
|
|
|
|
|
|
|
/* validate contents */
|
|
|
|
for(i=0; i < count-1; i++)
|
|
|
|
if(i >= NUM_ITEMS)
|
2004-06-07 19:33:53 +04:00
|
|
|
test_verify_int(i+1, OMPI_VALUE_ARRAY_GET_ITEM(&array, uint64_t, i));
|
2004-02-11 17:45:35 +03:00
|
|
|
else
|
2004-06-07 19:33:53 +04:00
|
|
|
test_verify_int(i, OMPI_VALUE_ARRAY_GET_ITEM(&array, uint64_t, i));
|
2004-02-11 17:45:35 +03:00
|
|
|
|
|
|
|
OBJ_DESTRUCT(&array);
|
|
|
|
return test_finalize();
|
|
|
|
}
|