Beispiel #1
0
static void _ensure_allocator_traced_init_stderr_sets_allocation_functions( void )
{
	allocator_traced_t alloc;
	allocator_traced_init_stderr( &alloc, allocator_default( ) );
	TEST_REQUIRE( alloc.alloc.alloc_fn );
	TEST_REQUIRE( alloc.alloc.free_fn );
}
Beispiel #2
0
static void _ensure_pool_return_gracefully_handles_address_not_in_pool( void )
{
	unsigned item_not_in_pool;
	pool_t pool;
	pool_init( &pool, 4, 1, allocator_default( ) );
	pool_return( &pool, &item_not_in_pool );
	TEST_REQUIRE( pool_take( &pool ) != &item_not_in_pool );
	TEST_REQUIRE( pool_take( &pool ) == 0 );
	pool_cleanup( &pool );
}
Beispiel #3
0
static void _ensure_pool_init_with_zero_element_count_constructs_valid_empty_pool( void )
{
	allocator_counted_t alloc;
	pool_t pool;

	allocator_counted_init_default( &alloc );
	pool_init( &pool, 4, 0, allocator_counted_get( &alloc ) );
	TEST_REQUIRE( pool_is_empty( &pool ) );
	pool_cleanup( &pool );
	TEST_REQUIRE( allocator_counted_get_current_count( &alloc ) == 0 );
}
Beispiel #4
0
static void _ensure_pool_new_returns_initialised_pool( void )
{
	pool_t * pool;
	allocator_guarded_t alloc;
	allocator_guarded_init_default( &alloc );
	pool = pool_new( 128, 4, allocator_guarded_get( &alloc ) );
	TEST_REQUIRE( pool );
	TEST_REQUIRE( pool->buffer );
	TEST_REQUIRE( allocator_guarded_length( pool->buffer ) >= 128 * 4 );
	TEST_REQUIRE( pool->next );
	TEST_REQUIRE( pool->allocator == allocator_guarded_get( &alloc ) );
	pool_delete( pool );
}
Beispiel #5
0
static void _ensure_pool_is_empty_returns_non_zero_on_empty_legitimate_pool( void )
{
	pool_t pool;
	pool_init( &pool, 4, 1, allocator_default( ) );
	TEST_REQUIRE( pool_is_empty( &pool ) == 0 );
	pool_cleanup( &pool );
}
Beispiel #6
0
static void _ensure_pool_is_empty_gracefully_handles_cleaned_up_pool( void )
{
	pool_t pool;
	pool_init( &pool, 4, 1, allocator_default( ) );
	pool_cleanup( &pool );
	TEST_REQUIRE( pool_is_empty( &pool ) != 0 );
}
Beispiel #7
0
static void _ensure_allocator_traced_init_sets_correct_parent_allocator( void )
{
	allocator_traced_t alloc;
	allocator_t * parent = allocator_default( );
	allocator_traced_init( &alloc, parent, stdout );
	TEST_REQUIRE( alloc.parent == parent );
}
Beispiel #8
0
static void _ensure_pool_delete_releases_all_allocated_memory( void )
{
	pool_t * pool;
	allocator_counted_t alloc;
	allocator_counted_init_default( &alloc );
	pool = pool_new( 128, 4, allocator_counted_get( &alloc ) );
	pool_delete( pool );
	TEST_REQUIRE( allocator_counted_get_current_count( &alloc ) == 0 );
}
Beispiel #9
0
static void _ensure_allocator_traced_alloc_returns_valid_memory_for_nonempty_allocation( void )
{
	void * mem;
	allocator_traced_t alloc;
	allocator_traced_init_stdout( &alloc, allocator_default( ) );
	mem = allocator_alloc( 1024, allocator_traced_get( &alloc ) );
	TEST_REQUIRE( mem != 0 );
	allocator_free( mem, allocator_traced_get( &alloc ) );
}
Beispiel #10
0
static void _ensure_pool_take_returns_null_when_empty( void )
{
	void * item;
	pool_t pool;
	pool_init( &pool, 4, 1, allocator_default( ) );
	pool_take( &pool );
	item = pool_take( &pool );
	TEST_REQUIRE( item == 0 );
	pool_cleanup( &pool );
}
Beispiel #11
0
static void _ensure_pool_delete_gracefully_handles_cleaned_up_pool( void )
{
	pool_t * pool;
	allocator_counted_t alloc;
	allocator_counted_init_default( &alloc );
	pool = pool_new( 128, 4, allocator_counted_get( &alloc ) );
	pool_cleanup( pool );
	pool_delete( pool );
	TEST_REQUIRE( allocator_counted_get_current_count( &alloc ) == 0 );
}
Beispiel #12
0
static void _ensure_pool_take_reuses_returned_elements( void )
{
	void * item;
	pool_t pool;
	pool_init( &pool, 4, 1, allocator_default( ) );
	item = pool_take( &pool );
	pool_return( &pool, item );
	TEST_REQUIRE( pool_take( &pool ) == item );
	pool_cleanup( &pool );
}
Beispiel #13
0
static void _ensure_pool_cleanup_releases_underlying_buffer( void )
{
	allocator_counted_t alloc;
	pool_t pool;

	allocator_counted_init_default( &alloc );
	pool_init( &pool, 4, 16, allocator_counted_get( &alloc ) );
	pool_cleanup( &pool );
	TEST_REQUIRE( allocator_counted_get_current_count( &alloc ) == 0 );
}
Beispiel #14
0
static void _ensure_pool_take_returns_object_when_not_empty( void )
{
	void * item;
	pool_t pool;
	pool_init( &pool, 4, 16, allocator_default( ) );
	item = pool_take( &pool );
	TEST_REQUIRE( item );
	item = 0;
	pool_cleanup( &pool );
}
static void test__require_calls(duk_context *ctx) {
	duk_int_t rc;

	printf("top: %ld\n", (long) duk_get_top(ctx));

	TEST_REQUIRE(test__undefined);
	TEST_REQUIRE(test__null);
	TEST_REQUIRE(test__boolean);
	TEST_REQUIRE(test__number);
	TEST_REQUIRE(test__string);
	TEST_REQUIRE(test__buffer);
	TEST_REQUIRE(test__pointer);
	TEST_REQUIRE(test__c_function);
	/* No duk_require_object(), duk_require_array(), duk_require_c_lightfunc(), etc. */
}
void test_scoreboard_helper(IScoreboard *pScoreboard)
{
	bool bRes = false;
	unsigned int uVal = 0;

	// Test to make sure that scoreboard has been initialized to all 0's
	for (unsigned int u = 0; u < IScoreboard::DIGIT_COUNT; u++)
	{
		bRes = pScoreboard->pre_get_digit(uVal, (IScoreboard::WhichDigit) u);
		TEST_REQUIRE(bRes);
		TEST_CHECK_EQUAL(uVal, 0x0F);
	}

	// try a value that's out of range
	bRes = pScoreboard->pre_get_digit(uVal, IScoreboard::DIGIT_COUNT);
	TEST_CHECK(!bRes);

	// now try the convenience functions

	// CREDITS
	// out of range
	bRes = pScoreboard->update_credits(2, 0);	// try a value out of range
	TEST_CHECK(!bRes);

	// out of range 2
	bRes = pScoreboard->update_credits(0, 17);	// try a value out of range
	TEST_CHECK(!bRes);

	// in range
	bRes = pScoreboard->update_credits(1, 5);
	TEST_CHECK(bRes);
	bRes = pScoreboard->pre_get_digit(uVal, IScoreboard::CREDITS1_1);
	TEST_CHECK_EQUAL(uVal, 5);

	// PLAYER LIVES
	// out of range
	bRes = pScoreboard->update_player_lives(0, 2);
	TEST_CHECK(!bRes);

	// within range
	bRes = pScoreboard->update_player_lives(9, 1);
	TEST_CHECK(bRes);

	// make sure value is correct
	bRes = pScoreboard->pre_get_digit(uVal, IScoreboard::LIVES1);
	TEST_CHECK_EQUAL(uVal, 9);

	// test annunciator value
	bRes = pScoreboard->update_player_lives(0x0C, 1);
	TEST_CHECK(bRes);

	// PLAYER SCORE
	// out of range on digit
	bRes = pScoreboard->update_player_score(6, 0, 0);
	TEST_CHECK(!bRes);

	// out of range on player
	bRes = pScoreboard->update_player_score(5, 0, 2);
	TEST_CHECK(!bRes);

	// should pass
	bRes = pScoreboard->update_player_score(5, 9, 1);
	TEST_CHECK(bRes);

	bRes = pScoreboard->pre_get_digit(uVal, IScoreboard::PLAYER2_5);
	TEST_CHECK_EQUAL(uVal, 9);

	// make sure that player1's digit hasn't changed
	bRes = pScoreboard->pre_get_digit(uVal, IScoreboard::PLAYER1_5);
	TEST_CHECK_EQUAL(uVal, 0xF);

	// test annunciator values
	bRes = pScoreboard->update_player_score(4, 0x0C, 0);
	TEST_CHECK(bRes);

	// now test player 1's score
	bRes = pScoreboard->update_player_score(1, 6, 0);
	TEST_CHECK(bRes);

	bRes = pScoreboard->pre_get_digit(uVal, IScoreboard::PLAYER1_1);
	TEST_CHECK_EQUAL(uVal, 6);
}
Beispiel #17
0
static void _ensure_allocator_traced_alloc_returns_null_for_empty_allocation( void )
{
	allocator_traced_t alloc;
	allocator_traced_init_stdout( &alloc, allocator_default( ) );
	TEST_REQUIRE( allocator_alloc( 0, allocator_traced_get( &alloc ) ) == 0 );
}
Beispiel #18
0
static void _ensure_allocator_traced_alloc_returns_null_when_parent_allocator_null( void )
{
	allocator_traced_t alloc;
	allocator_traced_init( &alloc, 0, stdout );
	TEST_REQUIRE( allocator_alloc( 1024, allocator_traced_get( &alloc ) ) == 0 );
}
Beispiel #19
0
static void _ensure_allocator_traced_get_returns_internal_allocator( void )
{
	allocator_traced_t alloc;
	allocator_traced_init_stdout( &alloc, allocator_default( ) );
	TEST_REQUIRE( allocator_traced_get( &alloc ) == &alloc.alloc );
}
Beispiel #20
0
static void _ensure_pool_take_gracefully_handles_null_pool( void )
{
	TEST_REQUIRE( pool_take( 0 ) == 0 );
}
Beispiel #21
0
static void _ensure_allocator_traced_init_stderr_sets_parent_allocator( void )
{
	allocator_traced_t alloc;
	allocator_traced_init_stderr( &alloc, allocator_default( ) );
	TEST_REQUIRE( alloc.parent == allocator_default( ) );
}
Beispiel #22
0
static void _ensure_pool_new_returns_null_when_no_more_memory( void )
{
	pool_t * pool = pool_new( 128, 4, allocator_always_fail( ) );
	TEST_REQUIRE( pool == 0 );
}
Beispiel #23
0
static void _ensure_pool_is_empty_gracefully_handles_null_pool( void )
{
	TEST_REQUIRE( pool_is_empty( 0 ) != 0 );
}