예제 #1
0
void test_array_list_add_and_remove ()
{
  array_list *list = create_array_list_simple ();
  TEST_ASSERT_NOT_NULL (list);

  // try to append an item and get it back later
  char *str1 = "hello";
  array_list_append (list, str1);
  TEST_ASSERT_EQUAL_INT (list->item_count, 1);
  TEST_ASSERT_EQUAL_STR (array_list_get (list, 0), str1);

  // try to append multiple items and get one back later
  char *strs1[] = {"world", "!"};
  array_list_append_all (list, (void **) strs1, 2);
  TEST_ASSERT_EQUAL_INT (list->item_count, 3);
  TEST_ASSERT_EQUAL_STR (array_list_get (list, 1), strs1[0]);
  TEST_ASSERT_EQUAL_STR (array_list_get (list, 2), strs1[1]);

  // try to add an item at a specific position
  char *str2 = " ";
  array_list_add (list, 1, str2);
  TEST_ASSERT_EQUAL_INT (list->item_count, 4);
  TEST_ASSERT_EQUAL_STR (array_list_get (list, 0), str1);
  TEST_ASSERT_EQUAL_STR (array_list_get (list, 1), str2);
  TEST_ASSERT_EQUAL_STR (array_list_get (list, 2), strs1[0]);
  TEST_ASSERT_EQUAL_STR (array_list_get (list, 3), strs1[1]);
  
  // try to add multiple items at a specific position
  char *strs2[] = {"WORLD", "?", "\n", "HELLO "};
  array_list_add_all (list, 2, (void **) strs2, 4);
  TEST_ASSERT_EQUAL_INT (list->item_count, 8);
  TEST_ASSERT_EQUAL_STR (array_list_get (list, 0), str1);
  TEST_ASSERT_EQUAL_STR (array_list_get (list, 1), str2);
  TEST_ASSERT_EQUAL_STR (array_list_get (list, 2), strs2[0]);
  TEST_ASSERT_EQUAL_STR (array_list_get (list, 3), strs2[1]);
  TEST_ASSERT_EQUAL_STR (array_list_get (list, 4), strs2[2]);
  TEST_ASSERT_EQUAL_STR (array_list_get (list, 5), strs2[3]);
  TEST_ASSERT_EQUAL_STR (array_list_get (list, 6), strs1[0]);
  TEST_ASSERT_EQUAL_STR (array_list_get (list, 7), strs1[1]);

  // try to remove an item
  array_list_remove (list, 6);
  TEST_ASSERT_EQUAL_INT (list->item_count, 7);
  TEST_ASSERT_EQUAL_STR (array_list_get (list, 0), str1);
  TEST_ASSERT_EQUAL_STR (array_list_get (list, 1), str2);
  TEST_ASSERT_EQUAL_STR (array_list_get (list, 2), strs2[0]);
  TEST_ASSERT_EQUAL_STR (array_list_get (list, 3), strs2[1]);
  TEST_ASSERT_EQUAL_STR (array_list_get (list, 4), strs2[2]);
  TEST_ASSERT_EQUAL_STR (array_list_get (list, 5), strs2[3]);
  TEST_ASSERT_EQUAL_STR (array_list_get (list, 6), strs1[1]);

  delete_array_list (list);
}
예제 #2
0
파일: ipc.c 프로젝트: bhargavz/cloudproxy
// Dequeue message for processing. Acknowledge the sender. 
// Caller must acquire the lock before calling.
// RETURN VALUE:    TRUE if message was dequeued, FALSE if queue is empty
static IPC_MESSAGE *ipc_dequeue_message(IPC_CPU_CONTEXT *ipc)
{
    IPC_MESSAGE  *msg = NULL;

    VMM_ASSERT(ipc != NULL);
    msg = (IPC_MESSAGE *) array_list_first(ipc->message_queue, NULL);
    if (msg != NULL) {
        array_list_remove(ipc->message_queue, msg);
        ipc_increment_ack(msg->before_handler_ack);
        ipc->num_of_received_ipc_messages++;            // Receive IPC message counting.
    }
    return msg;
}
예제 #3
0
파일: tst-array.c 프로젝트: chagge/friso
int main( int argc, char **args ) {
    
    //create a new array list.
    friso_array_t array = new_array_list();    
    fstring keys[] = {
        "chenmanwen", "yangqinghua",
        "chenxin", "luojiangyan", "xiaoyanzi", "bibi",
        "zhangrenfang", "yangjian",
        "liuxiao", "pankai",
        "chenpei", "liheng", "zhangzhigang", "zhgangyishao", "yangjiangbo",
        "caizaili", "panpan", "xiaolude", "yintanwen"
    };
    int j, idx = 2, len = sizeof( keys ) / sizeof( fstring );

    for ( j = 0; j < len; j++ ) {
        array_list_add( array, keys[j] );
    }

    printf("length=%d, allocations=%d\n", array->length, array->allocs );
    array_list_trim( array );
    printf("after tirm length=%d, allocations=%d\n", array->length, array->allocs );
    printf("idx=%d, value=%s\n", idx, ( fstring ) array_list_get( array, idx ) );

    printf("\nAfter set %dth item.\n", idx );
    array_list_set( array, idx, "chenxin__" );
    printf("idx=%d, value=%s\n", idx, ( fstring ) array_list_get( array, idx ) );

    printf("\nAfter remove %dth item.\n", idx );
    array_list_remove( array, idx );
    printf("length=%d, allocations=%d\n", array->length, array->allocs );
    printf("idx=%d, value=%s\n", idx, ( fstring ) array_list_get( array, idx ) );

    printf("\nInsert a item at %dth\n", idx );
    array_list_insert( array, idx, "*chenxin*" );
    printf("idx=%d, value=%s\n", idx, ( fstring ) array_list_get( array, idx ) );

    free_array_list( array );

    return 0;
}
예제 #4
0
Object array_remove(Array * const list, int index) {
  return array_list_remove((ArrayList * const ) list, index);
}