1
1
openmpi/test/class/ompi_value_array.c
Jeff Squyres 2753522f70 Change the test to properly check uint64_t in ompi_value_array -- it's
a better test to check that instead of int's

This commit was SVN r5157.
2005-04-04 17:53:58 +00:00

107 строки
2.9 KiB
C

/*
* Copyright (c) 2004-2005 The Trustees of Indiana University.
* All rights reserved.
* Copyright (c) 2004-2005 The Trustees of the University of Tennessee.
* All rights reserved.
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
* University of Stuttgart. All rights reserved.
* Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
/*
* This test is intended to test the ompi_value_array class
*/
#include "ompi_config.h"
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include <string.h>
#include "support.h"
#include "class/ompi_value_array.h"
#define NUM_ITEMS 10
int main(int argc, char **argv)
{
uint64_t i, val;
uint64_t count;
ompi_value_array_t array;
OBJ_CONSTRUCT(&array, ompi_value_array_t);
test_init("ompi_value_array_t");
ompi_value_array_init(&array, sizeof(uint64_t));
test_verify_int(0, ompi_value_array_get_size(&array));
/* add several items to the array */
for(i=0; i < NUM_ITEMS; i++) {
ompi_value_array_append_item(&array, &i);
}
test_verify_int(NUM_ITEMS, ompi_value_array_get_size(&array));
/* verify contents */
for(i=0; i < NUM_ITEMS; i++) {
val = OMPI_VALUE_ARRAY_GET_ITEM(&array, uint64_t, i);
if (val != i) {
test_failure("Comparison failure");
fprintf(stderr, " Expected result: %lld\n", (long long) i);
fprintf(stderr, " Test result: %lld\n", (long long) val);
fflush(stderr);
}
}
/* re-init array with new type */
ompi_value_array_init(&array, sizeof(uint64_t));
test_verify_int(0, ompi_value_array_get_size(&array));
/* set fixed size */
ompi_value_array_set_size(&array, NUM_ITEMS);
/* initialize array */
count = 0;
for(i=0; i < NUM_ITEMS; i++) {
OMPI_VALUE_ARRAY_SET_ITEM(&array, uint64_t, i, count++);
}
/* grow it */
for(i=0; i < NUM_ITEMS; i++) {
ompi_value_array_append_item(&array, &count);
count++;
}
/* check size */
test_verify_int(count, ompi_value_array_get_size(&array));
/* validate contents */
for(i=0; i < count; i++) {
test_verify_int(i, OMPI_VALUE_ARRAY_GET_ITEM(&array, uint64_t, i));
}
/* remove an item */
ompi_value_array_remove_item(&array, NUM_ITEMS);
/* check size */
test_verify_int(count-1, ompi_value_array_get_size(&array));
/* validate contents */
for(i=0; i < count-1; i++) {
if(i >= NUM_ITEMS) {
test_verify_int(i+1, OMPI_VALUE_ARRAY_GET_ITEM(&array, uint64_t, i));
} else {
test_verify_int(i, OMPI_VALUE_ARRAY_GET_ITEM(&array, uint64_t, i));
}
}
OBJ_DESTRUCT(&array);
return test_finalize();
}