Esempio n. 1
0
static void test_loop(int is_epoll)
{
	int res = 0;
	int tfd1 = -1, tfd2 = -1, tfd3 = -1;
	int fd = -1;
	struct test_data data;
	struct pomp_loop *loop = NULL;

	memset(&data, 0, sizeof(data));

	/* Create loop */
	loop = pomp_loop_new();
	CU_ASSERT_PTR_NOT_NULL_FATAL(loop);

	/* Create timers for testing */
	tfd1 = setup_timerfd(100, 500);
	CU_ASSERT_TRUE_FATAL(tfd1 >= 0);
	tfd2 = setup_timerfd(50, 500);
	CU_ASSERT_TRUE_FATAL(tfd2 >= 0);
	tfd3 = setup_timerfd(150, 500);
	CU_ASSERT_TRUE_FATAL(tfd3 >= 0);

	/* Add timer in loop */
	res = pomp_loop_add(loop, tfd1, POMP_FD_EVENT_IN, &timerfd_cb, &data);
	CU_ASSERT_EQUAL(res, 0);

	res = pomp_loop_has_fd(loop, tfd1);
	CU_ASSERT_EQUAL(res, 1);

	res = pomp_loop_has_fd(loop, tfd2);
	CU_ASSERT_EQUAL(res, 0);

	/* Invalid add (already in loop) */
	res = pomp_loop_add(loop, tfd1, POMP_FD_EVENT_IN, &timerfd_cb, &data);
	CU_ASSERT_EQUAL(res, -EEXIST);

	/* Invalid add (NULL param) */
	res = pomp_loop_add(NULL, tfd1, POMP_FD_EVENT_IN, &timerfd_cb, &data);
	CU_ASSERT_EQUAL(res, -EINVAL);
	res = pomp_loop_add(loop, tfd1, POMP_FD_EVENT_IN, NULL, &data);
	CU_ASSERT_EQUAL(res, -EINVAL);

	/* Invalid add (invalid events) */
	res = pomp_loop_add(loop, tfd1, 0, &timerfd_cb, &data);
	CU_ASSERT_EQUAL(res, -EINVAL);

	/* Invalid add (invalid fd) */
	res = pomp_loop_add(loop, -1, POMP_FD_EVENT_IN, &timerfd_cb, &data);
	CU_ASSERT_EQUAL(res, -EINVAL);

	/* Update events */
	res = pomp_loop_update(loop, tfd1, POMP_FD_EVENT_IN | POMP_FD_EVENT_OUT);
	CU_ASSERT_EQUAL(res, 0);

	/* Invalid update (NULL param) */
	res = pomp_loop_update(NULL, tfd1, POMP_FD_EVENT_IN | POMP_FD_EVENT_OUT);
	CU_ASSERT_EQUAL(res, -EINVAL);

	/* Invalid update (invalid events) */
	res = pomp_loop_update(loop, tfd1, 0);
	CU_ASSERT_EQUAL(res, -EINVAL);

	/* Invalid update (invalid fd) */
	res = pomp_loop_update(loop, -1, POMP_FD_EVENT_IN | POMP_FD_EVENT_OUT);
	CU_ASSERT_EQUAL(res, -EINVAL);

	/* Invalid remove (fd not registered) */
	res = pomp_loop_update(loop, 2, POMP_FD_EVENT_IN | POMP_FD_EVENT_OUT);
	CU_ASSERT_EQUAL(res, -ENOENT);

	/* Update again events */
	res = pomp_loop_update(loop, tfd1, POMP_FD_EVENT_IN);
	CU_ASSERT_EQUAL(res, 0);

	/* Add 2nd and 3rd timer in loop */
	res = pomp_loop_add(loop, tfd2, POMP_FD_EVENT_IN, &timerfd_cb, &data);
	CU_ASSERT_EQUAL(res, 0);
	res = pomp_loop_add(loop, tfd3, POMP_FD_EVENT_IN, &timerfd_cb, &data);
	CU_ASSERT_EQUAL(res, 0);

	/* Get loop fd */
	fd = pomp_loop_get_fd(loop);
	CU_ASSERT_TRUE((is_epoll && fd >= 0) || (!is_epoll && fd == -ENOSYS));
	fd = pomp_loop_get_fd(NULL);
	CU_ASSERT_EQUAL(fd, -EINVAL);

	/* Run loop with different timeout first one should have all timers) */
	res = pomp_loop_wait_and_process(loop, 500);
	CU_ASSERT_EQUAL(res, 0);
	res = pomp_loop_wait_and_process(loop, 0);
	CU_ASSERT_TRUE(res == -ETIMEDOUT || res == 0);
	res = pomp_loop_wait_and_process(loop, -1);
	CU_ASSERT_EQUAL(res, 0);

	/* Invalid run (NULL param) */
	res = pomp_loop_wait_and_process(NULL, 0);
	CU_ASSERT_EQUAL(res, -EINVAL);

	/* Invalid destroy (NULL param) */
	res = pomp_loop_destroy(NULL);
	CU_ASSERT_EQUAL(res, -EINVAL);

	/* Invalid destroy (busy) */
	res = pomp_loop_destroy(loop);
	CU_ASSERT_EQUAL(res, -EBUSY);

	/* Invalid remove (NULL param) */
	res = pomp_loop_remove(NULL, tfd1);
	CU_ASSERT_EQUAL(res, -EINVAL);

	/* Invalid remove (invalid fd) */
	res = pomp_loop_remove(loop, -1);
	CU_ASSERT_EQUAL(res, -EINVAL);

	/* Invalid remove (fd not registered) */
	res = pomp_loop_remove(loop, 2);
	CU_ASSERT_EQUAL(res, -ENOENT);

	/* Remove timers */
	res = pomp_loop_remove(loop, tfd1);
	CU_ASSERT_EQUAL(res, 0);
	res = pomp_loop_remove(loop, tfd2);
	CU_ASSERT_EQUAL(res, 0);
	res = pomp_loop_remove(loop, tfd3);
	CU_ASSERT_EQUAL(res, 0);

	/* Close timers */
	res = close(tfd1);
	CU_ASSERT_EQUAL(res, 0);
	res = close(tfd2);
	CU_ASSERT_EQUAL(res, 0);
	res = close(tfd3);
	CU_ASSERT_EQUAL(res, 0);

	/* Destroy loop */
	res = pomp_loop_destroy(loop);
	CU_ASSERT_EQUAL(res, 0);
}
void
test_modesense6_residuals(void)
{
        struct scsi_task *ms_task = NULL;

        logging(LOG_VERBOSE, LOG_BLANK_LINE);
        logging(LOG_VERBOSE, "Test of MODESENSE6 Residuals");

        logging(LOG_VERBOSE, "MODESENSE6 command should not result in any "
                "residuals");

        
        logging(LOG_VERBOSE, "Try a MODESENSE6 command with 4 bytes of "
                "transfer length and verify that we don't get residuals.");
        MODESENSE6(sd, &ms_task, 0, SCSI_MODESENSE_PC_CURRENT,
                   SCSI_MODEPAGE_RETURN_ALL_PAGES, 0, 4,
                   EXPECT_STATUS_GOOD);

        logging(LOG_VERBOSE, "[SUCCESS] All Pages fetched.");

        logging(LOG_VERBOSE, "Verify that we got at most 4 bytes of DATA-IN");
        if (ms_task->datain.size > 4) {
                logging(LOG_NORMAL, "[FAILED] got more than 4 bytes of "
                        "DATA-IN.");
        } else {
                logging(LOG_VERBOSE, "[SUCCESS] <= 4 bytes of DATA-IN "
                        "received.");
        }
        CU_ASSERT_TRUE(ms_task->datain.size <= 4);


        logging(LOG_VERBOSE, "Verify residual overflow flag not set");
        if (ms_task->residual_status == SCSI_RESIDUAL_OVERFLOW) {
                logging(LOG_VERBOSE, "[FAILED] Target set residual "
                        "overflow flag");
        }
        CU_ASSERT_NOT_EQUAL(ms_task->residual_status, SCSI_RESIDUAL_OVERFLOW);



        logging(LOG_VERBOSE, "Try a MODESENSE6 command with 255 bytes of "
                "transfer length and verify that we get residuals if the target returns less than the requested amount of data.");
        scsi_free_scsi_task(ms_task);
        MODESENSE6(sd, &ms_task, 0, SCSI_MODESENSE_PC_CURRENT,
                   SCSI_MODEPAGE_RETURN_ALL_PAGES, 0, 255,
                   EXPECT_STATUS_GOOD);
        logging(LOG_VERBOSE, "[SUCCESS] All Pages fetched.");

        if (ms_task->datain.size == 255) {
                logging(LOG_VERBOSE, "We got all 255 bytes of data back "
                        "from the target. Verify that underflow is not set.");

                if (ms_task->residual_status == SCSI_RESIDUAL_UNDERFLOW) {
                        logging(LOG_VERBOSE, "[FAILED] Target set residual "
                                "underflow flag");
                } else {
                        logging(LOG_VERBOSE, "[SUCCESS] Residual underflow "
                                "is not set");
                }
                CU_ASSERT_NOT_EQUAL(ms_task->residual_status,
                                SCSI_RESIDUAL_UNDERFLOW);
        } else {
                logging(LOG_VERBOSE, "We got less than the requested 255 bytes "
                        "from the target. Verify that underflow is set.");

                if (ms_task->residual_status != SCSI_RESIDUAL_UNDERFLOW) {
                        logging(LOG_VERBOSE, "[FAILED] Target did not set "
                                "residual underflow flag");
                } else {
                        logging(LOG_VERBOSE, "[SUCCESS] Residual underflow "
                                "is set");
                }
                CU_ASSERT_EQUAL(ms_task->residual_status,
                                SCSI_RESIDUAL_UNDERFLOW);
        }

        scsi_free_scsi_task(ms_task);
}
Esempio n. 3
0
void test_arrayList_isEmpty(void) {
	arrayList_clear(list);
	CU_ASSERT_EQUAL(list->size, 0);
	CU_ASSERT_TRUE(arrayList_isEmpty(list));
}
Esempio n. 4
0
static void test_event_cb_t(struct pomp_ctx *ctx, enum pomp_event event,
		struct pomp_conn *conn, const struct pomp_msg *msg,
		void *userdata)
{
	int fd;
	int res = 0;
	struct test_data *data = userdata;
	const char *eventstr = pomp_event_str(event);
	const struct sockaddr *addr = NULL;
	uint32_t addrlen = 0;
	const struct pomp_cred *cred = NULL;
	int isunix = 0;

	switch (event) {
	case POMP_EVENT_CONNECTED:
		data->connection++;

		/* Invalid get fd (NULL param) */
		fd = pomp_conn_get_fd(NULL);
		CU_ASSERT_EQUAL(fd, -EINVAL);

		fd = pomp_conn_get_fd(conn);
		CU_ASSERT_TRUE(fd >= 0);

		addr = pomp_conn_get_local_addr(conn, &addrlen);
		CU_ASSERT_TRUE(addr != NULL);
		addr = pomp_conn_get_peer_addr(conn, &addrlen);
		CU_ASSERT_TRUE(addr != NULL);
		isunix = addr->sa_family == AF_UNIX;

		/* Invalid get addr (NULL param) */
		addr = pomp_conn_get_local_addr(NULL, &addrlen);
		CU_ASSERT_TRUE(addr == NULL);
		addr = pomp_conn_get_local_addr(conn, NULL);
		CU_ASSERT_TRUE(addr == NULL);
		addr = pomp_conn_get_peer_addr(NULL, &addrlen);
		CU_ASSERT_TRUE(addr == NULL);
		addr = pomp_conn_get_peer_addr(conn, NULL);
		CU_ASSERT_TRUE(addr == NULL);

		if (!isunix) {
			/* Invalid get credentials (bad type or NULL param) */
			cred = pomp_conn_get_peer_cred(conn);
			CU_ASSERT_TRUE(cred == NULL);
			cred = pomp_conn_get_peer_cred(NULL);
			CU_ASSERT_TRUE(cred == NULL);
		} else {
			cred = pomp_conn_get_peer_cred(conn);
			CU_ASSERT_TRUE(cred != NULL);
		}
		break;

	case POMP_EVENT_DISCONNECTED:
		data->disconnection++;
		break;

	case POMP_EVENT_MSG:
		data->msg++;
		if (pomp_msg_get_id(msg) == 1) {
			res = pomp_conn_send(conn, 2, "%s", eventstr);
			CU_ASSERT_EQUAL(res, 0);
		}

		if (data->isdgram) {
			res = pomp_conn_disconnect(conn);
			CU_ASSERT_EQUAL(res, -ENOTCONN);

			/* Internal function invalid arguments checks */
			res = pomp_conn_send_msg_to(NULL, msg, NULL, 0);
			CU_ASSERT_EQUAL(res, -EINVAL);
			res = pomp_conn_send_msg_to(conn, NULL, NULL, 0);
			CU_ASSERT_EQUAL(res, -EINVAL);
		} else {
			/* Internal function invalid arguments checks */
			res = pomp_conn_send_msg(NULL, msg);
			CU_ASSERT_EQUAL(res, -EINVAL);
			res = pomp_conn_send_msg(conn, NULL);
			CU_ASSERT_EQUAL(res, -EINVAL);
		}

		/* Internal function invalid arguments checks */
		res = pomp_ctx_notify_event(NULL, POMP_EVENT_CONNECTED, conn);
		CU_ASSERT_EQUAL(res, -EINVAL);
		res = pomp_ctx_notify_event(ctx, POMP_EVENT_MSG, conn);
		CU_ASSERT_EQUAL(res, -EINVAL);
		res = pomp_ctx_notify_event(ctx, POMP_EVENT_CONNECTED, NULL);
		CU_ASSERT_EQUAL(res, -EINVAL);
		res = pomp_ctx_notify_msg(NULL, conn, msg);
		CU_ASSERT_EQUAL(res, -EINVAL);
		res = pomp_ctx_notify_msg(ctx, NULL, msg);
		CU_ASSERT_EQUAL(res, -EINVAL);
		res = pomp_ctx_notify_msg(ctx, conn, NULL);
		CU_ASSERT_EQUAL(res, -EINVAL);
		break;

	default:
		CU_ASSERT_TRUE_FATAL(0);
		break;
	}
}
Esempio n. 5
0
void teste_DT_verificaNovaTela_Y () {
	Tela teste;

	teste = nova_tela();
	CU_ASSERT_TRUE(teste.y);
}
Esempio n. 6
0
void test_linkedlist_addremove()
{
    CPLinkedListRef list;
    CPLinkedListItemRef item0;
    CPLinkedListItemRef item1;
    CPLinkedListItemRef item2;

    // Add retains/remove releases
    _test_linkedlist_total_item_count = 0;
    list = CPLinkedListCreate(offsetof(CPLinkedListItem, prevItem), offsetof(CPLinkedListItem, nextItem));
    CU_ASSERT(list != NULL);
    item0 = CPLinkedListItemCreate();
    CU_ASSERT(item0 != NULL);
    CU_ASSERT(_test_linkedlist_total_item_count == 1);
    CU_ASSERT_TRUE(CPLinkedListAddItem(list, item0));
    CPRelease(item0);
    CU_ASSERT(_test_linkedlist_total_item_count == 1);
    CPLinkedListRemoveItem(list, CPLinkedListGetHead(list));
    CU_ASSERT(_test_linkedlist_total_item_count == 0);
    CPRelease(list);
    _test_linkedlist_total_item_count = 0;

    // Adding multiple times
    _test_linkedlist_total_item_count = 0;
    list = CPLinkedListCreate(offsetof(CPLinkedListItem, prevItem), offsetof(CPLinkedListItem, nextItem));
    CU_ASSERT(list != NULL);
    item0 = CPLinkedListItemCreate();
    CU_ASSERT(item0 != NULL);
    CU_ASSERT(_test_linkedlist_total_item_count == 1);
    CU_ASSERT_TRUE(CPLinkedListAddItem(list, item0));
    CU_ASSERT_FALSE(CPLinkedListAddItem(list, item0));
    CU_ASSERT(_test_linkedlist_total_item_count == 1);
    CPLinkedListRemoveItem(list, item0);
    CPRelease(item0);
    CU_ASSERT(_test_linkedlist_total_item_count == 0);
    CPRelease(list);
    _test_linkedlist_total_item_count = 0;

    // Removing multiple times
    _test_linkedlist_total_item_count = 0;
    list = CPLinkedListCreate(offsetof(CPLinkedListItem, prevItem), offsetof(CPLinkedListItem, nextItem));
    CU_ASSERT(list != NULL);
    item0 = CPLinkedListItemCreate();
    CU_ASSERT(item0 != NULL);
    CU_ASSERT(_test_linkedlist_total_item_count == 1);
    CU_ASSERT_TRUE(CPLinkedListAddItem(list, item0));
    CPLinkedListRemoveItem(list, item0);
    CPLinkedListRemoveItem(list, item0);
    CPRelease(item0);
    CU_ASSERT(_test_linkedlist_total_item_count == 0);
    CPRelease(list);
    _test_linkedlist_total_item_count = 0;

    // Remove all
    _test_linkedlist_total_item_count = 0;
    list = CPLinkedListCreate(offsetof(CPLinkedListItem, prevItem), offsetof(CPLinkedListItem, nextItem));
    CU_ASSERT(list != NULL);
    item0 = CPLinkedListItemCreate();
    CU_ASSERT(item0 != NULL);
    CU_ASSERT(_test_linkedlist_total_item_count == 1);
    item1 = CPLinkedListItemCreate();
    CU_ASSERT(item1 != NULL);
    CU_ASSERT(_test_linkedlist_total_item_count == 2);
    item2 = CPLinkedListItemCreate();
    CU_ASSERT(item2 != NULL);
    CU_ASSERT(_test_linkedlist_total_item_count == 3);
    CU_ASSERT_TRUE(CPLinkedListAddItem(list, item0));
    CU_ASSERT_TRUE(CPLinkedListAddItem(list, item1));
    CU_ASSERT_TRUE(CPLinkedListAddItem(list, item2));
    CU_ASSERT(CPLinkedListGetCount(list) == 3);
    CU_ASSERT(CPLinkedListGetHead(list) != NULL);
    CU_ASSERT(CPLinkedListGetTail(list) != NULL);
    CPLinkedListRemoveAllItems(list);
    CU_ASSERT(CPLinkedListGetCount(list) == 0);
    CU_ASSERT(CPLinkedListGetHead(list) == NULL);
    CU_ASSERT(CPLinkedListGetTail(list) == NULL);
    CPRelease(item2);
    CPRelease(item1);
    CPRelease(item0);
    CU_ASSERT(_test_linkedlist_total_item_count == 0);
    CPRelease(list);
    _test_linkedlist_total_item_count = 0;

    // Remove all releases
    _test_linkedlist_total_item_count = 0;
    list = CPLinkedListCreate(offsetof(CPLinkedListItem, prevItem), offsetof(CPLinkedListItem, nextItem));
    CU_ASSERT(list != NULL);
    item0 = CPLinkedListItemCreate();
    CU_ASSERT(item0 != NULL);
    CU_ASSERT(_test_linkedlist_total_item_count == 1);
    item1 = CPLinkedListItemCreate();
    CU_ASSERT(item1 != NULL);
    CU_ASSERT(_test_linkedlist_total_item_count == 2);
    item2 = CPLinkedListItemCreate();
    CU_ASSERT(item2 != NULL);
    CU_ASSERT(_test_linkedlist_total_item_count == 3);
    CU_ASSERT_TRUE(CPLinkedListAddItem(list, item0));
    CU_ASSERT_TRUE(CPLinkedListAddItem(list, item1));
    CU_ASSERT_TRUE(CPLinkedListAddItem(list, item2));
    CU_ASSERT(CPLinkedListGetCount(list) == 3);
    CU_ASSERT(CPLinkedListGetHead(list) != NULL);
    CU_ASSERT(CPLinkedListGetTail(list) != NULL);
    CPRelease(item2);
    CPRelease(item1);
    CPRelease(item0);
    CU_ASSERT(_test_linkedlist_total_item_count == 3);
    CPLinkedListRemoveAllItems(list);
    CU_ASSERT(CPLinkedListGetCount(list) == 0);
    CU_ASSERT(CPLinkedListGetHead(list) == NULL);
    CU_ASSERT(CPLinkedListGetTail(list) == NULL);
    CU_ASSERT(_test_linkedlist_total_item_count == 0);
    CPRelease(list);
    _test_linkedlist_total_item_count = 0;
}
Esempio n. 7
0
void
test_prin_report_caps_simple(void)
{
	int ret = 0;
	const unsigned long long key = rand_key();
	struct scsi_task *tsk;
	struct scsi_persistent_reserve_in_report_capabilities *rcaps;
	struct test_prin_report_caps_types *type;

	CHECK_FOR_DATALOSS;

	logging(LOG_VERBOSE, LOG_BLANK_LINE);
	logging(LOG_VERBOSE,
		"Test Persistent Reserve In REPORT CAPABILITIES works.");

	/* register our reservation key with the target */
	ret = prout_register_and_ignore(sd, key);
	if (ret == -2) {
		logging(LOG_NORMAL, "[SKIPPED] PERSISTENT RESERVE OUT is not implemented.");
		CU_PASS("PERSISTENT RESERVE OUT is not implemented.");
		return;
	}
	CU_ASSERT_EQUAL(ret, 0);

	ret = prin_report_caps(sd, &tsk, &rcaps);
	CU_ASSERT_EQUAL(ret, 0);

	logging(LOG_VERBOSE,
		"Checking PERSISTENT RESERVE IN REPORT CAPABILITIES fields.");
	CU_ASSERT_EQUAL(rcaps->length, 8);
	CU_ASSERT_TRUE(rcaps->allow_commands <= 5);
	CU_ASSERT_EQUAL(rcaps->persistent_reservation_type_mask
			& ~SCSI_PR_TYPE_MASK_ALL, 0);

	for (type = &report_caps_types_array[0]; type->mask != 0; type++) {
		if (!(rcaps->persistent_reservation_type_mask & type->mask)) {
			logging(LOG_NORMAL,
				"PERSISTENT RESERVE op 0x%x not supported",
				type->op);
			continue;
		}

		logging(LOG_VERBOSE,
			"PERSISTENT RESERVE OUT op 0x%x supported, testing",
			type->op);

		/* reserve the target */
		ret = prout_reserve(sd, key, type->op);
		CU_ASSERT_EQUAL(ret, 0);

		/* verify target reservation */
		ret = prin_verify_reserved_as(sd,
				pr_type_is_all_registrants(type->op) ? 0 : key,
				type->op);
		CU_ASSERT_EQUAL(0, ret);

		/* release the target */
		ret = prout_release(sd, key, type->op);
		CU_ASSERT_EQUAL(ret, 0);
	}

	scsi_free_scsi_task(tsk);
	rcaps = NULL;	/* freed with tsk */

	/* drop registration */
	ret = prout_register_key(sd, 0, key);
	CU_ASSERT_EQUAL(ret, 0);
}
void stack_some_pieces()
{
    int numberOfRows = 20;
    int numberOfColumns = 10;
    int delay = 500;
    int imove;
    TrnGame* game = trn_game_new(numberOfRows, numberOfColumns, delay);
    
    // TrnPiece 0. While the piece is falling:
    // Rotate it 3 times.
    for (imove = 0; imove < 3; imove++) {
        CU_ASSERT_TRUE( trn_game_try_to_move_down(game) );
        CU_ASSERT_TRUE( trn_game_try_to_rotate_clockwise(game) );
    }

    // Move piece to left.
    CU_ASSERT_TRUE( trn_game_try_to_move_down(game) );
    CU_ASSERT_TRUE( trn_game_try_to_move_left(game) );
    // Reach bottom.
    while (true) {
        if (! trn_game_try_to_move_down(game))
            break;
    }
    
    // TrnPiece 1. While the piece is falling:
    // Rotate it 1 times.
    CU_ASSERT_TRUE( trn_game_try_to_move_down(game) );
    CU_ASSERT_TRUE( trn_game_try_to_rotate_clockwise(game) );

    // Move piece to left.
    for (imove = 0; imove < 4; imove++) {
        CU_ASSERT_TRUE( trn_game_try_to_move_down(game) );
        CU_ASSERT_TRUE( trn_game_try_to_move_left(game) );
    }
    
    // Reach bottom.
    while (true) {
        if (! trn_game_try_to_move_down(game))
            break;
    }
    
    // TrnPiece 2. While the piece is falling:
    // Rotate it 1 times.
    CU_ASSERT_TRUE( trn_game_try_to_move_down(game) );
    CU_ASSERT_TRUE( trn_game_try_to_rotate_clockwise(game) );
    // Move piece to left.
    for (imove = 0; imove < 2; imove++) {
        CU_ASSERT_TRUE( trn_game_try_to_move_down(game) );
        CU_ASSERT_TRUE( trn_game_try_to_move_left(game) );
    }
    // Reach bottom.
    while (true) {
        if (! trn_game_try_to_move_down(game))
            break;
    }
    
    // TrnPiece 3. While the piece is falling:
    // Rotate it 3 times.
    for (imove = 0; imove < 3; imove++) {
        CU_ASSERT_TRUE( trn_game_try_to_move_down(game) );
        CU_ASSERT_TRUE( trn_game_try_to_rotate_clockwise(game) );
    }
    // Move piece to left.
    for (imove = 0; imove < 3; imove++) {
        CU_ASSERT_TRUE( trn_game_try_to_move_down(game) );
        CU_ASSERT_TRUE( trn_game_try_to_move_left(game) );
    }
    // Reach bottom.
    while (true) {
        if (! trn_game_try_to_move_down(game))
            break;
    }

    TrnGrid* expected_grid = trn_grid_new(numberOfRows, numberOfColumns);
    int rowIndex;
    int columnIndex;
    TrnPositionInGrid pos;

    // Expected expected_grid type for pieces 0 and 2
    for (rowIndex = numberOfRows-4 ; rowIndex < numberOfRows ; rowIndex++) {
        pos.rowIndex = rowIndex;
        for (columnIndex = 2 ; columnIndex < 4 ; columnIndex++) {
            pos.columnIndex = columnIndex;
            trn_grid_set_cell(expected_grid, pos, TRN_TETROMINO_J);
        }
    }

    // Expected expected_grid type for pieces 1 and 3
    for (rowIndex = numberOfRows-4 ; rowIndex < numberOfRows ; rowIndex++) {
        pos.rowIndex = rowIndex;
        for (columnIndex = 0 ; columnIndex < 2 ; columnIndex++) {
            pos.columnIndex = columnIndex;
            trn_grid_set_cell(expected_grid, pos, TRN_TETROMINO_L);
        }
    }

    // Expected next piece
    pos.rowIndex = 0;
    pos.columnIndex = 3;
    trn_grid_set_cell(expected_grid, pos, TRN_TETROMINO_J);
    pos.rowIndex = 1;
    for (columnIndex = 3 ; columnIndex < 6 ; columnIndex++) {
      pos.columnIndex = columnIndex;
      trn_grid_set_cell(expected_grid, pos, TRN_TETROMINO_J);
    }

    CU_ASSERT_TRUE( trn_grid_equal(game->grid, expected_grid) );

    trn_game_destroy(game);
}
Esempio n. 9
0
//--------------------------------------------------------------------------------------------------
void Testle_sms_ReceivedList()
{
    le_result_t              res;
    le_sms_MsgRef_t         myMsg;
    le_sms_MsgRef_t         lMsg1, lMsg2;
    le_sms_MsgListRef_t     receivedList;
    le_sms_Status_t         mystatus;

    myMsg = le_sms_Create();
    CU_ASSERT_PTR_NOT_NULL(myMsg);

    res=le_sms_SetDestination(myMsg, DEST_TEST_PATTERN);
    CU_ASSERT_EQUAL(res, LE_OK);

    res=le_sms_SetText(myMsg, TEXT_TEST_PATTERN);
    CU_ASSERT_EQUAL(res, LE_OK);

    res=le_sms_Send(myMsg);
    CU_ASSERT_NOT_EQUAL(res, LE_FAULT);
    CU_ASSERT_NOT_EQUAL(res, LE_FORMAT_ERROR);

    res=le_sms_Send(myMsg);
    CU_ASSERT_NOT_EQUAL(res, LE_FAULT);
    CU_ASSERT_NOT_EQUAL(res, LE_FORMAT_ERROR);
    if (res == LE_OK)
    {
        uint32_t i=0;

        fprintf(stderr, "\nPlease ensure that the device has received at least 2 messages, then press enter\n");
        while ( getchar() != '\n' );

        if ((res == LE_OK) && (i<10))
        {
            // List Received messages
            receivedList=le_sms_CreateRxMsgList();
            CU_ASSERT_PTR_NOT_NULL(receivedList);

            lMsg1=le_sms_GetFirst(receivedList);
            CU_ASSERT_PTR_NOT_NULL(lMsg1);
            if (lMsg1 != NULL)
            {
                mystatus=le_sms_GetStatus(lMsg1);
                CU_ASSERT_TRUE((mystatus==LE_SMS_RX_READ)||(mystatus==LE_SMS_RX_UNREAD));
                LE_INFO("-TEST- Delete Rx message 1.%p", lMsg1);
                le_sms_Delete(lMsg1);
            }

            lMsg2=le_sms_GetNext(receivedList);
            CU_ASSERT_PTR_NOT_NULL(lMsg2);
            if (lMsg2 != NULL)
            {
                mystatus=le_sms_GetStatus(lMsg2);
                CU_ASSERT_TRUE((mystatus==LE_SMS_RX_READ)||(mystatus==LE_SMS_RX_UNREAD));
                LE_INFO("-TEST- Delete Rx message 2.%p", lMsg2);
                le_sms_Delete(lMsg2);
            }

            LE_INFO("-TEST- Delete the ReceivedList");
            le_sms_DeleteList(receivedList);
        }
        else
        {
            LE_ERROR("-TEST- Unable to complete Testle_sms_ReceivedList Test");
        }
    }
    else
    {
        LE_ERROR("-TEST- Unable to complete Testle_sms_ReceivedList Test");
    }

    // Delete sent message
    le_sms_Delete(myMsg);
}
Esempio n. 10
0
static void presence_information(void) {
	const char *bike_description = "Riding my bike";
	const char *vacation_note = "I'm on vacation until July 4th";
	const char *vacation_lang = "en";
	const char *contact = "sip:[email protected]";
	LinphoneCoreManager *marie = presence_linphone_core_manager_new("marie");
	LinphoneCoreManager *pauline = presence_linphone_core_manager_new("pauline");
	LinphonePresenceModel *presence;
	LinphonePresenceActivity *activity = NULL;
	LinphonePresenceNote *note = NULL;
	const char *description = NULL;
	const char *note_content = NULL;
	char *contact2;
	time_t current_timestamp, presence_timestamp;

	CU_ASSERT_TRUE(subscribe_to_callee_presence(marie, pauline));

	/* Presence activity without description. */
	presence = linphone_presence_model_new_with_activity(LinphonePresenceActivityDinner, NULL);
	linphone_core_set_presence_model(pauline->lc, presence);
	wait_for(marie->lc,pauline->lc,&marie->stat.number_of_LinphonePresenceActivityDinner,1);
	CU_ASSERT_EQUAL(marie->stat.number_of_LinphonePresenceActivityDinner, 1);
	activity = linphone_presence_model_get_activity(marie->stat.last_received_presence);
	CU_ASSERT_PTR_NOT_NULL(activity);
	CU_ASSERT_EQUAL(linphone_presence_activity_get_type(activity), LinphonePresenceActivityDinner);
	description = linphone_presence_activity_get_description(activity);
	CU_ASSERT_PTR_NULL(description);

	/* Presence activity with description. */
	presence = linphone_presence_model_new_with_activity(LinphonePresenceActivitySteering, bike_description);
	linphone_core_set_presence_model(pauline->lc, presence);
	wait_for(marie->lc,pauline->lc,&marie->stat.number_of_LinphonePresenceActivitySteering,1);
	CU_ASSERT_EQUAL(marie->stat.number_of_LinphonePresenceActivitySteering, 1);
	activity = linphone_presence_model_get_activity(marie->stat.last_received_presence);
	CU_ASSERT_PTR_NOT_NULL(activity);
	CU_ASSERT_EQUAL(linphone_presence_activity_get_type(activity), LinphonePresenceActivitySteering);
	description = linphone_presence_activity_get_description(activity);
	CU_ASSERT_PTR_NOT_NULL(description);
	if (description != NULL) CU_ASSERT_EQUAL(strcmp(description, bike_description), 0);

	/* Presence activity with description and note. */
	presence = linphone_presence_model_new_with_activity_and_note(LinphonePresenceActivityVacation, NULL, vacation_note, vacation_lang);
	linphone_core_set_presence_model(pauline->lc, presence);
	wait_for(marie->lc,pauline->lc,&marie->stat.number_of_LinphonePresenceActivityVacation,1);
	CU_ASSERT_EQUAL(marie->stat.number_of_LinphonePresenceActivityVacation, 1);
	activity = linphone_presence_model_get_activity(marie->stat.last_received_presence);
	CU_ASSERT_PTR_NOT_NULL(activity);
	CU_ASSERT_EQUAL(linphone_presence_activity_get_type(activity), LinphonePresenceActivityVacation);
	description = linphone_presence_activity_get_description(activity);
	CU_ASSERT_PTR_NULL(description);
	note = linphone_presence_model_get_note(marie->stat.last_received_presence, NULL);
	CU_ASSERT_PTR_NOT_NULL(note);
	if (note != NULL) {
		note_content = linphone_presence_note_get_content(note);
		CU_ASSERT_PTR_NOT_NULL(note_content);
		if (note_content != NULL) {
			CU_ASSERT_EQUAL(strcmp(note_content, vacation_note), 0);
		}
	}

	/* Presence contact. */
	presence = linphone_presence_model_new_with_activity(LinphonePresenceActivityOnThePhone, NULL);
	linphone_presence_model_set_contact(presence, contact);
	linphone_core_set_presence_model(pauline->lc, presence);
	wait_for(marie->lc,pauline->lc,&marie->stat.number_of_LinphonePresenceActivityOnThePhone,1);
	CU_ASSERT_EQUAL(marie->stat.number_of_LinphonePresenceActivityOnThePhone, 1);
	contact2 = linphone_presence_model_get_contact(presence);
	CU_ASSERT_PTR_NOT_NULL(contact2);
	if (contact2 != NULL) {
		CU_ASSERT_EQUAL(strcmp(contact, contact2), 0);
		ms_free(contact2);
	}

	/* Presence timestamp. */
	current_timestamp = ms_time(NULL);
	presence = linphone_presence_model_new_with_activity(LinphonePresenceActivityShopping, NULL);
	linphone_core_set_presence_model(pauline->lc, presence);
	wait_for(marie->lc,pauline->lc,&marie->stat.number_of_LinphonePresenceActivityShopping,1);
	CU_ASSERT_EQUAL(marie->stat.number_of_LinphonePresenceActivityShopping, 1);
	presence_timestamp = linphone_presence_model_get_timestamp(presence);
	CU_ASSERT_TRUE(presence_timestamp >= current_timestamp);

	linphone_core_manager_destroy(marie);
	linphone_core_manager_destroy(pauline);
}
void TestGridCanSetCellsWithPiece()
{
    /* Reminder on tetromino_srs_i at TRN_ANGLE_0 and TRN_ANGLE_90:

    T---+---+---+---+
    |   |   |  9|   |   T: topLeftCorner position in grid
    +---+---+---+---+   0: tetromino cells a TRN_ANGLE_0
    | 0 | 0 | 01| 0 |   9: tetromino cells a TRN_ANGLE_90
    +---+---+---+---+
    |   |   |  9|   |
    +---+---+---+---+
    |   |   |  9|   |
    +---+---+---+---+
    */

    // Create a grid.
    int numberOfRows = 10;
    int numberOfColumns = 10;
    TrnGrid* grid = trn_grid_new(numberOfRows, numberOfColumns);

    // For now, the grid has only void cells.

    // Ok, in grid and void.
    TrnPiece piece0 = trn_piece_create(TRN_TETROMINO_I,0,0,TRN_ANGLE_0);
    CU_ASSERT_TRUE( trn_grid_can_set_cells_with_piece(grid, &piece0) )

    // Ok, still in grid (in the first row).
    TrnPiece piece1 = trn_piece_create(TRN_TETROMINO_I,-1,0,TRN_ANGLE_0);
    CU_ASSERT_TRUE( trn_grid_can_set_cells_with_piece(grid, &piece1) )

    // No more in grid.
    TrnPiece piece2 = trn_piece_create(TRN_TETROMINO_I,-2,0,TRN_ANGLE_0);
    CU_ASSERT_FALSE( trn_grid_can_set_cells_with_piece(grid, &piece2) )

    // Ok, in grid and void.
    TrnPiece piece3 = trn_piece_create(TRN_TETROMINO_I,5,0,TRN_ANGLE_90);
    CU_ASSERT_TRUE( trn_grid_can_set_cells_with_piece(grid, &piece3) )

    // Ok, still in grid (in the first column).
    TrnPiece piece4 = trn_piece_create(TRN_TETROMINO_I,5,-2,TRN_ANGLE_90);
    CU_ASSERT_TRUE( trn_grid_can_set_cells_with_piece(grid, &piece4) )

    // No more in grid.
    TrnPiece piece5 = trn_piece_create(TRN_TETROMINO_I,5,-3,TRN_ANGLE_90);
    CU_ASSERT_FALSE( trn_grid_can_set_cells_with_piece(grid, &piece5) )

    // Now, fill the last grid row with non-void tetrominos.
    TrnPositionInGrid pos;
    int columnIndex;
    pos.rowIndex = numberOfRows-1 ;
    for (columnIndex = 0 ; columnIndex < grid->numberOfColumns ; columnIndex++) {
        pos.columnIndex = columnIndex;
        trn_grid_set_cell(grid, pos, TRN_TETROMINO_I);
    }

    // Ok, in grid and void.
    TrnPiece piece6 = trn_piece_create(TRN_TETROMINO_I,0,0,TRN_ANGLE_90);
    CU_ASSERT_TRUE( trn_grid_can_set_cells_with_piece(grid, &piece6) )

    // Still in grid and void, just above the non-void row.
    TrnPiece piece7 = 
		trn_piece_create(TRN_TETROMINO_I,numberOfRows-5,0,TRN_ANGLE_90);
    CU_ASSERT_TRUE( trn_grid_can_set_cells_with_piece(grid, &piece7) )

    // In grid, but last cell of piece overlap a non-void cell of the grid.
    TrnPiece piece8 = 
		trn_piece_create(TRN_TETROMINO_I,numberOfRows-4,0,TRN_ANGLE_90);
    CU_ASSERT_FALSE( trn_grid_can_set_cells_with_piece(grid, &piece8) )
}
Esempio n. 12
0
void teste_DT_Novo_Bloco_Y(void)
{
	Bloco resultado;
	resultado = novo_bloco(2,3, INVISIVEL);
	CU_ASSERT_TRUE (resultado.y == 3);
}
Esempio n. 13
0
void teste_DT_Novo_Bloco_Tipo_Quadrado(void)
{
	Bloco resultado;
	resultado = novo_bloco(2,3, QUADRADO);
	CU_ASSERT_TRUE (resultado.tipo == QUADRADO);
}
Esempio n. 14
0
void teste_DT_Novo_Bloco_Tipo_Invisivel(void)
{
	Bloco resultado;
	resultado = novo_bloco(2,3, INVISIVEL);
	CU_ASSERT_TRUE (resultado.tipo == INVISIVEL);
}
Esempio n. 15
0
/* Teste letra maiuscula */
void teste_DT_ProximaLetra_Z(void) {
	char resultado;
	resultado = ProximaLetra('Z');
	CU_ASSERT_TRUE( resultado == 'A' );
}
Esempio n. 16
0
static void testRange (void)
{
	CU_ASSERT_TRUE(EV_NUM_EVENTS < EVENT_INSTANTLY);
}
Esempio n. 17
0
//--------------------------------------------------------------------------------------------------
void TestInteractivele_sim_Authentication()
{
    le_result_t     res;
    bool            ready=false;
    int32_t         initTries=0;
    int32_t         tries=0;
    le_sim_ObjRef_t simRef;
    uint32_t        i=1;
    bool            pinReq=true;
    char            internalPin[2][16];
    le_sim_States_t state;

    getCodes();

    do
    {
        fprintf(stderr, "\nTake off, then insert SIM card.%d, wait for +WIND:1 (approx. 2s) and then press enter \n", i);
        while ( getchar() != '\n' );

        simRef = le_sim_Create(i);
        CU_ASSERT_PTR_NOT_NULL(simRef);

        state = le_sim_GetState(simRef);
        displaySIMState(state, i);
        fprintf(stderr, "\nPress enter to continue...\n");
        while ( getchar() != '\n' );

        strcpy((char*)&internalPin[i-1][0], (char*)&PIN_TEST[i-1][0]);

        // Enter PIN
        if(state == LE_SIM_READY)
        {
            pinReq=false;
            // Lock PIN
            res = le_sim_Lock(simRef, PIN_TOO_LONG_TEST);
            CU_ASSERT_EQUAL(res, LE_OVERFLOW);
            res = le_sim_Lock(simRef, PIN_TOO_SHORT_TEST);
            CU_ASSERT_EQUAL(res, LE_UNDERFLOW);
            res = le_sim_Lock(simRef, FAIL_PIN_TEST);
            CU_ASSERT_EQUAL(res, LE_NOT_POSSIBLE);
            res = le_sim_Lock(simRef, (char*)&internalPin[i-1][0]);
            CU_ASSERT_EQUAL(res, LE_OK);
            fprintf(stderr, "\nle_sim_Lock, res.%d  (should be LE_OK=0)\n", res);
            fprintf(stderr, "\nTake off, then insert SIM card.%d, wait for +WIND:1 (approx. 2s) and then press enter \n", i);
            while ( getchar() != '\n' );
        }

        initTries=le_sim_GetRemainingPINTries(simRef);
        res = le_sim_EnterPIN(simRef, PIN_TOO_LONG_TEST);
        CU_ASSERT_EQUAL(res, LE_OVERFLOW);
        res = le_sim_EnterPIN(simRef, PIN_TOO_SHORT_TEST);
        CU_ASSERT_EQUAL(res, LE_UNDERFLOW);
        res = le_sim_EnterPIN(simRef, FAIL_PIN_TEST);
        CU_ASSERT_EQUAL(res, LE_NOT_POSSIBLE);

        tries=le_sim_GetRemainingPINTries(simRef);
        CU_ASSERT_TRUE((initTries-tries == 1));

        ready=le_sim_IsReady(simRef);
        CU_ASSERT_FALSE(ready);

        res = le_sim_EnterPIN(simRef, (char*)&internalPin[i-1][0]);
        CU_ASSERT_EQUAL(res, LE_OK);

        ready=le_sim_IsReady(simRef);
        CU_ASSERT_TRUE(ready);
#if 0
        if (ready != true)
        {
            LE_FATAL("SIM card.%d NOT READY ! check it, test exits !", i);
        }
#endif
        fprintf(stderr, "\nle_sim_EnterPIN, res.%d (should be LE_OK=0) \n", res);
        fprintf(stderr, "\nWait for SIM card.%d answer (+CREG: 1, approx. 2s) and then press enter \n", i);
        while ( getchar() != '\n' );

        // Change PIN
        res = le_sim_ChangePIN(simRef, PIN_TOO_LONG_TEST, NEW_PIN_TEST);
        CU_ASSERT_EQUAL(res, LE_OVERFLOW);
        res = le_sim_ChangePIN(simRef, (char*)&internalPin[i-1][0], PIN_TOO_LONG_TEST);
        CU_ASSERT_EQUAL(res, LE_OVERFLOW);
        res = le_sim_ChangePIN(simRef, PIN_TOO_SHORT_TEST, NEW_PIN_TEST);
        CU_ASSERT_EQUAL(res, LE_UNDERFLOW);
        res = le_sim_ChangePIN(simRef, (char*)&internalPin[i-1][0], PIN_TOO_SHORT_TEST);
        CU_ASSERT_EQUAL(res, LE_UNDERFLOW);
        res = le_sim_ChangePIN(simRef, FAIL_PIN_TEST, NEW_PIN_TEST);
        CU_ASSERT_EQUAL(res, LE_NOT_POSSIBLE);
        res = le_sim_ChangePIN(simRef, (char*)&internalPin[i-1][0], NEW_PIN_TEST);
        CU_ASSERT_EQUAL(res, LE_OK);

        fprintf(stderr, "\nle_sim_ChangePIN, res.%d (should be LE_OK=0)\n", res);
        fprintf(stderr, "\nTake off, then insert SIM card.%d, wait for +WIND:1 (approx. 2s) and then press enter \n", i);
        while ( getchar() != '\n' );

        // Unblock PIN
        while((initTries=le_sim_GetRemainingPINTries(simRef))>0)
        {
            res = le_sim_EnterPIN(simRef, FAIL_PIN_TEST);
        }

        if(initTries < 0)
        {
            fprintf(stderr, "\nle_sim_GetRemainingPINTries error, res.%d (should be >=0)\n", initTries);
        }

        res = le_sim_Unblock(simRef, (char*)&PUK_TEST[i-1][0], PIN_TOO_LONG_TEST);
        CU_ASSERT_EQUAL(res, LE_OVERFLOW);
        res = le_sim_Unblock(simRef, (char*)&PUK_TEST[i-1][0], PIN_TOO_SHORT_TEST);
        CU_ASSERT_EQUAL(res, LE_UNDERFLOW);
        res = le_sim_Unblock(simRef, PUK_BAD_LENGTH_TEST, NEW_PIN_TEST);
        CU_ASSERT_EQUAL(res, LE_OUT_OF_RANGE);
        res = le_sim_Unblock(simRef, FAIL_PUK_TEST, NEW_PIN_TEST);
        CU_ASSERT_EQUAL(res, LE_NOT_POSSIBLE);
        res = le_sim_Unblock(simRef, (char*)&PUK_TEST[i-1][0], (char*)&internalPin[i-1][0]);
        CU_ASSERT_EQUAL(res, LE_OK);

        fprintf(stderr, "\nle_sim_Unblock, res.%d  (should be LE_OK=0), press enter to continue \n", res);
        while ( getchar() != '\n' );

        // Unlock PIN
        res = le_sim_Unlock(simRef, PIN_TOO_LONG_TEST);
        CU_ASSERT_EQUAL(res, LE_OVERFLOW);
        res = le_sim_Unlock(simRef, PIN_TOO_SHORT_TEST);
        CU_ASSERT_EQUAL(res, LE_UNDERFLOW);
        res = le_sim_Unlock(simRef, FAIL_PIN_TEST);
        CU_ASSERT_EQUAL(res, LE_NOT_POSSIBLE);
        res = le_sim_Unlock(simRef, (char*)&internalPin[i-1][0]);
        CU_ASSERT_EQUAL(res, LE_OK);

        fprintf(stderr, "\nle_sim_Unlock, res.%d  (should be LE_OK=0), press enter to continue  \n", res);
        while ( getchar() != '\n' );

        // Re-lock the SIM card
        if (pinReq)
        {
            res = le_sim_Lock(simRef, (char*)&internalPin[i-1][0]);
            CU_ASSERT_EQUAL(res, LE_OK);
        }

        le_sim_Delete(simRef);
        i++;
    } while (i<=le_sim_CountSlots());

    // Test case for SIM card absent: executed only on first slot
    simRef = le_sim_Create(1);
    CU_ASSERT_PTR_NOT_NULL(simRef);

    fprintf(stderr, "Take off SIM card.1 and then press enter \n");
    while ( getchar() != '\n' );

    // Enter PIN
    initTries=le_sim_GetRemainingPINTries(simRef);
    CU_ASSERT_TRUE((initTries == LE_NOT_FOUND) || (initTries == LE_NOT_POSSIBLE));

    res = le_sim_EnterPIN(simRef, PIN_TEMP);
    CU_ASSERT_TRUE((res == LE_NOT_FOUND) || (res == LE_NOT_POSSIBLE));

    ready=le_sim_IsReady(simRef);
    CU_ASSERT_FALSE(ready);

    // Change PIN
    res = le_sim_ChangePIN(simRef, PIN_TEMP, NEW_PIN_TEST);
    CU_ASSERT_TRUE((res == LE_NOT_FOUND) || (res == LE_NOT_POSSIBLE));

    // Unblock PIN
    res = le_sim_Unblock(simRef, (char*)&PUK_TEST[0][0], PIN_TEMP);
    CU_ASSERT_TRUE((res == LE_NOT_FOUND) || (res == LE_NOT_POSSIBLE));

    // Unlock PIN
    res = le_sim_Unlock(simRef, PIN_TEMP);
    CU_ASSERT_TRUE((res == LE_NOT_FOUND) || (res == LE_NOT_POSSIBLE));

    le_sim_Delete(simRef);

    fprintf(stderr, "Insert SIM card.1, wait for +WIND:1 (approx. 2s) and then press enter \n");
    while ( getchar() != '\n' );
}
static void early_media_with_multicast_base(bool_t video) {
	LinphoneCoreManager *marie, *pauline, *pauline2;
	MSList* lcs = NULL;
	int dummy=0;
	int leaked_objects;
	int begin;
	LinphoneVideoPolicy marie_policy, pauline_policy;
	LpConfig *marie_lp;

	belle_sip_object_enable_leak_detector(TRUE);
	begin=belle_sip_object_get_object_count();
	marie   = linphone_core_manager_new("marie_rc");
	pauline = linphone_core_manager_new("pauline_rc");
	pauline2 = linphone_core_manager_new("pauline_rc");

	marie_lp=linphone_core_get_config(marie->lc);
	lp_config_set_int(marie_lp,"misc","real_early_media",1);

	if (video) {
		linphone_core_enable_video_capture(pauline->lc, FALSE);
		linphone_core_enable_video_display(pauline->lc, TRUE);
		linphone_core_enable_video_capture(pauline2->lc, FALSE);
		linphone_core_enable_video_display(pauline2->lc, TRUE);
		linphone_core_enable_video_capture(marie->lc, TRUE);
		linphone_core_enable_video_display(marie->lc, FALSE);

		marie_policy.automatically_initiate=TRUE;
		marie_policy.automatically_accept=TRUE;
		pauline_policy.automatically_initiate=TRUE;
		pauline_policy.automatically_accept=TRUE;

		linphone_core_set_video_policy(marie->lc,&marie_policy);
		linphone_core_set_video_policy(pauline->lc,&pauline_policy);
		linphone_core_set_video_policy(pauline2->lc,&pauline_policy);
		linphone_core_set_video_multicast_addr(marie->lc,"224.1.2.3");
		linphone_core_enable_video_multicast(marie->lc,TRUE);
	}
	linphone_core_set_audio_multicast_addr(marie->lc,"224.1.2.3");
	linphone_core_enable_audio_multicast(marie->lc,TRUE);


	lcs = ms_list_append(lcs,marie->lc);
	lcs = ms_list_append(lcs,pauline->lc);
	lcs = ms_list_append(lcs,pauline2->lc);
	/*
		Marie calls Pauline, and after the call has rung, transitions to an early_media session
	*/

	linphone_core_invite_address(marie->lc, pauline->identity);

	CU_ASSERT_TRUE(wait_for_list(lcs, &pauline->stat.number_of_LinphoneCallIncomingReceived,1,3000));
	CU_ASSERT_TRUE(wait_for_list(lcs, &marie->stat.number_of_LinphoneCallOutgoingRinging,1,1000));


	if (linphone_core_inc_invite_pending(pauline->lc)) {
		/* send a 183 to initiate the early media */
		if (video) {
			/*check video path*/
			linphone_call_set_next_video_frame_decoded_callback(linphone_core_get_current_call(pauline->lc),linphone_call_cb,pauline->lc);
		}
		linphone_core_accept_early_media(pauline->lc, linphone_core_get_current_call(pauline->lc));

		CU_ASSERT_TRUE( wait_for_list(lcs, &pauline->stat.number_of_LinphoneCallIncomingEarlyMedia,1,2000) );
		CU_ASSERT_TRUE( wait_for_list(lcs, &marie->stat.number_of_LinphoneCallOutgoingEarlyMedia,1,2000) );

		if (linphone_core_inc_invite_pending(pauline2->lc)) {
				/* send a 183 to initiate the early media */
				if (video) {
					/*check video path*/
					linphone_call_set_next_video_frame_decoded_callback(linphone_core_get_current_call(pauline2->lc),linphone_call_cb,pauline2->lc);
				}
				linphone_core_accept_early_media(pauline2->lc, linphone_core_get_current_call(pauline2->lc));

				CU_ASSERT_TRUE( wait_for_list(lcs, &pauline2->stat.number_of_LinphoneCallIncomingEarlyMedia,1,2000) );
		}

		wait_for_list(lcs, &dummy, 1, 3000);

		CU_ASSERT_TRUE(linphone_call_get_audio_stats(linphone_core_get_current_call(pauline->lc))->download_bandwidth>70);
		CU_ASSERT_TRUE(linphone_call_get_audio_stats(linphone_core_get_current_call(pauline->lc))->download_bandwidth<90);

		CU_ASSERT_TRUE(linphone_call_get_audio_stats(linphone_core_get_current_call(pauline2->lc))->download_bandwidth>70);
		CU_ASSERT_TRUE(linphone_call_get_audio_stats(linphone_core_get_current_call(pauline2->lc))->download_bandwidth<90);


		if (video) {
			CU_ASSERT_TRUE( wait_for_list(lcs,&pauline->stat.number_of_IframeDecoded,1,2000));
			CU_ASSERT_TRUE( wait_for_list(lcs,&pauline2->stat.number_of_IframeDecoded,1,2000));
		}

		linphone_core_accept_call(pauline->lc, linphone_core_get_current_call(pauline->lc));

		CU_ASSERT_TRUE(wait_for_list(lcs, &marie->stat.number_of_LinphoneCallConnected, 1,1000));
		CU_ASSERT_TRUE(wait_for_list(lcs, &marie->stat.number_of_LinphoneCallStreamsRunning, 1,1000));

		linphone_core_update_call(	pauline->lc
									, linphone_core_get_current_call(pauline->lc)
									, linphone_call_get_current_params(linphone_core_get_current_call(pauline->lc)));

		CU_ASSERT_TRUE(wait_for_list(lcs, &marie->stat.number_of_LinphoneCallStreamsRunning, 2,1000));

		end_call(marie,pauline);
	}
	ms_free(lcs);
	linphone_core_manager_destroy(marie);
	linphone_core_manager_destroy(pauline);
	linphone_core_manager_destroy(pauline2);

	leaked_objects=belle_sip_object_get_object_count()-begin;
	CU_ASSERT_EQUAL(leaked_objects,0);
	if (leaked_objects>0){
		belle_sip_object_dump_active_objects();
	}
	belle_sip_object_enable_leak_detector(FALSE);
}
Esempio n. 19
0
void test_linkedlist_gets()
{
    CPLinkedListRef list;
    CPLinkedListItemRef item0;
    CPLinkedListItemRef item1;
    CPLinkedListItemRef item2;

    // Add 1 item
    _test_linkedlist_total_item_count = 0;
    list = CPLinkedListCreate(offsetof(CPLinkedListItem, prevItem), offsetof(CPLinkedListItem, nextItem));
    CU_ASSERT(list != NULL);
    CU_ASSERT(CPLinkedListGetCount(list) == 0);
    CU_ASSERT(CPLinkedListGetHead(list) == NULL);
    CU_ASSERT(CPLinkedListGetTail(list) == NULL);
    item0 = CPLinkedListItemCreate();
    CU_ASSERT(item0 != NULL);
    CU_ASSERT(_test_linkedlist_total_item_count == 1);
    CU_ASSERT_TRUE(CPLinkedListAddItem(list, item0));
    CU_ASSERT(CPLinkedListPrevItem(list, item0) == NULL);
    CU_ASSERT(CPLinkedListNextItem(list, item0) == NULL);
    CU_ASSERT(CPLinkedListGetCount(list) == 1);
    CU_ASSERT(CPLinkedListGetHead(list) == item0);
    CU_ASSERT(CPLinkedListGetTail(list) == item0);
    CPLinkedListRemoveItem(list, item0);
    CU_ASSERT(CPLinkedListPrevItem(list, item0) == NULL);
    CU_ASSERT(CPLinkedListNextItem(list, item0) == NULL);
    CU_ASSERT(CPLinkedListGetCount(list) == 0);
    CU_ASSERT(CPLinkedListGetHead(list) == NULL);
    CU_ASSERT(CPLinkedListGetTail(list) == NULL);
    CPRelease(item0);
    CPRelease(list);
    CU_ASSERT(_test_linkedlist_total_item_count == 0);
    _test_linkedlist_total_item_count = 0;

    // Add 2 items
    _test_linkedlist_total_item_count = 0;
    list = CPLinkedListCreate(offsetof(CPLinkedListItem, prevItem), offsetof(CPLinkedListItem, nextItem));
    CU_ASSERT(list != NULL);
    CU_ASSERT(CPLinkedListGetCount(list) == 0);
    CU_ASSERT(CPLinkedListGetHead(list) == NULL);
    CU_ASSERT(CPLinkedListGetTail(list) == NULL);
    item0 = CPLinkedListItemCreate();
    CU_ASSERT(item0 != NULL);
    CU_ASSERT(_test_linkedlist_total_item_count == 1);
    item1 = CPLinkedListItemCreate();
    CU_ASSERT(item1 != NULL);
    CU_ASSERT(_test_linkedlist_total_item_count == 2);
    CU_ASSERT_TRUE(CPLinkedListAddItem(list, item0));
    CU_ASSERT(CPLinkedListPrevItem(list, item0) == NULL);
    CU_ASSERT(CPLinkedListNextItem(list, item0) == NULL);
    CU_ASSERT(CPLinkedListPrevItem(list, item1) == NULL);
    CU_ASSERT(CPLinkedListNextItem(list, item1) == NULL);
    CU_ASSERT(CPLinkedListGetCount(list) == 1);
    CU_ASSERT(CPLinkedListGetHead(list) == item0);
    CU_ASSERT(CPLinkedListGetTail(list) == item0);
    CU_ASSERT_TRUE(CPLinkedListAddItem(list, item1));
    CU_ASSERT(CPLinkedListPrevItem(list, item0) == NULL);
    CU_ASSERT(CPLinkedListNextItem(list, item0) == item1);
    CU_ASSERT(CPLinkedListPrevItem(list, item1) == item0);
    CU_ASSERT(CPLinkedListNextItem(list, item1) == NULL);
    CU_ASSERT(CPLinkedListGetCount(list) == 2);
    CU_ASSERT(CPLinkedListGetHead(list) == item0);
    CU_ASSERT(CPLinkedListGetTail(list) == item1);
    CPLinkedListRemoveItem(list, item1);
    CU_ASSERT(CPLinkedListPrevItem(list, item0) == NULL);
    CU_ASSERT(CPLinkedListNextItem(list, item0) == NULL);
    CU_ASSERT(CPLinkedListPrevItem(list, item1) == NULL);
    CU_ASSERT(CPLinkedListNextItem(list, item1) == NULL);
    CU_ASSERT(CPLinkedListGetCount(list) == 1);
    CU_ASSERT(CPLinkedListGetHead(list) == item0);
    CU_ASSERT(CPLinkedListGetTail(list) == item0);
    CPLinkedListRemoveItem(list, item0);
    CU_ASSERT(CPLinkedListPrevItem(list, item0) == NULL);
    CU_ASSERT(CPLinkedListNextItem(list, item0) == NULL);
    CU_ASSERT(CPLinkedListGetCount(list) == 0);
    CU_ASSERT(CPLinkedListGetHead(list) == NULL);
    CU_ASSERT(CPLinkedListGetTail(list) == NULL);
    CPRelease(item1);
    CPRelease(item0);
    CPRelease(list);
    CU_ASSERT(_test_linkedlist_total_item_count == 0);
    _test_linkedlist_total_item_count = 0;

    // Add 3 and remove out of order
    _test_linkedlist_total_item_count = 0;
    list = CPLinkedListCreate(offsetof(CPLinkedListItem, prevItem), offsetof(CPLinkedListItem, nextItem));
    CU_ASSERT(list != NULL);
    CU_ASSERT(CPLinkedListGetCount(list) == 0);
    CU_ASSERT(CPLinkedListGetHead(list) == NULL);
    CU_ASSERT(CPLinkedListGetTail(list) == NULL);
    item0 = CPLinkedListItemCreate();
    CU_ASSERT(item0 != NULL);
    CU_ASSERT(_test_linkedlist_total_item_count == 1);
    item1 = CPLinkedListItemCreate();
    CU_ASSERT(item1 != NULL);
    CU_ASSERT(_test_linkedlist_total_item_count == 2);
    item2 = CPLinkedListItemCreate();
    CU_ASSERT(item2 != NULL);
    CU_ASSERT(_test_linkedlist_total_item_count == 3);
    CU_ASSERT_TRUE(CPLinkedListAddItem(list, item0));
    CU_ASSERT(CPLinkedListPrevItem(list, item0) == NULL);
    CU_ASSERT(CPLinkedListNextItem(list, item0) == NULL);
    CU_ASSERT(CPLinkedListPrevItem(list, item1) == NULL);
    CU_ASSERT(CPLinkedListNextItem(list, item1) == NULL);
    CU_ASSERT(CPLinkedListPrevItem(list, item2) == NULL);
    CU_ASSERT(CPLinkedListNextItem(list, item2) == NULL);
    CU_ASSERT(CPLinkedListGetCount(list) == 1);
    CU_ASSERT(CPLinkedListGetHead(list) == item0);
    CU_ASSERT(CPLinkedListGetTail(list) == item0);
    CU_ASSERT_TRUE(CPLinkedListAddItem(list, item1));
    CU_ASSERT(CPLinkedListPrevItem(list, item0) == NULL);
    CU_ASSERT(CPLinkedListNextItem(list, item0) == item1);
    CU_ASSERT(CPLinkedListPrevItem(list, item1) == item0);
    CU_ASSERT(CPLinkedListNextItem(list, item1) == NULL);
    CU_ASSERT(CPLinkedListPrevItem(list, item2) == NULL);
    CU_ASSERT(CPLinkedListNextItem(list, item2) == NULL);
    CU_ASSERT(CPLinkedListGetCount(list) == 2);
    CU_ASSERT(CPLinkedListGetHead(list) == item0);
    CU_ASSERT(CPLinkedListGetTail(list) == item1);
    CU_ASSERT_TRUE(CPLinkedListAddItem(list, item2));
    CU_ASSERT(CPLinkedListPrevItem(list, item0) == NULL);
    CU_ASSERT(CPLinkedListNextItem(list, item0) == item1);
    CU_ASSERT(CPLinkedListPrevItem(list, item1) == item0);
    CU_ASSERT(CPLinkedListNextItem(list, item1) == item2);
    CU_ASSERT(CPLinkedListPrevItem(list, item2) == item1);
    CU_ASSERT(CPLinkedListNextItem(list, item2) == NULL);
    CU_ASSERT(CPLinkedListGetCount(list) == 3);
    CU_ASSERT(CPLinkedListGetHead(list) == item0);
    CU_ASSERT(CPLinkedListGetTail(list) == item2);
    CPLinkedListRemoveItem(list, item1);
    CU_ASSERT(CPLinkedListPrevItem(list, item0) == NULL);
    CU_ASSERT(CPLinkedListNextItem(list, item0) == item2);
    CU_ASSERT(CPLinkedListPrevItem(list, item1) == NULL);
    CU_ASSERT(CPLinkedListNextItem(list, item1) == NULL);
    CU_ASSERT(CPLinkedListPrevItem(list, item2) == item0);
    CU_ASSERT(CPLinkedListNextItem(list, item2) == NULL);
    CU_ASSERT(CPLinkedListGetCount(list) == 2);
    CU_ASSERT(CPLinkedListGetHead(list) == item0);
    CU_ASSERT(CPLinkedListGetTail(list) == item2);
    CPLinkedListRemoveItem(list, item0);
    CU_ASSERT(CPLinkedListPrevItem(list, item0) == NULL);
    CU_ASSERT(CPLinkedListNextItem(list, item0) == NULL);
    CU_ASSERT(CPLinkedListPrevItem(list, item2) == NULL);
    CU_ASSERT(CPLinkedListNextItem(list, item2) == NULL);
    CU_ASSERT(CPLinkedListGetCount(list) == 1);
    CU_ASSERT(CPLinkedListGetHead(list) == item2);
    CU_ASSERT(CPLinkedListGetTail(list) == item2);
    CPLinkedListRemoveItem(list, item2);
    CU_ASSERT(CPLinkedListPrevItem(list, item2) == NULL);
    CU_ASSERT(CPLinkedListNextItem(list, item2) == NULL);
    CU_ASSERT(CPLinkedListGetCount(list) == 0);
    CU_ASSERT(CPLinkedListGetHead(list) == NULL);
    CU_ASSERT(CPLinkedListGetTail(list) == NULL);
    CPRelease(item2);
    CPRelease(item1);
    CPRelease(item0);
    CPRelease(list);
    CU_ASSERT(_test_linkedlist_total_item_count == 0);
    _test_linkedlist_total_item_count = 0;
}
Esempio n. 20
0
void test_Empty(void) {
	CU_ASSERT_TRUE(Empty(getEmptyString()));
	CU_ASSERT_FALSE(Empty(getTestString()));
}
Esempio n. 21
0
static void test_ctx(const struct sockaddr *addr1, uint32_t addrlen1,
		const struct sockaddr *addr2, uint32_t addrlen2,
		int isdgram, int israw, int withsockcb, int withsendcb)
{
	int res = 0;
	struct test_data data;
	struct pomp_loop *loop = NULL;
	struct pomp_conn *conn = NULL;
	struct pomp_msg *msg = NULL;
	int fd = -1;
	uint32_t i = 0, j = 0;
	struct pomp_buffer *buf = NULL;

	memset(&data, 0, sizeof(data));
	data.isdgram = isdgram;
	data.israw = israw;
	data.srv.addr = addr1;
	data.srv.addrlen = addrlen1;
	data.cli.addr = addr2;
	data.cli.addrlen = addrlen2;
	msg = pomp_msg_new();
	CU_ASSERT_PTR_NOT_NULL_FATAL(msg);

	/* Create context */
	data.srv.ctx = pomp_ctx_new(&test_event_cb_t, &data);
	CU_ASSERT_PTR_NOT_NULL_FATAL(data.srv.ctx);
	if (israw) {
		res = pomp_ctx_set_raw(data.srv.ctx, &test_ctx_raw_cb);
		CU_ASSERT_EQUAL(res, 0);
	}
	if (withsockcb) {
		res = pomp_ctx_set_socket_cb(data.srv.ctx, &test_ctx_socket_cb);
		CU_ASSERT_EQUAL(res, 0);
	}
	if (withsendcb) {
		res = pomp_ctx_set_send_cb(data.srv.ctx, &test_ctx_send_cb);
		CU_ASSERT_EQUAL(res, 0);
	}

	/* Create context without callback */
	data.cli.ctx = pomp_ctx_new(NULL, &data);
	CU_ASSERT_PTR_NOT_NULL_FATAL(data.cli.ctx);
	res = pomp_ctx_destroy(data.cli.ctx);
	CU_ASSERT_EQUAL(res, 0);

	/* Invalid create (NULL 3nd arg) */
	data.cli.ctx = pomp_ctx_new_with_loop(NULL, &data, NULL);
	CU_ASSERT_PTR_NULL(data.cli.ctx);
	data.cli.ctx = pomp_ctx_new_with_loop(&test_event_cb_t, &data, NULL);
	CU_ASSERT_PTR_NULL(data.cli.ctx);

	/* Create 2nd context */
	data.cli.ctx = pomp_ctx_new(&test_event_cb_t, &data);
	CU_ASSERT_PTR_NOT_NULL_FATAL(data.cli.ctx);
	if (israw) {
		res = pomp_ctx_set_raw(data.cli.ctx, &test_ctx_raw_cb);
		CU_ASSERT_EQUAL(res, 0);
	}
	if (withsockcb) {
		res = pomp_ctx_set_socket_cb(data.cli.ctx, &test_ctx_socket_cb);
		CU_ASSERT_EQUAL(res, 0);
	}
	if (withsendcb) {
		res = pomp_ctx_set_send_cb(data.cli.ctx, &test_ctx_send_cb);
		CU_ASSERT_EQUAL(res, 0);
	}

	if (!isdgram) {
		/* Invalid start server (NULL param) */
		res = pomp_ctx_listen(NULL, addr1, addrlen1);
		CU_ASSERT_EQUAL(res, -EINVAL);
		res = pomp_ctx_listen(data.srv.ctx, NULL, addrlen1);
		CU_ASSERT_EQUAL(res, -EINVAL);

		/* Start as server 1st context */
		res = pomp_ctx_listen(data.srv.ctx, addr1, addrlen1);
		CU_ASSERT_EQUAL(res, 0);

		/* Invalid start server (busy) */
		res = pomp_ctx_listen(data.srv.ctx, addr1, addrlen1);
		CU_ASSERT_EQUAL(res, -EBUSY);
	} else {
		/* Invalid bind (NULL param) */
		res = pomp_ctx_bind(NULL, addr1, addrlen1);
		CU_ASSERT_EQUAL(res, -EINVAL);
		res = pomp_ctx_bind(data.srv.ctx, NULL, addrlen1);
		CU_ASSERT_EQUAL(res, -EINVAL);

		/* Bind 1st context */
		res = pomp_ctx_bind(data.srv.ctx, addr1, addrlen1);
		CU_ASSERT_EQUAL(res, 0);

		/* Invalid bind (busy) */
		res = pomp_ctx_bind(data.srv.ctx, addr1, addrlen1);
		CU_ASSERT_EQUAL(res, -EBUSY);
	}

	if (!isdgram) {
		/* Invalid start client (NULL param) */
		res = pomp_ctx_connect(NULL, addr2, addrlen2);
		CU_ASSERT_EQUAL(res, -EINVAL);
		res = pomp_ctx_connect(data.cli.ctx, NULL, addrlen2);
		CU_ASSERT_EQUAL(res, -EINVAL);

		/* Start as client 2nd context */
		res = pomp_ctx_connect(data.cli.ctx, addr2, addrlen2);
		CU_ASSERT_EQUAL(res, 0);

		/* Invalid start client (busy) */
		res = pomp_ctx_connect(data.cli.ctx, addr2, addrlen2);
		CU_ASSERT_EQUAL(res, -EBUSY);
	} else {
		/* Invalid bind (NULL param) */
		res = pomp_ctx_bind(NULL, addr2, addrlen2);
		CU_ASSERT_EQUAL(res, -EINVAL);
		res = pomp_ctx_bind(data.cli.ctx, NULL, addrlen2);
		CU_ASSERT_EQUAL(res, -EINVAL);

		/* Bind 2nd context */
		res = pomp_ctx_bind(data.cli.ctx, addr2, addrlen2);
		CU_ASSERT_EQUAL(res, 0);

		/* Invalid bind (busy) */
		res = pomp_ctx_bind(data.cli.ctx, addr2, addrlen2);
		CU_ASSERT_EQUAL(res, -EBUSY);
	}

	/* Invalid set raw */
	res = pomp_ctx_set_raw(NULL, &test_ctx_raw_cb);
	CU_ASSERT_EQUAL(res, -EINVAL);
	res = pomp_ctx_set_raw(data.srv.ctx, NULL);
	CU_ASSERT_EQUAL(res, -EINVAL);
	res = pomp_ctx_set_raw(data.srv.ctx, &test_ctx_raw_cb);
	CU_ASSERT_EQUAL(res, -EBUSY);

	/* Invalid set socket cb */
	res = pomp_ctx_set_socket_cb(NULL, &test_ctx_socket_cb);
	CU_ASSERT_EQUAL(res, -EINVAL);
	res = pomp_ctx_set_socket_cb(data.srv.ctx, NULL);
	CU_ASSERT_EQUAL(res, -EINVAL);
	res = pomp_ctx_set_socket_cb(data.srv.ctx, &test_ctx_socket_cb);
	CU_ASSERT_EQUAL(res, -EBUSY);

	/* Invalid set send cb */
	res = pomp_ctx_set_send_cb(NULL, &test_ctx_send_cb);
	CU_ASSERT_EQUAL(res, -EINVAL);
	res = pomp_ctx_set_send_cb(data.srv.ctx, NULL);
	CU_ASSERT_EQUAL(res, -EINVAL);
	res = pomp_ctx_set_send_cb(data.srv.ctx, &test_ctx_send_cb);
	CU_ASSERT_EQUAL(res, -EBUSY);

	/* Invalid get loop (NULL param) */
	loop = pomp_ctx_get_loop(NULL);
	CU_ASSERT_PTR_NULL(loop);

	/* Invalid get fd (NULL param) */
	fd = pomp_ctx_get_fd(NULL);
	CU_ASSERT_EQUAL(fd, -EINVAL);

	/* Get loop and fd */
	loop = pomp_ctx_get_loop(data.srv.ctx);
	CU_ASSERT_PTR_NOT_NULL(loop);
	fd = pomp_ctx_get_fd(data.srv.ctx);
#ifdef POMP_HAVE_LOOP_EPOLL
	CU_ASSERT_TRUE(fd >= 0);
#else
	CU_ASSERT_EQUAL(fd, -ENOSYS);
#endif
	/* Invalid process fd (NULL param) */
	res = pomp_ctx_process_fd(NULL);
	CU_ASSERT_EQUAL(res, -EINVAL);

	/* Keepalive settings */
	if (!isdgram) {
		/* TODO: check that it actually does something */
		res = pomp_ctx_setup_keepalive(data.srv.ctx, 0, 0, 0, 0);
		CU_ASSERT_EQUAL(res, 0);
		res = pomp_ctx_setup_keepalive(data.srv.ctx, 1, 5, 2, 1);
		CU_ASSERT_EQUAL(res, 0);
		res = pomp_ctx_setup_keepalive(NULL, 0, 0, 0, 0);
		CU_ASSERT_EQUAL(res, -EINVAL);
	}

	/* Run contexts (they shall connect each other) */
	run_ctx(data.srv.ctx, data.cli.ctx, 100);
	if (!isdgram) {
		CU_ASSERT_EQUAL(data.connection, 2);

		/* Get remote connections */
		conn = pomp_ctx_get_next_conn(data.srv.ctx, NULL);
		CU_ASSERT_PTR_NOT_NULL(conn);
		conn = pomp_ctx_get_next_conn(data.srv.ctx, conn);
		CU_ASSERT_PTR_NULL(conn);
		conn = pomp_ctx_get_conn(data.cli.ctx);
		CU_ASSERT_PTR_NOT_NULL(conn);

		/* Invalid get remote connections */
		conn = pomp_ctx_get_next_conn(data.cli.ctx, NULL);
		CU_ASSERT_PTR_NULL(conn);
		conn = pomp_ctx_get_conn(data.srv.ctx);
		CU_ASSERT_PTR_NULL(conn);
		conn = pomp_ctx_get_next_conn(NULL, NULL);
		CU_ASSERT_PTR_NULL(conn);
		conn = pomp_ctx_get_conn(NULL);
		CU_ASSERT_PTR_NULL(conn);
	}

	/* Exchange some message */
	if (!isdgram) {
		if (!israw) {
			res = pomp_ctx_send(data.srv.ctx, 1, "%s", "hello1->2");
			CU_ASSERT_EQUAL(res, 0);
			res = pomp_ctx_send(data.cli.ctx, 1, "%s", "hello2->1");
			CU_ASSERT_EQUAL(res, 0);

			/* Invalid send (NULL param) */
			res = pomp_ctx_send(NULL, 1, "%s", "hello1->2");
			CU_ASSERT_EQUAL(res, -EINVAL);
			res = pomp_ctx_send_msg(data.srv.ctx, NULL);
			CU_ASSERT_EQUAL(res, -EINVAL);

			/* Invalid send (bad format) */
			res = pomp_ctx_send(data.srv.ctx, 1, "%o", 1);
			CU_ASSERT_EQUAL(res, -EINVAL);
			res = pomp_conn_send(pomp_ctx_get_conn(data.cli.ctx), 1, "%o", 1);
			CU_ASSERT_EQUAL(res, -EINVAL);

			/* Invalid send to (bad type) */
			res = pomp_ctx_send_msg_to(data.cli.ctx, msg, addr1, addrlen1);
			CU_ASSERT_EQUAL(res, -EINVAL);
		} else {
			buf = pomp_buffer_new(32);
			CU_ASSERT_PTR_NOT_NULL_FATAL(buf);
			memcpy(buf->data, "Hello World !!!", 15);
			buf->len = 15;

			res = pomp_ctx_send_raw_buf(data.srv.ctx, buf);
			data.datasent += 15;
			CU_ASSERT_EQUAL(res, 0);
			res = pomp_ctx_send_raw_buf(data.cli.ctx, buf);
			data.datasent += 15;
			CU_ASSERT_EQUAL(res, 0);

			/* Invalid send (NULL param) */
			res = pomp_ctx_send_raw_buf(NULL, buf);
			CU_ASSERT_EQUAL(res, -EINVAL);
			res = pomp_ctx_send_raw_buf(data.srv.ctx, NULL);
			CU_ASSERT_EQUAL(res, -EINVAL);

			pomp_buffer_unref(buf);
			buf = NULL;
		}
	} else {
		if (!israw) {
			res = pomp_msg_clear(msg);
			CU_ASSERT_EQUAL(res, 0);
			res = pomp_msg_write(msg, 1, "%s", "hello1->2");
			CU_ASSERT_EQUAL(res, 0);
			res = pomp_ctx_send_msg_to(data.srv.ctx, msg, addr2, addrlen2);
			CU_ASSERT_EQUAL(res, 0);

			res = pomp_msg_clear(msg);
			CU_ASSERT_EQUAL(res, 0);
			res = pomp_msg_write(msg, 1, "%s", "hello2->1");
			CU_ASSERT_EQUAL(res, 0);
			res = pomp_ctx_send_msg_to(data.cli.ctx, msg, addr1, addrlen1);
			CU_ASSERT_EQUAL(res, 0);

			/* Invalid send (not connected) */
			res = pomp_ctx_send_msg(data.cli.ctx, msg);
			CU_ASSERT_EQUAL(res, -ENOTCONN);

			/* Invalid send to (NULL param) */
			res = pomp_ctx_send_msg_to(NULL, msg, addr1, addrlen1);
			CU_ASSERT_EQUAL(res, -EINVAL);
			res = pomp_ctx_send_msg_to(data.cli.ctx, NULL, addr1, addrlen1);
			CU_ASSERT_EQUAL(res, -EINVAL);
			res = pomp_ctx_send_msg_to(data.cli.ctx, msg, NULL, addrlen1);
			CU_ASSERT_EQUAL(res, -EINVAL);
		} else {
			buf = pomp_buffer_new(32);
			CU_ASSERT_PTR_NOT_NULL_FATAL(buf);
			memcpy(buf->data, "Hello World !!!", 15);
			buf->len = 15;

			res = pomp_ctx_send_raw_buf_to(data.srv.ctx, buf, addr2, addrlen2);
			CU_ASSERT_EQUAL(res, 0);
			data.datasent += 15;
			res = pomp_ctx_send_raw_buf_to(data.cli.ctx, buf, addr1, addrlen1);
			CU_ASSERT_EQUAL(res, 0);
			data.datasent += 15;

			/* Invalid send (not connected) */
			res = pomp_ctx_send_raw_buf(data.cli.ctx, buf);
			CU_ASSERT_EQUAL(res, -ENOTCONN);

			/* Invalid send to (NULL param) */
			res = pomp_ctx_send_raw_buf_to(NULL, buf, addr1, addrlen1);
			CU_ASSERT_EQUAL(res, -EINVAL);
			res = pomp_ctx_send_raw_buf_to(data.cli.ctx, NULL, addr1, addrlen1);
			CU_ASSERT_EQUAL(res, -EINVAL);
			res = pomp_ctx_send_raw_buf_to(data.cli.ctx, buf, NULL, addrlen1);
			CU_ASSERT_EQUAL(res, -EINVAL);

			pomp_buffer_unref(buf);
			buf = NULL;
		}
	}

	/* Check no send callback directly called by the sending function. */
	CU_ASSERT_EQUAL(data.sendcount, 0);

	/* Run contexts (they shall have answered each other) */
	run_ctx(data.srv.ctx, data.cli.ctx, 100);
	if (!israw) {
		CU_ASSERT_EQUAL(data.msg, 4);
		if (withsendcb)
			CU_ASSERT_EQUAL(data.sendcount, 4);
	} else {
		if (data.isdgram)
			CU_ASSERT_EQUAL(data.buf, 2);
		CU_ASSERT_EQUAL(data.dataread, data.datasent);
		if (withsendcb)
			CU_ASSERT_EQUAL(data.sendcount, 2);
	}

	/* Dummy run */
	res = pomp_ctx_wait_and_process(data.srv.ctx, 100);
	CU_ASSERT_EQUAL(res, -ETIMEDOUT);
	res = pomp_ctx_wait_and_process(NULL, 100);
	CU_ASSERT_EQUAL(res, -EINVAL);

	/* Wakeup */
	res = pomp_ctx_wakeup(data.srv.ctx);
	CU_ASSERT_EQUAL(res, 0);
	res = pomp_ctx_wait_and_process(data.srv.ctx, 100);
	CU_ASSERT_EQUAL(res, 0);

	/* Invalid wakeup (NULL param) */
	res = pomp_ctx_wakeup(NULL);
	CU_ASSERT_EQUAL(res, -EINVAL);

	/* Overflow server by writing on client side without running loop */
	if (!isdgram) {
		for (i = 0; i < 1024; i++) {
			if (buf == NULL)
				buf = pomp_buffer_new(1024);
			CU_ASSERT_PTR_NOT_NULL_FATAL(buf);
			for (j = 0; j < 1024; j++)
				buf->data[j] = rand() % 255;
			buf->len = 1024;

			if (!israw) {
				res = pomp_ctx_send(data.cli.ctx, 3, "%p%u", buf->data, 1024);
				CU_ASSERT_EQUAL(res, 0);
			} else {
				res = pomp_ctx_send_raw_buf(data.cli.ctx, buf);
				CU_ASSERT_EQUAL(res, 0);
			}

			if (buf->refcount > 1) {
				pomp_buffer_unref(buf);
				buf = NULL;
			}
		}
		if (buf != NULL) {
			pomp_buffer_unref(buf);
			buf = NULL;
		}

		/* Run contexts (to unlock writes) */
		run_ctx(data.srv.ctx, data.cli.ctx, 100);
		if (!israw)
			CU_ASSERT_EQUAL(data.msg, 4 + 1024);
	}

	/* Recursive send */
	if (withsendcb) {
		/* reset counts */
		data.buf = 0;
		data.msg = 0;
		data.sendcount = 0;
		data.datasent = 0;
		data.dataread = 0;

		/* Enable recursive send. */
		data.srv.recurs_send_enabled = 1;
		send_msg(&data, &data.srv, &data.cli, "srv_to_cli");

		/* Check no send callback directly called by the sending function. */
		CU_ASSERT_EQUAL(data.sendcount, 0);

		run_ctx(data.srv.ctx, data.cli.ctx, 100);

		if (!israw) {
			CU_ASSERT_EQUAL(data.msg, 2);
			CU_ASSERT_EQUAL(data.sendcount, 2);
		} else {
			if (data.isdgram)
				CU_ASSERT_EQUAL(data.buf, 2);
			CU_ASSERT_EQUAL(data.dataread, data.datasent);
			CU_ASSERT_EQUAL(data.sendcount, 2);
		}

		/* Check client recursive send during server disconnection */
		data.cli.recurs_send_enabled = 1;
		send_msg(&data, &data.cli, &data.srv, "cli_to_srv");
	}

	/* Disconnect client from server */
	if (!isdgram) {
		if (withsendcb) {
			/* Check recursive write during disconnection */
			data.srv.recurs_send_enabled = 1;
			data.isdisconnecting = 1;
		}

		res = pomp_conn_disconnect(pomp_ctx_get_next_conn(data.srv.ctx, NULL));
		CU_ASSERT_EQUAL(res, 0);

		/* Check recursive send callback by disconnection */
		if (withsendcb)
			CU_ASSERT_EQUAL(data.sendcount, 2);
	}

	/* Run contexts (they shall disconnect each other) */
	run_ctx(data.srv.ctx, data.cli.ctx, 100);
	pomp_ctx_process_fd(data.cli.ctx);
	if (!isdgram) {
		CU_ASSERT_EQUAL(data.disconnection, 2);

		if (!israw) {
			/* Invalid send (client not connected) */
			res = pomp_ctx_send(data.cli.ctx, 1, "%s", "hello2->1");
			CU_ASSERT_EQUAL(res, -ENOTCONN);
		} else {
			/* TODO */
		}
	}

	/* Invalid destroy (NULL param) */
	res = pomp_ctx_destroy(NULL);
	CU_ASSERT_EQUAL(res, -EINVAL);

	/* Invalid destroy (busy) */
	res = pomp_ctx_destroy(data.srv.ctx);
	CU_ASSERT_EQUAL(res, -EBUSY);

	/* Stop server */
	res = pomp_ctx_stop(data.srv.ctx);
	CU_ASSERT_EQUAL(res, 0);

	/* Stop client */
	res = pomp_ctx_stop(data.cli.ctx);
	CU_ASSERT_EQUAL(res, 0);

	/* Invalid stop (NULL param) */
	res = pomp_ctx_stop(NULL);
	CU_ASSERT_EQUAL(res, -EINVAL);

	/* Stop when already done */
	res = pomp_ctx_stop(data.srv.ctx);
	CU_ASSERT_EQUAL(res, 0);

	/* Destroy contexts */
	res = pomp_ctx_destroy(data.srv.ctx);
	CU_ASSERT_EQUAL(res, 0);
	res = pomp_ctx_destroy(data.cli.ctx);
	CU_ASSERT_EQUAL(res, 0);

	res = pomp_msg_destroy(msg);
	CU_ASSERT_EQUAL(res, 0);
}
Esempio n. 22
0
/* Teste numero impar */
void teste_DT_VerificaParidade_Impar(void) {
	int resultado;
	resultado = VerificaParidade(3);
	CU_ASSERT_TRUE( resultado );
}
static LinphoneCoreManager* configure_lcm(void) {
	LinphoneCoreManager *mgr=linphone_core_manager_new( "multi_account_lrc");
	stats *counters=&mgr->stat;
	CU_ASSERT_TRUE(wait_for(mgr->lc,mgr->lc,&counters->number_of_LinphoneRegistrationOk,ms_list_size(linphone_core_get_proxy_config_list(mgr->lc))));
	return mgr;
}
Esempio n. 24
0
/* Teste numero zero */
void teste_DT_VerificaParidade_Zero(void) {
	int resultado;
	resultado = VerificaParidade(0);
	CU_ASSERT_TRUE( !resultado );
}
Esempio n. 25
0
void teste_DT_verificaNovaTela_invis () {
	Tela teste;

	teste = nova_tela();
	CU_ASSERT_TRUE(!teste->bloco[15][8].tipo);
}
Esempio n. 26
0
/* Teste letra maiuscula */
void teste_DT_ProximaLetra_Maiuscula(void){
	char resultado;
	resultado = ProximaLetra('A');
	CU_ASSERT_TRUE( resultado == 'B' );
}
Esempio n. 27
0
void testDstLen() {
	CU_ASSERT_EQUAL(dstlen(0), 1);
	CU_ASSERT_TRUE(dstlen(strlen("a ab ab")) > strlen("aab aab"));
}
Esempio n. 28
0
/* Teste letra maiuscula */
void teste_DT_ProximaLetra_Minuscula(void) {
	char resultado;
	resultado = ProximaLetra('d');
	CU_ASSERT_TRUE( resultado == 'e' );
}
Esempio n. 29
0
void test_multiPattern(void)
{
    HObs hObs = NULL;
    RU8 pattern1[] = { 0x01, 0x02, 0x03, 0x04 };
    RU8 pattern2[] = { 0x01, 0x02, 0x03, 0x06 };
    RU8 pattern3[] = { 0x01, 0x02, 0x06, 0x04 };
    RU8 pattern4[] = { 0xEF, 0x02, 0x03, 0x04 };
    RU8 buffer1[] = { 0x02, 0x04, 0xFF, 0xEF, 
                      0x01, 0x02, 0x03, 0x04 };
    RU8 buffer2[] = { 0x02, 0x04, 0xFF, 0xEF,
                      0x01, 0x02, 0x03, 0x04, 0xEE, 0x6F };
    RU8 buffer3[] = { 0x02, 0x04, 0xFF, 0xEF,
                      0x01, 0x02, 0x01, 0x04, 0xEE, 0x6F };
    RU8 buffer4[] = { 0x02, 0x04, 0xFF, 0xEF, 0x01, 
                      0x02, 0x03, 0x04, 0xEE, 0x6F,
                      0x01, 0x02, 0x03, 0x04 };
    RU8 buffer5[] = { 0x02, 0x04, 0xFF, 0xEF, 
                      0x02, 0x03, 0x04, 0x04, 
                      0xEE, 0x6F, 0x01, 0x02, 0x03, 0x04 };
    RU8 buffer6[] = { 0x02, 0x04, 0xFF, 0xEF,
                      0x02, 0x03, 0x04, 0x04, 
                      0xEE, 0x6F, 0x01, 0x02, 
                      0x03, 0x04, 0x01, 0x02, 0x06, 0x04 };
    RU32 context1 = 0;
    RU32 context2 = 0;
    RU32 context3 = 0;
    RU32 context4 = 0;
    PVOID hitCtx = NULL;
    RU8* hitLoc = NULL;

    hObs = obsLib_new( 0, 0 );

    CU_ASSERT_TRUE_FATAL( rpal_memory_isValid( hObs ) );

    CU_ASSERT_TRUE_FATAL( obsLib_addPattern( hObs, (RPU8)&pattern1, sizeof( pattern1 ), &context1 ) );
    CU_ASSERT_TRUE_FATAL( obsLib_addPattern( hObs, (RPU8)&pattern2, sizeof( pattern2 ), &context2 ) );
    CU_ASSERT_TRUE_FATAL( obsLib_addPattern( hObs, (RPU8)&pattern3, sizeof( pattern3 ), &context3 ) );
    CU_ASSERT_TRUE_FATAL( obsLib_addPattern( hObs, (RPU8)&pattern4, sizeof( pattern4 ), &context4 ) );

    // 1 pattern found end of buffer
    CU_ASSERT_TRUE_FATAL( obsLib_setTargetBuffer( hObs, buffer1, sizeof( buffer1 ) ) );
    CU_ASSERT_TRUE( obsLib_nextHit( hObs, &hitCtx, &hitLoc ) );
    CU_ASSERT_EQUAL( hitCtx, &context1 );
    CU_ASSERT_EQUAL( hitLoc, buffer1 + sizeof( buffer1 ) - 4 );
    CU_ASSERT_FALSE( obsLib_nextHit( hObs, &hitCtx, &hitLoc ) );

    // 1 pattern found middle of buffer
    CU_ASSERT_TRUE_FATAL( obsLib_setTargetBuffer( hObs, buffer2, sizeof( buffer2 ) ) );
    CU_ASSERT_TRUE( obsLib_nextHit( hObs, &hitCtx, &hitLoc ) );
    CU_ASSERT_EQUAL( hitCtx, &context1 );
    CU_ASSERT_EQUAL( hitLoc, buffer2 + sizeof( buffer2 ) - 6 );
    CU_ASSERT_FALSE( obsLib_nextHit( hObs, &hitCtx, &hitLoc ) );

    // 0 pattern found
    CU_ASSERT_TRUE_FATAL( obsLib_setTargetBuffer( hObs, buffer3, sizeof( buffer3 ) ) );
    CU_ASSERT_FALSE( obsLib_nextHit( hObs, &hitCtx, &hitLoc ) );

    // 2 pattern found end and middle of buffer
    CU_ASSERT_TRUE_FATAL( obsLib_setTargetBuffer( hObs, buffer4, sizeof( buffer4 ) ) );
    CU_ASSERT_TRUE( obsLib_nextHit( hObs, &hitCtx, &hitLoc ) );
    CU_ASSERT_EQUAL( hitCtx, &context1 );
    CU_ASSERT_EQUAL( hitLoc, buffer4 + sizeof( buffer4 ) - 10 );
    CU_ASSERT_TRUE( obsLib_nextHit( hObs, &hitCtx, &hitLoc ) );
    CU_ASSERT_EQUAL( hitCtx, &context1 );
    CU_ASSERT_EQUAL( hitLoc, buffer4 + sizeof( buffer4 ) - 4 );
    CU_ASSERT_FALSE( obsLib_nextHit( hObs, &hitCtx, &hitLoc ) );

    // Multi 1
    CU_ASSERT_TRUE_FATAL( obsLib_setTargetBuffer( hObs, buffer5, sizeof( buffer5 ) ) );
    CU_ASSERT_TRUE( obsLib_nextHit( hObs, &hitCtx, &hitLoc ) );
    CU_ASSERT_EQUAL( hitCtx, &context4 );
    CU_ASSERT_EQUAL( hitLoc, buffer5 + 3 );
    CU_ASSERT_TRUE( obsLib_nextHit( hObs, &hitCtx, &hitLoc ) );
    CU_ASSERT_EQUAL( hitCtx, &context1 );
    CU_ASSERT_EQUAL( hitLoc, buffer5 + sizeof( buffer5 ) - 4 );
    CU_ASSERT_FALSE( obsLib_nextHit( hObs, &hitCtx, &hitLoc ) );

    // Multi 2
    CU_ASSERT_TRUE_FATAL( obsLib_setTargetBuffer( hObs, buffer6, sizeof( buffer6 ) ) );
    CU_ASSERT_TRUE( obsLib_nextHit( hObs, &hitCtx, &hitLoc ) );
    CU_ASSERT_EQUAL( hitCtx, &context4 );
    CU_ASSERT_EQUAL( hitLoc, buffer6 + 3 );
    CU_ASSERT_TRUE( obsLib_nextHit( hObs, &hitCtx, &hitLoc ) );
    CU_ASSERT_EQUAL( hitCtx, &context1 );
    CU_ASSERT_EQUAL( hitLoc, buffer6 + sizeof( buffer6 ) - 8 );
    CU_ASSERT_TRUE( obsLib_nextHit( hObs, &hitCtx, &hitLoc ) );
    CU_ASSERT_EQUAL( hitCtx, &context3 );
    CU_ASSERT_EQUAL( hitLoc, buffer6 + sizeof( buffer6 ) - 4 );
    CU_ASSERT_FALSE( obsLib_nextHit( hObs, &hitCtx, &hitLoc ) );

    obsLib_free( hObs );
}
Esempio n. 30
0
static void test_loop(void)
{
	int res = 0;
	HANDLE htimer1 = NULL, htimer2 = NULL, htimer3 = NULL;
	struct test_data data;
	struct pomp_loop *loop = NULL;
	struct pomp_fd *pfd = NULL;

	memset(&data, 0, sizeof(data));

	/* Create loop */
	loop = pomp_loop_new();
	CU_ASSERT_PTR_NOT_NULL_FATAL(loop);

	/* Create timers for testing */
	htimer1 = setup_timer_win32(100, 500);
	CU_ASSERT_PTR_NOT_NULL_FATAL(htimer1);
	htimer2 = setup_timer_win32(50, 500);
	CU_ASSERT_PTR_NOT_NULL_FATAL(htimer2);
	htimer3 = setup_timer_win32(150, 500);
	CU_ASSERT_PTR_NOT_NULL_FATAL(htimer3);

	/* Add timer in loop */
	pfd = pomp_loop_win32_add_pfd_with_hevt(loop, htimer1, &timer_win32_cb, &data);
	CU_ASSERT_PTR_NOT_NULL(pfd);

	/* Add 2nd and 3rd timer in loop */
	pfd = pomp_loop_win32_add_pfd_with_hevt(loop, htimer2, &timer_win32_cb, &data);
	CU_ASSERT_PTR_NOT_NULL(pfd);
	pfd = pomp_loop_win32_add_pfd_with_hevt(loop, htimer3, &timer_win32_cb, &data);
	CU_ASSERT_PTR_NOT_NULL(pfd);

	/* Run loop with different timeout first one should have all timers) */
	res = pomp_loop_wait_and_process(loop, 500);
	CU_ASSERT_EQUAL(res, 0);
	res = pomp_loop_wait_and_process(loop, 0);
	CU_ASSERT_TRUE(res == -ETIMEDOUT || res == 0);
	res = pomp_loop_wait_and_process(loop, -1);
	CU_ASSERT_EQUAL(res, 0);

	/* Invalid run (NULL param) */
	res = pomp_loop_wait_and_process(NULL, 0);
	CU_ASSERT_EQUAL(res, -EINVAL);

	/* Invalid destroy (NULL param) */
	res = pomp_loop_destroy(NULL);
	CU_ASSERT_EQUAL(res, -EINVAL);

	/* Invalid destroy (busy) */
	res = pomp_loop_destroy(loop);
	CU_ASSERT_EQUAL(res, -EBUSY);

	/* Remove timers */
	pfd = pomp_loop_win32_find_pfd_by_hevt(loop, htimer1);
	CU_ASSERT_PTR_NOT_NULL(pfd);
	res = pomp_loop_remove_pfd(loop, pfd);
	CU_ASSERT_EQUAL(res, 0);
	free(pfd);
	pfd = pomp_loop_win32_find_pfd_by_hevt(loop, htimer2);
	CU_ASSERT_PTR_NOT_NULL(pfd);
	res = pomp_loop_remove_pfd(loop, pfd);
	CU_ASSERT_EQUAL(res, 0);
	free(pfd);
	pfd = pomp_loop_win32_find_pfd_by_hevt(loop, htimer3);
	CU_ASSERT_PTR_NOT_NULL(pfd);
	res = pomp_loop_remove_pfd(loop, pfd);
	CU_ASSERT_EQUAL(res, 0);
	free(pfd);

	/* Close timers */
	res = CloseHandle(htimer1);
	CU_ASSERT_EQUAL(res, 1);
	res = CloseHandle(htimer2);
	CU_ASSERT_EQUAL(res, 1);
	res = CloseHandle(htimer3);
	CU_ASSERT_EQUAL(res, 1);

	/* Destroy loop */
	res = pomp_loop_destroy(loop);
	CU_ASSERT_EQUAL(res, 0);
}