root/test/class/opal_value_array.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. main

   1 /*
   2  * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
   3  *                         University Research and Technology
   4  *                         Corporation.  All rights reserved.
   5  * Copyright (c) 2004-2005 The University of Tennessee and The University
   6  *                         of Tennessee Research Foundation.  All rights
   7  *                         reserved.
   8  * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
   9  *                         University of Stuttgart.  All rights reserved.
  10  * Copyright (c) 2004-2005 The Regents of the University of California.
  11  *                         All rights reserved.
  12  * Copyright (c) 2008-2014 Cisco Systems, Inc.  All rights reserved.
  13  * $COPYRIGHT$
  14  *
  15  * Additional copyrights may follow
  16  *
  17  * $HEADER$
  18  */
  19 
  20 /*
  21  * This test is intended to test the opal_value_array class
  22  */
  23 
  24 #include "opal_config.h"
  25 #include <stdlib.h>
  26 #include <stdio.h>
  27 #include <assert.h>
  28 #include <string.h>
  29 
  30 #include "support.h"
  31 #include "opal/class/opal_value_array.h"
  32 #include "opal/runtime/opal.h"
  33 
  34 #define NUM_ITEMS 10
  35 
  36 
  37 int main(int argc, char **argv)
  38 {
  39     uint64_t i, val;
  40     uint64_t count;
  41     opal_value_array_t array;
  42 
  43     test_init("opal_value_array_t");
  44 
  45     i = opal_init_util(&argc, &argv);
  46     test_verify_int(OPAL_SUCCESS, i);
  47     if (OPAL_SUCCESS != i) {
  48         test_finalize();
  49         exit(1);
  50     }
  51 
  52     OBJ_CONSTRUCT(&array, opal_value_array_t);
  53 
  54     opal_value_array_init(&array, sizeof(uint64_t));
  55     test_verify_int(0, opal_value_array_get_size(&array));
  56 
  57     /* add several items to the array */
  58     for(i=0; i < NUM_ITEMS; i++) {
  59         opal_value_array_append_item(&array, &i);
  60     }
  61     test_verify_int(NUM_ITEMS, opal_value_array_get_size(&array));
  62 
  63     /* verify contents */
  64     for(i=0; i < NUM_ITEMS; i++) {
  65         val = OPAL_VALUE_ARRAY_GET_ITEM(&array, uint64_t, i);
  66         if (val != i) {
  67             test_failure("Comparison failure");
  68             fprintf(stderr, " Expected result: %lld\n", (long long) i);
  69             fprintf(stderr, " Test result: %lld\n", (long long) val);
  70             fflush(stderr);
  71         }
  72     }
  73 
  74     /* re-init array with new type */
  75     opal_value_array_init(&array, sizeof(uint64_t));
  76     test_verify_int(0, opal_value_array_get_size(&array));
  77 
  78     /* set fixed size */
  79     opal_value_array_set_size(&array, NUM_ITEMS);
  80 
  81     /* initialize array */
  82     count = 0;
  83     for(i=0; i < NUM_ITEMS; i++) {
  84         OPAL_VALUE_ARRAY_SET_ITEM(&array, uint64_t, i, count++);
  85     }
  86 
  87     /* grow it */
  88     for(i=0; i < NUM_ITEMS; i++) {
  89         opal_value_array_append_item(&array, &count);
  90         count++;
  91     }
  92     /* check size */
  93     test_verify_int(count, opal_value_array_get_size(&array));
  94 
  95     /* validate contents */
  96     for(i=0; i < count; i++) {
  97         test_verify_int(i, OPAL_VALUE_ARRAY_GET_ITEM(&array, uint64_t, i));
  98     }
  99 
 100     /* remove an item */
 101     opal_value_array_remove_item(&array, NUM_ITEMS);
 102 
 103     /* check size */
 104     test_verify_int(count-1, opal_value_array_get_size(&array));
 105 
 106     /* validate contents */
 107     for(i=0; i < count-1; i++) {
 108         if(i >= NUM_ITEMS) {
 109             test_verify_int(i+1, OPAL_VALUE_ARRAY_GET_ITEM(&array, uint64_t, i));
 110         } else {
 111             test_verify_int(i, OPAL_VALUE_ARRAY_GET_ITEM(&array, uint64_t, i));
 112         }
 113     }
 114 
 115     OBJ_DESTRUCT(&array);
 116 
 117     opal_finalize_util ();
 118 
 119     return test_finalize();
 120 }

/* [<][>][^][v][top][bottom][index][help] */