| 1 |
|
| 2 |
|
| 3 |
#include "universal_memory_arena_test.h" |
| 4 |
#include "u8arena/universal_memory_arena.h" |
| 5 |
#include "test_fixture.h" |
| 6 |
#include "test_expect.h" |
| 7 |
#include "test_environment_assert.h" |
| 8 |
#include "test_case_result.h" |
| 9 |
#include <string.h> |
| 10 |
#include <stdint.h> |
| 11 |
#include <assert.h> |
| 12 |
|
| 13 |
static test_fixture_t * set_up(); |
| 14 |
static void tear_down( test_fixture_t *fix ); |
| 15 |
static test_case_result_t test_alloc_blocks( test_fixture_t *fix ); |
| 16 |
|
| 17 |
test_suite_t universal_memory_arena_test_get_suite(void) |
| 18 |
{ |
| 19 |
test_suite_t result; |
| 20 |
test_suite_init( &result, |
| 21 |
"universal_memory_arena_test_get_suite", |
| 22 |
TEST_CATEGORY_UNIT | TEST_CATEGORY_CONTINUOUS | TEST_CATEGORY_COVERAGE, |
| 23 |
&set_up, |
| 24 |
&tear_down |
| 25 |
); |
| 26 |
test_suite_add_test_case( &result, "test_alloc_blocks", &test_alloc_blocks ); |
| 27 |
return result; |
| 28 |
} |
| 29 |
|
| 30 |
static test_fixture_t * set_up() |
| 31 |
{ |
| 32 |
return NULL; |
| 33 |
} |
| 34 |
|
| 35 |
static void tear_down( test_fixture_t *fix ) |
| 36 |
{ |
| 37 |
} |
| 38 |
|
| 39 |
static test_case_result_t test_alloc_blocks( test_fixture_t *fix ) |
| 40 |
{ |
| 41 |
char thirty_three[33]; |
| 42 |
|
| 43 |
universal_memory_arena_t test_me; |
| 44 |
universal_memory_arena_init( &test_me, &(thirty_three[1]), sizeof(thirty_three)-1 ); |
| 45 |
|
| 46 |
void *block_1; |
| 47 |
u8_error_t err; |
| 48 |
err = universal_memory_arena_get_block( &test_me, 1, &block_1 ); |
| 49 |
TEST_EXPECT_EQUAL_INT( U8_ERROR_NONE, err ); |
| 50 |
TEST_EXPECT( NULL != block_1 ); |
| 51 |
TEST_EXPECT( &(thirty_three[1]) == block_1 ); |
| 52 |
|
| 53 |
void *block_2; |
| 54 |
err = universal_memory_arena_get_block( &test_me, 1, &block_2 ); |
| 55 |
TEST_EXPECT_EQUAL_INT( U8_ERROR_NONE, err ); |
| 56 |
TEST_EXPECT( NULL != block_2 ); |
| 57 |
TEST_EXPECT( &(thirty_three[1+sizeof(int)]) == block_2 ); |
| 58 |
|
| 59 |
universal_memory_arena_reset( &test_me ); |
| 60 |
|
| 61 |
void *block_3; |
| 62 |
err = universal_memory_arena_get_block( &test_me, 33-sizeof(int), &block_3 ); |
| 63 |
TEST_EXPECT_EQUAL_INT( U8_ERROR_NONE, err ); |
| 64 |
TEST_EXPECT( NULL != block_3 ); |
| 65 |
TEST_EXPECT( &(thirty_three[1]) == block_3 ); |
| 66 |
|
| 67 |
void *block_4; |
| 68 |
err = universal_memory_arena_get_block( &test_me, sizeof(int), &block_4 ); |
| 69 |
TEST_EXPECT_EQUAL_INT( U8_ERROR_ARRAY_BUFFER_EXCEEDED, err ); |
| 70 |
TEST_EXPECT( NULL == block_4 ); |
| 71 |
|
| 72 |
universal_memory_arena_destroy( &test_me ); |
| 73 |
return TEST_CASE_RESULT_OK; |
| 74 |
} |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|