void test_deck_createDeck() { struct Deck *deck; cut_assert_equal_pointer(NULL, deck_createDeck(MAX_GAME_PLAYERS + 1)); cut_assert_equal_pointer(NULL, deck_createDeck(MIN_GAME_PLAYERS - 1)); for (int i = MIN_GAME_PLAYERS; i <= MAX_GAME_PLAYERS; i++) { deck = deck_createDeck(i); int check = 0; if (deck == NULL) check++; cut_assert_equal_int(0, check); cut_assert_equal_int(i * MAX_CARDS, deck_getDeckSize(deck)); int duplicates = 0; for (int j = 0; j < DECK_SIZE; j++) for (int k = 0; k < DECK_SIZE; k++) if (k != j && deck->cards[k] != NULL && deck->cards[j] != NULL && deck->cards[k]->suit == deck->cards[j]->suit && deck->cards[k]->value == deck->cards[j]->value) duplicates++; cut_assert_equal_int(0, duplicates); deck_deleteDeck(&deck); } }
void test_round_createRound() { cut_assert_equal_pointer(NULL, round_createRound(MIN_CARDS - 1)); cut_assert_equal_pointer(NULL, round_createRound(MAX_CARDS + 1)); struct Round *round = round_createRound(MIN_CARDS); int check = 0; if (round == NULL) check++; cut_assert_equal_int(0, check); for (int i = 0; i < MAX_GAME_PLAYERS; i++) { cut_assert_equal_pointer(NULL, round->players[i]); cut_assert_equal_int(0, round->bids[i]); cut_assert_equal_int(0, round->handsNumber[i]); cut_assert_equal_int(0, round->pointsNumber[i]); cut_assert_equal_int(0, round->bonus[i]); } cut_assert_equal_int(MIN_CARDS, round->roundType); cut_assert_equal_pointer(NULL, round->hand); cut_assert_equal_pointer(NULL, round->trump); round_deleteRound(&round); }
void test_fixture_function (gconstpointer data) { const FixtureTestData *test_data = data; CutStartupFunction expected_startup_function = NULL; CutStartupFunction actual_startup_function = NULL; CutShutdownFunction expected_shutdown_function = NULL; CutShutdownFunction actual_shutdown_function = NULL; CutSetupFunction expected_setup_function = NULL; CutSetupFunction actual_setup_function = NULL; CutTeardownFunction expected_teardown_function = NULL; CutTeardownFunction actual_teardown_function = NULL; gchar *so_filename; loader = loader_new("fixture", test_data->file_name); test_case = cut_loader_load_test_case(loader); cut_assert(test_case); g_object_get(G_OBJECT(loader), "so-filename", &so_filename, NULL); module = g_module_open(so_filename, G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL); g_free(so_filename); cut_assert_not_null(module); if (test_data->startup_function_name) cut_assert_true(g_module_symbol(module, test_data->startup_function_name, (gpointer)&expected_startup_function)); if (test_data->setup_function_name) cut_assert_true(g_module_symbol(module, test_data->setup_function_name, (gpointer)&expected_setup_function)); if (test_data->teardown_function_name) cut_assert_true(g_module_symbol(module, test_data->teardown_function_name, (gpointer)&expected_teardown_function)); if (test_data->shutdown_function_name) cut_assert_true(g_module_symbol(module, test_data->shutdown_function_name, (gpointer)&expected_shutdown_function)); g_object_get(G_OBJECT(test_case), "startup-function", &actual_startup_function, "setup-function", &actual_setup_function, "teardown-function", &actual_teardown_function, "shutdown-function", &actual_shutdown_function, NULL); cut_assert_equal_pointer(expected_startup_function, actual_startup_function); cut_assert_equal_pointer(expected_setup_function, actual_setup_function); cut_assert_equal_pointer(expected_teardown_function, actual_teardown_function); cut_assert_equal_pointer(expected_shutdown_function, actual_shutdown_function); }
void test_two_prepends(void) { int x, y; List *l = list_prepend(NULL, &x); l = list_prepend(l, &y); cut_assert_not_null(l); cut_assert_equal_pointer(&y, l->data); cut_assert_not_null(l->next); cut_assert_equal_pointer(&x, l->next->data); cut_assert_null(l->next->next); }
void test_atomic (void) { gint i; gint atomic = -5; gpointer atomic_pointer = NULL; gpointer biggest_pointer = (gpointer)((gsize)atomic_pointer - 1); for (i = 0; i < 15; i++) g_atomic_int_inc (&atomic); cut_assert_equal_int (10, atomic); for (i = 0; i < 9; i++) cut_assert (!g_atomic_int_dec_and_test (&atomic)); cut_assert (g_atomic_int_dec_and_test (&atomic)); cut_assert_equal_int (0, atomic); cut_assert_equal_int (0, g_atomic_int_exchange_and_add (&atomic, 5)); cut_assert_equal_int (5, atomic); cut_assert_equal_int (5, g_atomic_int_exchange_and_add (&atomic, -10)); cut_assert_equal_int (-5, atomic); g_atomic_int_add (&atomic, 20); cut_assert_equal_int (15, atomic); g_atomic_int_add (&atomic, -35); cut_assert_equal_int (-20, atomic); cut_assert_equal_int (atomic, g_atomic_int_get (&atomic)); cut_assert (g_atomic_int_compare_and_exchange (&atomic, -20, 20)); cut_assert_equal_int (20, atomic); cut_assert (!g_atomic_int_compare_and_exchange (&atomic, 42, 12)); cut_assert_equal_int (20, atomic); cut_assert (g_atomic_int_compare_and_exchange (&atomic, 20, G_MAXINT)); cut_assert_equal_int (G_MAXINT, atomic); cut_assert (g_atomic_int_compare_and_exchange (&atomic, G_MAXINT, G_MININT)); cut_assert_equal_int (G_MININT, atomic); cut_assert (g_atomic_pointer_compare_and_exchange (&atomic_pointer, NULL, biggest_pointer)); cut_assert_equal_pointer (biggest_pointer, atomic_pointer); cut_assert_equal_pointer (atomic_pointer, g_atomic_pointer_get (&atomic_pointer)); cut_assert (g_atomic_pointer_compare_and_exchange (&atomic_pointer, biggest_pointer, NULL)); cut_assert (biggest_pointer); }
void test_two_appends(void) { List *l = list_append(NULL, INT_TO_POINTER(1)); cut_assert_not_null(l); cut_assert_null(l->next); cut_assert_equal_pointer(INT_TO_POINTER(1), l->data); l = list_append(l, INT_TO_POINTER(2)); cut_assert_equal_pointer(INT_TO_POINTER(1), l->data); cut_assert_not_null(l->next); cut_assert_equal_pointer(INT_TO_POINTER(2), l->next->data); cut_assert_null(l->next->next); }
void test_deck_createCard() { struct Card *card; cut_assert_equal_pointer(NULL, deck_createCard(SuitEnd, VALUES[0])); cut_assert_equal_pointer(NULL, deck_createCard(DIAMONDS, -1)); cut_assert_equal_pointer(NULL, deck_createCard(SuitEnd, -1)); for (int i = 0; i < SuitEnd; i++) for (int j = 0; VALUES[j] != -1; j++) { card = deck_createCard(i, VALUES[j]); cut_assert_equal_int(card->suit, i); cut_assert_equal_int(card->value, VALUES[j]); deck_deleteCard(&card); } }
void test_hand_createHand() { struct Hand *hand = hand_createHand(); int check = 0; if (hand != NULL) check++; cut_assert_equal_int(1, check); for (int i = 0; i < MAX_GAME_PLAYERS; i++) { cut_assert_equal_pointer(NULL, hand->cards[i]); cut_assert_equal_pointer(NULL, hand->players[i]); } hand_deleteHand(&hand); }
void test_mb_aiom_prep_pwrite(void) { char buf[512]; int fd = 3; long long offset = 23456; struct iocb *_iocb; aiom = mb_aiom_make(64); cut_assert_equal_int(0, aiom->nr_pending); _iocb = mb_aiom_prep_pwrite(aiom, fd, buf, 512, offset); cut_assert_equal_int(1, aiom->nr_pending); cut_assert_not_null(_iocb); cut_assert_equal_int(63, mb_aiom_nr_submittable(aiom)); cut_assert_equal_int(IO_CMD_PWRITE, _iocb->aio_lio_opcode); cut_assert_equal_int(fd, _iocb->aio_fildes); cut_assert_equal_pointer(buf, _iocb->u.c.buf); cut_assert_equal_int(512, _iocb->u.c.nbytes); cut_assert(offset == _iocb->u.c.offset); }
void test_mb_aiom_submit_pwrite(void) { mb_mock_init(); char buf[512]; int fd = 123; aiom = mb_aiom_make(64); mb_mock_assert_will_call("io_submit", MOCK_ARG_PTR, aiom->context, MOCK_ARG_INT, 1, MOCK_ARG_SKIP, NULL, NULL); struct iocb *head = aiom->cbpool->head->data; cut_assert_equal_int(0, aiom->nr_inflight); cut_assert_equal_int(1, mb_aiom_submit_pwrite(aiom, fd, buf, 512, 9999)); cut_assert_equal_int(1, aiom->nr_inflight); cut_assert_equal_int(IO_CMD_PWRITE, head->aio_lio_opcode); cut_assert_equal_int(fd, head->aio_fildes); cut_assert_equal_pointer(buf, head->u.c.buf); cut_assert_equal_int(512, head->u.c.nbytes); cut_assert(9999 == head->u.c.offset); cut_assert_equal_int(63, mb_aiom_nr_submittable(aiom)); mb_mock_finish(); }
void test_hand_addCard() { struct Hand *hand = hand_createHand(); struct Deck *deck = deck_createDeck(MAX_GAME_PLAYERS); struct Player *players[MAX_GAME_PLAYERS + 1]; for (int i = 0; i < MAX_GAME_PLAYERS; i++) { players[i] = player_createPlayer("A", i); hand_addPlayer(hand, players[i]); struct Card *card = deck->cards[i]; struct Card *card2 = deck->cards[i]; cut_assert_equal_int(FUNCTION_NO_ERROR, hand_addCard(hand, players[i], &(deck->cards[i]))); cut_assert_equal_pointer(NULL, deck->cards[i]); int check = 0; for (int j = 0; j < MAX_GAME_PLAYERS; j++) if (players[i] == hand->players[j] && card == hand->cards[j]) check++; cut_assert_equal_int(1, check); } players[MAX_GAME_PLAYERS] = player_createPlayer("A", 1); cut_assert_equal_int(NOT_FOUND, hand_addCard(hand, players[MAX_GAME_PLAYERS], &deck->cards[MAX_GAME_PLAYERS])); for (int i = 0; i <= MAX_GAME_PLAYERS; i++) player_deletePlayer(&players[i]); deck_deleteDeck(&deck); hand_deleteHand(&hand); }
void test_round_distributeDeck() { struct Round *round = round_createRound(MAX_CARDS); struct Deck *deck = deck_createDeck(MAX_GAME_PLAYERS); struct Player *players[MAX_GAME_PLAYERS]; cut_assert_equal_int(ROUND_NULL, round_distributeDeck(NULL, deck)); cut_assert_equal_int(DECK_NULL, round_distributeDeck(round, NULL)); for (int i = 0; i < MAX_GAME_PLAYERS; i++) { players[i] = player_createPlayer("A", i); round_addPlayer(round, players[i]); } cut_assert_equal_int(FUNCTIOON_NO_ERROR, round_distributeDeck(round, deck)); cut_assert_equal_pointer(NULL, round->trump); for (int i = 0; i < MAX_GAME_PLAYERS; i++) { int nullCards = 0; int duplicate = 0; for (int j = 0; j < MAX_CARDS; j++) if (round->players[i]->hand[j] == NULL) nullCards++; for (int j = 0; j < MAX_CARDS - 1; j++) for (int k = j + 1; k < MAX_CARDS; k++) if (round->players[i]->hand[j] == round->players[i]->hand[k]) duplicate++; cut_assert_equal_int(0, nullCards); cut_assert_equal_int(0, duplicate); } round_deleteRound(&round); deck_deleteDeck(&deck); for (int i = 0; i < MAX_GAME_PLAYERS; i++) player_deletePlayer(&players[i]); }
void test_flag_normalize(void) { default_flags = GRN_SNIP_NORMALIZE; cut_assert_open_snip(); cut_assert_equal_pointer(GRN_NORMALIZER_AUTO, grn_snip_get_normalizer(&context, snip)); }
void test_round_deleteRound() { struct Round *round = round_createRound(MIN_CARDS); cut_assert_equal_int(POINTER_NULL, round_deleteRound(NULL)); cut_assert_equal_int(FUNCTIOON_NO_ERROR, round_deleteRound(&round)); cut_assert_equal_int(ROUND_NULL, round_deleteRound(&round)); cut_assert_equal_pointer(NULL, round); }
void test_deck_deleteCard() { struct Card *card = deck_createCard(DIAMONDS, VALUES[0]); cut_assert_equal_int(POINTER_NULL, deck_deleteCard(NULL)); cut_assert_equal_int(FUNCTIOON_NO_ERROR, deck_deleteCard(&card)); cut_assert_equal_pointer(NULL, card); cut_assert_equal_int(CARD_NULL, deck_deleteCard(&card)); }
void test_reverse_list(void) { List *l = list_prepend(NULL, INT_TO_POINTER(1)); l = list_prepend(l, INT_TO_POINTER(2)); l = list_prepend(l, INT_TO_POINTER(3)); l = list_reverse(l); cut_assert_not_null(l); cut_assert_equal_pointer(INT_TO_POINTER(1), l->data); cut_assert_not_null(l->next); cut_assert_equal_pointer(INT_TO_POINTER(2), l->next->data); cut_assert_not_null(l->next->next); cut_assert_equal_pointer(INT_TO_POINTER(3), l->next->next->data); cut_assert_null(l->next->next->next); }
void test_deck_deleteDeck() { cut_assert_equal_int(POINTER_NULL, deck_deleteDeck(NULL)); struct Deck *deck = deck_createDeck(MAX_GAME_PLAYERS); cut_assert_equal_int(FUNCTIOON_NO_ERROR, deck_deleteDeck(&deck)); cut_assert_equal_pointer(NULL, deck); cut_assert_equal_int(DECK_NULL, deck_deleteDeck(&deck)); }
void test_player_deletePlayer() { struct Player *player = player_createPlayer("A", 1); cut_assert_equal_int(POINTER_NULL, player_deletePlayer(NULL)); cut_assert_equal_int(FUNCTION_NO_ERROR, player_deletePlayer(&player)); cut_assert_equal_pointer(NULL, player); cut_assert_equal_int(PLAYER_NULL, player_deletePlayer(&player)); }
void test_hand_deleteHand() { struct Hand *hand = hand_createHand(); cut_assert_equal_int(FUNCTION_NO_ERROR, hand_deleteHand(&hand)); cut_assert_equal_pointer(NULL, hand); cut_assert_equal_int(HAND_NULL, hand_deleteHand(&hand)); cut_assert_equal_int(POINTER_NULL, hand_deleteHand(NULL)); }
void test_prepending_into_null(void) { int x = 0; List *l = list_prepend(NULL, &x); cut_assert_not_null(l); cut_assert_null(l->next); cut_assert_equal_pointer(&x, l->data); }
void test_round_addTrump() { struct Round *round = round_createRound(MIN_CARDS); struct Card *trump = deck_createCard(DIAMONDS, VALUES[0]); struct Card *trump2 = trump; cut_assert_equal_int(ROUND_NULL, round_addTrump(NULL, &trump)); cut_assert_equal_int(POINTER_NULL, round_addTrump(round, NULL)); cut_assert_operator_int(0, >, round_addTrump(NULL, NULL)); cut_assert_equal_int(FUNCTIOON_NO_ERROR, round_addTrump(round, &trump)); cut_assert_equal_pointer(NULL, trump); cut_assert_equal_pointer(trump2, round->trump); cut_assert_equal_int(FUNCTIOON_NO_ERROR, round_addTrump(round, &trump)); cut_assert_equal_pointer(NULL, trump); cut_assert_equal_pointer(NULL, round->trump); round_deleteRound(&round); }
void test_mb_res_pool_make(void) { cbpool = mb_res_pool_make(64); cut_assert_not_null(cbpool); cut_assert_not_null(cbpool->ring); cut_assert_not_null(cbpool->head); cut_assert_not_null(cbpool->tail); cut_assert_equal_int(64, cbpool->size); cut_assert_equal_pointer(cbpool->ring, cbpool->head); cut_assert_false(cbpool->ring == cbpool->tail); // check it is a ring int i; mb_res_pool_cell_t *cell; for(cell = cbpool->ring, i = 0; i < 64; cell = cell->next, i++){} cut_assert_equal_pointer(cbpool->ring, cell); // initially a pool is empty cut_assert_equal_int(0, cbpool->nr_avail); }
void test_round_addPlayersInHand() { struct Round *round = round_createRound(MIN_CARDS); cut_assert_equal_int(ROUND_NULL, round_addPlayersInHand(NULL, 0)); cut_assert_equal_int(ILLEGAL_VALUE, round_addPlayersInHand(round, -1)); cut_assert_equal_int(ILLEGAL_VALUE, round_addPlayersInHand(round, MAX_GAME_PLAYERS + 1)); cut_assert_equal_int(HAND_NULL, round_addPlayersInHand(round, 0)); round->hand = hand_createHand(); cut_assert_equal_int(INSUFFICIENT_PLAYERS, round_addPlayersInHand(round, 0)); struct Player *players[MAX_GAME_PLAYERS]; for (int i = 0; i < MAX_GAME_PLAYERS; i++) { players[i] = player_createPlayer("A", i); round_addPlayer(round, players[i]); } for (int i = 0 ; i < MAX_GAME_PLAYERS; i++) { cut_assert_equal_int(FUNCTIOON_NO_ERROR, round_addPlayersInHand(round, i)); int position = 0; for (int j = i; j < MAX_GAME_PLAYERS; j++) { cut_assert_equal_pointer(round->players[j], round->hand->players[position]); position++; } for (int j = 0; j < i; j++) { cut_assert_equal_pointer(round->players[j], round->hand->players[position]); position++; } hand_deleteHand(&round->hand); round->hand = hand_createHand(); } round_deleteRound(&round); for(int i = 0; i < MAX_GAME_PLAYERS; i++) player_deletePlayer(&players[i]); }
void test_normalizer_accessor(void) { grn_obj *normalizer; cut_assert_open_snip(); cut_assert_null(grn_snip_get_normalizer(&context, snip)); normalizer = grn_ctx_get(&context, "NormalizerNFKC51", -1); cut_assert_not_null(normalizer); grn_snip_set_normalizer(&context, snip, normalizer); cut_assert_equal_pointer(normalizer, grn_snip_get_normalizer(&context, snip)); }
void test_get_test_suite (void) { result = cut_test_result_new(CUT_TEST_RESULT_SUCCESS, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); cut_assert_null(cut_test_result_get_test_suite(result)); suite = cut_test_suite_new_empty(); cut_test_result_set_test_suite(result, suite); cut_assert_equal_pointer(suite, cut_test_result_get_test_suite(result)); cut_test_result_set_test_suite(result, NULL); cut_assert_null(cut_test_result_get_test_suite(result)); }
void test_table(gpointer data) { grn_obj *table; grn_obj_flags flags = GPOINTER_TO_INT(data); grn_table_cursor *cursor; table = grn_table_create(context, NULL, 0, NULL, flags, get_object("ShortText"), NULL); cursor = grn_table_cursor_open(context, table, NULL, 0, NULL, 0, 0, -1, 0); /* FIXME: grn_test_assert_equal_object() */ cut_assert_equal_pointer(table, grn_table_cursor_table(context, cursor)); }
void test_table(gpointer data) { grn_obj *table; grn_obj_flags flags = GPOINTER_TO_INT(data); grn_table_cursor *cursor; table = grn_table_create(&context, NULL, 0, NULL, flags, OBJECT("<shorttext>"), 0); cursor = grn_table_cursor_open(&context, table, NULL, 0, NULL, 0, 0); /* FIXME: grn_test_assert_equal_object() */ cut_assert_equal_pointer(table, grn_table_cursor_table(&context, cursor)); }
void test_round_addHand() { struct Round *round = round_createRound(MIN_CARDS); struct Hand *hand = hand_createHand(); cut_assert_equal_int(ROUND_NULL, round_addHand(NULL, &hand)); cut_assert_equal_int(POINTER_NULL, round_addHand(round, NULL)); cut_assert_operator_int(0, >, round_addHand(NULL, NULL)); cut_assert_equal_int(FUNCTIOON_NO_ERROR, round_addHand(round, &hand)); cut_assert_equal_int(HAND_NULL, round_addHand(round, &hand)); cut_assert_equal_pointer(NULL, hand); int check = 0; if (round->hand == NULL) check++; cut_assert_equal_int(0, check); round_deleteRound(&round); }
void test_player_createPlayer() { struct Player *player; cut_assert_equal_pointer(NULL, player_createPlayer(NULL, 1)); char *name[] = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J" }; for (int i = 0; i < 10; i++) { player = player_createPlayer(name[i], i); int check = 0; if (player == NULL) check++; cut_assert_equal_int(0, check); cut_assert_equal_int(i, player->isHuman); cut_assert_equal_string(name[i], player->name); for (int j = 0; j < MAX_CARDS; j++) if (player->hand[j] != NULL) check++; cut_assert_equal_int(0, check); player_deletePlayer(&player); } }
void test_round_getPlayerWhichWonHand() { struct Round *round = round_createRound(1); struct Player *player; struct Card *cards[6]; cut_assert_equal_pointer(NULL, round_getPlayerWhichWonHand(NULL)); cut_assert_equal_pointer(NULL, round_getPlayerWhichWonHand(round)); round->hand = hand_createHand(); cut_assert_equal_pointer(NULL, round_getPlayerWhichWonHand(round)); for (int i = 0; i < 6; i++) { player = player_createPlayer("A", i); round_addPlayer(round, player); hand_addPlayer(round->hand, player); player = NULL; } cards[0] = deck_createCard(DIAMONDS, 6); cards[1] = deck_createCard(DIAMONDS, 7); cards[2] = deck_createCard(DIAMONDS, 8); cards[3] = deck_createCard(DIAMONDS, 15); cards[4] = deck_createCard(CLUBS, 14); cards[5] = deck_createCard(SPADES, 7); cut_assert_equal_pointer(NULL, round_getPlayerWhichWonHand(round)); for (int i = 0; i < 6; i++) hand_addCard(round->hand, round->hand->players[i], &cards[i]); struct Card *trump = deck_createCard(DIAMONDS, 14); cut_assert_equal_pointer(round->hand->players[3], round_getPlayerWhichWonHand(round)); round->trump = trump; cut_assert_equal_pointer(round->hand->players[3], round_getPlayerWhichWonHand(round)); round->trump->suit = CLUBS; cut_assert_equal_pointer(round->hand->players[4], round_getPlayerWhichWonHand(round)); round->trump->suit = SPADES; cut_assert_equal_pointer(round->hand->players[5], round_getPlayerWhichWonHand(round)); round->trump->suit = HEARTS; cut_assert_equal_pointer(round->hand->players[3], round_getPlayerWhichWonHand(round)); round->hand->cards[0]->suit = HEARTS; cut_assert_equal_pointer(round->hand->players[0], round_getPlayerWhichWonHand(round)); round->trump = NULL; cut_assert_equal_pointer(round->hand->players[0], round_getPlayerWhichWonHand(round)); round->trump = trump; round->trump->suit = DIAMONDS; cut_assert_equal_pointer(round->hand->players[3], round_getPlayerWhichWonHand(round)); round->trump->suit = CLUBS; cut_assert_equal_pointer(round->hand->players[4], round_getPlayerWhichWonHand(round)); round->trump->suit = SPADES; cut_assert_equal_pointer(round->hand->players[5], round_getPlayerWhichWonHand(round)); for (int i = 0; i < 6; i++) player_deletePlayer(&round->players[i]); round_deleteRound(&round); }