/*
 * input map code
 *
 * Copyright 2003 Jacob Robbins
 *
 *
 * 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.
 *
 * 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.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */


#include <stdio.h>
#include <stdlib.h>

#include "../include.h"




/*test the submap object's functionality for rough accuracy verification*/



int main(int argc, char** argv){
  int i;
  event_map_action_t* act;
  event_submap_t* local_submap;


  printf("\n\n\ntesting the submap object for rough accuracy verification..\n");

  /*Create local submap*/
  if (!(local_submap =  event_submap_create(EVENT_PARAMETER_DATA_TYPE_UCHAR, SUBMAP_TEST_TYPE_EXACT))){
    printf("could not make a submap, memory problem.");
    exit(3);
  }

  /*TODO it would be nice to go through the names here, instead of the bare codes*/
  printf("\nmade submap with data type: %d  ", event_submap_get_parameter_data_type(local_submap));
  printf("and test type: %d\n\n",event_submap_get_parameter_test_type(local_submap));
 
  print_submap(local_submap);



  /*make tests*/
  printf("\n\n making 3 tests\n\n");
  event_submap_set_test_array_size(local_submap, 3);
  print_submap(local_submap);


  /*append test*/
  i=13;
  printf("\n\n appending test\n\n");
  event_submap_append_test(local_submap, &i,0);
  print_submap(local_submap);


  /*insert tests*/
  i=14;
  printf("\n\n inserting test at position 2\n\n");
  event_submap_insert_test(local_submap, 2, &i, 0);
  print_submap(local_submap);


  /*remove tests*/
  printf("\n\n removing test at position 0 \n\n");
  event_submap_remove_test(local_submap, 0);
  print_submap(local_submap);



  /*append actions to tests*/
  printf("\n\n appending 3 actions to first test, 23 24 & 25\n\n");
  for (i=0;i<3;++i){
    if (!(act = event_submap_append_test_action(local_submap,0))) {printf("failure adding action");exit(-2);}
    event_map_action_set_target_index(act, i + 23);
  }
  print_submap(local_submap);
  
  /*prepend actions to tests*/
  printf("\n\n prepending action to first test, 26\n\n");
  if (!(act = event_submap_prepend_test_action(local_submap,0))) {printf("failure prepending action");exit(-2);}
  event_map_action_set_target_index(act, 26);
  print_submap(local_submap);

  /*insert actions to tests*/
  printf("\n\n inserting action to first test at action position 0, 27\n\n");
  if (!(act = event_submap_insert_test_action(local_submap,0,0))) {printf("failure inserting action");exit(-2);}
  event_map_action_set_target_index(act, 27);
  print_submap(local_submap);

  printf("\n\n inserting action to first test at action position 3, 28\n\n");
  if (!(act = event_submap_insert_test_action(local_submap,0,3))) {printf("failure inserting action");exit(-2);}
  event_map_action_set_target_index(act, 28);
  print_submap(local_submap);

  i = event_submap_get_test_action_count(local_submap,0);
  printf("\n\n inserting action to first test at one past last action position (%d), 29\n\n", i);
  if (!(act = event_submap_insert_test_action(local_submap,0,i))) {
    printf("failure inserting action");exit(-2);
  }
  event_map_action_set_target_index(act, 29);
  print_submap(local_submap);


  /*remove action from tests*/
  printf("\n\n removing action from first test at position 4\n\n");
  if ((event_submap_remove_test_action(local_submap,0,4)) < 0) {
    printf("failure removing action");exit(-2);
  }
  print_submap(local_submap);



  printf("\n that is all of this test, be sure to try out the static test too\n\n");




  /*deallocate local submap*/
  printf("\n\ncleaning up");
  event_submap_destroy(local_submap);
  printf("\n\ndone \n\n");
  return 0;
}



