void test_board_init_start_sets_pieces() { int rank, file; board_t *board = board_init_start(); /* Check for white's pieces (ranks: 0-1) */ for (rank = 0; rank <= 1; rank++) { for (file = 0; file < BOARD_SIZE; file++) { TEST_ASSERT_MESSAGE( board->spaces[rank][file] != NULL, "Expected square_t* to be non-NULL but found NULL" ); TEST_ASSERT_MESSAGE( board->spaces[rank][file]->piece != NULL, "Expected valid piece_t*, but found NULL" ); } } /* Check for black's pieces (ranks: 6-7) */ for (rank = 6; rank < BOARD_SIZE; rank++) { for (file = 0; file < BOARD_SIZE; file++) { TEST_ASSERT_MESSAGE( board->spaces[rank][file] != NULL, "Expected square_t* to be non-NULL, but found NULL" ); TEST_ASSERT_MESSAGE( board->spaces[rank][file]->piece != NULL, "Expected valid black piece_t* found NULL" ); } } board_destroy(board); }
static void test_encrypt_op(const uint8_t* key, uint8_t key_len, const uint8_t* adata, size_t adata_len, const uint8_t* nonce, uint8_t nonce_len, const uint8_t* plain, size_t plain_len, const uint8_t* output_expected, size_t output_expected_len, uint8_t mac_length) { cipher_t cipher; int len, err, cmp; size_t len_encoding = nonce_and_len_encoding_size - nonce_len; TEST_ASSERT_MESSAGE(sizeof(data) >= output_expected_len, "Output buffer too small"); err = cipher_init(&cipher, CIPHER_AES_128, key, key_len); TEST_ASSERT_EQUAL_INT(1, err); len = cipher_encrypt_ccm(&cipher, adata, adata_len, mac_length, len_encoding, nonce, nonce_len, plain, plain_len, data); TEST_ASSERT_MESSAGE(len > 0, "Encryption failed"); TEST_ASSERT_EQUAL_INT(output_expected_len, len); cmp = compare(output_expected, data, len); TEST_ASSERT_MESSAGE(1 == cmp , "wrong ciphertext"); }
void test_board_save_to_file_saved_board_matches_original_when_loaded() { const char *filename = "test_board.chs"; board_t *to_save = board_init_start(); bool overwrite = true; int result; /* Save the file */ result = board_save_to_file(filename, to_save, overwrite); TEST_ASSERT_MESSAGE( result == 0, "Expected overwriting save of valid board to succeed" ); /* Reload the file into a new board_t* */ board_t *loaded_board; loaded_board = board_load_from_file(filename); TEST_ASSERT_MESSAGE( loaded_board != NULL, "Expected board load from valid file to succeed" ); /* Check that the old and new board match */ bool boards_match; boards_match = board_equal(to_save, loaded_board); TEST_ASSERT_MESSAGE( boards_match, "Expected the loaded board to match the saved one" ); board_destroy(loaded_board); board_destroy(to_save); }
void test_ThatWeCanAskForAllSortsOfSizes(void) { unsigned int i; CMOCK_MEM_INDEX_TYPE first = CMOCK_GUTS_NONE; CMOCK_MEM_INDEX_TYPE next; unsigned int sizes[10] = {3, 1, 80, 5, 8, 31, 7, 911, 2, 80}; unsigned int sizes_buffered[10] = {16, 16, 88, 16, 16, 40, 16, 920, 16, 88}; //includes counter unsigned int sum = 0; unsigned int cap; for (i = 0; i < 10; i++) { next = CMock_Guts_MemNew(sizes[i]); TEST_ASSERT_MESSAGE(next != CMOCK_GUTS_NONE, "Should Not Have Returned CMOCK_GUTS_NONE"); first = CMock_Guts_MemChain(first, next); TEST_ASSERT_MESSAGE(first != CMOCK_GUTS_NONE, "Should Not Have Returned CMOCK_GUTS_NONE"); sum += sizes_buffered[i]; cap = (StartingSize > (sum + CMOCK_MEM_SIZE)) ? StartingSize : (sum + CMOCK_MEM_SIZE); TEST_ASSERT_EQUAL(sum, CMock_Guts_MemBytesUsed()); TEST_ASSERT(cap >= CMock_Guts_MemBytesFree()); } //verify we can still walk through the elements allocated next = first; for (i = 0; i < 10; i++) { TEST_ASSERT_MESSAGE(next != CMOCK_GUTS_NONE, "Should Not Have Returned CMOCK_GUTS_NONE"); next = CMock_Guts_MemNext(next); } //there aren't any after that TEST_ASSERT_EQUAL_HEX( CMOCK_GUTS_NONE, next); }
void test_ThatWeCanAskForAllSortsOfSizes(void) { unsigned int i; CMOCK_MEM_INDEX_TYPE first = CMOCK_GUTS_NONE; CMOCK_MEM_INDEX_TYPE next; unsigned int sizes[5] = {3, 1, 80, 5, 4}; unsigned int sizes_buffered[5] = {4, 4, 80, 8, 4}; unsigned int sum = 0; for (i = 0; i < 5; i++) { next = CMock_Guts_MemNew(sizes[i]); TEST_ASSERT_MESSAGE(next != CMOCK_GUTS_NONE, "Should Not Have Returned CMOCK_GUTS_NONE"); first = CMock_Guts_MemChain(first, next); TEST_ASSERT_MESSAGE(first != CMOCK_GUTS_NONE, "Should Not Have Returned CMOCK_GUTS_NONE"); sum += sizes_buffered[i] + 4; TEST_ASSERT_EQUAL(sum, CMock_Guts_MemBytesUsed()); TEST_ASSERT_EQUAL(CMOCK_MEM_SIZE - sum, CMock_Guts_MemBytesFree()); } //show that we can't ask for too much memory TEST_ASSERT_EQUAL_HEX(CMOCK_GUTS_NONE, CMock_Guts_MemNew(12)); TEST_ASSERT_EQUAL_HEX(CMOCK_GUTS_NONE, CMock_Guts_MemNew(5)); //but we CAN ask for something that will still fit next = CMock_Guts_MemNew(4); TEST_ASSERT_MESSAGE(next != CMOCK_GUTS_NONE, "Should Not Have Returned CMOCK_GUTS_NONE"); first = CMock_Guts_MemChain(first, next); TEST_ASSERT_MESSAGE(first != CMOCK_GUTS_NONE, "Should Not Have Returned CMOCK_GUTS_NONE"); //verify we're used up now TEST_ASSERT_EQUAL(CMOCK_MEM_SIZE, CMock_Guts_MemBytesUsed()); TEST_ASSERT_EQUAL(0, CMock_Guts_MemBytesFree()); //verify we can still walk through the elements allocated next = first; for (i = 0; i < 6; i++) { TEST_ASSERT_MESSAGE(next != CMOCK_GUTS_NONE, "Should Not Have Returned CMOCK_GUTS_NONE"); next = CMock_Guts_MemNext(next); } //there aren't any after that TEST_ASSERT_EQUAL_HEX(CMOCK_GUTS_NONE, next); }
void test_op(void) { struct _OP* op_test = op("add", ADD); TEST_ASSERT_MESSAGE(op_test != NULL, "op() returned a null pointer!"); TEST_ASSERT_EQUAL_STRING("add", op_test->str); TEST_ASSERT_EQUAL_INT(ADD, op_test->type); free(op_test); }
/* Check that pieces are in the same place on original and copy boards */ void test_board_copy_deep_piece_values_match() { board_t *original = board_init_start(); board_t *copy = board_copy_deep(original); int rank, file; for (rank = 0; rank < BOARD_SIZE; rank++) { for (file = 0; file < BOARD_SIZE; file++) { /* Check that all original pieces can be found on the new board */ piece_t *original_piece = original->spaces[rank][file]->piece; if (original_piece) { /* Check that the copied piece matches the original */ piece_t *copied_piece = copy->spaces[rank][file]->piece; bool equal = piece_equal(original_piece, copied_piece); TEST_ASSERT_MESSAGE( equal, "Original and copied pieces dont match" ); } } } board_destroy(original); board_destroy(copy); }
static void test_base64_04_free_conversion(void) { size_t elements = 255; unsigned char elm[elements]; size_t elem_base64_out_size = 0; unsigned char elm_base64_out[((elements / 3) * 4) + (elements / 10)]; size_t elem_base64_out_decoded_size = 0; unsigned char elem_base64_out_decoded[ elements + 10 ]; /* fill some values */ for (int i = 0; i < (int)elements; ++i) { elm[i] = i; } int ret = base64_encode(elm, elements, NULL, &elem_base64_out_size); TEST_ASSERT_EQUAL_INT(BASE64_ERROR_BUFFER_OUT_SIZE, ret); ret = base64_encode(elm, elements, elm_base64_out, &elem_base64_out_size); TEST_ASSERT_EQUAL_INT(BASE64_SUCCESS, ret); ret = base64_decode(elm_base64_out, elem_base64_out_size, \ NULL, &elem_base64_out_decoded_size); TEST_ASSERT_EQUAL_INT(BASE64_ERROR_BUFFER_OUT_SIZE, ret); ret = base64_decode(elm_base64_out, elem_base64_out_size, \ elem_base64_out_decoded, &elem_base64_out_decoded_size); TEST_ASSERT_EQUAL_INT(BASE64_SUCCESS, ret); for (int i = 0; i < (int)elements; ++i) { TEST_ASSERT_MESSAGE(elem_base64_out_decoded[i] == elm[i], \ "decoding failed!(produced unexpected output)"); } }
void test_ThatCMockStopsReturningMoreDataWhenAskForMoreThanItHasLeftEvenIfNotAtExactEnd(void) { unsigned int i; CMOCK_MEM_INDEX_TYPE first = CMOCK_GUTS_NONE; CMOCK_MEM_INDEX_TYPE next; //we're asking for 12 bytes each time now (4 for index, 8 for data). //10 requests will give us 120 bytes used, which isn't enough for another 12 bytes if total memory is 128 for (i = 0; i < 10; i++) { TEST_ASSERT_EQUAL(i*12, CMock_Guts_MemBytesUsed()); TEST_ASSERT_EQUAL(CMOCK_MEM_SIZE - i*12, CMock_Guts_MemBytesFree()); next = CMock_Guts_MemNew(8); TEST_ASSERT_MESSAGE(next != CMOCK_GUTS_NONE, "Should Not Have Returned CMOCK_GUTS_NONE"); first = CMock_Guts_MemChain(first, next); TEST_ASSERT_MESSAGE(first != CMOCK_GUTS_NONE, "Should Not Have Returned CMOCK_GUTS_NONE"); //verify writing data won't screw us up *((unsigned int*)CMock_Guts_GetAddressFor(next)) = i; } //verify we're at top of memory TEST_ASSERT_EQUAL(CMOCK_MEM_SIZE - 8, CMock_Guts_MemBytesUsed()); TEST_ASSERT_EQUAL(8, CMock_Guts_MemBytesFree()); //The very next call will return a NONE, and any after that TEST_ASSERT_EQUAL_HEX(CMOCK_GUTS_NONE, CMock_Guts_MemNew(8)); TEST_ASSERT_EQUAL_HEX(CMOCK_GUTS_NONE, CMock_Guts_MemNew(5)); //verify nothing has changed TEST_ASSERT_EQUAL(CMOCK_MEM_SIZE - 8, CMock_Guts_MemBytesUsed()); TEST_ASSERT_EQUAL(8, CMock_Guts_MemBytesFree()); //verify we can still walk through the elements allocated next = first; for (i = 0; i < 10; i++) { TEST_ASSERT_MESSAGE(next != CMOCK_GUTS_NONE, "Should Not Have Returned CMOCK_GUTS_NONE"); TEST_ASSERT_EQUAL(i, *((unsigned int*)CMock_Guts_GetAddressFor(next))); next = CMock_Guts_MemNext(next); } //there aren't any after that TEST_ASSERT_EQUAL_HEX(CMOCK_GUTS_NONE, next); }
void test_board_copy_deep_with_bad_args_returns_null() { board_t *copy = board_copy_deep(NULL); TEST_ASSERT_MESSAGE( copy == NULL, "Expected copy to return NULL when given NULL argument" ); }
void test_NtpToTime(void) { # if SIZEOF_TIME_T <= 4 TEST_IGNORE_MESSAGE("test only useful for sizeof(time_t) > 4, skipped"); # else static const uint32_t ntp_vals[6] = { UINT32_C(0x00000000), UINT32_C(0x00000001), UINT32_C(0x7FFFFFFF), UINT32_C(0x80000000), UINT32_C(0x80000001), UINT32_C(0xFFFFFFFF) }; static char lbuf[128]; vint64 hold; time_t pivot, texp, diff; uint32_t back; int loops, iloop; pivot = 0; for (loops = 0; loops < 16; ++loops) { for (iloop = 0; iloop < 6; ++iloop) { hold = ntpcal_ntp_to_time( ntp_vals[iloop], &pivot); texp = vint64_to_time(&hold); /* constraint 1: texp must be in the * (right-open) intervall [p-(2^31), p+(2^31)[ */ diff = texp - pivot; snprintf(lbuf, sizeof(lbuf), "bounds check: piv=%lld exp=%lld dif=%lld", (long long)pivot, (long long)texp, (long long)diff); TEST_ASSERT_MESSAGE((diff >= INT32_MIN) && (diff <= INT32_MAX), lbuf); /* constraint 2: conversion from full time back * to truncated NTP time must yield same result * as input. */ back = (uint32_t)texp + JAN_1970; snprintf(lbuf, sizeof(lbuf), "modulo check: ntp(in)=$%08lu ntp(out)=$%08lu", (unsigned long)ntp_vals[iloop], (unsigned long)back); TEST_ASSERT_EQUAL_MESSAGE(ntp_vals[iloop], back, lbuf); } pivot += 0x20000000; } # endif }
void test_ThatCMockStopsReturningMoreDataWhenItRunsOutOfMemory(void) { unsigned int i; CMOCK_MEM_INDEX_TYPE first = CMOCK_GUTS_NONE; CMOCK_MEM_INDEX_TYPE next; //even though we are asking for one byte, we've told it to align to closest 4 bytes, therefore it will waste a byte each time //so each call will use 8 bytes (4 for the index, 1 for the data, and 3 wasted). //therefore we can safely allocated total/8 times. for (i = 0; i < (CMOCK_MEM_SIZE / 8); i++) { TEST_ASSERT_EQUAL(i*8, CMock_Guts_MemBytesUsed()); TEST_ASSERT_EQUAL(CMOCK_MEM_SIZE - i*8, CMock_Guts_MemBytesFree()); next = CMock_Guts_MemNew(1); TEST_ASSERT_MESSAGE(next != CMOCK_GUTS_NONE, "Should Not Have Returned CMOCK_GUTS_NONE"); first = CMock_Guts_MemChain(first, next); TEST_ASSERT_MESSAGE(first != CMOCK_GUTS_NONE, "Should Not Have Returned CMOCK_GUTS_NONE"); } //verify we're at top of memory TEST_ASSERT_EQUAL(CMOCK_MEM_SIZE, CMock_Guts_MemBytesUsed()); TEST_ASSERT_EQUAL(0, CMock_Guts_MemBytesFree()); //The very next call will return a NULL, and any after that TEST_ASSERT_EQUAL_HEX(CMOCK_GUTS_NONE, CMock_Guts_MemNew(1)); TEST_ASSERT_EQUAL_HEX(CMOCK_GUTS_NONE, CMock_Guts_MemNew(1)); TEST_ASSERT_EQUAL_HEX(CMOCK_GUTS_NONE, CMock_Guts_MemNew(1)); //verify nothing has changed TEST_ASSERT_EQUAL(CMOCK_MEM_SIZE, CMock_Guts_MemBytesUsed()); TEST_ASSERT_EQUAL(0, CMock_Guts_MemBytesFree()); //verify we can still walk through the elements allocated next = first; for (i = 0; i < (CMOCK_MEM_SIZE / 8); i++) { TEST_ASSERT_MESSAGE(next != CMOCK_GUTS_NONE, "Should Not Have Returned CMOCK_GUTS_NONE"); next = CMock_Guts_MemNext(next); } //there aren't any after that TEST_ASSERT_EQUAL_HEX(CMOCK_GUTS_NONE, next); }
void test_NtpToNtp(void) { # if SIZEOF_TIME_T <= 4 TEST_IGNORE_MESSAGE("test only useful for sizeof(time_t) > 4, skipped"); # else static const uint32_t ntp_vals[6] = { UINT32_C(0x00000000), UINT32_C(0x00000001), UINT32_C(0x7FFFFFFF), UINT32_C(0x80000000), UINT32_C(0x80000001), UINT32_C(0xFFFFFFFF) }; static char lbuf[128]; vint64 hold; time_t pivot, texp, diff; int loops, iloop; pivot = 0; for (loops = 0; loops < 16; ++loops) { for (iloop = 0; iloop < 6; ++iloop) { hold = ntpcal_ntp_to_ntp( ntp_vals[iloop], &pivot); texp = vint64_to_time(&hold); /* constraint 1: texp must be in the * (right-open) intervall [p-(2^31), p+(2^31)[, * but the pivot 'p' must be taken in full NTP * time scale! */ diff = texp - (pivot + JAN_1970); snprintf(lbuf, sizeof(lbuf), "bounds check: piv=%lld exp=%lld dif=%lld", (long long)pivot, (long long)texp, (long long)diff); TEST_ASSERT_MESSAGE((diff >= INT32_MIN) && (diff <= INT32_MAX), lbuf); /* constraint 2: low word must be equal to * input */ snprintf(lbuf, sizeof(lbuf), "low check: ntp(in)=$%08lu ntp(out[0:31])=$%08lu", (unsigned long)ntp_vals[iloop], (unsigned long)hold.D_s.lo); TEST_ASSERT_EQUAL_MESSAGE(ntp_vals[iloop], hold.D_s.lo, lbuf); } pivot += 0x20000000; } # endif }
void test_MemNewWillNowSupportSizesGreaterThanTheDefinesCMockSize(void) { TEST_ASSERT_EQUAL(0, CMock_Guts_MemBytesFree()); TEST_ASSERT_MESSAGE(CMock_Guts_MemNew(CMOCK_MEM_SIZE - TEST_MEM_INDEX_SIZE + 1) != CMOCK_GUTS_NONE, "Should Not Have Returned CMOCK_GUTS_NONE"); TEST_ASSERT_EQUAL(CMOCK_MEM_SIZE + TEST_MEM_INDEX_PAD, CMock_Guts_MemBytesUsed()); TEST_ASSERT_EQUAL(CMOCK_MEM_SIZE, CMock_Guts_MemBytesFree()); }
void test_board_init_start_makes_square_array() { board_t *board = board_init_start(); TEST_ASSERT_MESSAGE( board != NULL, "Expected board_init_start to set square array, found NULL pointer" ); board_destroy(board); }
void test_board_init_start_moves_white_first() { board_t *board = board_init_start(); TEST_ASSERT_MESSAGE( board->moves_next == WHITE, "Expected board_init to let WHITE move first, but found BLACK" ); board_destroy(board); }
void test_board_load_from_file_returns_null_if_filename_doesnt_exist() { const char *filename = "bad_board_filename.chs"; board_t *loaded_board = board_load_from_file(filename); TEST_ASSERT_MESSAGE( loaded_board == NULL, "Expected board_load_from_file to return NULL when given non-existent file" ); }
void test_board_init_start_returns_non_null() { board_t *board = board_init_start(); TEST_ASSERT_MESSAGE( board != NULL, "Expected board_init_start to return board_t, but found NULL" ); board_destroy(board); }
void test_board_init_makes_square_array() { board_t *board = board_init(); TEST_ASSERT_MESSAGE( board->spaces != NULL, "Expected board_init to create initialize an array of squares, but found NULL" ); board_destroy(board); }
void test_board_load_from_file_returns_null_for_invalid_args() { board_t *loaded_board; loaded_board = board_load_from_file(NULL); TEST_ASSERT_MESSAGE( loaded_board == NULL, "Expected board_load_from_file to return NULL when given NULL filename" ); }
void test_board_copy_deep_returns_board_at_new_address() { board_t *original = board_init_start(); board_t *copy = board_copy_deep(original); TEST_ASSERT_MESSAGE( original != copy, "Expected original and copy board_t* to point to different places" ); board_destroy(original); board_destroy(copy); }
void test_board_copy_deep_moves_next_is_preserved() { board_t *original = board_init_start(); board_t *copy = board_copy_deep(original); TEST_ASSERT_MESSAGE( original->moves_next == copy->moves_next, "Expected original and copy boards to have same 'next-movers'" ); board_destroy(original); board_destroy(copy); }
void testNotEqualInts(void) { int failed; EXPECT_ABORT_BEGIN TEST_ASSERT_EQUAL_INT(3982, 3983); EXPECT_ABORT_END failed = Unity.CurrentTestFailed; Unity.CurrentTestFailed = 0; TEST_ASSERT_MESSAGE(1U == failed, "This is expected"); }
void testNotEqualBits(void) { int failed; EXPECT_ABORT_BEGIN TEST_ASSERT_BITS(0xFF00, 0x5555, 0x5A55); EXPECT_ABORT_END failed = Unity.CurrentTestFailed; Unity.CurrentTestFailed = 0; TEST_ASSERT_MESSAGE(1U == failed, "This is expected"); }
/* Test length checking in ccm functions. */ static void test_crypto_modes_ccm_check_len(void) { int ret; /* Just 1 to big to fit */ ret = _test_ccm_len(cipher_encrypt_ccm, 2, NULL, 1 << 16, 0); TEST_ASSERT_EQUAL_INT(CCM_ERR_INVALID_LENGTH_ENCODING, ret); ret = _test_ccm_len(cipher_decrypt_ccm, 2, NULL, 1 << 16, 0); TEST_ASSERT_EQUAL_INT(CCM_ERR_INVALID_LENGTH_ENCODING, ret); /* adata_len should not change the result (was wrong in previous implem) */ ret = _test_ccm_len(cipher_encrypt_ccm, 2, NULL, 1 << 16, 65535); TEST_ASSERT_EQUAL_INT(CCM_ERR_INVALID_LENGTH_ENCODING, ret); ret = _test_ccm_len(cipher_decrypt_ccm, 2, NULL, 1 << 16, 65535); TEST_ASSERT_EQUAL_INT(CCM_ERR_INVALID_LENGTH_ENCODING, ret); /* Valid length that were wrongly checked */ /* Check should work with len_encoding >= 4, test with 8 */ uint8_t input[8]; ret = _test_ccm_len(cipher_encrypt_ccm, 8, input, 8, 0); TEST_ASSERT_MESSAGE(ret > 0, "Encryption : failed with valid input_len"); /* einput is encrypted value for * - 8 * 0 input * - All 0 nonce and key * - adata_len == 0 * - mac_len == 8 and len_encoding = 8 */ uint8_t einput[16] = { 0xa2, 0x46, 0x75, 0xfc, 0x5f, 0x1b, 0x01, 0x37, 0x8a, 0x85, 0xd7, 0xf8, 0x42, 0x82, 0x6a, 0x63, }; ret = _test_ccm_len(cipher_decrypt_ccm, 8, einput, 16, 0); TEST_ASSERT_MESSAGE(ret > 0, "Decryption : failed with valid input_len"); /* ccm library does not support auth_data_len > 0xFEFF */ ret = _test_ccm_len(cipher_encrypt_ccm, 2, NULL, 0, 0xFEFF + 1); TEST_ASSERT_EQUAL_INT(-1, ret); }
void test_board_init_sets_no_pieces() { board_t *board = board_init(); int rank, file; for (rank = 0; rank < BOARD_SIZE; rank++) { for (file = 0; file < BOARD_SIZE; file++) { TEST_ASSERT_MESSAGE( board->spaces[rank][file]->piece == NULL, "Expected all squares to be empty, found non-null piece_t*" ); } } board_destroy(board); }
void test_board_init_creates_each_square() { board_t *board = board_init(); int rank, file; for (rank = 0; rank < BOARD_SIZE; rank++) { for (file = 0; file < BOARD_SIZE; file++) { TEST_ASSERT_MESSAGE( board->spaces[rank][file] != NULL, "Expected square to be square_t, but found NULL" ); } } board_destroy(board); }
void test_board_save_to_file_returns_neg_one_for_invalid_args() { const char *filename = "saved1.chs"; board_t *to_save = board_init_start(); bool overwrite = true; int result; /* Return error code when given bad filename */ result = board_save_to_file(NULL, to_save, overwrite); TEST_ASSERT_MESSAGE( result == -1, "Expected to return -1 when given bad filename" ); /* Return error code when given bad board */ result = board_save_to_file(filename, NULL, overwrite); TEST_ASSERT_MESSAGE( result == -1, "Expected to return -1 when given bad board_t" ); board_destroy(to_save); }
void test_board_save_to_file_returns_neg_two_if_file_exists() { const char *filename = "existing_board.chs"; board_t *to_save = board_init_start(); bool overwrite = false; int result; /* Return error code if the file exists and we dont want to overwrite */ result = board_save_to_file(filename, to_save, overwrite); TEST_ASSERT_MESSAGE( result == -2, "Expected to return error when not overwriting existing file" ); board_destroy(to_save); }
void test_board_copy_deep_squares_pointers_are_different() { board_t *original = board_init_start(); board_t *copy = board_copy_deep(original); int rank, file; for (rank = 0; rank < BOARD_SIZE; rank++) { for (file = 0; file < BOARD_SIZE; file++) { TEST_ASSERT_MESSAGE( original->spaces[rank][file] != copy->spaces[rank][file], "Expected square_t ptrs to be different after deep copy" ); } } board_destroy(original); board_destroy(copy); }